Last time tested on: August 2018
- Python 3.6.1
- Python 2.7.10
I'm not sure if it was the case back when the original question was posted, but as of today:
db.execute("INSERT INTO present VALUES('test', ?, 9)", "This is a test!")
throws
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 15 supplied.
when ran.
Because execute()
accepts sql
— which is sql query to execute, and parameters
— which is iterable, containing query parameters (currently this is true for both Python 2 and Python 3. As string is iterable — it treats it accordingly.
Docs clearly state, that Python None
type correspond to SQLite NULL
type.
So, correct way to do it would be:
db.execute("INSERT INTO present VALUES('test2', :null, 10)", {'null':None})
#or
db.execute("INSERT INTO present VALUES('test2', ?, 10)", (None,))