It looks like all the methods for loading SQLite involve loading from a named file using a string. I would like to load SQlite database from memory.
The database is already loaded into memory.
It looks like all the methods for loading SQLite involve loading from a named file using a string. I would like to load SQlite database from memory.
The database is already loaded into memory.
Use a special file name, :memory:
sqlite3_open(":memory:", &db);
libsqlite
must have been compiled without SQLITE_OMIT_MEMORYDB
defined, as pointed out in SQLite documentation:
SQLITE_OMIT_MEMORYDB
When this is defined, the library does not respect the special database name
":memory:"
(normally used to create an in-memory database). If":memory:"
is passed tosqlite3_open()
,sqlite3_open16()
, orsqlite3_open_v2()
, a file with this name will be opened or created.
If you want to read the database that is already fully loaded into memory however, it will be more work. You will have to implement a custom VFS layer to operate on memory files and register it with your SQLite context.
See:
I have not implemented it myself, so I can't reliably tell whether you have to implement the entire new VFS layer, or you can get away with substituting some functions in the default one (latter is unlikely).
There is a memvfs implementation at
http://sqlite.org:8080/cgi-bin/mailman/private/sqlite-users/2009-May/011205.html