mysql事务错误处理 [英] mysql transaction error handling

查看:246
本文介绍了mysql事务错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING, NOT FOUND 
BEGIN 
    ROLLBACK; 
END;
START TRANSACTION;      

    UPDATE tbl_order SET TransactionID="abc" WHERE OrderID=1;
    UPDATE tbl_order SET TransactionID="xyz" WHERE OrderID=;
    UPDATE tbl_order SET TransactionID="zzz" WHERE OrderID=13;


COMMIT;

由于某种原因,订单1和13被填充而没有回滚,并且我得到出口hadler的语法错误.

for some reason order 1 and 13 are filled without rollback and i get syntax error for the exit hadler.

Query:  DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING, NOT FOUND BEGIN ROLLBACK

Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING, NOT FOUND 
BEGIN 
    ROLLBACK' at line 1

有人可以帮我弄清楚我在做什么错吗?

can someone help me figure out what i'm doing wrong?

预先感谢

编辑

更新tbl_order SET TransactionID ="xyz" WHERE OrderID =;

是故意的

推荐答案

我认为出口处理程序只能在存储过程中使用.该文档没有明确说明这一点,但暗示了

I believe exit handlers can only be used in stored procedures. The documentation doesn't explicitly state this, but alludes to

在执行存储程序期间可能需要特殊处理的条件

Conditions may arise during stored program execution that require special handling

http://dev.mysql.com/doc/refman/5.1/en/condition-handling.html

这篇关于mysql事务错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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