END; 

Suppose that t1.int_col  is an integer column that is declared as NOT NULL . The procedure produces these results when invoked to insert non- NULL  and NULL  values, respectively: 

mysql> CALL do_insert(1); +---------------------------------+ | result | +---------------------------------+ | insert succeeded, row count = 1 | +---------------------------------+ mysql> CALL do_insert(NULL); +-------------------------------------------------------------------------+ | result | +-------------------------------------------------------------------------+ | insert failed, error = 23000, message = Column ’int_col’ cannot be null | +-------------------------------------------------------------------------+ 

When a condition handler activates, a push to the diagnostics area stack occurs: 

•The first (current) diagnostics area becomes the second (stacked) diagnostics area and a new current diagnostics area is created as a copy of it. 

• GET [CURRENT] DIAGNOSTICS  and GET STACKED DIAGNOSTICS  can be used within the handler to access the contents of the current and stacked diagnostics areas. 

•Initially, both diagnostics areas return the same result, so it is possible to get information from the current diagnostics area about the condition that activated the handler, as long as  you execute no statements within the handler that change its current diagnostics area. 

•However, statements executing within the handler can modify the current diagnostics area, clearing and setting its contents according to the normal rules (see How the Diagnostics Area is Cleared and Populated). 

A more reliable way to obtain information about the handler-activating condition is to use the stacked diagnostics area, which cannot be modified by statements executing within the handler except RESIGNAL . For information about when the current diagnostics area is set and cleared, see Section 13.6.7.7, “The MySQL Diagnostics Area” . 

The next example shows how GET STACKED DIAGNOSTICS  can be used within a handler to obtain information about the handled exception, even after the current diagnostics area has been modified by handler statements. 

Within a stored procedure p() , we attempt to insert two values into a table that contains a TEXT NOT NULL  column. The first value is a non- NULL  string and the second is NULL . The column prohibits NULL values, so the first insert succeeds but the second causes an exception. The procedure includes an exception handler that maps attempts to insert NULL  into inserts of the empty string: 

DROP TABLE IF EXISTS t1; CREATE TABLE t1 (c1 TEXT NOT NULL); DROP PROCEDURE IF EXISTS p; delimiter // CREATE PROCEDURE p () BEGIN -- Declare variables to hold diagnostics area information DECLARE errcount INT; DECLARE errno INT; DECLARE msg TEXT; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN 

