我在Firebird数据库中定义了这个存储过程:
create or alter procedure GET_MSG (
IDLNG smallint,
IDMSG integer)
returns (
MSG varchar(200) character set UTF8)
as
begin
IF (:IDMSG > 40000) THEN
BEGIN
IF (:IDLNG = 1) THEN
BEGIN
SELECT NOMBRE01 FROM XMSG2 WHERE ID_XMSG2 = :IDMSG INTO :MSG;
EXIT;
END
IF (:IDLNG = 2) THEN
BEGIN
SELECT NOMBRE02 FROM XMSG2 WHERE ID_XMSG2 = :IDMSG INTO :MSG;
EXIT;
END
END ELSE
BEGIN
IF (:IDLNG = 1) THEN
BEGIN
SELECT NOMBRE01 FROM XMSG WHERE ID_XMSG = :IDMSG INTO :MSG;
EXIT;
END
IF (:IDLNG = 2) THEN
BEGIN
SELECT NOMBRE02 FROM XMSG WHERE ID_XMSG = :IDMSG INTO :MSG;
EXIT;
END
END
end
我使用此代码从Firedac调用此存储过程:
SPGeneric.StoredProcName:= 'GET_MSG';
SPGeneric.FetchOptions.Items:= SPGeneric.FetchOptions.Items - [fiMeta];
SPGeneric.Prepare;
with SPGeneric.Params do begin
Clear;
with Add do begin
Name:= 'IDLNG';
ParamType:= ptInput;
DataType:= ftSmallint;
Value:= IdLan;
end;
with Add do begin
Name:= 'IDMSG';
ParamType:= ptInput;
DataType:= ftInteger;
Value:= Id;
end;
with Add do begin
Name:= 'MSG';
ParamType:= ptOutput;
DataType:= ftString;
Size:= 200;
end;
end;
SPGeneric.ExecProc;
result:= VarToStr(SPGeneric.Params[2].Value);
问题在于,当我使用正确的参数调用此代码(在Firebird中检查)时,结果始终为null。这段代码有什么问题吗?感谢
这是可行的代码:
SPGeneric.StoredProcName:= 'GET_MSG';
SPGeneric.FetchOptions.Items:= SPGeneric.FetchOptions.Items - [fiMeta];
SPGeneric.Params.Clear;
with SPGeneric.Params.Add do begin
Name:= 'IDLNG';
ParamType:= ptInput;
DataType:= ftSmallint;
end;
with SPGeneric.Params.Add do begin
Name:= 'IDMSG';
ParamType:= ptInput;
DataType:= ftInteger;
end;
with SPGeneric.Params.Add do begin
Name:= 'MSG';
ParamType:= ptOutput;
DataType:= ftWideString;
Size:= 200;
end;
SPGeneric.Prepare;
SPGeneric.Params[0].Value:= IdLan;
SPGeneric.Params[1].Value:= Id;
SPGeneric.ExecProc;
result:= VarToStr(SPGeneric.Params[2].Value);
答案 0 :(得分:2)
调用Prepare后,应用程序无法更改命令参数数据类型和大小。否则,在下一个Execute / ExecSQL / ExecProc / Open调用期间,将引发异常。 建议在准备呼叫之前设置参数。
您已选择不使用
自动填充参数信息next()
因此,由于您是手动定义参数,因此在>强调next()
之前应该执行此操作。