Effect of Signals on Handlers, Cursors, and Statements
Signals have different effects on statement execution depending on the signal class. The class determines how severe an error is. MariaDB ignores the value of the sql_mode
system variable; in particular, strict SQL mode does not matter. MariaDB also ignores IGNORE
: The intent of SIGNAL
is to raise a user-generated error explicitly, so a signal is never ignored.
In the following descriptions, "unhandled" means that no handler for the signaled SQLSTATE
value has been defined with DECLARE ... HANDLER
.
- Class =
'00'
(success)Illegal.
SQLSTATE
values that begin with'00'
indicate success and are not valid forSIGNAL
. - Class =
'01'
(warning)The value of the
warning-count
system variable goes up.SHOW WARNINGS
shows the signal.SQLWARNING
handlers catch the signal. If the signal is unhandled in a function, statements do not end. - Class =
'02'
(not found)NOT FOUND
handlers catch the signal. There is no effect on cursors. If the signal is unhandled in a function, statements end. - Class >
'02'
(exception)SQLEXCEPTION
handlers catch the signal. If the signal is unhandled in a function, statements end. - Class =
'40'
Treated as an ordinary exception.
Example:
mysql>delimiter //
mysql>CREATE FUNCTION f () RETURNS INT
->BEGIN
->SIGNAL SQLSTATE '01234'; -- signal a warning
->RETURN 5;
->END//
mysql>delimiter ;
mysql>CREATE TABLE t (s1 INT);
mysql>INSERT INTO t VALUES (f());
The result is that a row containing 5 is inserted into table t
. The warning that is signaled can be viewed with SHOW WARNINGS
.