MySQL help

supercomputer at gmail.com supercomputer at gmail.com
Mon Aug 1 14:58:37 EDT 2005


So i'm writing this program to check if a row exists in a table.  If it
doesn't it inserts it if it does it will update that row with the
current info.

Well it sorta works but not fully.  It goes through and executes the
correct querries but when it comes to determining if the row exists it
doesn't get back a result.  Yet if I mannually enter it into the mysql
console I get a result.  This only happens when my if statement to
determine if there was a result returned is not commented out.  If it
is commented out it returns that the row exists.  Any help would be
great.

Thanks.

here is a snippet of the code assume a cursor has been defined, import
MySQL has occured and the connection have all taken place.

"a" is the table the query is taking place on.
name is nodeXXX and b is either a 0-3 number.


        check="SELECT * FROM "+a+" WHERE nodeid='"+name+"' AND
lid='"+b+"'"
        result = cursor.execute(check)
        numrows = int(cursor.rowcount)
        print "numrows:", numrows
        cursor = db.cursor()
        if numrows == 0:
                output="INSERT INTO  "+a+" SET nodeid='"+name+"',
lid='"+b+space+", ".join(v)
                cursor.execute(output)
                db.commit()
                print "Insert"
                result=''
        else:
                output="UPDATE "+a+" SET nodeid='"+name+"',
lid='"+b+space+", ".join(v)
                cursor.execute(output)
                result=''
                db.commit()
                print "Updating"

        id.append(int(db.insert_id()))


Thanks,




More information about the Python-list mailing list