JSON序列——根据JSON生成事务性SQL2

时间:2024-07-21 20:35:26

JSON序列——根据JSON生成事务性SQL2

procedure TForm1.Button3Click(Sender: TObject);
begin
var json:string:=''+
'{'+
'"deltas":'+
'['+
'{'+
'"table":"tunit",'+
'"rows":'+
'['+
'{"action": "modify", "original": {"unitid":"11","unitname":"个"}, "current": {"unitid":"11","unitname":"中"}},'+
'{"action": "delete", "original": {"unitid":"66","unitname":"国"}},'+
'{"action": "insert", "current":{"unitid":"13","unitname":"人"}}'+
']'+
'}'+
']'+
'}';
var serial: TynJsonCross := TynJsonCross.Create;
try
Memo1.Text := serial.JsonsToSql(json);
finally
serial.DisposeOf;
end;
end;

  生成的事务性SQL:

update tunit set unitid='11',unitname='中' where unitid='11' and unitname='个'
delete from tunit where unitid='66' and unitname='国'
insert into tunit (unitid,unitname) values ('13','人' )