MySQL Forums
Forum List  »  Connector/Python

Help - mysqldb claims to update database but does not.
Posted by: Dainis Nams
Date: August 17, 2007 03:17PM

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

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)
newtrans = '''SELECT status FROM transactions WHERE filename = '%s' AND equipment_name = '%s' ''' %(file, equip)
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):

Here's the function I call to close it.

Any help would be GREAT thanks!!!!

Options: ReplyQuote

Written By
Help - mysqldb claims to update database but does not.
August 17, 2007 03:17PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.