Subject | How to "lock" a record |
---|---|
Author | Chad Z. Hower aka Kudzu |
Post date | 2004-11-03T22:22:30Z |
I have a table which stores "Items". In most cases (but not all, its
determined by a "type" flag in each row) each row can only be "used" once.
Once I use it, I assign it to a field in anothoer table, lets call it
"user". I cannot put a constraint on the user table as for some rows they
can be used multiple times.
How is the best way to "reserve" a row in the items table? I would like to
do this in a non FB specfic manner if possible.
My idea is this:
Select min(serial) where used = false
Update Item Set Used = true where serial=x and used=false
If the execute count returns 1- I know I have it. If it returns 0, someone
else got it before me. Is this ok to count on in FB (And SQL DBs in
general?)
determined by a "type" flag in each row) each row can only be "used" once.
Once I use it, I assign it to a field in anothoer table, lets call it
"user". I cannot put a constraint on the user table as for some rows they
can be used multiple times.
How is the best way to "reserve" a row in the items table? I would like to
do this in a non FB specfic manner if possible.
My idea is this:
Select min(serial) where used = false
Update Item Set Used = true where serial=x and used=false
If the execute count returns 1- I know I have it. If it returns 0, someone
else got it before me. Is this ok to count on in FB (And SQL DBs in
general?)