unhappy_mage
[H]ard|DCer of the Month - October 2005
- Joined
- Jun 29, 2004
- Messages
- 11,455
I'm writing a Python program that interfaces with a MySQL database using the standard MySQLdb interface. I construct a list of tuples like this:
and then pass it to acursor.executemany(), like so:
and I get an error message like this:
If I remove the "ON DUPLICATE KEY" clause, and take the last value out of "thedata", it works fine. Is something wrong with my SQL query? Any ideas what's wrong?
PS: Here's the table definition:
and if I substitute the values manually it works fine.
Code:
[(1L, 115L, 50, 50), (2L, 115L, 44, 44), (3L, 115L, 85, 85), (4L, 115L, 46, 46), (5L, 115L, 81, 81)]
Code:
c.executemany("""INSERT INTO r1r (candidate, vid, score) VALUES
(%s, %s, %s) ON DUPLICATE KEY UPDATE score = %s""", thedata)
Code:
Traceback (most recent call last):
File "index.cgi", line 60, in <module>
oldpage.processData(vcode_form)
File "../vote/Range.py", line 128, in processData
c.executemany("""INSERT INTO r1r (candidate, vid, score) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE score = %s""", thedata)
File "/usr/site/lib/python2.5/site-packages/MySQLdb/cursors.py", line 212, in executemany
self.errorhandler(self, TypeError, msg)
File "/usr/site/lib/python2.5/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
TypeError: not all arguments converted during string formatting
If I remove the "ON DUPLICATE KEY" clause, and take the last value out of "thedata", it works fine. Is something wrong with my SQL query? Any ideas what's wrong?
PS: Here's the table definition:
Code:
CREATE TABLE r1r (
vid INT REFERENCES vcodes(id),
cid INT REFERENCES candidates(id),
score NUMERIC(2),
PRIMARY KEY (vid, cid)
) Engine=InnoDB;