Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#321 Using MySQL function in insert values with executemany fails

MySQLdb-1.2
closed
Andy Dustman
MySQLdb (285)
5
2012-09-19
2012-04-02
Fred
No

When I use the executemany function with a mysql function in the values, the call fails. For example:

c.executemany("""
INSERT INTO invoice_item (invoice_id, sku_id, invoice_item_qty, invoice_item_added_date)
VALUES (%s, %s, %s, NOW() )""",
(stmt))
db.commit()
where stmt is a list of lists with 3 values in each sub-list (e.g, [(26L, 1L, 1), (26L, 7L, 7), (26L, 10L, 6600)] ).

The relevant traceback is as follows
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 218, in executemany
r = self._query('\n'.join([query[:p], ',\n'.join(q), query[e:]]))
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 312, in _query
rowcount = self._do_query(q)
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 276, in _do_query
db.query(q)
_mysql_exceptions.ProgrammingError: (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 6")

When I replace NOW() with CURRENT_TIMESTAMP, everything works as expected.

Note, I have used NOW() successfully with the execute function:
c.execute( """
INSERT into invoice (cust_id, invoice_amt_due, invoice_created_date)
VALUES (%s, %s, NOW())""",
(cust_id, running_total))

Using ubuntu 10.04LTS, mysqldb 1.2.2 with python 2.6.

Discussion

  • Andy Dustman
    Andy Dustman
    2012-09-07

    I added a test case for this (test_bug_3514287) and it passes in post-1.2.3. Committed to revision 657, will be in version 1.2.4.