0

I am trying to do error handling as I can do in stored procedures in mysql but functions don't support to support them. Is there a way I can do something like this?

delimiter //
CREATE FUNCTION supports_ft()
 RETURNS INT
 BEGIN
 DECLARE CONTINUE HANDLER FOR SQLSTATE 'HY000' return 0;
 SELECT @@innodb_ft_cache_size;
 return 1;
END;
asked Aug 30, 2015 at 16:12

1 Answer 1

1

Functions support exception handlers, but that won't necessarily catch a blatantly invalid operation that could never succeed, such as what you are trying here, which is an unbounded select. This is only supported in stored procedures, not functions (or triggers).

ERROR 1415 (0A000): Not allowed to return a result set from a function

You need to try to load the system variable's content into a dummy variable. The following should work, unless MySQL tries to validate the variable at function declaration time, which it may or may not... you'll need to verify:

SET @dummy = @@innodb_ft_cache_size;

If validation is done early, you'll need to use a prepared statement to avoid that early validation.

HY000 is a pretty vague sqlstate, and you might be better off with DECLARE CONTINUE HANDLER FOR SQLEXCEPTION.

answered Aug 31, 2015 at 0:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.