Issue
I am new to database management and I want to update my SQLite database when two conditions match, but my Python code below is returning the error:
try:
cursor.execute("UPDATE mytable SET field1 = ?, field2 = ?, field3 = ?, field4 = ? WHERE field5 = ? AND field6 = ?;", var1, var2, var3, var4, var5, var6)
except Exception as e:
Logging.Error("Exception "+str(e))
Error:
Exception execute expected at most 2 arguments, got 7
What am I doing wrong?
Thank you
Solution
The execute
functions takes 2 parameters: A string (the SQL statement) and a tuple of values. What you pass in is a string and 6 other values. You need to put the last 6 values in a tuple:
cursor.execute(
"UPDATE mytable SET field1 = ?, field2 = ?, field3 = ?, field4 = ?"
" WHERE field5 = ? AND field6 = ?;",
(var1, var2, var3, var4, var5, var6),
)
Answered By - Hai Vu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.