Getting SQLEXCEPTION message in MySQL 5.5.x procedures

How can I get the error text in a MySQL 5.5 stored procedure when it occurs SQLEXCEPTION

?

I need something along these lines to figure out what went wrong:

DECLARE EXIT HANDLER FOR SQLEXCEPTION    
BEGIN
    GET DIAGNOSTICS CONDITION 1
    SELECT "Table @p5 (Msg State @p2): @p1"
END;

      

Similar to Getting SQLEXCEPTION message in MySQL procedures , but the version was 5.6.4 - so GET DIAGNOSTICS .. p>

+1


source to share


1 answer


As I know, there is no way to emulate or replace functionality GET DIAGNOSTICS

in lower MySQL versions (below 5.6.4).

On bugs.mysql.com and on the MySQL forums that request this feature. (Lke this: http://bugs.mysql.com/bug.php?id=11660 )

I don't know if you may or may not update your MySQL instance, but as I know this is your only chance.

I found (you may have found them) some questions related to this, but they all either talk about version 5.6.4 or there are no answers:



EDIT

If you can, handle MySQL errors in the client application.

You can list errors and warnings using SHOW ERRORS

and SHOW WARNINGS

outside HANDLER

s operators , but you cannot insert the result of those statements into a table. Internally, these assertions will produce an empty result set.

For specific states, you can declare separate handlers. Thus, you may know the state, but you do not know any other details.

Check out this article: http://www.mysqltutorial.org/mysql-error-handling-in-stored-procedures/

+6


source







All Articles