SQLite Forum

SQLite3 - Open & Attach
Login

SQLite3 - Open & Attach

(1) By anonymous on 2020-12-14 17:47:23 [link] [source]

Is it possible to execute across database queries using the handle(s) of opened databases, something akin to the way it is possible to do with attached databases?

(2) By Stephan Beal (stephan) on 2020-12-14 17:51:41 in reply to 1 [source]

Is it possible to execute across database queries using the handle(s) of opened databases...

No. Each distinct db handle result from sqlite3_open() and friends is a universe unto itself and it does not/cannot cooperate at the query level with other handles.

(3) By Stephan Beal (stephan) on 2020-12-14 17:58:25 in reply to 2 [link] [source]

.. is a universe unto itself and it does not/cannot cooperate at the query level with other handles.

That's not to say that you cannot, e.g., loop over data from one handle to process data in another handle. You cannot, however, formulate an SQL query which crosses the boundary between those handles.

(5) By ddevienne on 2020-12-14 18:32:41 in reply to 2 [link] [source]

Well, to be pedantic, you can coordinate queries across DB handles
to use the same WAL point-in-time I think, for read-consistency.

I.e. you can obtain a piece of data from one db handle that will
influence the data returned by other db handle(s).

That's a small bridge between universes, no? :)

(4) By Larry Brasfield (LarryBrasfield) on 2020-12-14 18:15:18 in reply to 1 [link] [source]

Without contradicting Mr. Beal's response(s), I can say:

There is nothing preventing somebody from using a SQLite API for retreiving a filename from a connection, then attaching the named DB to another existing connection.

(6) By anonymous on 2020-12-14 18:38:14 in reply to 4 [link] [source]

Is it safe (in the interest of database integrity) or advisable (in the interest of concurrent access) to do so?

(7) By Larry Brasfield (LarryBrasfield) on 2020-12-14 18:46:30 in reply to 6 [link] [source]

The SQLite library normally arranges for putatively concurrent accesses to be done safely. Of course, you could always close that DB "handle" (which is just a pointer to a data structure) and have the same situation you originally implied.