Help - mysqldb claims to update database but does not.
I've written a Python file transfer program and it keeps track of the files using mysqldb. Once a file is processed on the receiving end the database is updated (change the enum 'status' from 'transmitting' to 'received'). Almost always this works fine. However, sometimes the LAST file in the transfer line will NOT get its status updated, even though at the time the function claims it was updated.
Here's a point-form outline of the program.
-get list of files
-process each one
-update database for each file once processed
-close
here's code
class records:
def __init__(self):
self.conn = connect (db=dbname, host=hst,user=username, passwd=password)
self.cursor = self.conn.cursor()
This connects it to the database.
def UpdateRecord(self, equip, file, status):
timenow = strftime("%Y-%m-%d %H:%M:%S", localtime())
transaction = '''UPDATE transactions SET status='%s', date_reassembled = '%s' WHERE filename='%s' AND equipment_name = '%s' ''' %(status, timenow, file, equip)
self.cursor.execute (transaction)
self.conn.commit()
newtrans = '''SELECT status FROM transactions WHERE filename = '%s' AND equipment_name = '%s' ''' %(file, equip)
self.cursor.execute(newtrans)
newstat = self.cursor.fetchone()[0]
print status, newstat, file
return 1
This is a function run in a loop, once for each file. You see it updates the database and then checks the status that it just updated. When it checks the status here it is ALWAYS 'received.' However, sometimes I go back and check the database and the status did NOT change. This ONLY happens for the last file in a run.
def Close(self):
self.cursor.close()
self.conn.commit()
self.conn.close()
Here's the function I call to close it.
Any help would be GREAT thanks!!!!