You COULD do what we do:
select GET_LOCK(date)
select & (update | insert)
select RELEASE_LOCK(date)
[I don't recall the exact syntax on the get lock)
Anyway, all of our software uses this to emulate row-level locking. It is
not as elegant as a 2 line SQL statement,but it is effective and readable. =)
On Thursday 13 September 2001 05:40 am, you wrote:
> Hi!
>
> I have a counter that is increased each time an event occur. The number of
> events should be reported as events / month, so along with the counter i
> have a date-field. The table structure looks like this:
>
> table stats
> count int unsigned not null default 0
> date timestamp (using only year/month part)
>
> I update this table with:
>
> UPDATE stats SET count=count+1 WHERE date=XXX
>
> BUT, if the date is not there, no counter will be updated so I must first
> check this and insert a record if date is not found. Since there is more
> than one thread that can write to this table I must use a lock:
>
> LOCK TABLES stats WRITE
> SELECT COUNT(*) FROM stats WHERE date=XXX
>
> if count == 0
> INSERT INTO stats ...
> else
> UPDATE stats ...
>
> UNLOCK TABLES
>
> Can this be specified as one statement, so that I dont have to use table
> locks??
>
> Thanks!
>
> /torgil
>
>
>
>
>
> ---------------------------------------------------------------------
> 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
---------------------------------------------------------------------
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