Menu

#38 fix cursor.executemany "ON DUPLICATE MANY" problem

MySQLdb
closed
MySQLdb (53)
5
2012-09-19
2007-02-09
Shin Adachi
No

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.

Discussion

  • Shin Adachi

    Shin Adachi - 2007-02-09

    based on revision 465 /trunk/MySQLdb/MySQLdb/cursors.py

     
  • Andy Dustman

    Andy Dustman - 2007-02-10

    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?

     
  • Shin Adachi

    Shin Adachi - 2007-02-10
     
  • Shin Adachi

    Shin Adachi - 2007-02-10

    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.

    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

     
  • Andy Dustman

    Andy Dustman - 2007-02-10

    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.

     
  • Andy Dustman

    Andy Dustman - 2007-02-10

    Logged In: YES
    user_id=71372
    Originator: NO

    I've commited a fix in r468; please test and report back.

     
  • Shin Adachi

    Shin Adachi - 2007-02-11

    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.

    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.

     
  • Andy Dustman

    Andy Dustman - 2007-02-11

    Logged In: YES
    user_id=71372
    Originator: NO

    Fixed in r475

     
  • Shin Adachi

    Shin Adachi - 2007-02-11

    Logged In: YES
    user_id=1714212
    Originator: YES

    Thanks adustman!

     

Log in to post a comment.