On Thu, Aug 16, 2001 at 02:04:25PM +0100, Ken Guest wrote:
> 
> hi,
> I'm new to this list, but not so new to using MySQL and have a question
> about locking. (This is my first foray into datalocking with MySQL.)
> 
> I'd like to lock a table (a row in that table would be better) for read
> and write access to prevent mishaps from occurring during data
> manipulation.
> 
> At the moment, what I am doing is:
> 
>       execute "LOCK TABLES foo READ"
>       select info from foo
>       //next lock implictly unlocks previous one
>       //as it's done by the same thread/process
>       //chances of conflicts occurring are probably
>       //only theoritical.
>       execute "LOCK TABLES foo WRITE"
>       manipulate info
>       update_sql = ...
>       execute update_sql
>       execute "UNLOCK TABLES"
> 
> and it seems to work fairly ok, but I'd like to get an opinion on
> this from somebody experienced.
> 
> any help/opinions on this would be much appreciated.
> 
> thanks
> 
> Ken
> 

Bad idea! I'm not shure if mysql uses lock cues but this leaves you open to a serious 
race condition in many if not all sql enviroments. Consider the following: if you 
start two copies of this query at the same time, one and only one gets the lock, the 
other is put on hold, in the cue, when your first script atempts to get its second 
lock the first is realsed and your second script starts executing, and your first gets 
put on hold. exactly what you do not want. use a single write lock for the entire 
operation, read and write. simple, easy, no problem.

-- 
-----

DISCLAIMER: Anyone sending me unsolicited commercial electronic mail
automatically agrees to be held to the following legal terms:

US Code Title 47, Sec.227(a)(2)(B), a computer/modem/printer meets the
definition of a telephone fax machine. By Sec.227(b)(1)(C), it is
unlawful to send any unsolicited advertisement to such equipment. By
Sec.227(b)(3)(C), a violation of the aforementioned Section is punishable
by action to recover actual monetary loss, or $500, whichever is greater,
for each violation.





---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to