salix/db/routines/hedera/procedures/survey_vote.sql

20 lines
498 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`survey_vote`(vAnswer INT)
BEGIN
DECLARE vSurvey INT;
DECLARE vCount TINYINT;
DECLARE EXIT HANDLER FOR 1062
CALL util.throw('You cannot vote twice to the same survey');
SELECT durveyFk INTO vSurvey
FROM surveyAnswer WHERE id = vAnswer;
INSERT INTO surveyVote SET
surveyFk = vSurvey,
userFk = account.myUser_getId();
UPDATE surveyAnswer SET votes = votes + 1
WHERE id = vAnswer;
END$$
DELIMITER ;