ApplyUpdates on REST with Firedac

白昼怎懂夜的黑 提交于 2019-12-06 15:18:31

I had similar problem and I got it resolved passing the table name to Query.UpdateOptions.UpdateTableName before ApplyUpdates.

  • Are you doing it inside "CriaQuery"?
  • What is your Delphi Version?

Here is my working code, I have tested it in Delphi XE7 e XE7 Update 1:

procedure TDBDM.ApplyDeltas(const ADeltaList: TFDJSONDeltas; const TableName: string);
var
  JSONDeltas: IFDJSONDeltasApplyUpdates;
  Query: TFDQuery;
begin
  JSONDeltas := TFDJSONDeltasApplyUpdates.Create(ADeltaList);
  Query := CreateQuery(TableName);
  try
    Query.UpdateOptions.UpdateTableName := TableName;
    JSONDeltas.ApplyUpdates(0, Query.Command);

    if JSONDeltas.Errors.Count > 0 then
    begin
      raise Exception.Create(JSONDeltas.Errors.Strings.Text);
    end;
  finally
    Query.Free;
  end;
end;

Notes

  • different from your code, Query.Open is not called.
  • TFDMemTable.CachedUpdates must be True

Edit: Added the client side code to applyUpdates

I call this method in TFDMemTable.AfterPost event.

    const
      CustomerTableName = 'CUSTOMER';

    procedure TCustomersDataModuleClient.ApplyUpdates;
    var
      Deltas: TFDJSONDeltas;
    begin
      Deltas := TFDJSONDeltas.Create;
      TFDJSONDeltasWriter.ListAdd(Deltas, CustomerTableName, CustomersMemTable);
      RestClientModule.CustomersMethodsClient.ApplyUpdates(Deltas);
      CustomersMemTable.CommitUpdates;
    end;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!