简体   繁体   English

锁定表中记录的正确/更好的方法是什么?

[英]What should be the correct/better approach for locking a record in table?

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. 我提供了一些用于搜索,查看和编辑记录的GUI。 Now if the user is trying to edit a record perform some particular action, which takes say 1 minute to process. 现在,如果用户正在尝试 编辑记录,请 执行某些特定操作,这需要1分钟的时间来处理。 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? 还有什么其他方法可以做到这一点?

SELECT FOR UPDATE is the way. SELECT FOR UPDATE是方法。 We get this kinda behaviour by using this. 通过使用此行为,我们可以得到这种行为。

As Vinegar said , SELECT FOR UPDATE - accept his answer, not mine :) 正如Vinegar所说SELECT FOR UPDATE -接受他的回答,而不是我的:)

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. 根据您的应用程序,您可以打开一个单独的窗口,用户在该窗口中进行修改,然后确认/取消,因此您可以执行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. 并确保另一个试图更改同一行的用户不会遇到冻结的应用程序,而必须等待锁定被释放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM