php - MySQL Trigger Problem -


i'm starting use triggers in mysql, , have problem. wrote triggers update users table , make notifications=notifications+1 (to user) when insert in notifications table. seems work, have made 'check-cron-script', runs every minute, , updates users table 100% true values should there (count notifications table). cron sends me email if updates rows. if script makes change, it'll send me email containing user_id had bad value. while ago, received 2 emails in row (22:53, 22:54) telling me script found bad value in users table, , had update 1 row. both emails same (same user, same thing). , i'm wondering happened.

update query: insert notifications (user_id,title,notification) values (%i,%s,%s)  after insert trigger: begin if new.`new` > 0 update users set notifications=notifications+1 id=new.user_id; end if; end  after update trigger: begin if old.`new` != new.`new` if old.`new` > 0 update users set notifications=notifications-1 id=old.user_id; end if; if new.`new` > 0 update users set notifications=notifications+1 id=new.user_id; end if; end if; end  after delete trigger: begin if old.`new` > 0 update users set notifications=notifications-1 id=old.user_id; end if; end 

notifications.new tinyint indicates if user read notification allready (the default value 1)

the notifications table not being updated frequently, thinking should have happened, , thing think should happened is: 1. update query run 2. cron executed before trigger, , had change value, cause wrong 3. trigger run 4. in next run of cron value higher had be, cron had update again (same user, same thing, same email)

but don't know if thing can happen. if after trigger delayed bit, , if cron can executed after query, before trigger.

triggers atomic. unless you're running tx_isolation=read-uncommitted, scenario described shouldn't possible.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -