你可以在客户端序列FireDAC数据集的DELTA , 将序列后的STREAM发送给中间件,
中间件的TFDQuery或TFDMemTable调用LOADFROMSTREAM()方法加载流,
然后调用ApplyUpdates()将数据保存进数据库中。
怎样转换TFDQuery或TFDMemTable的Delta为STREAM?
你将需要设置FDQuery或TFDMemTable的ResourceOptions.StoreItems 为 [siDelta]或 [siMeta, siDelta]。
然后调用SaveToStream()方法即可。
下面是演示用的代码:
var
Stream:TMemoryStream;
begin
// qryDataSource have 100 records,modified 1 record,so have 1
delta record
Stream := TMemoryStream.Create;
qryDataSource.ResourceOptions.StoreItems :=
[siData,siMeta,siDelta];
Stream := TMemoryStream.Create;
qryDataSource.SaveToStream(Stream);
//restore StoreItems
// qryDataSource.ResourceOptions.StoreItems :=
[siData,siMeta,siDelta];
Stream.Position := 0;
// remote app,transports stream by http
qryRemote.Close;
qryRemote.CachedUpdates := True;
qryRemote.UpdateOptions.KeyFields := 'ID';
qryRemote.UpdateOptions.UpdateTableName := 'BAS_COLORS';
qryRemote.SQL.Text := 'select * from BAS_COLORS where 1=0';
qryRemote.ResourceOptions.StoreItems := [siMeta,siDelta,siData];
//It load 100 reocrds,not only 1 delta record
qryRemote.LoadFromStream(Stream);
Stream.Free;
// commit and refresh
qryRemote.ApplyUpdates();
qryDataSource.CommitUpdates;
qryDataSource.Refresh;
end;