ODBC bug

Jimmy Retzlaff jimmy at retzlaff.com
Sun Aug 8 22:09:40 EDT 2004


Elbert Lev wrote:
> for ID, PWD in rs:
>     upd = "UPDATE TABLE SET PWD = \'%s\' WHERE ID = %u" % \
>                     (encode(PWD), ID)
>     mycursor.execute(upd)
...

> #This script updates (encodes) passwords in the database, 
> #but does this rather slowly if the the recordset contains 2000
> records.

Try replacing the above lines with something like this (untested, but
should be close):

upd = []
for ID, PWD in rs:
    upd.append((encode(PWD), ID))

mycursor.execute("UPDATE TABLE SET PWD = ? WHERE ID = ?", upd)


This should perform pretty well for a few thousand records. For hundreds
of thousands or millions of records you might want to write the contents
of upd to a file and do a bulk insert to a temp table, then do an update
with a join (if you'll be doing such an update often enough to justify
the programming time).

Jimmy




More information about the Python-list mailing list