classification
Title: Documentation about sqlite3 isolation_level
Type: enhancement Stage: patch review
Components: Documentation Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, georg.brandl, ghaering, nagylzs, terry.reedy
Priority: normal Keywords: patch

Created on 2010-03-15 09:01 by nagylzs, last changed 2010-12-20 19:27 by eric.araujo.

Files
File name Uploaded Description Edit
sqlite3.rst.diff nagylzs, 2010-03-15 09:01 unified diff to http://svn.python.org/projects/python/branches/release26-maint/Doc/library/sqlite3.rst
Messages (3)
msg101090 - (view) Author: Laszlo Nagy (nagylzs) Date: 2010-03-15 09:01
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
msg109948 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-07-11 00:00
If the content of the patch is correct, it looks ready to apply, with only a touch of editing. Do we have a resident expert of sqlite3? Or Laszlo, do you have a reference for the statements made?
msg109965 - (view) Author: Laszlo Nagy (nagylzs) Date: 2010-07-11 05:29
2010/7/11 Terry J. Reedy <report@bugs.python.org>

>
> Terry J. Reedy <tjreedy@udel.edu> added the comment:
>
> If the content of the patch is correct, it looks ready to apply, with only
> a touch of editing. Do we have a resident expert of sqlite3? Or Laszlo, do
> you have a reference for the statements made?
>

Sorry, the only reference I have is that mailing list thread (
http://mail.python.org/pipermail/python-list/2010-March/1239374.html ).

There you can find an example with SQL statements, showing the problem.

Ryan Kelly wrote the following:

<quote>
I have a theory, based on a quick perusal of the sqlite3 bindings
source.

The bindings think that "SAVEPOINT sp1" is a "non-DML, non-query"
statement. So when isolation_level is something other than None, this
statement implicitly commits the current transaction and throws away
your savepoints!
</quote>

So the problem is with the sqlite binding code, not sqlite itself. I'm not
an expert in C, so I'm not sure I can help more.

Thanks,

   Laszlo
History
Date User Action Args
2010-12-20 19:27:07eric.araujosetfiles: - unnamed
nosy: georg.brandl, terry.reedy, ghaering, nagylzs, docs@python
2010-08-07 20:17:30terry.reedysetstage: patch review
versions: - Python 2.6
2010-07-11 05:29:53nagylzssetfiles: + unnamed

messages: + msg109965
2010-07-11 00:00:16terry.reedysetversions: + Python 3.1, Python 2.7, Python 3.2
nosy: + terry.reedy, docs@python

messages: + msg109948

assignee: georg.brandl -> docs@python
2010-03-16 14:01:34ghaeringsetnosy: + ghaering
2010-03-15 09:01:44nagylzscreate