3

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.

2
  • 1
    I think this is due to a bug that was fixed in 5.7.2. Commented Dec 4, 2014 at 12:40
  • Thanks. I'll upgrade and report back. Commented Dec 4, 2014 at 12:45

1 Answer 1

1

(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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.