I was confronted executemany problem with “ON DUPLICATE KEY” same as [1556443]. (http://sourceforge.net/tracker/index.php?func=detail&aid=1556443&group_id=22307&atid=374932)
I make a patch for this problem. And fix minor character encoding bug.
I fix my patch around ln.193 (remove query type check), and remake it based on revision 466.
Can you show me an example query string?
if use "ON DUPLICATE KEY..." clause and "VALUES()"
INSERT INTO foo (bar) VALUES (%s) ON DUPLICATE UPDATE bar=VALUES(bar)
regex '\svalues\s*((.+))' matches " VALUES (%s) ON DUPLICATE UPDATE bar=VALUES(bar)" and executemany() repeats this string.
File Added: cursors.py.patch
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yeah, I told you trunk, and that was wrong; should have been branch/MySQLdb-1.2. Sorry.
What bothers me about this is what if you have parameters in the ON DUPLICATE section. There are two possibilities:
1) If there is anything after the initial VALUES (...) clause, do multiple single-row inserts and not a single multi-row insert.
2) Forbid parameters in the ON DUPLICATE UPDATE section in executemany().
r468 works fine on my platforms. (WinXP & FreeBSD 6.2 w/ MySQL 5.0.33), thanks!
Hopefully. please implement to "q = [ qv % db.literal(a) for a in args ]" instead of
qargs = db.literal(args)
q = [ qv % a for a in qargs ]
because it can use iterator to args.
According to examples here, it looks like the second interpretation may be
better. I suspect you think the same.
yes, i think same. 2nd case is better than 1st case.
1st case is out of spec of DB-API.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
based on revision 465 /trunk/MySQLdb/MySQLdb/cursors.py
Logged In: YES
user_id=71372
Originator: NO
Try your patch again off the current SVN trunk. I'm not convinced your regex is correct either. Can you show me an example query string?
Logged In: YES
user_id=1714212
Originator: YES
I fix my patch around ln.193 (remove query type check), and remake it based on revision 466.
regex '\svalues\s*((.+))' matches " VALUES (%s) ON DUPLICATE UPDATE bar=VALUES(bar)" and executemany() repeats this string.
File Added: cursors.py.patch
Logged In: YES
user_id=71372
Originator: NO
Yeah, I told you trunk, and that was wrong; should have been branch/MySQLdb-1.2. Sorry.
What bothers me about this is what if you have parameters in the ON DUPLICATE section. There are two possibilities:
1) If there is anything after the initial VALUES (...) clause, do multiple single-row inserts and not a single multi-row insert.
2) Forbid parameters in the ON DUPLICATE UPDATE section in executemany().
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
According to examples here, it looks like the second interpretation may be better. I suspect you think the same.
Logged In: YES
user_id=71372
Originator: NO
I've commited a fix in r468; please test and report back.
Logged In: YES
user_id=1714212
Originator: YES
r468 works fine on my platforms. (WinXP & FreeBSD 6.2 w/ MySQL 5.0.33), thanks!
Hopefully. please implement to "q = [ qv % db.literal(a) for a in args ]" instead of
qargs = db.literal(args)
q = [ qv % a for a in qargs ]
because it can use iterator to
args.yes, i think same. 2nd case is better than 1st case.
1st case is out of spec of DB-API.
Logged In: YES
user_id=71372
Originator: NO
Fixed in r475
Logged In: YES
user_id=1714212
Originator: YES
Thanks adustman!