Re: table locking ... not required ?
| From: | Tim Van Wassenhove | Date: | Fri, 09 Jul 2004 09:31:17 +0000 |
| Subject: | Re: table locking ... not required ? | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-35171@lists.php.net to get a copy of this message | ||
In article <20040709082212.856.qmail@pb1.pair.com>, Torsten Roehr wrote:
> Add an int field oca to your table. Increment this value on every update.
> When someone edits a row, read the value and put it into a hidden field.
> Then on update check for condition WHERE oca = $ocaFromHiddenField AND id =
> $id etc. Check the affected rows of your update. If it is 0 someone else has
> updated between the start and end of your editing (because oca will have
> been incremented). Then tell your user that someone has just made a change
> to the record set he is editing and he should abort and start again.
update 'rows you would update anyway' and 'oca=oca+1' where 'regular
stuff'
and 'oca=$ocaFromHiddenField'
If you don't update the 'rows you would update anyway' and 'oca=oca+1'
at the same time you run again into concurrency problems.
--
Tim Van Wassenhove <http://home.mysth.be/~timvw>