Python-sqlite3 placeholder

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.