pythonsqlitetransactionsisolation-level

How to set SQLite isolation levels in Python?


I know that in the SQL standard there are four isolation levels when dealing with transactions:

READ UNCOMMITTED - will allow everything
READ COMMITTED - will not allow dirty reads 
REPEATABLE READ - will not allow dirty, non-repearable reads   
SERIALIZABLE - will not allow dirty, non-repearable, phantom reads

When dealing with MySQL I can do something like:

cursor = db.cursor()
cursor.execute("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED")

Or, if I'm dealing with Postgresql, I can do something like:

db.set_isolation_level(3) # corresponds to SERIALIZABLE

So, I wonder, if I can do something similar to that when dealing with SQLite.

I've only seen the following but I'm not sure what it means and how I can set other isolation levels (if they exist in the context of SQLite)

db.isolation_level = None

Solution

  • There are PRAGMA statements in sqlite. It seems you can do this:

    db.execute("PRAGMA read_uncommitted = true;");