Datasnap \ FireDAC:查询执行两次 [英] Datasnap\FireDAC: Query executed twice

查看:214
本文介绍了Datasnap \ FireDAC:查询执行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:

1)我使用Delphi XE7开发了一个三层系统.

1) I use Delphi XE7 to develop a 3-layer system.

2)服务器层,使用REST使用datasnap创建.

2) The server layer, created with datasnap using REST.

3)我将Firebird用作数据库,并使用FireDAC进行访问.

3) I use Firebird as database and the access is performed with FireDAC.

4)我有一个值为 01 的序列.

4) I have a sequence with value 01.

5)我在服务器层创建了以下查询:

5) I created the following query in the server layer:

从rdb $数据库中选择GEN_ID(gen_my_sequence,1)

6)在服务器上返回查询中的序列值是: 02 .

6) On the server returns the sequence value in the query is: 02.

7)但是客户端层返回03.

7) But the client layer returns 03.

我不明白为什么查询要执行两次.

I do not understand why the query is executed twice.

有人可以帮助我吗?

推荐答案

我使用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.

这篇关于Datasnap \ FireDAC:查询执行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆