Jay Sprenkle  wrote:
Every time you open a :memory: database you get a separate instance,
identified only by its sqlite3* handle. I'm not sure if ATTACH would
work with :memory:, but even if it does it would just create a new,
empty in-memory database, not refer to the one (of possibly many) you
already have open and populated.

sqlite> create table x(y text);
sqlite> insert into x(y) values('one');
sqlite> select * from x;
one
sqlite> attach ":memory:" as db1;
sqlite> create table db1.x(y text);
sqlite> insert into db1.x(y) values('two');
sqlite> select * from db1.x;
two
sqlite> select * from x;
one
sqlite> attach ":memory:" as db2;
sqlite> create table db2.x(y text);
sqlite>  insert into db2.x(y) values('three');
sqlite>  select * from db2.x;
three
sqlite>  select * from db1.x;
two
sqlite>  select * from x;
one
sqlite>

Would that work with pre-existing memory databases? Here, you create several new memory databases attached to an existing one. The whole contraption hangs off of a single sqlite* handle. For all intents and purposes, you have a single in-memory database, just with somewhat unusual table names.

This technique may be cute, but I don't quite see how it's useful. It defeats the whole point of having multiple independent memory databases - for example the ability to write to them concurrently from different threads.

Igor Tandetnik

Reply via email to