Is It Possible To Open A Locked Sqlite Database In Read Only Mode?
Solution 1:
I believe it depends on the lock set by the transaction.
http://www.sqlite.org/lockingv3.html#shared_lock http://www.sqlite.org/lang_transaction.html
SQLite exclusive transactions lock both read and write where immediate and deferred transactions will still allow readers.
So it really depends on the transactions used by Chromium.
Solution 2:
Chromium is holding a database lock for long periods of time? Yuck! That's really not a very good idea at all. Still, not your fault…
You could try just copying the database file (e.g., with the system utility cp
) and using that snapshot for reading purposes; SQLite keeps all its committed state in a single file per database. Yes, there's a chance of seeing a partial transaction, but you will definitely not have lock problems on Unix as SQLite definitely doesn't use mandatory locks. (This might well not work on Windows due to the different locking scheme there.)
Solution 3:
It seems we can bypass the lock by opening the database in immutable
mode, e.g.:
sqlite3 'file:places.sqlite?immutable=1'
As explained here https://www.sqlite.org/c3ref/open.html
This can cause querying errors if the underlying database file changes, or obviously not seeing updates that are made to the file, but I found that re-opening the connection on each new query helps with that.
To achieve the same thing with most SQLite drivers, because we can't directly set SQLITE_IOCAP_IMMUTABLE
, the best way is to open the connection with the flag SQLITE_OPEN_READONLY | SQLITE_OPEN_URI
to allow passing the file:...?immutable=1
URI as filename
.
Post a Comment for "Is It Possible To Open A Locked Sqlite Database In Read Only Mode?"