Skip to content

Commit dc60c75

Browse files
committed
Issue python#10513: Fix a regression in Connection.commit()
Statements should not be reset after a commit. Backported from ghaering/pysqlite@0290508
1 parent 3f0222c commit dc60c75

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎Lib/sqlite3/test/regression.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,36 @@ def CheckNullCharacter(self):
328328
self.assertRaises(ValueError, cur.execute, " \0select 2")
329329
self.assertRaises(ValueError, cur.execute, "select 2\0")
330330

331+
def CheckCommitCursorReset(self):
332+
"""
333+
Connection.commit() did reset cursors, which made sqlite3
334+
to return rows multiple times when fetched from cursors
335+
after commit. See issues 10513 and 23129 for details.
336+
"""
337+
con = sqlite.connect(":memory:")
338+
con.executescript("""
339+
create table t(c);
340+
create table t2(c);
341+
insert into t values(0);
342+
insert into t values(1);
343+
insert into t values(2);
344+
""")
345+
346+
self.assertEqual(con.isolation_level, "")
347+
348+
counter = 0
349+
for i, row in enumerate(con.execute("select c from t")):
350+
con.execute("insert into t2(c) values (?)", (i,))
351+
con.commit()
352+
if counter == 0:
353+
self.assertEqual(row[0], 0)
354+
elif counter == 1:
355+
self.assertEqual(row[0], 1)
356+
elif counter == 2:
357+
self.assertEqual(row[0], 2)
358+
counter += 1
359+
self.assertEqual(counter, 3, "should have returned exactly three rows")
360+
331361

332362
def suite():
333363
regression_suite = unittest.makeSuite(RegressionTests, "Check")

‎Misc/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Core and Builtins
3333
Library
3434
-------
3535

36+
- Issue #10513: Fix a regression in Connection.commit(). Statements should
37+
not be reset after a commit.
38+
3639
- Issue #2466: posixpath.ismount now correctly recognizes mount points which
3740
the user does not have permission to access.
3841

‎Modules/_sqlite/connection.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args)
458458
}
459459

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

463462
Py_BEGIN_ALLOW_THREADS
464463
rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail);

0 commit comments

Comments
 (0)