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