Advertisement
pmcgee

FDMem -> Sqlite on disk

Sep 26th, 2019
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.36 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, FireDAC.Stan.Intf,
  8.   FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
  9.   FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.StorageBin,
  10.   FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async,
  11.   FireDAC.Phys, FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef,
  12.   FireDAC.Stan.ExprFuncs, FireDAC.VCLUI.Wait, FireDAC.DApt, FireDAC.Comp.Client,
  13.   FireDAC.Comp.DataSet, Vcl.Grids, Vcl.DBGrids, Vcl.StdCtrls;
  14.  
  15. type
  16.   TForm1 = class(TForm)
  17.     FDMemTable1: TFDMemTable;
  18.     DBGrid1: TDBGrid;
  19.     DataSource1: TDataSource;
  20.     FDConnection1: TFDConnection;
  21.     DBGrid2: TDBGrid;
  22.     DataSource2: TDataSource;
  23.     FDTable1: TFDTable;
  24.     Button1: TButton;
  25.     Button2: TButton;
  26.     FDSQLiteBackup1: TFDSQLiteBackup;
  27.     FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;
  28.     Button3: TButton;
  29.     procedure Button1Click(Sender: TObject);
  30.     procedure Button2Click(Sender: TObject);
  31.     procedure Button3Click(Sender: TObject);
  32.   private
  33.     { Private declarations }
  34.     procedure DoNothing;
  35.   public
  36.     { Public declarations }
  37.   end;
  38.  
  39. var
  40.   Form1: TForm1;
  41.  
  42. implementation
  43.  
  44. {$R *.dfm}
  45.  
  46.  
  47. procedure TForm1.DoNothing;
  48. begin
  49.      // Literally nothing.
  50. end;
  51.  
  52. procedure TForm1.Button1Click(Sender: TObject);
  53. begin
  54.      FDTable1.Close;
  55.      FDTable1.TableName := 'Copied Data';
  56.      FDTable1.FieldDefs.Clear;
  57.      FDTable1.FieldDefs.Assign(FDMemTable1.FieldDefs);
  58.      FDTable1.CreateTable(True);
  59.      FDTable1.CopyDataSet(FDMemTable1, [coStructure, coRestart, coAppend]);
  60.      FDTable1.Open;
  61.      DoNothing;
  62. end;
  63.  
  64. procedure TForm1.Button2Click(Sender: TObject);
  65. begin
  66.     //FDConnection1.DriverName := 'SQLite';
  67.     FDConnection1.Open;
  68.  
  69.     FDSQLiteBackup1.DatabaseObj  := FDConnection1.CliObj;
  70.     FDSQLiteBackup1.DestDatabase := 'C:\Users\...\data.sdb';
  71.     //FDSQLiteBackup1.DestMode := smCreate;
  72.     FDSQLiteBackup1.Backup;
  73.     ShowMessage('Backup Complete');
  74. end;
  75.  
  76.  
  77. procedure TForm1.Button3Click(Sender: TObject);
  78. begin
  79.     FDTable1.Close;
  80.     ShowMessage('Backup Check');
  81.     FDConnection1.Close;
  82.     FDConnection1.Params.Database := 'C:\Users\...\data.sdb';
  83.     FDConnection1.Open;
  84.     FDTable1.Open('COPIED DATA');
  85. end;
  86.  
  87. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement