Search code examples
qtsqlitein-memory-database

How to backup/store between sqlite memory database and file database in Qt?


What's the easiest way to backup/restore sqlite memory database to file database in Qt.


Solution

  • I think you will need to work with SQLite directly to do this. SQLite has an Online Backup API, the first example is backing up an in-memory database to a file database, so it should be possible to do what you need to do.

    To get a sqlite3* database handle, get the driver (QSqlDatabase::driver) from the database then get the handle (QSqlDriver::handle). The example code in the Qt docs shows how to cast the QVariant into a sqlite3* handle.