Sqlite (vii) under Delphi FIREDAC Backup, optimization, and transactions (Transaction)

Source: Internet
Author: User
Tags sqlite sqlite database backup

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

Related Article

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.