这是我的Python代码-
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))
这是我在SQLite3管理器(火狐扩展)中尝试的SQL语句。
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)
我得到的错误是-
sqlite3.OperationalError: near "%": syntax error
我已经尝试了许多网络搜索,包括SO、教程和自我故障排除,但这个错误并没有消失。我到底做错了什么。
发布于 2012-03-24 10:46:38
我认为Python的SQLite实现使用了?
占位符,而不像MySQLdb的%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))
发布于 2019-05-10 08:37:00
也可以使用%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))
https://stackoverflow.com/questions/9848697
复制相似问题