Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL exit handler ignored

An exit handler is being ignored by my stored procedure. I execute the following line:

CALL updateTemplate('MyObject', 'NewTemplate');

And receive the error:

Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (db.objects, CONSTRAINT Object: Template Foreign Key FOREIGN KEY (TemplateId) REFERENCES templates (TemplateId) ON UPDATE CASCADE)

Indeed, a constraint does fail, because 'NewTemplate' does not exist in the template table. But why do I not receive the custom error message in the exit handler of the stored procedure 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 info, I'm running MySQL 5.6.20.

like image 947
Franzl Avatar asked Mar 07 '26 09:03

Franzl


1 Answers

(Acknowledge GarethD)

This is due to a bug that was fixed in version 5.7.2.

Upgraded to MySQL 5.7.5, and all is now working.

http://bugs.mysql.com/bug.php?id=68831

like image 134
Franzl Avatar answered Mar 09 '26 22:03

Franzl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!