tags:

views:

1026

answers:

2

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.

+6  A: 

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 to sqlite3_open(), sqlite3_open16(), or sqlite3_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).

Alex B
Any details for how that would be implemented or is that beyond the scope for this question? I would appreciate if someone can fill in those details so there is an end to end solution here.
Klathzazt
+1  A: 

There is a memvfs implementation at

http://sqlite.org:8080/cgi-bin/mailman/private/sqlite-users/2009-May/011205.html

this is not a public page
Klathzazt
http://article.gmane.org/gmane.comp.db.sqlite.general/46450Here is the public page.