implement locking

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Felix Natter

    implement locking

    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 "LockedSinc e int not
    null", a timestamp).

    My current logic is: when the user enters the form to modify a record,
    lock it (set LockedBy=$UserI D). 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
  • Andy Jeffries

    #2
    Re: implement locking

    On Mon, 11 Aug 2003 16:06:47 +0200, Felix Natter wrote:[color=blue]
    > 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[/color]

    You can't.
    [color=blue]
    > 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!)[/color]

    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

    Comment

    • Paul Liversidge

      #3
      Re: implement locking

      Felix Natter <fnatter@gmx.ne t> wrote in message news:<m3ekzsxp8 o.fsf@werkstatt 4.ldc>...[color=blue]
      > 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 "LockedSinc e int not
      > null", a timestamp).
      >
      > My current logic is: when the user enters the form to modify a record,
      > lock it (set LockedBy=$UserI D). 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[/color]

      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

      Comment

      • Guest's Avatar

        #4
        Re: implement locking

        In article <bf26a194.03081 11155.40b7cf0a@ posting.google. com>,
        Paul Liversidge <paul_liversidg e@hotmail.com> wrote:
        [color=blue]
        >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.[/color]

        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.

        --


        Comment

        • Jochen Daum

          #5
          Re: implement locking

          Hi felix!

          On 11 Aug 2003 16:06:47 +0200, Felix Natter <fnatter@gmx.ne t> wrote:
          [color=blue]
          >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 "LockedSinc e int not
          >null", a timestamp).
          >[/color]

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

          "LastUpdate dBy" and "LastUpdatedDat eTime"

          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.
          Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

          Comment

          Working...