Last active
August 2, 2019 08:03
-
-
Save 0x49D1/bbc73d9d59aafd16ced01e145c3b34b0 to your computer and use it in GitHub Desktop.
MySQL catch exception and log it into another table for example.
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
# CREATE PROCEDURE AND OTHER DECLARE STATEMENTS HERE | |
# .... | |
DECLARE EXIT HANDLER FOR SQLEXCEPTION | |
BEGIN | |
GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE, @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT; | |
ROLLBACK; | |
SET @full_error = CONCAT('ERR:', @errno, '(', @sqlstate, '):', @text); | |
CALL sp_logaction(@full_error); # Some logging procedure | |
RESIGNAL; | |
END; | |
# PROCEDURE BODY WITH START TRANSACTION & COMMIT HERE | |
# ..... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment