2012-03-24 34 views
12

Đây là mã Python của tôi -Sqlite3 - Cập nhật bảng sử dụng mã Python - Lỗi cú pháp gần% 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)) 

Đây là câu lệnh SQL tôi cố gắng trong quản lý SQLite3 (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) 

Lỗi tôi nhận được là -

sqlite3.OperationalError: near "%": syntax error 

Tôi đã thử nhiều tìm kiếm trên web bao gồm SO, hướng dẫn và tự gỡ rối nhưng điều này lỗi không biến mất. Chính xác thì tôi đang làm sai ở đây.

Trả lời

24

Tôi tin rằng việc triển khai SQLite của Python sử dụng ? trình giữ chỗ, không giống như %s của MySQLdb. 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)) 
+0

Cảm ơn! Điều đó hoạt động rất tốt. – Sumod

Các vấn đề liên quan