简体   繁体   中英

How to get delta dataset from TFDJSONDeltas for creating server side UpdateSQL command dynamically

I am doing a test with Delphi DataSnap REST application. With wizard I can get a good starting point to have a working application between Server and Client. Program codes are shown here.

procedure TServerMethodsMain.ApplyDataSetChanges(const ATableName: String;
                                                     const ADeltaList: TFDJSONDeltas);
    var
      LApply: IFDJSONDeltasApplyUpdates;
    begin
      LApply := TFDJSONDeltasApplyUpdates.Create(ADeltaList);

      DataModule1.FDQuery1.UpdateOptions.UpdateTableName := ATableName;

      LApply.ApplyUpdates(ATableName, DataModule1.FDQuery1.Command);

      if LApply.Errors.Count > 0 then
        raise Exception.Create(LApply.Errors.Strings.Text);
    end;

Now here is one issue about data update in server side:

All fields values will be updated together and all OLDVALUEs will be used as reference to identify original record. So, if another user changed one or more values in the same record, client application will generate an error.

I would like to know how to get delta records from TFDJSONDeltas. If so, it will be possible to create an UPDATE SQL with modified values only. And also, record can be identified with primary/key field only.

Thanks.

FireDAC is perfectly capable for generating UPDATE SQL you want. It has lot of options!

Specify FDQuery1.UpdateOptions.KeyFields property and leave FDQuery1.UpdateOptions.UpdateMode to default value upWhereKeyOnly.

Also, Delphi ships with lot of FireDAC samples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM