1.SQLEXCEPTION对应存储过程中的所有异常
2.通过输出参数,来返回事务是否执行成功
3.一个疑问:为什么mysql事务执行成功后,受影响的记录数都是0呢?
下为SQL代码:
-- Procedure "Users_Test" DDL
CREATE DEFINER=`root`@`%` PROCEDURE `Users_Test`(out pCode int)
begin
declare userID int default 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
begin
rollback;
SET pCode=1;
end;
set pCode = 0;
-- savepoint sp;
-- SET AUTOCOMMIT= 1;
start transaction;
-- call Users_WriteLog('haha ,log');
insert into Users_Login (LoginName,LoginPwd,Banned) values ('1234','0000',0);
set userID = @@IDENTITY;
insert into Users_Profile(UserID,UserName,CharactorName,HeadImageID,Sex,FromType,ProfileComplete)
values ( 5,'999999',10,1,1,0,1);
commit;
-- SELECT ROW_COUNT();
-- set rowcnt = mysql_affected_rows();
-- rollback to sp;
end;