Hi,
>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:
You COULD do the following (thatīs what i do):
UPDATE stats ..
if number_of_affected_rows==0 {
// first time to access the date, must insert new row
// should be a rare case
INSERT INTO stats SET .....
if mysql_error!=0 {
// some other thread happened to do the insert just between the two
previous statement
// must update
// should be even rarer
UPDATE stats ....
assert(number_of_affected_rows==1) //must always be true else bomb
}
}
in most of the cases there is just one query being executed.
bye
henning schroeder
---------------------------------------------------------------------
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