Skip to content
Advertisement

Sqlite3 – Update table using Python code – syntax error near %s

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.

Advertisement

Answer

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))
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement