5
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語法錯誤。mysql事務錯誤處理
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
有人能幫我弄清楚我做錯了什麼嗎?
預先感謝
EDIT
UPDATE SET tbl_order = TransactionID的 「XYZ」 WHERE訂單ID =;
是故意
瞎猜過程中可能出現的:是分號'回滾後過早結束退出處理程序? – sarnold 2012-02-02 00:51:58
nope ..它沒有幫助 – robert 2012-02-02 02:23:12
所以無論如何我繼續前進,並用代碼而不是使用mysql查詢來處理錯誤。假設打開連接 MySqlCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.Transaction = conn.BeginTransaction(); try {cmd.CommandText = strSQL; cmd.ExecuteNonQuery(); cmd.Transaction.Commit(); (例外){ cmd.Transaction.Rollback(); dblog.ErrorFormat(「*** Transaction Rollback:{0} \ n Params:{1} \ n例如:{2} \ n」,strSQL,ex.InnerException); } – robert 2012-02-02 04:54:20