SIGNAL,
RESIGNAL, and
GET DIAGNOSTICS are not permissible
as prepared statements. For example, this statement is invalid:
PREPARE stmt1 FROM 'SIGNAL SQLSTATE "02000"';
SQLSTATE values in class
'04' are not treated specially. They are
handled the same as other exceptions.
Standard SQL has a diagnostics area stack, containing a
diagnostics area for each nested execution context. Standard SQL
syntax includes GET STACKED DIAGNOSTICS for
referring to stacked areas. MySQL does not support the
STACKED keyword because there is a single
diagnostics area containing information from the most recent
statement that wrote to it. See also
Section 13.6.7.7, “The MySQL Diagnostics Area”.
In standard SQL, the first condition relates to the
SQLSTATE value returned for the previous SQL
statement. In MySQL, this is not guaranteed, so to get the main
error, you cannot do this:
GET DIAGNOSTICS CONDITION 1 @errno = MYSQL_ERRNO;
Instead, do this:
GET DIAGNOSTICS @cno = NUMBER; GET DIAGNOSTICS CONDITION @cno @errno = MYSQL_ERRNO;