The sqlite3
module supports the kinds of placeholders:question marks (Qmark style) and named placeholders (named Style).
execute
(SQL[, parameters])
The Sqlite3 module supports two placeholders:? placeholders and well-known placeholder characters.
But in use? placeholder, be aware that when you pass in a parameter and the argument is a string, you convert the string to a list or tuple.
The verification process is as follows: Look closely at the notes and run
1 #as a list2 #as the placeholder represented in this way, you need to consider it as a parameter to receive list3sql ="UPDATE a SET para=? WHERE input_id=1"4 #c.execute (SQL, ["Hello"])5 #c.execute (SQL, [string_new])6 #c.execute (sql, "Hello")7 ##sqlite3. Programmingerror:incorrect number of bindings supplied. The current statement uses 0, and there is 5 supplied.8 ##从这个报错信息可以看出: The incoming placeholder argument as a list, current statement only uses 0-position elements, but provides 5 elements, and only one placeholder, just insert an element, and many other elements do not know how to deal with the error 9C.execute (SQL, ("Hello",))Ten One ##作为元组 A #sql = "UPDATE a SET para= (?) WHERE input_id=1 " - ##c. Execute (SQL, ("Hello1",)) - ##c. Execute (SQL, (String_new,)) the ##c. Execute (SQL, ["Hello"]) - #c.execute (SQL, [string_new]) - - #? Placeholder Summary + #when a string is passed in execute (sql,parameters), the string cannot be passed directly as a parameter, to be converted to a list or tuple, otherwise sqlite3 will use each character in the string as a parameter - + #Well -known placeholders A #sql = "UPDATE a SET para=:str WHERE input_id=1" at #c.execute (SQL, {"str": string_new})
Python-sqlite3 placeholder