Reputation: 965
Im trying to make a MySQL update statement with python, but I keep getting the "You have an error in your SQL syntax" error, while the statement totally works when I try the query in MySQL workbench. I have no idea what I am doing wrong.
Code
self.cur.execute('UPDATE UserAction SET count=%s WHERE user=%s AND action=%s)',
(count, id, action))
Full error
1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1"
Upvotes: 1
Views: 88
Reputation: 4583
Looks like this has been answered here: https://stackoverflow.com/a/2741646/1781207.
self.cur.execute('UPDATE UserAction SET count=%s WHERE user=%s AND action=\'%s\'', (count, id, action))
Looks like you have an extra ")" inside your SQL statement
Upvotes: 3
Reputation: 708
A couple of things are causing problems here:
First, you need single quotes around all %s formatters. I'm not familiar with python, but usually you have to use an escape sequence like \' to add quotes.
Second, you seem to have a misplaced close-parenthesis at the end of your statement. Good luck!
Upvotes: 1