What's the easiest way to backup/restore sqlite memory database to file database in Qt.
1 Answer
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.
4 Comments
xucheng
I think this way is not native enough. Because by using this, I should add
sqlite3.c and sqlite3.h into project,when Qt already complies these two files into library. Isn't it make the program file large and bad by adding the same code into one file.Silas Parker
If you are using dynamic libraries, then you only need to include
sqlite3.h and link against sqlite3.xucheng
Can you tell me how to link against
sqlite3 without using sqlite3.dllSilas Parker
You can either statically compile sqlite into your program by compiling in
sqlite3.c, or dynamically link against sqlite3.dll, the code needs to be somewhere! The other option would be to link against the qtsql_sqlite driver, but that would only work if the sqlite symbols were exposed by the driver DLL (check using Dependency Walker ).