> Generally speaking, no matter how they are created, a given in-memory > database has one and only one connection. You cannot, for example, use a URI > ?filename? with mode=memory to open the same in-memory database more than > once (I assume that?s what you mean by ?by name??). For example: > > > $ ./sqlite3 > SQLite version 3.8.4.2 2014-03-26 18:51:19 > Enter ".help" for usage hints. > Connected to a transient in-memory database. > Use ".open FILENAME" to reopen on a persistent database. > sqlite> ATTACH DATABASE "file:data.db?mode=memory" AS db1; > sqlite> ATTACH DATABASE "file:data.db?mode=memory" AS db2; > sqlite> ATTACH DATABASE "file:data.db?mode=memory" AS db3; > sqlite> .databases > seq name file > --- --------------- > ---------------------------------------------------------- > 0 main > 2 db1 > 3 db2 > 4 db3 > sqlite> CREATE TABLE main.t_main ( c ); > sqlite> CREATE TABLE db1.t_db1( c ); > sqlite> CREATE TABLE db2.t_db2( c ); > sqlite> select * from main.sqlite_master; > table|t_main|t_main|2|CREATE TABLE t_main ( c ) > sqlite> select * from db1.sqlite_master; > table|t_db1|t_db1|2|CREATE TABLE t_db1( c ) > sqlite> select * from db2.sqlite_master; > table|t_db2|t_db2|2|CREATE TABLE t_db2( c ) > sqlite> select * from db3.sqlite_master; > sqlite> > > You can see that even though I?ve opened the same ?file:data.db?mode=memory? > database more than once, it is actually three distinct databases. I?m pretty > sure that when mode=memory, the path/filename are ignored.
If you open the databases using "file:data.db?mode=memory&cache=shared" then db1, db2 and db3 will all refer to the same in-memory database. Which will fail, as you cannot attach the same db to a single handle more than once. But, if your process has two separate database handles and they both attach "file:data.db?mode=memory&cache=shared" then both handles will be connected to the same in-memory database. Dan.