Re: Lock Record on Postgresql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Torsten: Thank's a lot, I think I get it!

> Hi Norma,
>
> you can achieve this in a much more comfortable and elegant way:
>
> Create an integer column named oca (stands for Optimistic Concurrency
> Control Attribute). When you load the data to show them in the editing
form
> store the value in a hidden field or in the session (if you are using
> sessions). Then when you update the data use the following statement:
>
> UPDATE table SET column = '$value' ..., oca = oca + 1 WHERE user_id =
> $user_id AND oca = $value_from_hidden_field
>
> After performing the query check the affected rows. If there is one
affected
> row the update was succesful. If there are no affected rows it means that
> someone else updated this row in the meantime (thereby incrementing oca)
and
> you can show a message like:
>
> "Since the start of your editing process someone else updated this record
> set. Please cancel and edit the record again."
>
> This way you will never lock out a record set forever like Miles wrote and
> the user will at least be able to "open" the record set and see all data -
> even if sometimes (should be very seldom) he has to cancel and start
again.
>
> I hope you get my point - it's a bit difficult to explain.
>
> Best regards, Torsten Roehr
>
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux