在程序MySQL 5.5.x中获取SQLEXCEPTION消息 [英] Getting SQLEXCEPTION message in procedures MySQL 5.5.x

查看:417
本文介绍了在程序MySQL 5.5.x中获取SQLEXCEPTION消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果发生 SQLEXCEPTION 时,如何在 MySQL 5.5 存储过程中获取错误文本?



  SQLEXCEPTION的DECLARE EXIT处理程序
BEGIN
获取诊断条件1
SELECTTable @ p5(Msg State @ p2):@ p1
END;

类似于在MySQL程序中获取SQLEXCEPTION消息,但是版本是5.6.4 - 所以 GET DIAGNOSTICS 可用。

解决方案

正如我所知,没有办法在较低版本的MySQL中模拟或替换 GET DIAGNOSTICS 的功能(低于5.6.4 )。



bugs.mysql.com中有许多条目和在这个功能的MySQL论坛上。 (Lke this one: http://bugs.mysql.com/bug.php?id = 11660



我不知道你可以或不能升级你的MySQL实例,但据我所知,这是你唯一的机会。 p>

我发现(可能你也发现他们)有一些与此相关的问题,但他们都在谈论5.6.4版本或者没有答案:





编辑



如果可以,请处理客户端应用程序中的MySQL错误。



您可以列出错误和警告s SHOW ERRORS SHOW WARNINGS HANDLER之外的语句 s,但是您不能将这些语句的结果插入到表中。在处理程序中,这些语句将给出空的结果集。



对于特定的状态,可以声明个别处理程序。这样,你可以知道状态,但你不知道任何其他细节。



查看这篇文章: http://www.mysqltutorial.org/mysql-error-handling-in-stored-procedures/


How can I get error text in MySQL 5.5 stored procedure when SQLEXCEPTION occurs?

I need something along these lines to see 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 there the Version was 5.6.4 - so GET DIAGNOSTICS was available.

解决方案

As I know, there is no way to emulate or replace the functionality of GET DIAGNOSTICS in lower versions of MySQL (lower than 5.6.4).

There are many entries on bugs.mysql.com and on MySQL forums which asks this feature. (Lke this one: http://bugs.mysql.com/bug.php?id=11660)

I do not know that you can or can not upgrade your MySQL instance, but as I know, this is your only chance.

I found (possibly you found them too) some questions related to this one, but all of them are either talking about version 5.6.4 or there are no answers:

EDIT

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

You can list the errors and warnings with SHOW ERRORS and SHOW WARNINGS statements outside of the HANDLERs, but you can not insert the result of those statements into a table. Inside the handler, those statements will give empty resultset.

For specific states, you can declare individual handlers. This way, you could 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/

这篇关于在程序MySQL 5.5.x中获取SQLEXCEPTION消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆