multi-user application record locking – best method? Ask

Questionsmulti-user application record locking – best method? Ask
Christian asked 7 years ago

Hi,

I am building a web-app that allows several users to perform read and write-operations on the same table. What is the smartest way of preventing that a record in the table is simultaneously edited by different users (ie. changes from user A get overwritten by user B without any of users noticing the conflicting behaviour)?

Thanks!
C

4 Answers
Abu Ghufran answered 7 years ago

Hello,

I have not tested this scenario before.
I'll let you know after some research on jqgrid available events.

Abu Ghufran answered 7 years ago

If you can limit with dialog editing, you can use following events of edit dialogs.
afterShowForm and onClose. You can make a custom ajax call in JS function to set lock field of edited row id.

Plus, you need to set "rowactions"=>false to disable inline editing.

Demo usage here: https://gist.github.com/gridphp/a8598a323d7e06ed53a5a897b7c58f64

pcattani answered 2 years ago

Abu,

I am writing an application which will be used by multiple users and am considering how to use database locks.  Can you clarify the nature of this function in your above example?:

jQuery(document).data(‘lock_rowid’,rowid);

 

Is lock_rowid a custom function which needs to be written?  This looks like it’s a lock on the front-end with the GUI rather than at the database level.  Is that correct?

 

Thanks

– pcatt

Abu Ghufran Staff answered 2 years ago

Yes, that’s correct. It’s Client side locking solution. For server side, you need to introduce a field of locked with that item.

jQuery(document).data('lock_rowid',rowid);

Above code is a jQuery solution of a JS global variable which is available everywhere in JS code. So we set it when dialog is opened and unset when it’s closed.

Demo does not show how to apply this limitation when opening edit dialog.

I’ve updated demo to have this as well.

https://gist.github.com/gridphp/a8598a323d7e06ed53a5a897b7c58f64 (line 30-55)

You need to put custom ajax calls to check on server if that rowid is locked or not.

Let me know in case of further queries.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

12 + 14 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?