Menu

Lost INSERTs? Help, please

Help
Anonymous
2002-06-04
2012-09-19
  • Anonymous

    Anonymous - 2002-06-04

    Hello!

    I'm a newby in Python, sorry for lame-question :)

    Look (pseudo-code):

    crs=db.cursor()
    f=open("file")

    while (some condition):
        rd=crs.execute( """INSERT INTO db
             VALUES (%s...)""", data...)
        print >> f, "%format" % data
        . . .

    About 100 INSERTs executed every time this script runs.  But when I compare data in MySQL table and plain file (written with printf >> f), I see that not all information stored in MySQL, i.e. some INSERTs are not executed.

    How can I check result of cursor.execute()?  According to Python DB API 2.0 returning value is not defined :((

     
    • Andy Dustman

      Andy Dustman - 2002-07-01

      While the DB-API 2.0 doesn't define the return value from execute(), DB_API 1.0 defined it as the number of rows affected. MySQLdb also returns this.

      Another (better) way to find this out is to look at crs.rowcount, which is a DB-API 2.0 extension.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.