Jump to content

detect if a record is open by other user?


jason213123

Recommended Posts

hi,

i need know if there is any way to lock a record for exclusive editing

in mysql for other user can´t edit the same record at same time.

The ideia is before the user edit the record he see that the current record

is open for other user.

it´s possible to do something like this?

thanks a lot for your help

:)

 

You could have a lock table that stored the tables and ids of rows that are locked and the time of when they were locked.  This would need to expire at some point in case someone opened an edit form and then went to lunch or whatever.

or perhaps add in a field 'in_editing' with a 1 or 0 avail..  when someone attempts to open a record, it checks that field using the WHERE clause, ie: WHERE in_editing = '0';

 

if in_editing = 0 {

// grant permission to edit.

// update the field to 1

} else {

// sucks to be you!  move faster next time!

}

 

though like Abra points out this leads to trouble.  if someone opens it up, then goes to lunch or whatever it's still locked so no one can modify that record..

 

so in that case  you'd want to add a time_lock field in it, with datetime parameter set..  when you update the in_editing to 1 you also set the time_lock to now()

 

then you would have to create a cron job say every other hour, to run and modify this time_lock field to blank, and the in_editing firled to 0.

then you would have to create a cron job say every other hour, to run and modify this time_lock field to blank, and the in_editing firled to 0.

 

Or just check the lock time the next time a user goes to edit the record.  If its greater than 5 minutes or whatever then remove the lock.  No need for cron.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.