Skip to content

Commit

Permalink
Fixes #49.
Browse files Browse the repository at this point in the history
Or Python bug tracker, fixes  http://bugs.python.org/issue23129, http://bugs.python.org/issue10513

Statements should not be reset after a commit.
  • Loading branch information
ghaering committed Aug 18, 2015
1 parent 10dbbe4 commit 0290508
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 33 additions & 0 deletions lib/test/regression.py
Expand Up @@ -282,6 +282,39 @@ def foo():
except sqlite.ProgrammingError:
pass

def CheckCommitCursorReset(self):
"""
See http://bugs.python.org/issueXXXX
Connection.commit() did reset cursors, which made pysqlite to return
rows multiple times when fetched from cursors after commit.
"""
con = sqlite.connect(":memory:")
con.executescript("""
create table t(c);
create table t2(c);
insert into t values(0);
insert into t values(1);
insert into t values(2);
""")

cur = con.cursor()
counter = 0
for idx, row in enumerate(con.execute("select c from t")):
con.execute("insert into t2(c) values (?)", (idx,))
con.commit()

if counter == 0:
self.assertEqual(row[0], 0)
elif counter == 1:
self.assertEqual(row[0], 1)
elif counter == 2:
self.assertEqual(row[0], 2)
else:
self.fail("should have returned exactly three rows")

counter += 1

def suite():
regression_suite = unittest.makeSuite(RegressionTests, "Check")
return unittest.TestSuite((regression_suite,))
Expand Down
2 changes: 0 additions & 2 deletions src/connection.c
Expand Up @@ -442,8 +442,6 @@ PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args)
}

if (self->inTransaction) {
pysqlite_do_all_statements(self, ACTION_RESET, 0);

Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail);
Py_END_ALLOW_THREADS
Expand Down

0 comments on commit 0290508

Please sign in to comment.