首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Firedac运行SQL存储过程

使用Firedac运行SQL存储过程
EN

Stack Overflow用户
提问于 2015-03-12 07:56:52
回答 1查看 4.9K关注 0票数 3

我想弄清楚如何使用firedac运行存储过程

代码语言:javascript
复制
unit DataLayer.OilCommanderConnection;

interface

uses
  FireDAC.Phys.FB,
  Generics.Collections,
  Model.Sample,
  Model.Batch,

  FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error,
  FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool,
  FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MySQL, Data.DB,
  FireDAC.Comp.Client, FireDAC.Phys.MSSQL,
  FireDAC.DApt,
  FireDAC.Comp.UI
  ;

type
  TOilCommanderConnection = class
    strict private
    public
      Connection : TFDConnection;

      function GetSampleTypesForBatch(Batch : TBatch) : Boolean;  

      function Connect:Boolean;
      constructor Create;
      destructor Destroy; override;
  end;

implementation

uses
  SysUtils
  ;

function TOilCommanderConnection.Connect:Boolean;
var
    OK : Boolean;
begin
    OK := true;
    Connection := TFDConnection.Create(nil);
    try
        Connection.Params.LoadFromFile('MSSQL.ini');
    finally
        Result := OK;
    end;
end;

function TOilCommanderConnection.GetSampleTypesForBatch(Batch : TBatch) : Boolean;
var
    StoredProc : TFDStoredProc;
begin
    Connect;

    StoredProc := TFDStoredProc.Create(nil);
    try
        StoredProc.Connection := Connection;
        StoredProc.StoredProcName := 'GetSampleTypesForBatch';
        StoredProc.Prepare;

        StoredProc.FetchOptions.Items := StoredProc.FetchOptions.Items - [fiMeta];
        with StoredProc.Params do
        begin
            Clear;
            with Add do
            begin
                Name := 'BatchNo';
                ParamType := ptInput;
                DataType := ftString;
                Size := 6;
            end;            
        end;

        StoredProc.StoredProcName := 'GetSampleTypesForBatch';
        StoredProc.Prepare;
        StoredProc.Params[0].Value := Batch.RackNo;
        StoredProc.ExecProc;

        while not StoredProc.Eof do
        begin
            //StoredProc.FieldByName('').AsS
            StoredProc.Next;
        end;

    finally
        FreeAndNil(StoredProc);
    end;

    Result := true;
end;

constructor TOilCommanderConnection.Create;
begin
    inherited;
    Connection := TFDConnection.Create(nil);
end;

destructor TOilCommanderConnection.Destroy;
begin
    if Assigned(Connection) then FreeAndNil(Connection);

    inherited;
end;


end.

我收到一条错误消息,这是行的第一次出现。

StoredProc.Prepare;

这是一条信息

-“调试器例外通知” Project RefractiveIndexTests.exe引发异常类异常,其消息是“类{3E9B315B-F456-4175-A864-B2573C4A2201}的对象工厂”。要注册它,可以将组件TFDGUIxWaitCursor放到项目中。

我调用了这个函数

代码语言:javascript
复制
OilCommanderConnection.GetSampleTypesForBatch(batch);

来自一个测试项目。

我读到的教程没有解释如何处理这种情况。

正如错误消息所示,我尝试将TFDGUIxWaitCursor添加到我的项目中,但这并没有起到任何作用。我想知道这个问题是否与我将数据库连接逻辑保持在一个独立的单元中与我的主表单有关。我希望能够将我的用户界面与我的数据层分开。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-12 09:38:48

根据应用程序的类型,在“使用”子句中包含以下单元之一:

  • FireDAC.VCLUI.Wait -适用于VCL应用程序;
  • FireDAC.FMXUI.Wait -适用于FireMonkey应用程序;
  • FireDAC.ConsoleUI.Wait -用于控制台/非可视应用程序。
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29004499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档