Friday, February 24, 2012

How do I do the concept of record checkouts?

Without using locks and with only using pure ANSI-92 SQL, I need to
pull off the concept of record checkouts. Imagine a table full of work
orders. I can only let someone use the web app to edit the work order
for 15 minutes. If someone has the work order checked out, and someone
else wants to edit it, it should prevent this unless 15 minutes have
passed. If 15 minutes have passed, then it should set this field to
null and let the other user edit the record. The way I have decided to
implement it is by storing 2 things -- the minute that the record was
checked out for editing, and the username of the user conducting the
task. I'm thinking in terms of an UPDATE statement with a special WHERE
clause that can clear any records where the checked out minute is older
than 15 minutes. This is not as simple as it first seems because you
have to look at what happens when the minute hand wraps around the
clock hour.
That is, unless you have an easier way to do the whole business.Instead of storing minutes, store the smalldatetime that the row was locked.
You can then use datediff(minute,LockedTime,getdate()) which will return the
number of minutes elapsed.
"Alfred" <99m@.myway.com> wrote in message
news:1139943161.167707.100660@.g43g2000cwa.googlegroups.com...
> Without using locks and with only using pure ANSI-92 SQL, I need to
> pull off the concept of record checkouts. Imagine a table full of work
> orders. I can only let someone use the web app to edit the work order
> for 15 minutes. If someone has the work order checked out, and someone
> else wants to edit it, it should prevent this unless 15 minutes have
> passed. If 15 minutes have passed, then it should set this field to
> null and let the other user edit the record. The way I have decided to
> implement it is by storing 2 things -- the minute that the record was
> checked out for editing, and the username of the user conducting the
> task. I'm thinking in terms of an UPDATE statement with a special WHERE
> clause that can clear any records where the checked out minute is older
> than 15 minutes. This is not as simple as it first seems because you
> have to look at what happens when the minute hand wraps around the
> clock hour.
> That is, unless you have an easier way to do the whole business.
>

No comments:

Post a Comment