ODBC bug

E

Elbert Lev

# W2K MSSQL-2000

import dbi, odbc

myconn = odbc.odbc('DSN=db; UID=sa; PWD=')
mycursor = myconn.cursor()

mycursor.execute("SELECT ID, PWD FROM TABLE")
rs = mycursor.fetchall()
for ID, PWD in rs:
upd = "UPDATE TABLE SET PWD = \'%s\' WHERE ID = %u" % \
(encode(PWD), ID)
mycursor.execute(upd)
myconn.commit()

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

To speedup I decided to concatenate upd strings and execute it:

mycursor.execute("SELECT ID, PWD FROM TABLE")
rs = mycursor.fetchall()
updlst = []
for ID, PASSWORD in rs:
upd = "UPDATE TABLE SET PWD = \'%s\' WHERE ID = %u" % \
(encode(PWD), ID)
updlst.append(upd)
upd = " ".join(updlst)
mycursor.execute(upd)
myconn.commit()

#This one works much faster, but if the joined upd string is longer
then about 40K ONLY THE FIRST 40K are actually executed. The rest is
IGNORED. No exceptions and execute() returnes 1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top