With the Tfdsqlitebackup control, two or three lines of code can complete the backup of the Sqlite database.
procedure Tform1.button1click (sender:tobject);
begin
{Initialize target} first}
Fdconnection1.drivername: = ' SQLite ';
FDCONNECTION1.PARAMS.ADD (' Database=c:\temp\fddemo_back.sdb '); If you do not specify this path, you are backing up to memory
Fdconnection1.open ();
{Backup C:\Temp\FDDemo.sdb}
Fdsqlitebackup1.driverlink: = FDPhysSQLiteDriverLink1;
Fdsqlitebackup1.database: = ' C:\Temp\FDDemo.sdb '; Support Url
fdsqlitebackup1.destdatabaseobj: = fdconnection1.cliobj;
Fdsqlitebackup1.backup;
end;
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Delphi/
After some action, the database may be fragmented, and optimizations can be performed through the Sweep method of the Tfdsqlitevalidate control.
{Common Code} begin
Fdsqlitevalidate1.driverlink: = FDPhysSQLiteDriverLink1;
Fdsqlitevalidate1.database: = ' C:\Temp\FDDemo.sdb ';
end;
In order to avoid errors in database operation, it can be rolled back and forth through transaction (Transaction); It should be a universally used means.
{Common Code} begin
Fdconnection1.starttransaction; Start a transaction
try{The code}fdconnection1.commit that may be wrong; Submit
exceptfdconnection1.rollback;//Roll back end
;
end;
Author:cnblogs in case