且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Datasnap \ FireDAC:查询执行两次

更新时间:2023-02-05 19:43:18

我使用Embarcadero指示的技术标准.

I use technical standards that the Embarcadero indicates.

我意识到的是:

1) TFDJSONInterceptor.ItemListToJSONObject 例程中的单元 Data.FireDACJSONReflect 具有以下代码块:

1) The unit Data.FireDACJSONReflect in TFDJSONInterceptor.ItemListToJSONObject routine has this block of code:

if not LActive then
   LDataSet.Active := True;
try
   LJSONDataSet := DataSetToJSONValue(LDataSet);
   // Use AddPair overload that will accept blank key
   AJSONObject.AddPair(TJSONPair.Create(LPair.Key, LJSONDataSet))
finally
   if not LActive then
      LDataSet.Active := False;
 end;

看到他一次激活查询,导致序列增加.

See he activates the query once, causing the sequence to be incremented.

但是在 DataSetToJSONValue(LDataSet)例程中;该代码块是:

But in DataSetToJSONValue (LDataSet) routine; This code block is:

if  (LMemTable = nil) then
    begin
    LMemTable := TFDMemTable.Create(nil);
    LAdapter := TFDTableAdapter.Create(nil);
    LMemTable.Adapter := LAdapter;
    LAdapter.SelectCommand := ADataSet.Command;
    LMemTable.Active := True;
    end;

请参阅他再次激活查询,在该查询中该序列再次递增.

See he again activates the query, where the sequence is again incremented.

现在我不知道我是否犯了一个错误或它是否是一个错误,但是我创建了一个继承自 TFDMemTable 的新类,并认为该类中存在一些错误,但是进行了测试使用 TFDMemTable 组件(FireDAC的标准组件),然后甚至两次激活任何查询,因为代码没有将这两个类中的任何一个视为 TFDCustomMemTable ,即使它们直接从此类继承而来.

Now I do not know if I made a mistake or if it is a bug, but I created a new class inherited from TFDMemTable and thought there was some mistake in this class, but did a test with TFDMemTable component, standard component of FireDAC, and even then the activation of any query is performed twice, because the code does not consider any of these two classes, as a TFDCustomMemTable, even though they were inherited directly from this class.

我注释了 DataSetToString例程(const ADataSet:TFDAdaptedDataSet)的代码,如下所示:

I commented the code of DataSetToString routine (const ADataSet: TFDAdaptedDataSet) that looked like this:

LMemTable   := nil;
LAdapter    := nil;
try
    //if  (ADataSet is TFDCustomMemTable) then
  LMemTable := TFDCustomMemTable(ADataSet);

  {if  (LMemTable = nil) then
      begin
      LMemTable := TFDMemTable.Create(nil);
      LAdapter := TFDTableAdapter.Create(nil);
      LMemTable.Adapter := LAdapter;
      LAdapter.SelectCommand := ADataSet.Command;
      LMemTable.Active := True;
      end;}

通过这种方式解决了问题,并且应用程序的性能似乎有所提高.

In this way the problem was solved, and the performance of the application seemed to have improved.