5

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?

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great! Thank you for the explanation and the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.