Fetching and Populating Questions (FireDAC)Go Up to FAQ (FireDAC)This topic contains a list of qu

Fetching and Populating Questions (FireDAC)

Go Up to FAQ (FireDAC)

This topic contains a list of questions and answers related to fetching records and populating datasets.

Q1: Does FireDAC provide fast forward-only, read-only access to the result dataset?

A: Set FDQuery.FetchOptions:

Q2: How can I append multiple result sets to a FDQuery or a FDMemTable?

A: The following approach with the client dataset to hold multiple result sets:

  begin loop
    // run SqlQuery with new params
    ...
    ClientDataset.AppendData(SqlQuery.Data)
    ...
  end loop

may be replaced with the single TFDQuery. For example:

  // initial open and fetch
  FDQuery1.Params[0].AsInteger := 1;
  FDQuery1.Open;

  // reexecute command, fetch rows again and append them
  // to the existing rows
  FDQuery1.Command.Close;
  FDQuery1.Params[0].AsInteger := 2;
  FDQuery1.Command.Open;
  FDQuery1.FetchAgain;
  FDQuery1.FetchAll;

  // reexecute again with different parameter value
  FDQuery1.Command.Close;
  FDQuery1.Params[0].AsInteger := 3;
  FDQuery1.Command.Open;
  FDQuery1.FetchAgain;
  FDQuery1.FetchAll;

Q3: How can I execute a query and append its result set to an existing dataset, without inserting these records into the database?

A: See the TFDDataSet.FetchAgain method description. Alternatively, you can execute a SQL command that will fetch the additional records into an existing dataset:

FDCommand1.CommandText := 'select ... from ... where id= :id';
FDCommand1.Open;
FDCommand1.Fetch(ADQuery1.Table);
FDCommand1.Close;

Q4: My query returns 800 records, but RecordCount returns 50. What is wrong?

A: By default, the RecordCount shows the number of records in the dataset record's cache. For more information about record counting modes, see the FetchOptions.RecordCountMode property.

50 is the default rowset size. This is the number of records FireDAC will fetch at a single request. So, right after opening, the dataset will have <= 50 records, that is what RecordCount is showing. When you navigate through the dataset, it will fetch additional rowsets and the number of records may grow.

To show the total number of records that the query returns, you may do one of the following:

  • Perform ADQuery1.FetchAll. As a result, all records will be fetched and RecordCount will show their number;
  • Set FetchOptions.RecordCountMode to cmTotal. Note that this may lead to performance degradation, as FireDAC will perform an additional SELECT COUNT(*) query for each SELECT query.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值