Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I serialize an in-memory SQLite Database?

Tags:

c

sqlite

I have an in-memory SQLite database which I want to serialize and send to another computer. Is this possible without writing the database out to disk and reading the file from there?

like image 770
chacham15 Avatar asked May 24 '26 00:05

chacham15


2 Answers

You could use the online backup API to transfer the in-memory database, to a file-based database created in shared memory (for Linux, in /dev/shm for instance) avoiding the disk operations. Then this pseudo-file is transferred to the remote host (still put in /dev/shm), and the online load API is used to transfer from the file-based database, to your target in-memory database.

See:

http://www.sqlite.org/backup.html

http://www.sqlite.org/c3ref/backup_finish.html

AFAIK, there is no API to perform online/load without intermediate databases.

like image 57
Didier Spezia Avatar answered May 25 '26 16:05

Didier Spezia


The sqlite3 shell program contains a .dump command that "dumps the database in an SQL text format." You can use the source code for .dump (it is public domain) to create your own serializer.

like image 38
Doug Currie Avatar answered May 25 '26 15:05

Doug Currie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!