By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,350 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,350 IT Pros & Developers. It's quick & easy.

implement locking

P: n/a
hi,

I would like to lock a record so that when one user is modifying a
particular record, then it is locked for all other users. For this
purpose, I have two fields in every table ("LockedBy int null", which
contains the UserID of the editing user and "LockedSince int not
null", a timestamp).

My current logic is: when the user enters the form to modify a record,
lock it (set LockedBy=$UserID). when the user presses the submit-button
to commit his/her changes, unlock the record.

The problem with this is that the user may press fwd+back buttons of
the browser. So either I find a way to disable these in the
editing-forms or I need to find a different way to do this

Of course I could use a timeout (by using LockedSince-field) for cases
where one form has been locked for > 2 hours, but that alone is not
enough (I can't always lock records for that long!)

thanks in advance,

--
Felix Natter
Jul 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Mon, 11 Aug 2003 16:06:47 +0200, Felix Natter wrote:
The problem with this is that the user may press fwd+back buttons of
the browser. So either I find a way to disable these in the
editing-forms or I need to find a different way to do this
You can't.
Of course I could use a timeout (by using LockedSince-field) for cases
where one form has been locked for > 2 hours, but that alone is not
enough (I can't always lock records for that long!)


That sounds wise (along with a BREAK LOCK link so that users can click it,
see that "John Smith locked this record 50 minutes ago, do you want to
break the lock?").

Cheers,
Andy
Jul 16 '05 #2

P: n/a
Felix Natter <fn*****@gmx.net> wrote in message news:<m3************@werkstatt4.ldc>...
I would like to lock a record so that when one user is modifying a
particular record, then it is locked for all other users. For this
purpose, I have two fields in every table ("LockedBy int null", which
contains the UserID of the editing user and "LockedSince int not
null", a timestamp).

My current logic is: when the user enters the form to modify a record,
lock it (set LockedBy=$UserID). when the user presses the submit-button
to commit his/her changes, unlock the record.

The problem with this is that the user may press fwd+back buttons of
the browser. So either I find a way to disable these in the
editing-forms or I need to find a different way to do this


If you really need locking then perhaps you need to use a different
backend database that does support row locking otherwise the best
you'll ever achieve is a kludge.

If you have problems with your 'locks' being released you could add to
your logic that a lock can't be held if the user has moved off that
page. It would still mean that if the user clicks on edit and then
goes to lunch, goes home or closes their browser the lock would still
be active.

If you wanted to get really fancy you can have a page that constantly
reports the page is open and the lock is still required.

You place a 1px by 1px image in the page but change the source to
refer to a PHP page, i.e. keeplock.php. You then add some JavaScript
to the page that reloads the image every 30 seconds or so.

In the keeplock.php, you update your locking field to reflect the new
time and then send a header ("image/gif") and the contents of a blank
1px by 1px gif.

If the browser does go back or shutdown the lock will not be updated
and you can safely release the lock.

It still doesn't help if they leave the edit page on their browser
when they go to lunch or go home but a smack round the head with a
large wet tuna may help to remedy that problem.

Paul
Jul 16 '05 #3

P: n/a
In article <bf**************************@posting.google.com >,
Paul Liversidge <pa*************@hotmail.com> wrote:
If you really need locking then perhaps you need to use a
different backend database that does support row locking
otherwise the best you'll ever achieve is a kludge.


How would that help? The real problem is the read/update
cycle when using a web interface. You just can't be
sure that the user that locked the record will *ever* return
the lock. It's not an easy problem to solve.

--
http://www.spinics.net/lists/phpdb/

Jul 16 '05 #4

P: n/a
Hi felix!

On 11 Aug 2003 16:06:47 +0200, Felix Natter <fn*****@gmx.net> wrote:
hi,

I would like to lock a record so that when one user is modifying a
particular record, then it is locked for all other users. For this
purpose, I have two fields in every table ("LockedBy int null", which
contains the UserID of the editing user and "LockedSince int not
null", a timestamp).


I would use optimistic locking with web interfaces. This means you
have fields:

"LastUpdatedBy" and "LastUpdatedDateTime"

Also, you keep in mind when you read it for editing.

When you save and someone else saved it meanwhile, you give a warning
"Someone else changed the record, etc pp.". With some knowlegde about
the table or a "before image" you may alsoi be able to merge the
records automatically.

HTH, Jochen
--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.