Подскажите, почему триггер не работает? Хотя по отдельности запросы работают?
DELIMITER ;
DELIMITER $$
BEGIN
SET @isGame = (SELECT COUNT(buy.key_games) FROM buy INNER JOIN key_in_game USING (key_games) INNER JOIN game USING (id_games) WHERE buy.id_buyer = NEW.id_buyer AND game.name = GameInKey(NEW.key_games) GROUP BY(game.name) HAVING COUNT(buy.key_games) > 0);
SET @isMoney = (select IsMoneyTrue(buyer.cash, game.price) FROM buyer INNER JOIN buy USING (id_buyer) INNER JOIN key_in_game USING (key_games) INNER JOIN game USING (id_games) WHERE buyer.ID_buyer = NEW.ID_buyer AND key_in_game.key_games=NEW.key_games);
IF (SELECT IFNULL(GameInKey(NEW.key_games),0)) = 0 THEN
SIGNAL SQLSTATE VALUE '45000' SET MESSAGE_TEXT = 'Игры нет в наличии';
ELSEIF (@isGame>0) THEN
SIGNAL SQLSTATE VALUE '45000' SET MESSAGE_TEXT = 'Вы уже купили эту игру';
ELSEIF (@isMoney = 0) THEN
SIGNAL SQLSTATE VALUE '45000' SET MESSAGE_TEXT = 'Недостаточно средств для покупки игры';
ELSE
UPDATE key_in_game SET `status` = 1 WHERE key_in_game.key_games = NEW.key_games;
END IF;
END$$
DELIMITER ;
fiddle
Прикрепленные файлы:
shop (1).sql, Размер: 18,795 байт, Скачано: 550