SQL语句的提交,请指教?谢谢!

Leony 2002-01-23 11:16:41
我有几条SQL语句:
update table1 set ......... where ..............using sqlca;
update table2 set ......... where ..............using sqlca;
delete table3 set ..........where .............using sqlca;
if sqlca.sqlnrows>0 then
commit using sqlca;
else
rollback using sqlca;
end if
这样能做到只有同时做成功地update 了table1 和 table2,再删除table3吗?
应该怎么做呢?谢谢!
...全文
252 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
dongdongxiao 2002-01-23
  • 打赏
  • 举报
回复
sqlca.atutocommit = false
update table1 set ......... where ..............using sqlca;

if sqlca.sqlcode<>0 then
messagebox("","")
rollback using sqlca;
sqlca.atutocommit = True
ruturn
end if

update table2 set ......... where ..............using sqlca;

if sqlca.sqlcode<>0 then
messagebox("","")
rollback using sqlca;
sqlca.atutocommit = True
ruturn
end if

delete table3 set ..........where .............using sqlca;

if sqlca.sqlcode<>0 then
messagebox("","")
rollback using sqlca;
sqlca.atutocommit = True
ruturn
end if

commit using sqlca;
sqlca.atutocommit = True
dongdongxiao 2002-01-23
  • 打赏
  • 举报
回复
sqlca.atutocommit = false
update table1 set ......... where ..............using sqlca;

if sqlca.sqlnrows<>0 then
messagebox("","")
rollback using sqlca;
sqlca.atutocommit = True
ruturn
end if

update table2 set ......... where ..............using sqlca;

if sqlca.sqlnrows<>0 then
messagebox("","")
rollback using sqlca;
sqlca.atutocommit = True
ruturn
end if

delete table3 set ..........where .............using sqlca;

if sqlca.sqlnrows<>0 then
messagebox("","")
rollback using sqlca;
sqlca.atutocommit = True
ruturn
end if

commit using sqlca;
sqlca.atutocommit = True
Distance_Man 2002-01-23
  • 打赏
  • 举报
回复
commit 和 rollback 是结束事物.习惯上是作对了就commit,做错了就rollback.
应尽量保持事物的短小.比如你就以这组操作为一个事物,都作对了就commit.
Distance_Man 2002-01-23
  • 打赏
  • 举报
回复
commit
fzymr 2002-01-23
  • 打赏
  • 举报
回复
还是用sqlca.sqlcode判断
Leony 2002-01-23
  • 打赏
  • 举报
回复
commit不是提交自上一次commit之后的所有SQL语句吗?
我有什么条件可以判断这些commit的语句都执行成功了呢?
Distance_Man 2002-01-23
  • 打赏
  • 举报
回复
sqlca.sqlcode 等保存的是最近一条sql发生的信息.
llitcwl 2002-01-23
  • 打赏
  • 举报
回复
用if sqlca.sqlcode<>0 then 作层层嵌套判断是保险的做法
fzymr 2002-01-23
  • 打赏
  • 举报
回复
update t1 ..
if sqlca.sqlcode = 0 then
update t2
if sqlca.sqlcode = 0 then
delete t3
if sqlca.sqlcode = 0 then
commit;
else
rollback;
end if
else
rollback;
end if

else
rollback;
end if
tangjianhua 2002-01-23
  • 打赏
  • 举报
回复
不能。应分别写。
pinglv 2002-01-23
  • 打赏
  • 举报
回复
二楼  fzymr(风中游牧人)
的方法就好了

401

社区成员

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

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