Created
October 28, 2014 20:43
-
-
Save ramsey/e016b272589d1cc28f8e to your computer and use it in GitHub Desktop.
Example of declaring a continue handler in MySQL and rolling back or committing, based on status of _rollback
This file contains 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
DROP PROCEDURE IF EXISTS test_rollback_proc; | |
DELIMITER // | |
CREATE PROCEDURE test_rollback_proc() | |
BEGIN | |
DECLARE `_rollback` BOOL DEFAULT 0; | |
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET `_rollback` = 1; | |
START TRANSACTION; | |
/* SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Custom error'; */ | |
IF `_rollback` THEN | |
SELECT 'rolling back' AS status; | |
ROLLBACK; | |
ELSE | |
SELECT 'committing' AS status; | |
COMMIT; | |
END IF; | |
END// | |
DELIMITER ; | |
CALL test_rollback_proc(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment