Reputation: 3846
This is my Python code -
cursor.execute("""UPDATE tasks SET task_owner=%s,task_remaining_hours=%s, task_impediments=%s,task_notes=%s WHERE task_id=%s""", (new_task_owner,new_task_remaining_hours,new_task_impediments,
new_task_notes,task_id))
This is the SQL statement I try in SQLite3 manager (Firefox extension)
UPDATE tasks SET task_owner=%s,task_remaining_hours=%d,task_impediments=%s,task_notes=%s WHERE task_id=%d,("sumod",10,"none","test",1)
The error I get is -
sqlite3.OperationalError: near "%": syntax error
I have tried many web searches including SO, tutorials and self-troubleshooting, but this error does not go away. What exactly I am doing wrong here.
Upvotes: 15
Views: 34226
Reputation: 5075
It is also possible to use %s:
cursor.execute("UPDATE tasks SET task_owner='%s', task_remaining_hours='%s',
task_impediments = '%s', task_notes = '%s' WHERE task_id= '%s' " %
(new_task_owner,new_task_remaining_hours,new_task_impediments,new_task_notes,task_id))
Upvotes: 0
Reputation: 270607
I believe Python's SQLite implementation uses ?
placeholders, unlike MySQLdb's %s
. Review the documentation.
cursor.execute("""UPDATE tasks SET task_owner = ? ,task_remaining_hours = ?,task_impediments = ?,task_notes = ? WHERE task_id= ? """,
(new_task_owner,new_task_remaining_hours,new_task_impediments,new_task_notes,task_id))
Upvotes: 31