|
楼主 |
发表于 2007-1-17 13:10:34
|
显示全部楼层
5、6测试:事务不回滚
存储过程代码:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Alter procedure sp_test
@Err varchar(100) output
as
update TTest
Set F = '修改成功'
set @Err = '失败:存储过程字符串-测试'
--RaisError( '失败:存储过程字符串-测试', 16, 1) --抛错也不回滚
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
平台代码:
procedure TMainForm.Button1Click(Sender: TObject);
var
lStoredProc:TStoredProc;
lTransactionHandle :TTransactionHandle;
iReturn:integer;
Result: string;
begin
iReturn := -1;
Result :='';
lStoredProc := nil;
lStoredProc:=TStoredProc.Create(lStoredProc);
try
lStoredProc.ConnectionString:='DATABASEURL=Biz:\SDH_SMIS\SDH_SMISDB.Database';
lStoredProc.StoredProcName:='SP_Test';
lStoredProc.Params.Clear;
lStoredProc.Params.CreateParam(TFieldType.ftInteger,'@RETURN_VALUE',TParamType.ptResult);
lStoredProc.Params.CreateParam(TFieldType.ftString,'@Err',TParamType.ptoutput );
lStoredProc.Close;
with lStoredProc.Connection.Transaction do
begin
lTransactionHandle := Start(True);
try
lStoredProc.Execute;
//lStoredProc.Active := true ;
iReturn:=lStoredProc.Params.ParamByName('@RETURN_VALUE').AsInteger;
if iReturn<>0 then
begin
Result:=lStoredProc.Params.ParamByName('@Err').AsString;
Rollback(lTransactionHandle);
end
else
begin
Commit(lTransactionHandle);
Result:='执行存储过程成功!';
end
except
Rollback(lTransactionHandle);
Result:='执行存储过程失败!';
end;
end;
finally
lStoredProc.Close;
lStoredProc.free;
end;
Forms.Application.MessageBox(Result, '系统提示', 0);
end; |
|