Is it possible to access database in one process, created in another? I tried:
IDLE #1
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute("create table test(testcolumn)")
c.execute("insert into test values('helloooo')")
conn.commit()
conn.close()
IDLE #2
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute("select * from test")
Error:
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
q = c.execute("select * from test")
sqlite3.OperationalError: no such table: test
of course I agree with @Martijn because doc says so, but if you are focused on unix like systems, then you can make use of shared memory:
If you create file in
/dev/shm
folder, all files create there are mapped directly to RAM, so you can use to access the-same database from two-different processes.it takes that much time:
for at least 2 million records, doing the same on HDD takes (this is the same command but
FILE=/tmp/test.db
):so basically this allows you accessing the same databases from different processes (without loosing r/w speed):
Here is demo demonstrating this what I am talking about:
No, they cannot ever access the same in-memory database from different processes Instead, a new connection to
:memory:
always creates a new database.From the SQLite documentation:
This is different from an on-disk database, where creating multiple connections with the same connection string means you are connecting to one database.
Within one process it is possible to share an in-memory database if you use the
file::memory:?cache=shared
URI:but this is still not accessible from other another process.