您的位置:首页 > 数据库 > MySQL

关于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


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql 事物回滚