In an application already deployed, using SQLObject, I need to update a value only if the previous value match a certain value.
The equivalent sql could be:
UPDATE jobs SET status='150' WHERE id=1234 AND status='100'
I need this because we have many instances of a daemon on different servers (not knowing each others) which may want to take jobs and update the db to mark the job as "taken".
I want to prevent "double updates" from two nodes setting the same value.
It would be nice if I can get as a result the number of affected rows. With a result of 0 it would permit to say "job was already taken between fetch and update"...
The actual part of code doing the update looks like:
def __setattr__(self, name, value):
"""Override setattr to log build status changes"""
[...]
sqlobject.SQLObject.__setattr__(self, name, value)