同时向不同的表中写数据,提交失败后,数据库事务不回滚!!!!!

mengsuo 2010-08-12 05:21:37
代码如下:

string ls_temp_string1,ls_temp_string2

ls_temp_string1="a"

ls_temp_string2="b"

//a数据插入
INSERT INTO T_a(……)
USING at_Trans;

if at_Trans.SqlCode = 0 then
//b数据插入
INSERT INTO T_b(……)
USING at_Trans;

if at_Trans.SqlCode = 0 then
//c数据插入
INSERT INTO T_c(……)
USING at_Trans;
COMMIT USING at_Trans;

if at_Trans.SqlCode = 0 then
return STATE_OK
else
//c数据插入失败
ROLLBACK USING at_Trans;
gf_wtkj_log(ls_temp_string1)
openwithparm(w_message_error,"数据库故障3")
return STATE_ERROR
end if
else
//b数据插入失败
ROLLBACK USING at_Trans;
gf_wtkj_log(ls_temp_string1+ls_temp_string2)
openwithparm(w_message_error,"数据库故障2")
return STATE_ERROR
end if
else
//a数据插入失败
gf_wtkj_log(ls_temp_string1)
openwithparm(w_message_error,"数据库故障1")
return STATE_ERROR
end if
...全文
178 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wag_enu 2010-08-15
  • 打赏
  • 举报
回复
请先确定 at_Trans.autocommit = false
hchjjun 2010-08-15
  • 打赏
  • 举报
回复
你中间有个commit了呀
jornye 2010-08-12
  • 打赏
  • 举报
回复
可以这样写,更清晰和捕捉错误些·
string ls_temp_string1,ls_temp_string2

ls_temp_string1="a"

ls_temp_string2="b"

//a数据插入
INSERT INTO T_a(……)
USING at_Trans;
if sqlca.sqlcode <> 0 then
//a数据插入失败
ROLLBACK USING at_Trans;
gf_wtkj_log(ls_temp_string1)
openwithparm(w_message_error,"数据库故障1")
return STATE_ERROR
end if

//b数据插入
INSERT INTO T_b(……)
USING at_Trans;
if sqlca.sqlcode <> 0 then
//b数据插入失败
ROLLBACK USING at_Trans;
gf_wtkj_log(ls_temp_string1+ls_temp_string2)
openwithparm(w_message_error,"数据库故障2")
return STATE_ERROR
end if

//c数据插入
INSERT INTO T_c(……)
USING at_Trans;
//c数据插入失败
if sqlca.sqlcode <> 0 then
ROLLBACK USING at_Trans;
gf_wtkj_log(ls_temp_string1)
openwithparm(w_message_error,"数据库故障3")
return STATE_ERROR
end if

commit using at_Trans;
mengsuo 2010-08-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 leef_zh 的回复:]
LZ的程序寫的真叫一個醜啊
[/Quote]

请赐教 ,应该如何写,谢谢!!!!
leef_zh 2010-08-12
  • 打赏
  • 举报
回复
LZ的程序寫的真叫一個醜啊
mengsuo 2010-08-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 sjlion 的回复:]
USING at_Trans;
COMMIT USING at_Trans;

if at_Trans.SqlCode = 0 then
return STATE_OK

I 服了 you .已经提交过了然后判断sqlcode再回滚 看的我两眼一黑....
[/Quote]

这里我改成这样:
USING at_Trans;

if at_Trans.SqlCode = 0 then
COMMIT USING at_Trans;
return STATE_OK
…………………………

可是:
a数据插成功了,b数据插失败了,怎么不回滚呀!!!!!!


lao_bulls 2010-08-12
  • 打赏
  • 举报
回复
楼上正解
jornye 2010-08-12
  • 打赏
  • 举报
回复
格式一理,问题自然就看出来了·

光这一句:
//a数据插入
INSERT INTO T_a(……)
USING at_Trans;

如果不成功,你都没有回滚·

另外,看看你的autocommit是否设置为false
jornye 2010-08-12
  • 打赏
  • 举报
回复
楼主不会提问吧·格式都没整·

string ls_temp_string1,ls_temp_string2

ls_temp_string1="a"

ls_temp_string2="b"

//a数据插入
INSERT INTO T_a(……)
USING at_Trans;

if at_Trans.SqlCode = 0 then
//b数据插入
INSERT INTO T_b(……)
USING at_Trans;

if at_Trans.SqlCode = 0 then
//c数据插入
INSERT INTO T_c(……)
USING at_Trans;
COMMIT USING at_Trans;

if at_Trans.SqlCode = 0 then
return STATE_OK
else
//c数据插入失败
ROLLBACK USING at_Trans;
gf_wtkj_log(ls_temp_string1)
openwithparm(w_message_error,"数据库故障3")
return STATE_ERROR
end if
else
//b数据插入失败
ROLLBACK USING at_Trans;
gf_wtkj_log(ls_temp_string1+ls_temp_string2)
openwithparm(w_message_error,"数据库故障2")
return STATE_ERROR
end if
else
//a数据插入失败
gf_wtkj_log(ls_temp_string1)
openwithparm(w_message_error,"数据库故障1")
return STATE_ERROR
end if
sjlion 2010-08-12
  • 打赏
  • 举报
回复
USING at_Trans;
COMMIT USING at_Trans;

if at_Trans.SqlCode = 0 then
return STATE_OK

I 服了 you .已经提交过了然后判断sqlcode再回滚 看的我两眼一黑....
mengsuo 2010-08-12
  • 打赏
  • 举报
回复
是这样 ,有时a表插成功了,b表插失败了,但a中依然有数据,没有回滚!!!!!

752

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧