Condition Handling | op | errno | msg | +--------------------------------+-------+----------------------------+ | stacked DA after mapped insert | 1048 | Column ’c1’ cannot be null | +--------------------------------+-------+----------------------------+ When the condition handler ends, its current diagnostics area is popped from the stack and the stacked diagnostics area becomes the current diagnostics area in the stored procedure. After the procedure returns, the table contains two rows. The empty row results from the attempt to insert NULL  that was mapped to an empty-string insert: In the preceding example, the first two  GET DIAGNOSTICS  statements within the condition handler that retrieve information from the current and stacked diagnostics areas return the same values. This is not the case if statements that reset the current diagnostics area execute earlier within the handler. Suppose that p()  is rewritten to place the  DECLARE  statements within the handler definition rather than preceding it: +----------+ | c1 | +----------+ | string 1 | | | +----------+ CREATE PROCEDURE p () BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN -- Declare variables to hold diagnostics area information DECLARE errcount INT; DECLARE errno INT; DECLARE msg TEXT; GET CURRENT DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO, msg = MESSAGE_TEXT; SELECT ’current DA before mapped insert’ AS op, errno, msg; GET STACKED DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO, msg = MESSAGE_TEXT; SELECT ’stacked DA before mapped insert’ AS op, errno, msg; ... In this case, the result is version dependent: In MySQL 5.7.2, work was done to ensure that all nondiagnostic statements populate the diagnostics area, per the SQL standard.  DECLARE  is one of them, so in 5.7.2 and higher,  DECLARE  statements executing at the beginning of the handler clear the current diagnostics area and the  GET DIAGNOSTICS statements produce different results: +---------------------------------+-------+------+ | op | errno | msg | +---------------------------------+-------+------+ | current DA before mapped insert | NULL | NULL | +---------------------------------+-------+------+ +---------------------------------+-------+----------------------------+ | op | errno | msg | +---------------------------------+-------+----------------------------+ | stacked DA before mapped insert | 1048 | Column ’c1’ cannot be null | +---------------------------------+-------+----------------------------+ •Before MySQL 5.7.2,  DECLARE  does not change the current diagnostics area, so the first two  GET DIAGNOSTICS  statements return the same result, just as in the original version of  p() . To avoid this issue within a condition handler when seeking to obtain information about the condition that activated the handler, be sure to access the stacked diagnostics area, not the current diagnostics area. 2816