当我尝试删除不存在的行时,为什么这段代码没有捕捉到错误?无论我作为行的名称传入什么参数,它总是返回“1 行已删除”并且不使用退出处理程序。应该只捕获这种类型的错误。
USE yoga;
DROP PROCEDURE IF EXISTS delete_warmup;
DELIMITER //
CREATE PROCEDURE delete_warmup
(
warmup_name_param VARCHAR(100)
)
BEGIN
DECLARE row_not_found TINYINT DEFAULT FALSE;
DECLARE sql_exception TINYINT DEFAULT FALSE;
BEGIN
DECLARE EXIT HANDLER FOR 1329
SET row_not_found = TRUE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
SET sql_exception = TRUE;
DELETE FROM warmup
WHERE warmup_name = warmup_name_param;
SELECT '1 row was deleted.' AS message;
END;
IF row_not_found = TRUE THEN
SELECT 'Row not deleted - row not found' AS message;
ELSEIF sql_exception = TRUE THEN
SHOW ERRORS;
END IF;
END//
DELIMITER ;
CALL delete_warmup ('Monkey business');