changeset: 102919:030e100f048a branch: 2.7 parent: 102912:24e580e667fb user: Berker Peksag date: Fri Aug 26 22:19:05 2016 +0300 files: Lib/sqlite3/test/regression.py Misc/NEWS Modules/_sqlite/connection.c description: Issue #10513: Fix a regression in Connection.commit() Statements should not be reset after a commit. Backported from https://github.com/ghaering/pysqlite/commit/029050896b1e6058573abeef5a8970384c0c7faa diff -r 24e580e667fb -r 030e100f048a Lib/sqlite3/test/regression.py --- a/Lib/sqlite3/test/regression.py Thu Aug 25 20:04:08 2016 -0400 +++ b/Lib/sqlite3/test/regression.py Fri Aug 26 22:19:05 2016 +0300 @@ -328,6 +328,36 @@ self.assertRaises(ValueError, cur.execute, " \0select 2") self.assertRaises(ValueError, cur.execute, "select 2\0") + def CheckCommitCursorReset(self): + """ + Connection.commit() did reset cursors, which made sqlite3 + to return rows multiple times when fetched from cursors + after commit. See issues 10513 and 23129 for details. + """ + 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); + """) + + self.assertEqual(con.isolation_level, "") + + counter = 0 + for i, row in enumerate(con.execute("select c from t")): + con.execute("insert into t2(c) values (?)", (i,)) + 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) + counter += 1 + self.assertEqual(counter, 3, "should have returned exactly three rows") + def suite(): regression_suite = unittest.makeSuite(RegressionTests, "Check") diff -r 24e580e667fb -r 030e100f048a Misc/NEWS --- a/Misc/NEWS Thu Aug 25 20:04:08 2016 -0400 +++ b/Misc/NEWS Fri Aug 26 22:19:05 2016 +0300 @@ -33,6 +33,9 @@ Library ------- +- Issue #10513: Fix a regression in Connection.commit(). Statements should + not be reset after a commit. + - Issue #2466: posixpath.ismount now correctly recognizes mount points which the user does not have permission to access. diff -r 24e580e667fb -r 030e100f048a Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c Thu Aug 25 20:04:08 2016 -0400 +++ b/Modules/_sqlite/connection.c Fri Aug 26 22:19:05 2016 +0300 @@ -458,7 +458,6 @@ } if (self->inTransaction) { - pysqlite_do_all_statements(self, ACTION_RESET, 0); Py_BEGIN_ALLOW_THREADS rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail);