First page Back Continue Last page Image

The same Procedure with an Error Handler

DELIMITER //

 

CREATE PROCEDURE test()

BEGIN

DECLARE duplicate_entry_for_key TINYINT DEFAULT FALSE;

 

DECLARE CONTINUE HANDLER FOR 1062

SET duplicate_entry_for_key = TRUE;

 

INSERT INTO general_ledger_accounts VALUES (130, 'Cash');

IF duplicate_entry_for_key = TRUE THEN

SELECT 'Row was not inserted - duplicate key encountered.'

AS message;

ELSE

SELECT '1 row was inserted.' AS message;

END IF;

END//

This message would only work during development, not on a production system, what is the user going to do with it? In production I would use “Something bad happened please tell the database administrator ASAP”

Consider the most likely recipient when making an error message

Should we even be using the CONTINUE option?