我正在使用德瓦特氏MyDac和MySQL服务器5.0.41。下面是关于使用TMyConnection.ExecProc执行存储过程的文档中的一节:
注意:与存储过程不同的是,存储函数返回内部通过结果参数获得的结果值。您将不再需要在Params数组中提供匿名值来描述函数的结果。存储的函数结果是从Params索引属性或使用ParamByName(“结果”)方法调用获得的。
他们还举例说明了如何执行存储的函数:
aStringVariable1 := TMyConnection.ExecProc('StoredFunctionName',['Param1','Param2']); aStringVariable2 := TMyConnection.ParamByName('Result').AsString;
通过遵循这些示例,我对存储函数的执行将返回变量中的Param1,查询浏览器中函数的执行将返回正确的结果。在MyDAC中使用TMyConnection或TMyStoredProc执行存储函数的正确方法的任何指针都将不胜感激。
提前谢谢。
发布于 2010-09-14 08:02:52
下面是我们用来调用存储过程的代码--希望它有帮助。
function TDbControl.DatabaseStoredProc(FConnectionsAddr: integer; SpName: string;var Params: TDAParams): boolean;
var
MyStoredProc: TMyStoredProc;
PramsTxt: String;
Idx, Idx2: Integer;
begin
result := False;
MyStoredProc := nil;
try
try
MyStoredProc := TMyStoredProc.Create(nil);
MyStoredProc.Connection := TMyConnection(FConnectionsAddr);
MyStoredProc.StoredProcName := SpName;
MyStoredProc.ParamCheck := False;
if assigned(Params) then
begin
for Idx := 0 to Params.Count - 1 do
begin
MyStoredProc.ParamByName(Params[Idx].Name).DataType := Params[Idx].DataType;
MyStoredProc.ParamByName(Params[Idx].Name).Value := Params[Idx].Value;
end;
end;
MyStoredProc.Execute;
if assigned(Params) then
begin
for Idx := 0 to Params.Count - 1 do
begin
if (Params[Idx].ParamType = ptOutput ) then
Params[Idx].Value := MyStoredProc.ParamByName(Params[Idx].Name).Value;
end;
end;
result := True;
except
on E: Exception do
begin
PramsTxt := '';
if assigned(Params) then
begin
for Idx2 := 0 to Params.Count - 1 do
begin
PramsTxt := PramsTxt + Params.Items[Idx2].Name + '=' + Params[Idx2].AsString + ',';
end;
end;
LogText(FConnectionsAddr, 'DatabaseStoredProc Err:' + E.Message + ' SpName:' + SpName + ' Prams:' + PramsTxt);
raise ;
end;
end;
finally
FreeAndNil(MyStoredProc);
end;
end;https://stackoverflow.com/questions/3704173
复制相似问题