Here is how to use Python’s DB-API parameter substitution with a single value.
1234567891011
importsqlite3defmain():conn=sqlite3.connect('data.db')cursor=conn.cursor()# blows up because of single quotes around question markcursor.execute("update prefs set value = '?' where key = 'testing'",('123',))# blows up because missing comma after single value tuplecursor.execute("update prefs set value = ? where key = 'testing'",('123'))# this workscursor.execute("update prefs set value = ? where key = 'testing'",('123',))
It’s subtle, but if you put single quotes around the question mark or forget the comma after the single value tuple, you’ll get a sqlite3.ProgrammingError exception.