I know that I can open multiple connections to an In-Memory sqlite database using file:DB_NAME?mode=memory&cache=shared
in sqlite3_open_v2()
.
I open 2 connections to an In-Memory database. One with the flags SQLITE_OPEN_URI | SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE
and another with SQLITE_OPEN_READONLY | SQLITE_OPEN_URI
.
The problem is that sqlite lets me modify the database even when the connection is Read-Only.
Is there any way to make the connection Read-Only? Should I write my own VFS to accomplish it?
The most common way to force an SQLite database to exist purely in memory is to open the database using the special filename ":memory:". In other words, instead of passing the name of a real disk file into one of the sqlite3_open(), sqlite3_open16(), or sqlite3_open_v2() functions, pass in the string ":memory:".
SQLite in-memory databases are databases stored entirely in memory, not on disk. Use the special data source filename :memory: to create an in-memory database. When the connection is closed, the database is deleted. When using :memory: , each connection creates its own database.
The default limit is 1,024.
SQLite isn't a network database, so it doesn't have any network connection ability built into it. You would need to either: Make the SQLite DB available on a network-accessible shared drive OR. Write/find an existing network server/web service for it.
The SQLITE_OPEN_READONLY
flag affects how the database accesses any files and handles transactions.
In shared-cache mode, multiple connections appear as a single connection in the interface to the file system. Therefore, they share the file access/transaction settings.
To prevent a connection from starting any write transactions, use PRAGMA query_only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With