Use fdmemtable instead of Clientdataset to resolve errors that are updated with CDs multiple times for MySQL5.6 (including) versions

Source: Internet
Author: User

Read MySQL saved to fdmemtable

Procedure Tform3.btnopen1click (Sender:tobject);
Var
Stream, Stream2:tmemorystream;
Buf:tbytes;
Begin
Stream: = Tmemorystream.create;
Try
Try
Fdquery1.close;
FDQuery1.SQL.Clear;
Fdquery1.open (' select * from Glfmkhjl ');
Fdquery1.savetostream (stream, tfdstorageformat.sfbinary);

Stream is converted to buffer, and the buffer is transferred over a network sub-packet
Stream. Position: = 0;
SetLength (BUF, stream. Size);
Stream. Read (Buf[0], stream. Size);

Buffer converted to stream
STREAM2: = tmemorystream.create;
Stream2. Write (Buf[0], Length (BUF));
Stream2. Position: = 0;

Fdmemtable1.cachedupdates: = True;
Fdmemtable1.close;
Fdmemtable1.loadfromstream (stream2, tfdstorageformat.sfbinary);
Except
On E:exception do
Begin
ShowMessage (' ERROR: ' + e.message);
End
End
Finally
Fdquery1.close;
Stream. Free;
Stream2. Free;
End
End

Edit data from fdmemtable, save to MySQL via Fdquery

Procedure Tform3.btnsaveclick (Sender:tobject);
Var
Stream, Stream2:tmemorystream;
Buf:tbytes;
Begin
Stream: = Tmemorystream.create;
Try
Try
If fdmemtable1.state in [Dsinsert, DsEdit] Then
Fdmemtable1.post;
If Fdmemtable1.changecount = 0 Then
Exit;
FDMemTable1.ResourceOptions.StoreItems: = [Sidelta, Simeta]; Commit only the modified data
Fdmemtable1.savetostream (stream, tfdstorageformat.sfbinary);
Stream is converted to buffer, and the buffer is transferred over a network sub-packet
Stream. Position: = 0;
SetLength (BUF, stream. Size);
Stream. Read (Buf[0], stream. Size);

Buffer converted to stream
STREAM2: = tmemorystream.create;
Stream2. Write (Buf[0], Length (BUF));
Stream2. Position: = 0;

Fdquery1.close;
Fdschemaadapter1.close;
Fdquery1.schemaadapter: = FDSchemaAdapter1;
Fdquery1.cachedupdates: = True;
FDQuery1.SQL.Clear;
FDQuery1.sql.Text: = ' select * from GLFMKHJL where 1=2 ';
Fdquery1.open;
Fdschemaadapter1.loadfromstream (stream2, tfdstorageformat.sfbinary);
ShowMessage (FDSchemaAdapter1.ApplyUpdates.ToString);//Return 0 success
Except
On E:exception do
Begin
ShowMessage (' ERROR: ' + e.message);
End
End
Finally
Fdquery1.close;
Stream. Free;
Stream2. Free;
End
End

Use fdmemtable instead of Clientdataset to resolve errors that are updated with CDs multiple times for MySQL5.6 (including) versions

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.