Subject Re: [firebird-support] get_lock / release_lock
Author Helen Borrie
At 11:18 PM 31/07/2008, Kjell wrote:
>Martijn Tonies wrote:
>
>> > Can't they put in a where condition in the update double checking that
>> > the locked_by is null?
>>
>> Sure, but what if it was unlocked already by a user, then it will
>> overwrite the changes without even knowing there were changes.
>
>I expect Steve meant:
>
>1. User 1: update <table> set LockedByUser = 'Me' where RecId =
>something and LockedByUser is null, then check that 1 rec was updated.
>If not, then someone already had the lock.
>
>I expect this would work...?

Actually
update <table> set Recid=Recid where Recid=Recid will do fine. It's pointless adding a LockedBy field to all your records, since nobody can read it except when the record is NOT locked - and then (by your logic) it would always be null. ;-)

K.I.S.S. There's nothing at all wrong with pessimistically locking one record and keeping it "in transaction" as long as you need. Just take care that your transaction is not involving whole bunches of other records that you're NOT interested in.

./heLen