Submit 1 request to open multiple TDAMemDataTable

Hi,
Is it possible submit 1 request to open multiple TDAMemDataTable? For example, I don’t want to using 3 times of “Open” command. Is it possible like “Open[clientdatamodule.sp_userarrright, clientdatamodule.sp_sysright, clientdatamodule.sys_button]”

clientdatamodule.sp_UserAllRight.ParamByName(‘Lang’).Value := Sys_Language;
clientdatamodule.sp_UserAllRight.Open;
clientdatamodule.sp_SysRight.Close;
clientdatamodule.sp_SysRight.ParamByName(‘Lang’).Value := Sys_Language;
clientdatamodule.sp_SysRight.Open;
clientdatamodule.SYS_Button.Open;

Thanks!

Hi Timothy

yes, you can. Use DARemoteAdpater.Fill method. From documentation:

Fill(aTables: array of TDADataTable; aSaveCursor, aIncludeSchema, aAppendMode: Boolean);

Retrieves data from the server for all of the specified TDADataTables. In most scenarios you will not call this method yourself, but simply open the respective data table, causing data to be retrieved automatically. However, calling Fill yourself provides additional flexibility, including the option to fill multiple data tables at the same time, avoiding unnecessary server round-trips."

https://docs.dataabstract.com/API/Delphi/Classes/TDARemoteDataAdapter/

In your case, after you have setted the params, call this

clientdatamodule.RDA.Fill([clientdatamodule.sp_UserAllRight, clientdatamodule.sp_SysRight, clientdatamodule.SYS_Button])

Hi,

as Claudio already said, you can use

RemoteDataAdapter.Fill([table1,.. tableN]);

See example of usage in the ClonedSource sample:

procedure TClientDataModule.LoadData;
begin
  tbl_Orders.Close;
  tbl_Users.Close;
  // get 2 tables in one request :
  RemoteDataAdapter.Fill([tbl_Users,tbl_Orders]);
end;

In my version of DA (7.xxx) for Delphi, when using Fill() the AfterOpen of each table is not fired. Has this changed in later versions? Is there a workaround?

Hi,

Just tested - the OnAfterOpen event is fired after using RDA.Fill in DA10.

check that events aren’t disabled with table.DisableUserEventHandlers;.
you also can check DA code for DisableUserEventHandlers.

Thanks so much. I tested it OK.

Thanks again. But I want to know the performance of this method should be better than open 1 by 1. Right?

Hi,

table.Open uses RDA.Fill internally so

RDA.Fill([table1, table2]);

will show better performance than

table1.Open;
table2.Open;

Noted with thanks!

Hi,
Can RDA.FillWithDASql also using the same function?

Hi,

we have 3 overloads for this method:

    procedure FillWithDASql(aTable: TDADataTable; aSQL: String; aParameters: DataParameterArray); overload;
    procedure FillWithDASql(aTables: array of TDADataTable; aSQLs: array of String; aParameters: array of DataParameterArray); overload;
    procedure FillWithDASql(aTables: array of TDADataTable; aSQLs: array of String); overload;

Hi,
I tried that has the following error.

Hi,

looks like it cannot convert array of widestring to array of string automatically …

Hi,
I need to using widestring because it needs to support Chinese characters in SQL command.

Hi,
You are right. I changed widestring to string that work fine without error.