Serialization and restoration of Adodataset.recordset (reproduced)

Source: Internet
Author: User

Data set serialization function Recordsettoxml (const Recordset: _recordset): String;var rs:variant;  Stream:tstringstream;begin Result: = ";  If Recordset = nil then Exit;  Stream: = Tstringstream.create (');    Try RS: = Recordset; ADPERSISTADTG saved as a binary file adPersistXML saved as XML. The binary transfer efficiency is higher than the XML RS.    Save (Tstreamadapter.create (stream) as IUnknown, ADPERSISTADTG);    Stream.position: = 0;  Result: = stream.datastring;  Finally Stream.free; End;end; Strxml: = Recordsettoxml (Fadoquery.recordset);//Compress the data, note the compression ratio do not select the highest iscompress: = Eclcompressandencryptstring (StrXML,      Outstr, PassWord, CompressionLevel, false); If Iscompress then begin//formatted as 16 binary string Compressstr: = Strtoformat (PChar (OUTSTR), Length (OUTSTR), fmthex);//Tell to receive        The length of the data to be sent AThread.Connection.WriteInteger (length (COMPRESSSTR));        Stream: = Tstringstream.create (COMPRESSSTR);//Send Data AThread.Connection.WriteStream (Stream, True); Stream.free; Restore DataSet function Recordsetfromxml (const xml:string): _reCordset;var rs:variant;  Stream:tstringstream;begin Result: = nil;  If XML = ' then Exit ';    Try Stream: = Tstringstream.create (XML);    Stream.position: = 0; RS: = Createoleobject (' ADODB.    Recordset '); Rs.    Open (Tstreamadapter.create (Stream) as IUnknown);  Result: = IUnknown (RS) as _recordset;  Finally Stream.free; End;end;         Procedure Ttcpadoclient.open (value:string); var hexstr, decstr:string;  Stream:tstringstream;  Lenbuf:integer;begin Value: = uppercase (value);  Fidtcpclient.writeln (' selectsql: ' + Value);  Fcommand: = Value;  Application.processmessages;  If not fidtcpclient.connected then exit;  Lenbuf: = Fidtcpclient.readinteger;  Stream: = Tstringstream.create (');    try//Read Data Fidtcpclient.readstream (Stream, Lenbuf, False);    Hexstr: = Formattostr (PChar (stream.datastring), Length (stream.datastring), fmthex);//Extract data    Ecldecompressanddecryptstring (Hexstr, Decstr, PassWord); application.processmessages;//Restore DataSet Frecordset: = RecordsetfromxML (DECSTR);  Finally Stream.free;  End RecordSet: = Frecordset;end;

  

Serialization and restoration of Adodataset.recordset (reproduced)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.