While using sqlite3 from C/C++ I learned that it has a open-in-read-only mode option, which is very handy to avoid accidental data-corruption. Is there such a thing in the Python binding?
39
votes
Possible duplicate of: stackoverflow.com/questions/4239606/…
- Chris
@Chris Thanks, I will redact an answer just to save some work to future people with the same question.
- dsign
possible duplicate of force python to forego native sqlite3 and use the (installed) latest sqlite3 version
- Jakob Bowyer
4 Answers
52
votes
As of Python 3.4.0 you can open the database in read only mode with the following:
db = sqlite3.connect('file:/path/to/database?mode=ro', uri=True)
Also see the documentation.
16
votes
8
votes
4
votes
As by the link given by @Chris, no. But there is another wrapper for sqlite3, which is less PEP 249-compliant and that wraps sqlite3 more tightly, assimilating new features of the engine: http://code.google.com/p/apsw/ . That wrapper does support opening the database in read-only mode, plus other niceties.