Page 1 of 1

How can an in-memory SQLite database be saved to disk?

Posted: 03.07.2016, 16:17
by vfclists
How can an in-memory SQLite database be saved to disk?

Is there support for it in Zeoslib, or does it have to be coded separately?

On checking StackOverflow I found this link http://www.sqlite.org/backup.html which uses the C-API. Does Zeoslib expose the necessary handles or variables which can allow the example there to be used?

Re: How can an in-memory SQLite database be saved to disk?

Posted: 05.07.2016, 11:04
by marsupilami
Hello vfclists,

this is not (yet) part of Zeos. But it should be fairly simple to implement. One would have to import sqlite3_backup_init() into the plain driver via modifying ZPlainSqLiteDriver.pas. After that you can implement something on top of this either as part of the dbc layer (ZDbcSqLite.pas) or as a separate object that only gets the session handle from the dbc layer.

If you want to implemet this, you can get the connection handle like this:

Code: Select all

(ZConnection1.DbcConnection as IZSQLiteConnection).GetConnectionHandle
And you can get the plain driver like this

Code: Select all

(ZConnection1.DbcConnection as IZSQLiteConnection).GetPlainDriver
Let me know if you need more information on implementing this. Since Zeos 7.2 is in Beta Stage I am not sure if these modifications can go in there or really should be part of the Zeos 7.3 branch that until now only has an OLEDB driver as its only difference to 7.2 until now.

If you decide to implemet this, and share your code here, your code could help to build a backup and recovery facility for Zeoi in the future. Firebird also supports doing backups via an API, that I want to implement at some time in the future...

With best regards,

Jan