博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FIREDAC的TFDJSONDataSets和TFDJSONDeltas查询和提交数据
阅读量:7238 次
发布时间:2019-06-29

本文共 2505 字,大约阅读时间需要 8 分钟。

 

服务端代码:

uses 

Data.FireDACJSONReflect,

FireDAC.Stan.Storage, FireDAC.Stan.StorageBin, FireDAC.Stan.StorageJSON,
FireDAC.Stan.StorageXML;

1)查询

function TServerMethods1.QuerySql2(const accountNo, sql: string): TFDJSONDataSets;

var
d: TfrmDB;
begin
Result := nil;
if (accountNo = '') or (sql = '') then
Exit;
d := GetDBPool(accountNo).Lock;
if not Assigned(d) then
Exit;
try
try
d.qryOpen.Close;
d.qryOpen.sql.Clear;
d.qryOpen.sql.Text := sql;
d.qryOpen.Open;
Result := TFDJSONDataSets.Create;
TFDJSONDataSetsWriter.ListAdd(Result, '1', d.qryOpen);
except
on e: Exception do
begin
Result := nil;
Log.WriteLog('TServerMethods1.QuerySql2 ' + e.Message);
end;
end;
finally
d.qryOpen.Close;
GetDBPool(accountNo).Unlock(d);
end;
end;

2)提交

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
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);
end;
end;

客户端代码:

uses

FireDAC.Stan.StorageJSON, FireDAC.Stan.StorageBin

,Data.FireDACJSONReflect, FireDAC.Stan.StorageXML ,FireDAC.Stan.Storage;

切记:

FDMemTable1.CachedUpdates := True;

1)查询

procedure TForm1.btnQueryClick(Sender: TObject);

var
r: TServerMethods1Client;
LDataSetList: TFDJSONDataSets;
LDataSet: TFDDataSet;
begin
r := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
LDataSetList := r.QuerySql2('0', 'select * from t1');
LDataSet := TFDJSONDataSetsReader.GetListValueByName(LDataSetList,'1');
FDMemTable1.Close;
FDMemTable1.AppendData(LDataSet);
r.Free;
end;

2)提交

procedure TForm1.btnSaveClick(Sender: TObject);

var
r: TServerMethods1Client;
d: TFDJSONDeltas;
begin
r := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
if FDMemTable1.State in dsEditModes then
FDMemTable1.Post;
if FDMemTable1.ChangeCount = 0 then
Exit;
d := TFDJSONDeltas.Create;
TFDJSONDeltasWriter.ListAdd(d, '1', FDMemTable1);
if r.SaveData2('0', 't1', d) then
Self.Caption := 'save ok'
else self.Caption := 'save fail';
r.Free;
end;

转载地址:http://twgfm.baihongyu.com/

你可能感兴趣的文章
stl非变易算法(二)
查看>>
java 关键字 transient
查看>>
Ubuntu配置和修改IP地址
查看>>
转载:如何设计一个可扩展的用户登录系统
查看>>
python对redis的常用操作 上 (对列表、字符串、散列结构操作)
查看>>
I.MX6 i2c_data_write_byte ioctl error: I/O error
查看>>
myisam MySQL 锁问题
查看>>
为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录...
查看>>
告诉你一个真实的OpenStack:都谁在用,用来干什么?
查看>>
在idea中maven项目jdk编译version总是跳到1.5
查看>>
理解与应用css中的display属性
查看>>
升级openssl环境至openssl-1.1.0c
查看>>
javaScript判断浏览器类型
查看>>
SQL注入之SQLmap入门
查看>>
Hibernate缓存研究
查看>>
Cesium原理篇:3D Tiles(1)渲染调度
查看>>
neuroph Perceptron Sample
查看>>
关于navicat连接oracle 报 ORA-12737 set CHS16GBK错误的解决方案
查看>>
MEP自定义参数化风机盘管族
查看>>
(android控件)巧用background属性,实现图片可选择效果
查看>>