Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set SQLite isolation levels, using Python

I know (or at least, I think that I know), that in 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

I know that and, for example, 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 Postgre, 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:

db.isolation_level = None

but I'm not sure what it means and how I can set other isolation levels (if they exist in the context of SQLite). Thanks!

like image 337
Jacobian Avatar asked Nov 30 '15 14:11

Jacobian


1 Answers

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

db.execute("PRAGMA read_uncommitted = true;");
like image 87
Martin Vseticka Avatar answered Sep 30 '22 20:09

Martin Vseticka