【发布时间】:2020-05-05 18:07:23
【问题描述】:
我有一个带有日期时间参数的 FDStored 过程:
create procedure [dbo].[p_gl_for_ap]
(@inMode char(1), --I=Invoice, C=Check
@inId_Invoice integer, --reqd for invoice or credit memo maintenance, I
@inReg char(3), --reqd for check update or void, C
@inCheckNo integer, --reqd for check update or void, C
@inIs_Reversal char, --Y only if Invoice Delete or Check Void
@inDt_Rev datetime, --reqd only for reversal
@inDt datetime, --optl G/L tran date; normally null
@inId_glsrcjrn varchar(10),
@inId_create integer,
@ret integer output)
AS
declare....
我有一个使用存储过程的 FDStoredProc 组件: (以下是从组件到代码)
var
spGLForAP: TFDStoredProc;
spGLForAP := TFDStoredProc.Create(Self);
spGLForAP.Name := 'spGLForAP';
spGLForAP.Connection := dmConnect.cnxData;
with spGLForAP.FormatOptions.MapRules.Add do begin
SourceDataType := dtDateTime;
TargetDataType := dtDateTimeStamp;
end;
spGLForAP.StoredProcName := 'p_gl_for_ap';
with spGLForAP.ParamData.Add do begin
Position := 1;
Name := 'RESULT';
DataType := ftInteger;
ParamType := ptResult;
end;
with spGLForAP.ParamData.Add do begin
Position := 2;
Name := 'inMode';
DataType := ftFixedChar;
ParamType := ptInput;
Size := 1;
end;
with spGLForAP.ParamData.Add do begin
Position := 3;
Name := 'inId_Invoice';
DataType := ftInteger;
ParamType := ptInput;
end;
with spGLForAP.ParamData.Add do begin
Position := 4;
Name := 'inReg';
DataType := ftFixedChar;
ParamType := ptInput;
Size := 3;
end;
with spGLForAP.ParamData.Add do begin
Position := 5;
Name := 'inCheckNo';
DataType := ftInteger;
ParamType := ptInput;
end;
with spGLForAP.ParamData.Add do begin
Position := 6;
Name := 'inIs_Reversal';
DataType := ftFixedChar;
ParamType := ptInput;
Size := 1;
end;
with spGLForAP.ParamData.Add do begin
Position := 7;
Name := 'inDt_Rev';
DataType := ftDateTime;
FDDataType := dtDateTimeStamp;
NumericScale := 3;
ParamType := ptInput;
end;
with spGLForAP.ParamData.Add do begin
Position := 8;
Name := 'inDt';
DataType := ftDateTime;
FDDataType := dtDateTimeStamp;
NumericScale := 3;
ParamType := ptInput;
end;
with spGLForAP.ParamData.Add do begin
Position := 9;
Name := 'inId_glsrcjrn';
DataType := ftString;
ParamType := ptInput;
Size := 10;
end;
with spGLForAP.ParamData.Add do begin
Position := 10;
Name := 'inId_create';
DataType := ftInteger;
ParamType := ptInput;
end;
with spGLForAP.ParamData.Add do begin
Position := 11;
Name := 'ret';
DataType := ftInteger;
ParamType := ptInputOutput;
end;
我正在使用以下代码进行初始化:
function tdmAP.DoGLForAP(whichInvoice: integer; hasDelete: Boolean):
integer;
begin
spGLForAP.Params.ClearValues;
spGLForAP.ParamByName('inMode').AsString := 'I';
spGLForAP.ParamByName('inId_Invoice').AsInteger := whichInvoice;
spGLForAP.ParamByName('inReg').AsString := '';
spGLForAP.ParamByName('inCheckNo').AsInteger := 0;
if hasDelete then
begin
spGLForAP.ParamByName('inIs_Reversal').AsString := 'Y';
spGLForAP.ParamByName('indt_Rev').value := Date;
end
else
begin
spGLForAP.ParamByName('inIs_Reversal').AsString := 'N';
spGLForAP.ParamByName('indt_Rev').AsDateTime := Date;
end;
spGLForAP.ParamByName('indt').AsDateTime := Date;
spGLForAP.ParamByName('inId_glsrcjrn').AsString := '';
spGLForAP.ParamByName('inId_create').AsInteger := LoginRec.LoginUserId;;
try
spGLForAP.Prepare;
spGLForAP.Execute;
Result := spGLForAP.ParamByName('ret').AsInteger;
except
on E:Exception do
begin
ShowMessage('Error executing stored procedure p_gl_for_ap: ' + e.Message);
result := -1;
end;
end;
end;
但我不断收到来自 fireac 的错误消息,抱怨参数类型发生了变化: error on execute 我尝试过使用数据类型映射。 我试过使用这段代码: spGLForAP.ParamByName('indt_Rev').value = 0;
和 spGLForAP.ParamByName('indt_Rev').AsDateTime := 日期;
和 spGLForAP.ParamByName('indt_Rev').AsDateTime := 现在;
我还尝试将两个日期参数的数据类型从 ftTimeStamp 更改为 ftDateTime,在设置参数类型后重新准备查询,以及我能想到的任何其他事情。显然,我错过了一些东西......
使用 Delphi 10.2.2 Tokyo,针对 mssql server 2008R2。
注意:在这种特殊情况下,我试图将 inDt_rev 和 inDt 设置为 0。但似乎无法成功地将它们设置为任何值。
【问题讨论】:
-
为什么你在这里使用
dtDateTimeStamp,而你的列的数据类型是DateTime而不是TimeStamp?? -
您只是在参数名称中错过了
@前缀,并混淆了映射规则方向。对于参数,它类似于TargetDataType映射到SourceDataType。但我会简单地失去这个手动参数准备(不会弄乱内部使用的FDDataType,没有设置精度等等),让 FireDACPrepare从元数据中收集参数(只保留那个映射)。