MySQL exit handler ignored
The output handler is being ignored by my stored procedure. I am executing the following line:
CALL updateTemplate('MyObject', 'NewTemplate');
And get the error:
Error code: 1452. Unable to add or update child row: foreign key failed (
db
.objects
, CONSTRAINTObject: Template Foreign Key
FOREIGN KEY (TemplateId
) REFERENCEStemplates
(TemplateId
) ON CASCADE UPDATE)
Indeed, the restriction does not work because "NewTemplate" does not exist in the template table. But why am I not getting a custom error message in the stored procedure exit handler below?
CREATE DEFINER=`root`@`localhost` PROCEDURE `updateTemplate`(in inObjectId varchar(45), in inTemplateId varchar(45))
BEGIN
declare exit handler for 1452
begin
signal sqlstate '45000' set MESSAGE_TEXT = 'The template identifier is invalid.';
end;
UPDATE objects SET TemplateId=inTemplateId WHERE ObjectId=inObjectId;
END
For information, I am running MySQL 5.6.20.
source to share