15

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.

2 Answers 2

31

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))
Sign up to request clarification or add additional context in comments.

Comments

0

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))

1 Comment

it is possible, but it is very dangerous and strongly advised against it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.