SQLite Forum

DB creates file despite URI param "mode=memory"
Login

DB creates file despite URI param "mode=memory"

(1) By Christian Möller (dcmoeller) on 2021-08-17 09:29:13 [link] [source]

Hello,

I've tried to open two different in-memory SQLite instances for unit testing purposes (within a Python/SQLAlchemy project). Using (what I call "named") databases applying URIs like "sqlite+pysqlite:///file:should-not-exist?mode=memory&cache=shared" I expected that no database file is created on local filesystem due to the usage of mode=memory URI parameter (see description of mode=memory here).

But test case shows that this is not the case: I've found database file ./should-not-exist gets created by using the shown DB URI!

I've also found a statement "Note that in order for the special ":memory:" name to apply and to create a pure in-memory database, there must be no additional text in the filename." (found here), which - at least to me - contradicts the aforementioned statement regarding "mode=memory".

Is there anything to further consider to get two distinct in-memory SQLite databases?

Thanks

Christian

(2) By Richard Hipp (drh) on 2021-08-17 11:54:55 in reply to 1 [source]

My guess: The Python/SQLAlchemy layer is stripping off the query parameters before they reach SQLite.

(3) By Christian Möller (dcmoeller) on 2021-08-18 14:37:17 in reply to 2 [link] [source]

Hi Richard,

thanks for guiding me slightly in the right direction :-)

This post provides me the solution.

Regards

Christian