executemany & UPDATE (MySQL & Python)

Gerhard Häring gerhard at bigfoot.de
Fri Jun 14 18:54:43 CEST 2002


In article <mailman.1024071438.5095.python-list at python.org>, Nick Arnett wrote:
> Can anyone confirm that it is *not* possible to pass a list to the Python
> MySQLdb module in UPDATE operations?

executemany accepts a sequence of sequences, like:

self.dbh.execute("UPDATE Foo SET bla=%s, blorg=%s WHERE snork=%s",
    [(1,2,3), (4,5,6)])

> Doing the latter with a loop in Python is much slower than I'd expect that
> doing it with a list would be.

For database modules that don't support prepared statements, the db module
implements executemany with multiple calls to execute, anyway.

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))



More information about the Python-list mailing list