Datasnap data submitted by FIREDAC Tfdjsondeltas
FIREDAC's Tfdjsondeltas is equivalent to the delta of Clientdataset, appearing as a substitute for Clientdataset.delta.
Tfdjsondeltas is a collection of multiple dataset deltas that can submit modified data from multiple datasets to the database at once.
Service-Side code:
function Tservermethods1.savedata2 (const ACCOUNTNO, tablename:string; delta:tfdjsondeltas): Boolean;
Var
D:tfrmdb;
Lapply:ifdjsondeltasapplyupdates;
Begin
Result: = False;
if (Accountno = ") or (TableName =") or (delta = nil) Then
Exit;
D: = Getdbpool (Accountno). Lock;
If not Assigned (d) Then
Exit;
Try
Try
Settraceon (d);
D.qryopen.close;
D.qryopen.sql.clear;
D.qryopen.sql.text: = ' select * from ' + TableName + ' where 1=2 ';
D.qryopen.open;
Lapply: = tfdjsondeltasapplyupdates.create (delta);
Lapply.applyupdates (0, D.qryopen.command);
Result: = LApply.Errors.Count = 0;
Except
On E:exception do
Begin
Result: = False;
Log.writelog (' tservermethods1.savedata2 ' + e.message);
End
End
Finally
D.qryopen.close;
Getdbpool (Accountno). Unlock (d);
Settraceoff (d);
End
End
Client code:
Procedure Tform1.btnsave2click (Sender:tobject);
Var
Ldeltas:tfdjsondeltas;
Begin
If fdmemtable1.state in dseditmodes then//commit modifications to the memory table
Fdmemtable1.post
Else
Exit;
Ldeltas: = tfdjsondeltas.create;
Tfdjsondeltaswriter.listadd (Ldeltas, ' 1 ', FDMemTable1);
If methods. SaveData2 (' 0 ', ' t1 ', Ldeltas) then
Self.caption: = ' Save OK '
Else
Self.caption: = ' save fail ';
End
Datasnap data submitted by FIREDAC Tfdjsondeltas