Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening sqlite3 database from python in read-only mode

Tags:

python

sqlite

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?

like image 340
dsign Avatar asked Apr 18 '12 08:04

dsign


People also ask

How fetch data from sqlite3 database in Python?

SQLite Python: Querying Data First, establish a connection to the SQLite database by creating a Connection object. Next, create a Cursor object using the cursor method of the Connection object. Then, execute a SELECT statement. After that, call the fetchall() method of the cursor object to fetch the data.

Is SQLite can be used with Python only?

Introduction. SQLite is a self-contained, file-based SQL database. SQLite comes bundled with Python and can be used in any of your Python applications without having to install any additional software.

Is sqlite3 default in Python?

SQLite3 can be integrated with Python using sqlite3 module, which was written by Gerhard Haring. It provides an SQL interface compliant with the DB-API 2.0 specification described by PEP 249. You do not need to install this module separately because it is shipped by default along with Python version 2.5. x onwards.


1 Answers

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.

like image 108
anthonyryan1 Avatar answered Sep 29 '22 05:09

anthonyryan1