]> granicus.if.org Git - python/commitdiff
Issue #10513: Fix a regression in Connection.commit()
authorBerker Peksag <berker.peksag@gmail.com>
Fri, 26 Aug 2016 19:07:51 +0000 (22:07 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Fri, 26 Aug 2016 19:07:51 +0000 (22:07 +0300)
Statements should not be reset after a commit.

Backported from https://github.com/ghaering/pysqlite/commit/029050896b1e6058573abeef5a8970384c0c7faa

Lib/sqlite3/test/regression.py
Misc/NEWS
Modules/_sqlite/connection.c

index 44974b008b9cb5dcfc3c44689762ff95af271818..cb465bad7b322ee9000d5be2c770a87f22872d48 100644 (file)
@@ -322,6 +322,37 @@ class RegressionTests(unittest.TestCase):
         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")):
+            with self.subTest(i=i, row=row):
+                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")
index 1bd3fb31508dec29fedd99eeedec0941862e0cdc..f9e2d09ebd430f650cd0bb0196ecc487c66a75b7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #10513: Fix a regression in Connection.commit().  Statements should
+  not be reset after a commit.
+
 - A new version of typing.py from https://github.com/python/typing:
   - Collection (only for 3.6) (Issue #27598)
   - Add FrozenSet to __all__ (upstream #261)
index 6aa4764b6c6b0b01cfbc772bdb462caefd73e0b0..fcc1695ed06fa28ba6fe1faa47e9a9762fe428c5 100644 (file)
@@ -426,7 +426,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);