Message101090
Clarify what isolation_level does, and how to use it, and why connections do not commit/rollback in some cases.
Details here:
http://mail.python.org/pipermail/python-list/2010-March/1239374.html
I'll paste code for ctx_manager_2.py here. This is a new file, I could not include it as a diff:
import sqlite3
class MyConn(sqlite3.Connection):
def __enter__(self):
self.execute("BEGIN")
return self
def __exit__(self,exc_type,exc_info,traceback):
if exc_type is None:
self.execute("COMMIT")
else:
self.execute("ROLLBACK")
conn = sqlite3.connect(':memory:',factory=MyConn)
conn.isolation_level = None
with conn:
conn.execute("create table a ( i integer ) ")
conn.execute("insert into a values (1)")
try:
with conn:
conn.execute("insert into a values (2)")
conn.execute("savepoint sp1")
conn.execute("insert into a values (3)")
conn.execute("rollback to sp1")
conn.execute("insert into a values (4)")
print "Before rollback: 1,2,4"
for row in conn.execute("select * from a"):
print row[0] # prints 1,2,4
raise Exception
except:
pass
print "After rollback: 1"
for row in conn.execute("select * from a"):
print row[0] # prints 1 |
|
Date |
User |
Action |
Args |
2010-03-15 09:01:46 | nagylzs | set | recipients:
+ nagylzs, georg.brandl |
2010-03-15 09:01:45 | nagylzs | set | messageid: <1268643705.49.0.319902511171.issue8145@psf.upfronthosting.co.za> |
2010-03-15 09:01:43 | nagylzs | link | issue8145 messages |
2010-03-15 09:01:42 | nagylzs | create | |
|