Search code examples
delphidelphi-xe4firedac

FireDAC SQLite backup saves no data


When executing the following code, the database file only has table names. No field names or actual data seems to be getting copied over.

procedure TdbModule.BackupDB();
begin
  ADConnection1.Connected := True;
  ADSQLiteBackup1.DatabaseObj := ADConnection1.CliObj;
  ADSQLiteBackup1.DestDatabase := 'd:\dan.sdb';
  ADSQLiteBackup1.Backup;
end;

The dan.sdb file is being created, it just lacks any backup data. The application displays data and works fine.

Ideas?


Solution

  • Do you have a SQLite in-memory database with several TADMemTable / other datasets connected to it using FireDAC LocalSQL ?

    If yes, then backup will not copy content of the datasets, because they are represented as SQLite virtual tables. Backup copies only content of the regular tables.

    As workaround you should:

    • perform CREATE TABLE ... AS SELECT ... commands for each ADMemTable to copy them to regular tables;
    • set ADLocalSQL.Active to False;
    • perform backup.