On Apr 20, 2016, at 8:10 AM, Dominique Devienne <ddevienne at gmail.com> wrote:
> Thanks. I mistakenly assumes ":memory:" was a "singleton" memory DB > for that particular connection. Thanks to your example, and a little testing > on my own, I now realize > each one is an independent memory DB, and not just different "aliases" to > just one memory DB. > > And I was also confused by something we did a few weeks ago, which is to have > several named > memory DBs, and connecting several times (as independent connections) to one > of those mem DB's by name. > I believe this use case is only possible with URI style file type. All > in-process of course. Am I wrong on that too? ?DD Yea, pretty sure you can?t do that. 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. -j -- Jay A. Kreibich < J A Y @ K R E I B I.C H > "Intelligence is like underwear: it is important that you have it, but showing it to the wrong people has the tendency to make them feel uncomfortable." -- Angela Johnson