Murray,

I also have records that need to be 'checked out' for some time and
your solution seems simple and elegant. So much so I may steal it.

I use one sequence for every primary key in the database so a table
named "lock" with

key primary key
timestamp timestamp
userid

should do it. UserId lets me know who has it.

to see if a record is locked and get lock key

select count(*) as locked, key, timestamp from lock where key = ? and
timestamp less than 20 minutes old group by key, timestamp

1 is locked 0 unlocked timestamp is the key to lock the recored

to lock a record

if key == null
insert into lock values ( key, now, userid)
else
update lock set timestamp = now, userid = ? where key = ? and timestamp = ?

if you update 1 row you've got it otherwise someone else does

to unlock

update lock set timestamp = null where key = ? and timestamp = ?

if you don't get 1 row updated something bad happened

Seems easy. Records are locked a max of 20 minutes and no races I can see.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to