File tree 2 files changed +15
-4
lines changed
2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -342,7 +342,13 @@ def _do_get_result(self):
342
342
self ._rows = result .rows
343
343
344
344
def __iter__ (self ):
345
- return iter (self .fetchone , None )
345
+ return self
346
+
347
+ def __next__ (self ):
348
+ row = self .fetchone ()
349
+ if row is None :
350
+ raise StopIteration
351
+ return row
346
352
347
353
Warning = err .Warning
348
354
Error = err .Error
@@ -459,9 +465,6 @@ def fetchall_unbuffered(self):
459
465
"""
460
466
return iter (self .fetchone , None )
461
467
462
- def __iter__ (self ):
463
- return self .fetchall_unbuffered ()
464
-
465
468
def fetchmany (self , size = None ):
466
469
"""Fetch many."""
467
470
self ._check_executed ()
Original file line number Diff line number Diff line change @@ -25,6 +25,14 @@ def setUp(self):
25
25
self .test_connection = pymysql .connect (** self .databases [0 ])
26
26
self .addCleanup (self .test_connection .close )
27
27
28
+ def test_cursor_is_iterator (self ):
29
+ """Test that the cursor is an iterator"""
30
+ conn = self .test_connection
31
+ cursor = conn .cursor ()
32
+ cursor .execute ("select * from test" )
33
+ self .assertEqual (cursor .__iter__ (), cursor )
34
+ self .assertEqual (cursor .__next__ (), ("row1" ,))
35
+
28
36
def test_cleanup_rows_unbuffered (self ):
29
37
conn = self .test_connection
30
38
cursor = conn .cursor (pymysql .cursors .SSCursor )
You can’t perform that action at this time.
0 commit comments