Roy Holzem
Roy Holzem

Reputation: 870

MySQL update does not update

I have a problem that the update mysql part is sometimes not updating a value and it appears to be random I can't find the cause for it. it takes MYSQL entries with key value "TRANSFER" and schould set the same key value to "EXECUTED". Sometimes iI have 20 processes that work fine, sometimes I have 10 processes and half didnt get updated.

try:
    db = MySQLdb.connect(
        host='localhost',
        user='root',
        passwd='pw',
        db='db',
    )
    db.autocommit(True)

except Exception as e:
    sys.exit("Can't connect to db")

cur = db.cursor()
setstatus = "EXECUTED"
for fn in os.listdir('.'):
     if os.path.isfile(fn):
        UUID = fn.replace(".ac", "")
        try:
            cur.execute("""
                UPDATE olorequest
                SET status = %s
                WHERE UUID = %s
            """, (setstatus, UUID))
        except Exception as e:
            raise IOError(e)
        ftp.storlines('STOR ' + fn, open(fn, 'r+'))
        try:
            shutil.move(fn, executed_ac_files)
        except Exception as e:
            shutil.move(fn, error_files)
            raise IOError(e)
        time.sleep(5)

Upvotes: 0

Views: 70

Answers (1)

St3an
St3an

Reputation: 806

Basically the reason why a row is not updated in an UPDATE request is that the predicate of the WHERE clause is not met. Additionnaly, as you perform this action through a program, also check its logic and its reliability.

Upvotes: 1

Related Questions