Last active
December 19, 2015 05:59
-
-
Save theory/5908699 to your computer and use it in GitHub Desktop.
A MySQL function that throws an error in a `SELECT` statement will have its error suppressed in a `DO` statement.
This file contains hidden or 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
| DELIMITER | | |
| CREATE FUNCTION checkit(doit INTEGER, message VARCHAR(256)) RETURNS INTEGER | |
| BEGIN | |
| IF doit IS NULL OR doit = 0 THEN | |
| SIGNAL SQLSTATE 'ERR0R' SET MESSAGE_TEXT = message; | |
| END IF; | |
| RETURN doit; | |
| END; | |
| | | |
| DELIMITER ; | |
| select checkit(NULL, 'foo'); | |
| do checkit(NULL, 'foo'); | |
| -- Output: | |
| -- Query OK, 0 rows affected (0.00 sec) | |
| -- | |
| -- ERROR 1644 (ERR0R): foo | |
| -- | |
| -- Query OK, 0 rows affected, 1 warning (0.00 sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment