ODBC bug

Discussion in 'Python' started by Elbert Lev, Aug 5, 2004.

  1. Elbert Lev

    Elbert Lev Guest

    # 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.
    Elbert Lev, Aug 5, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    Re: BUG? OR NOT A BUG?

    John, Sep 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    549
  2. Joe

    mx.ODBC 2.0.7 bug?

    Joe, Mar 3, 2005, in forum: Python
    Replies:
    3
    Views:
    346
  3. jc

    [bug] DBD::ODBC

    jc, Dec 28, 2004, in forum: Ruby
    Replies:
    1
    Views:
    92
    Michael Neumann
    Dec 31, 2004
  4. Wes Gamble
    Replies:
    1
    Views:
    159
    Gerardo Santana Gómez Garrido
    Apr 5, 2006
  5. David Bennett
    Replies:
    0
    Views:
    123
    David Bennett
    Jan 10, 2009
Loading...

Share This Page