What's going wrong
MySQLdb 1.2.4b4 1.2.5, unubtu answer, , cursors.py. , , , , , , .
, , VALUES ( ... ) INSERT . , executemany , . I.e., , :
INSERT INTO table
(foo, bar, ...)
VALUES
(%s, %s, ...);
, :
INSERT INTO table
(foo, bar, ...)
VALUES
(1, 2, ...),
(3, 4, ...),
(5, 6, ...),
...;
, , , executemany , , VALUES. , :
INSERT INTO table
(foo, bar, ...)
VALUES
(%s, %s, ...)
ON DUPLICATE KEY UPDATE baz=%s;
:
INSERT INTO table
(foo, bar, ...)
VALUES
(1, 2, ...),
(3, 4, ...),
(5, 6, ...),
...
ON DUPLICATE KEY UPDATE baz=%s;
, MySQLdb . VALUES ( ... ), MySQLdb (%s, %s, ...), , UPDATE.
VALUES executemany, TypeError, . , INSERT ... ON DUPLICATE UPDATE VALUES, UPDATE %s placeholder. MySQL.
, MySQLdb 1.2.3c1 . , , , , . , executemany , , execute .
, 1.2.3c1, . , .
, unubtu Q & A, , , .
, VALUES() UPDATE. , , ( MySQL docs).
, :
dData = [[u'Daniel', u'00-50-56-C0-00-12', u'Daniel']]
sql = """
INSERT INTO app_network_white_black_list
(biz_id, shop_id, type, mac_phone, remarks, create_time)
VALUES
(%s, %s, %s, %s, %s, NOW())
ON DUPLICATE KEY UPDATE
type=VALUES(type), remarks=VALUES(remarks), create_time=VALUES(create_time);
"""
cur.executemany(sql, ((bsid, shop_id, dType, mac, rem) for mac, rem in dData))
, UPDATE , MySQLdb insert .
:
executemany; .- SQL Python, ; , .
- , ? , .
- ,
NOW(). , CURRENT_TIMESTAMP DEFAULT . . , , . UPDATE - , (t212) UPDATE VALUES - 'll execute executemany.