Reputation: 25632
We have several pairs of databases that relate to each other, i.e.
where there are cross-db joints between db1a and db1b, 2a and 2b, etc.
Having an open sqlite database connection, they can be attached, i.e.
ATTACH 'db1a' as a; ATTACH 'db1b' as b;
and later detached and replaced with other pairs when needed.
How should the database "connection" be created, though, as there is originally no real database to attach to? Using the first one as the main database gives it much more significance which is not meaningful - and as it is not detachable it's a hinderance later on.
The only way I can see is opening a :memory:
or a temporary (''
) database connection. Is there some better option available?
Upvotes: 0
Views: 269
Reputation: 180192
In the absence of any better alternative, :memory:
is the best choice. (:temp:
is a normal file name, and invalid in many OSes; a temp DB would have an empty file name.)
If you have some meta database that lists all other databases, you could use that.
Please note that when you have multiple attached databases, any change to one of them will involve a multi-database transaction. So if the various database pairs do not have any relationship with other databases with different numbers, consider using a new connection for each pair.
Upvotes: 1