[New-bugs-announce] [issue8145] Documentation about sqlite3 isolation_level

Laszlo Nagy report at bugs.python.org
Mon Mar 15 10:01:45 CET 2010


New submission from Laszlo Nagy <nagylzs at gmail.com>:

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

----------
assignee: georg.brandl
components: Documentation
files: sqlite3.rst.diff
keywords: patch
messages: 101090
nosy: georg.brandl, nagylzs
severity: normal
status: open
title: Documentation about sqlite3 isolation_level
type: feature request
versions: Python 2.6
Added file: http://bugs.python.org/file16554/sqlite3.rst.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8145>
_______________________________________


More information about the New-bugs-announce mailing list