views:

52

answers:

2

Actually, the problem is like this:-
i am having a table, say Payments. I have provided few GUI for searching, viewing and editing the record. Now if the user is trying to edit a record perform some particular action, which takes say 1 minute to process. Then another user should not be able to perform that particular operation on the same record.

Traditional approach of doing this is, have a column in the table, say _isLocked_. and whenever user is performing that action it should change the value of said column to, say, true. Once the process is completed it should reset the value of the column. Also, just before someone tries to perform the action, it should check the value of the column and notifies the user if the record is locked.

What other approached are there to do the same?

+2  A: 

SELECT FOR UPDATE is the way. We get this kinda behaviour by using this.

Adeel Ansari
+2  A: 

As Vinegar said, SELECT FOR UPDATE - accept his answer, not mine :)

Make sure to know when the user really wants to edit a row, and when he/she is done. Depending on your application, you could open a separate window where user does the modification and then confirms/cancels, so you can do your COMMIT/ROLLBACK.

And make sure that another user who attempts to change the same row will not face a frozen application and have to wait for the lock to be released.

Peter Lang