回复 12楼 fanjinyu9108
程序代码:
If Not SQLExec(connhandle,"set lock_timeout 1000") = 1 &&设置超时时间
Messagebox("错误提示")
RETURN
ENDIF
If Not SQLExec(connhandle,"Begin Transaction") = 1 &&开始事务
Messagebox("不能开始事务")
RETURN
ENDIF
sqlok = SQLExec(connhandle,"delete ……")
If sqlok < 0
If Aerror(laErr)>0
cErrorText = ALLTRIM(SUBSTR(Transform(laErr(1,3)),RAT("]",Transform(laErr(1,3)),1)+1,200))
cErrorHeader = ALLTRIM(Transform(laErr(1,1)))
ENDIF
SQLExec(connhandle,"Rollback Transaction") &&回滚事物
MESSAGEBOX(cErrorText,0+16,"错误:"+cErrorHeader)
Return
ENDIF
sqlok = SQLExec(connhandle,"update ……")
If sqlok < 0
If Aerror(laErr)>0
cErrorText = ALLTRIM(SUBSTR(Transform(laErr(1,3)),RAT("]",Transform(laErr(1,3)),1)+1,200))
cErrorHeader = ALLTRIM(Transform(laErr(1,1)))
ENDIF
SQLExec(connhandle,"Rollback Transaction") &&回滚事物
MESSAGEBOX(cErrorText,0+16,"错误:"+cErrorHeader)
Return
ENDIF
sqlok = SQLExec(connhandle,"insert ……")
If sqlok < 0
If Aerror(laErr)>0
cErrorText = ALLTRIM(SUBSTR(Transform(laErr(1,3)),RAT("]",Transform(laErr(1,3)),1)+1,200))
cErrorHeader = ALLTRIM(Transform(laErr(1,1)))
ENDIF
SQLExec(connhandle,"Rollback Transaction") &&回滚事物
MESSAGEBOX(cErrorText,0+16,"错误:"+cErrorHeader)
Return
ENDIF
If Not SQLExec(connhandle,"Commit Transaction") = 1 &&完成事务
SQLExec(connhandle,"Rollback Transaction") &&回滚事物
Messagebox("未能完成事务")
Return
ENDIF