//执行存储过程
function TSocialInsurance.MTS_ExecProc(const AiHosCode: WideString;
AiTermInfo, AiBuffer01, AiBuffer02: OleVariant;
out AoBuffer01,
AoBuffer02, AoMsg: OleVariant): OleVariant;
Var
i, iParamInLowBound, iParamInHighBound, iParamInCount, iParamOutCount : Integer;
do
Trans : Boolean;
rdTermInfo : TrdTermInfo;
MTS_StoredProc : TStoredProc;
sMsg : String;
begin
Result := -1;
SetTermInfo(AiTermInfo, rdTermInfo);
do
Trans := (AiBuffer02[0]='T');
//T处理事务/F不处理事务
Ifdo
Trans then
MTS_Database.StartTransaction;
MTS_StoredProc := TStoredProc.Create(Nil);
Try
Try
iParamInLowBound := VarArrayLowBound(AiBuffer01, 1);
iParamInHighBound := VarArrayHighBound(AiBuffer01, 1);
iParamInCount := iParamInHighBound - iParamInLowBound + 1;
With MTS_StoredProcdo
begin
Close;
DatabaseName := _DBName;
StoredProcName := UpperCase(AiBuffer02[1]);
Prepare;
iParamOutCount := ParamCount - iParamInCount;
For i := iParamInLowBound To iParamInHighBounddo
Params[i-iParamInLowBound].AsString := AiBuffer01;
ExecProc;
end;
//
AoBuffer01 := VarArrayCreate([0, iParamOutCount-1], VarOleStr);
For i := 0 To iParamOutCount-1do
AoBuffer01 := MTS_StoredProc.Params[iParamInCount + i].AsString;
If MTS_StoredProc.Params[iParamInCount + iParamOutCount-1].DataType = TFieldType(ftString) then
begin
sMsg := AoBuffer01[iParamOutCount-1];
Result := AoBuffer01[iParamOutCount-2];
End
else
begin
sMsg := AoBuffer01[iParamOutCount-2];
Result := AoBuffer01[iParamOutCount-1];
end;
AoMsg := sMsg;
//
If (do
Trans And MTS_Database.InTransaction ) then
MTS_Database.Commit;
UserLog(AiHosCode, rdTermInfo, AiBuffer02[1] + ':' + sMsg);
Except
On E:Exceptiondo
begin
If (do
Trans And MTS_Database.InTransaction ) then
MTS_Database.Rollback;
sMsg := AiBuffer02[1] + ':' + E.Message;
AoMsg := sMsg;
UserLog(AiHosCode, rdTermInfo, sMsg);
end;
end;
Finally
FreeAndNil(MTS_StoredProc);
end;
end;