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()
.
我知道我可以使用file:DB_NAME?mode = memory&cache = shared in sqlite3_open_v2()打开与内存中sqlite数据库的多个连接。
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
.
我打开2个连接到内存数据库。一个带有标志SQLITE_OPEN_URI | SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE和另一个SQLITE_OPEN_READONLY | SQLITE_OPEN_URI。
The problem is that sqlite lets me modify the database even when the connection is Read-Only.
问题是,即使连接是只读的,sqlite也允许我修改数据库。
Is there any way to make the connection Read-Only? Should I write my own VFS to accomplish it?
有没有办法使连接只读?我应该编写自己的VFS来完成它吗?
1 个解决方案
#1
3
The SQLITE_OPEN_READONLY
flag affects how the database accesses any files and handles transactions.
SQLITE_OPEN_READONLY标志会影响数据库访问任何文件和处理事务的方式。
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.
要防止连接启动任何写入事务,请使用PRAGMA query_only。
#1
3
The SQLITE_OPEN_READONLY
flag affects how the database accesses any files and handles transactions.
SQLITE_OPEN_READONLY标志会影响数据库访问任何文件和处理事务的方式。
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.
要防止连接启动任何写入事务,请使用PRAGMA query_only。