mysql 获取异常信息,在程序MySQL 5.5.x中获取SQLEXCEPTION消息

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值