Created
August 16, 2012 10:01
-
-
Save cloudsben/3369038 to your computer and use it in GitHub Desktop.
Mysql event procedure project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE db_article; | |
drop procedure click_insert; | |
DELIMITER // | |
CREATE PROCEDURE click_insert() | |
BEGIN | |
DECLARE rarcid INT; | |
DECLARE done, duplicate INT DEFAULT 0; | |
DECLARE cur CURSOR FOR SELECT | |
arcid | |
FROM article_click | |
ORDER BY id ASC; | |
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; | |
DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' SET duplicate = 1; | |
OPEN cur; | |
REPEAT | |
FETCH cur INTO rarcid; | |
if not done then | |
UPDATE archives | |
SET click = click + (SELECT click FROM article_click WHERE arcid = rarcid) | |
WHERE id = rarcid; | |
DELETE FROM article_click WHERE arcid = rarcid; | |
end if; | |
UNTIL done END REPEAT; | |
CLOSE cur; | |
END;// | |
SET GLOBAL event_scheduler=1; | |
DELIMITER // | |
CREATE EVENT job_insert_article | |
ON SCHEDULE | |
EVERY 4 SECOND | |
STARTS NOW() | |
DO | |
BEGIN | |
Call click_insert(); | |
End;// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment