VFP中的SQL Server的事务处理简单例子
*********************************************************************************
Transactions_error=.f. &&事务过程失败标志
= SQLSETPROP(myconnect, ‘Transactions’, 2) &&启动手动事务处理
**————————————————————
TEXT TO sql_tmp1 NOSHOW
INSERT INTO amt_bum(id_bum, bum_bh)
values (?id_bum, ?bum_bh)
IF (SELECT count(1) FROM amt_bum WHERE bum_bh = ?bum_bh) > 1
SELECT 9 as ok
ELSE
SELECT 1 as ok
ENDTEXT
**————————————-
IF Transactions_error=.F.
SELECT My_mt_bum_fm_bum
IF sqlexec(myconnect,sql_tmp1,’My_mt_bum_fm_my_int_tm’)<=0
WAIT WINDOW "新增部门资料失败!" NOWAIT
Transactions_error=.t.
ELSE
SELECT My_mt_bum_fm_my_int_tm
DO case
CASE ok = 1
**正常
CASE ok = 9
MESSAGEBOX("此部门有重复不允许存盘!","")
Transactions_error=.t.
ENDCASE
use
ENDIF
ENDIF
**————————————-
IF Transactions_error=.t.
=SQLROLLBACK(myconnect)
ELSE
=SQLCOMMIT(myconnect)
WAIT WINDOW "数据存盘成功!" NOWAIT
ENDIF
= SQLSETPROP(myconnect, ‘Transactions’, 1) &&恢复自动事务处理
*********************************************************************************
Transactions_error=.f. &&事务过程失败标志
= SQLSETPROP(myconnect, ‘Transactions’, 2) &&启动手动事务处理
**————————————————————
TEXT TO sql_tmp1 NOSHOW
INSERT INTO amt_bum(id_bum, bum_bh)
values (?id_bum, ?bum_bh)
IF (SELECT count(1) FROM amt_bum WHERE bum_bh = ?bum_bh) > 1
SELECT 9 as ok
ELSE
SELECT 1 as ok
ENDTEXT
**————————————-
IF Transactions_error=.F.
SELECT My_mt_bum_fm_bum
IF sqlexec(myconnect,sql_tmp1,’My_mt_bum_fm_my_int_tm’)<=0
WAIT WINDOW "新增部门资料失败!" NOWAIT
Transactions_error=.t.
ELSE
SELECT My_mt_bum_fm_my_int_tm
DO case
CASE ok = 1
**正常
CASE ok = 9
MESSAGEBOX("此部门有重复不允许存盘!","")
Transactions_error=.t.
ENDCASE
use
ENDIF
ENDIF
**————————————-
IF Transactions_error=.t.
=SQLROLLBACK(myconnect)
ELSE
=SQLCOMMIT(myconnect)
WAIT WINDOW "数据存盘成功!" NOWAIT
ENDIF
= SQLSETPROP(myconnect, ‘Transactions’, 1) &&恢复自动事务处理
*********************************************************************************