Small. Fast. Reliable.
Choose any three.
This page is about using in-memory SQLite databases.


2003-04-15: The in-memory database is now in the CVS tree, though it is still mostly untested.

2003-05-09: In-memory databases are now a feature of the standard SQLite library. To open an in-memory database, use filename ":memory:".


While connections to on-disk databases should not be carried across a Unix fork(), is there any reason not to do it with an in-memory database? (2003-10-21 by drh:) Not that I know of.

DK: Of course, when you do the fork() you are creating a new copy of the in-memory db for the child process. So subsequent edits to the db in the child won't show up in the parents copy, and vice-versa.

NgPS: Multiple connections to ":memory:" within a single process creates a fresh database each time:

  * (defvar db (sql:connect '(":memory:")
                            :database-type :sqlite
                            :make-default nil
                            :if-exists :new))
  DB
  * (sql:execute-command "create table a (id integer primary key, x varchar)"
                         :database db)
  T
  * (sql:execute-command "insert into a values (NULL, 'aaa')" :database db)
  T
  * (sql:execute-command "insert into a values (NULL, 'bbb')" :database db)
  T
  * (sql:execute-command "insert into a values (NULL, 'ccc')" :database db)
  T
  * (sql:query "select * from a" :database db)
  (("1" "aaa") ("2" "bbb") ("3" "ccc"))
  * (sql:query "select * from sqlite_master" :database db)
  (("table" "a" "a" "3" "create table a (id integer primary key, x varchar)"))
  * (defvar db2 (sql:connect '(":memory:")
                             :database-type :sqlite
                             :make-default nil
                             :if-exists :old))
  DB2
  * (sql:query "select * from sqlite_master" :database db2)
  NIL