posted 16 years ago
It's common to put a timestamp for each update on the database. The user gets the timestamp (maybe in a hidden field) when they retrieve the record. If it doesn't match the database when they want to update the record, that means somebody else beat them to the update. The system says something like "Another user has changed this record. Please refresh it and see what it looks like." The user usually has to discard his changes, get the fresh record and start over. That's "optimistic" locking, meaning we don't think bad things will happen very often and we can stand the pain if they do. It's also called "first update wins" some times.
For "pessimistic" locking where we think this kind of problem is frequent enough that we want to avoid it, we might update the record with a "locked by userid" column when a user retrieves it for update. Then nobody else can retrieve it for update until he does an update or unlock to unset the "locked by" column. You have to make the user declare his intention to update. And the user might turn off the PC and walk away, leaving the record locked forever.
Any of those choices sound good?
[ August 20, 2007: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi