标签:begin end RawUTF8 mormot json mtable dtable 主从
mormot json主从表
//cxg 2021-6-2 mormot json主从表 unit service.tables; interface uses mormot, sysutils, yn.log, yn.Unidac, yn.UnidacPool, SynCrtSock, Classes, SynCommons, SynVirtualDataSet; type TMasterTable = class(mORMot.TSQLRecord) //主表 private fBillId: RawUTF8; fOperator: RawUTF8; published property BillId: RawUTF8 read fBillId write fBillId; property operator: RawUTF8 read fOperator write fOperator; end; TDetailTable = class(mORMot.TSQLRecord) //从表 private fProductId: RawUTF8; fProductName: RawUTF8; published property ProductId: RawUTF8 read fProductId write fProductId; property ProductName: RawUTF8 read fProductName write fProductName; end; function serial(const url: sockstring): SockString; procedure deserial(const json: string); implementation procedure deserial(const json: string); var mtable: TMasterTable; dtable: TDetailTable; js: TDocVariantData; m, d, tmp: string; begin js.InitJSON(json); m := utf8toansi(js.GetValueByPath(['mtable'])); //主表 mtable := TMasterTable.CreateAndFillPrepare(m); while mtable.FillOne do begin tmp := mtable.BillId; tmp := mtable.operator; end; mtable.Free; d := utf8toansi(js.GetValueByPath(['dtable'])); //从表 dtable := TDetailTable.CreateAndFillPrepare(d); while dtable.FillOne do begin tmp := dtable.ProductId; tmp := dtable.ProductName; end; dtable.Free; end; function serial(const url: sockstring): SockString; //get url: /tables/{accountno} var i: Integer; mTable: TMasterTable; dTable: TDetailTable; m, d: string; jo: Variant; begin m := '['; for i := 1 to 2 do //生成主表数据 begin TMasterTable.AutoFree(mTable); mTable.BillId := inttostr(i); mtable.operator := 'name' + inttostr(i); if i < 2 then m := m + mtable.GetJSONValues(true, false, soselect) + ',' else m := m + mtable.GetJSONValues(true, false, soselect); end; m := m + ']'; d := '['; for i := 1 to 2 do //生成从表数据 begin TDetailTable.AutoFree(dTable); dTable.ProductId := inttostr(i); dtable.ProductName := 'p' + inttostr(i); if i < 2 then d := d + dtable.GetJSONValues(true, false, soselect) + ',' else d := d + dtable.GetJSONValues(true, false, soselect); end; d := d + ']'; TDocVariant.New(jo); jo.mTable := _JSon(m); //生成主从表数据 jo.dTable := _JSon(d); result := ansitoutf8(VariantSaveJSON(jo)); //{"mTable":[{"BillId":"1","operator":"name1"},{"BillId":"2","operator":"name2"}],"dTable":[{"ProductId":"1","ProductName":"p1"},{"ProductId":"2","ProductName":"p2"}]} end; end.
标签:begin,end,RawUTF8,mormot,json,mtable,dtable,主从 来源: https://www.cnblogs.com/hnxxcxg/p/14840997.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。