TFDSQLiteBackup control with two or three lines of code to complete the backup Sqlite database.
Procedure TForm1.Button1Click (Sender: TObject); the begin {initialize certain} FDConnection1.DriverName: = 'the SQLite' ; FDConnection1.Params.Add ( 'Database = C: \ the Temp \ FDDemo_Back.sdb' ); // if not specified this path is the backup to memory FDConnection1.Open (); {backup C: \ the Temp \ FDDemo.sdb} FDSQLiteBackup1.DriverLink: = FDPhysSQLiteDriverLink1; FDSQLiteBackup1.Database: = 'C: \ the Temp \ FDDemo.sdb' ; // support URL FDSQLiteBackup1.DestDatabaseObj: = FDConnection1.CliObj; FDSQLiteBackup1.Backup; End ;
After some operations, the database may be fragmented, then the optimization can be performed by Sweep method TFDSQLiteValidate control.
Common Code {} the begin FDSQLiteValidate1.DriverLink: = FDPhysSQLiteDriverLink1; FDSQLiteValidate1.Database: = 'C: \ the Temp \ FDDemo.sdb' ; FDSQLiteValidate1.Sweep; // can auto_vacuum = FULL connection parameter; (0: NONE, 1: FULL, 2: INCREMENTAL) specify automatic cleanup End ;
To avoid mistakes in database operations can be rolled back by the transaction (Transaction); it should be a means in common use.
Common Code {} the begin FDConnection1.StartTransaction; // start a transaction the try {code that might go wrong} FDConnection1.Commit; // submit the except FDConnection1.Rollback; // rollback End ; End ;