0

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?

Dan
  • 303
  • 1
  • 13
  • 1
    Not related, just a side note, in Delphi, you don't have to include the parentheses `()` at the end of methods like other languages require. If you have no parameters, then you can delete them. – Jerry Dodge May 23 '13 at 23:37
  • 1
    Wouldn't it be enough to just close connection to db, call CopyFile(...) for backup, reopen connection to db? –  May 24 '13 at 04:38
  • 2
    @ComputerSaysNo It could, but the [SQLite3 backup API was designed to be better](http://www.sqlite.org/backup.html): "This procedure works well in many scenarios and is usually very fast. However, this technique has the following shortcomings: Any database clients wishing to write to the database file while a backup is being created must wait until the shared lock is relinquished. It cannot be used to copy data to or from in-memory databases. If a power failure or operating system failure occurs while copying the database file the backup database may be corrupted following system recovery" – Arnaud Bouchez May 24 '13 at 06:06

1 Answers1

3

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.
da-soft
  • 7,670
  • 28
  • 36
  • This is now I had it yes. I have recently changed my design so that the database connection refers to :memory: and I create my tables direct to the memory database. Then using TADTable I can create backups. Works perfectly. Thanks. – Dan May 25 '13 at 00:06