关于MYSQL调用事物回滚的整理
2014-10-09 20:03
260 查看
BEGIN
declare t_error int default 0;
declare addtime int default 0;
declare starttime int default 0;
declare endtime int default 0;
declare userid int default 0;
declare doctorid int default 0;
declare count int default 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=-1;
select start_time,end_time,user_id,doctor_id into @starttime,@endtime,@userid,@doctorid from doctor_order where id=orderid;
select count(*) into @count from user_doctor where user_id=userid and doctor_id=doctorid;
start TRANSACTION;
update doctor_order set pay_status=1 where id=orderid;
IF count>0 THEN
update user_doctor set
start_time=@starttime,end_time=@endtime,status=1 where
user_id=@userid and doctor_id=@doctori;
end if;
IF count=0 THEN
insert into user_doctor (user_id,doctor_id,add_time,start_time,end_time,status) values(@userid,@doctorid,123,@starttime,@endtime,1);
end if;
IF t_error = -1 THEN
ROLLBACK;
ELSE
COMMIT;
END IF;
select t_error;
END
declare t_error int default 0;
declare addtime int default 0;
declare starttime int default 0;
declare endtime int default 0;
declare userid int default 0;
declare doctorid int default 0;
declare count int default 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=-1;
select start_time,end_time,user_id,doctor_id into @starttime,@endtime,@userid,@doctorid from doctor_order where id=orderid;
select count(*) into @count from user_doctor where user_id=userid and doctor_id=doctorid;
start TRANSACTION;
update doctor_order set pay_status=1 where id=orderid;
IF count>0 THEN
update user_doctor set
start_time=@starttime,end_time=@endtime,status=1 where
user_id=@userid and doctor_id=@doctori;
end if;
IF count=0 THEN
insert into user_doctor (user_id,doctor_id,add_time,start_time,end_time,status) values(@userid,@doctorid,123,@starttime,@endtime,1);
end if;
IF t_error = -1 THEN
ROLLBACK;
ELSE
COMMIT;
END IF;
select t_error;
END
相关文章推荐
- 关于 vmware linux mysql 的一些转帖整理
- php调用mysql存储过程(关于CLIENT_MULTI_RESULTS)
- MySQL 事物回滚Demo
- Spring+hibernate+mysql事物不回滚的原因以及处理
- Spring+hibernate+mysql事物不回滚的原因以及处理
- 关于回滚,mysql
- Spring+hibernate+mysql事物不回滚的原因以及处理
- 关于 HTML5 调用用户的 照相机、相册 初步整理
- 关于sql和mysql对于别名不能调用的一些理解
- Spring+hibernate+mysql事物不回滚的原因以及处理
- php调用mysql存储过程(关于CLIENT_MULTI_RESULTS)
- 关于Mysql的常规操作整理
- php中关于mysqli和mysql区别的一些知识点整理
- phpmywind教程:关于日期函数调用整理
- 关于Java调用批处理命令向mysql导入数据的中文乱码有关问题
- [MYSQL] 存储过程 动态表名/异常处理/事物回滚/日期
- 关于ADO连接MYSQL调用存储过程的ERROR1064错误
- 关于php应该在何时调用mysql_close()以及pconnect方式和传统方式有何种区别收藏
- Spring+hibernate+mysql事物不回滚的原因以及处理
- Spring+hibernate+mysql事物不回滚的原因以及处理