@@ -131,19 +131,52 @@ def test_locking(self):
131131 self .con1 .commit ()
132132
133133 def test_rollback_cursor_consistency (self ):
134- """
135- Checks if cursors on the connection are set into a "reset" state
136- when a rollback is done on the connection.
137- """
134+ """Check that cursors behave correctly after rollback."""
138135 con = sqlite .connect (":memory:" )
139136 cur = con .cursor ()
140137 cur .execute ("create table test(x)" )
141138 cur .execute ("insert into test(x) values (5)" )
142139 cur .execute ("select 1 union select 2 union select 3" )
143140
144141 con .rollback ()
145- with self .assertRaises (sqlite .InterfaceError ):
146- cur .fetchall ()
142+ self .assertEqual (cur .fetchall (), [(1 ,), (2 ,), (3 ,)])
143+
144+
145+ class RollbackTests (unittest .TestCase ):
146+ """bpo-44092: sqlite3 now leaves it to SQLite to resolve rollback issues"""
147+
148+ def setUp (self ):
149+ self .con = sqlite .connect (":memory:" )
150+ self .cur1 = self .con .cursor ()
151+ self .cur2 = self .con .cursor ()
152+ with self .con :
153+ self .con .execute ("create table t(c)" );
154+ self .con .executemany ("insert into t values(?)" , [(0 ,), (1 ,), (2 ,)])
155+ self .cur1 .execute ("begin transaction" )
156+ select = "select c from t"
157+ self .cur1 .execute (select )
158+ self .con .rollback ()
159+ self .res = self .cur2 .execute (select ) # Reusing stmt from cache
160+
161+ def tearDown (self ):
162+ self .con .close ()
163+
164+ def _check_rows (self ):
165+ for i , row in enumerate (self .res ):
166+ self .assertEqual (row [0 ], i )
167+
168+ def test_no_duplicate_rows_after_rollback_del_cursor (self ):
169+ del self .cur1
170+ self ._check_rows ()
171+
172+ def test_no_duplicate_rows_after_rollback_close_cursor (self ):
173+ self .cur1 .close ()
174+ self ._check_rows ()
175+
176+ def test_no_duplicate_rows_after_rollback_new_query (self ):
177+ self .cur1 .execute ("select c from t where c = 1" )
178+ self ._check_rows ()
179+
147180
148181
149182class SpecialCommandTests (unittest .TestCase ):
0 commit comments