Skip to content

Commit d431ac9

Browse files
committed
Merge pull request #28 from PyMySQL/fix/py3-iter
Fix SSCursor is not iterator on Python 3
2 parents acadc9c + d408114 commit d431ac9

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

MySQLdb/cursors.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,16 @@ def execute(self, query, args=None):
224224

225225
def executemany(self, query, args):
226226
"""Execute a multi-row query.
227-
227+
228228
query -- string, query to execute on server
229229
230230
args
231231
232232
Sequence of sequences or mappings, parameters to use with
233233
query.
234-
234+
235235
Returns long integer rows affected, if any.
236-
236+
237237
This method improves performance on multiple-row INSERT and
238238
REPLACE. Otherwise it is equivalent to looping over args with
239239
execute().
@@ -279,11 +279,10 @@ def executemany(self, query, args):
279279
r = self._query(qs)
280280
if not self._defer_warnings: self._warning_check()
281281
return r
282-
283-
def callproc(self, procname, args=()):
284282

283+
def callproc(self, procname, args=()):
285284
"""Execute stored procedure procname with args
286-
285+
287286
procname -- string, name of procedure to execute on server
288287
289288
args -- Sequence of parameters to use with procedure
@@ -318,26 +317,28 @@ def callproc(self, procname, args=()):
318317
q = q.encode(db.unicode_literal.charset)
319318
self._query(q)
320319
self.nextset()
321-
320+
322321
q = "CALL %s(%s)" % (procname,
323322
','.join(['@_%s_%d' % (procname, i)
324323
for i in range(len(args))]))
325324
if isinstance(q, unicode):
326325
q = q.encode(db.unicode_literal.charset)
327326
self._query(q)
328327
self._executed = q
329-
if not self._defer_warnings: self._warning_check()
328+
if not self._defer_warnings:
329+
self._warning_check()
330330
return args
331-
331+
332332
def _do_query(self, q):
333333
db = self._get_db()
334334
self._last_executed = q
335335
db.query(q)
336336
self._do_get_result()
337337
return self.rowcount
338338

339-
def _query(self, q): return self._do_query(q)
340-
339+
def _query(self, q):
340+
return self._do_query(q)
341+
341342
def _fetch_row(self, size=1):
342343
if not self._result:
343344
return ()
@@ -356,7 +357,7 @@ def __iter__(self):
356357
InternalError = InternalError
357358
ProgrammingError = ProgrammingError
358359
NotSupportedError = NotSupportedError
359-
360+
360361

361362
class CursorStoreResultMixIn(object):
362363

@@ -403,11 +404,11 @@ def fetchall(self):
403404
result = self._rows
404405
self.rownumber = len(self._rows)
405406
return result
406-
407+
407408
def scroll(self, value, mode='relative'):
408409
"""Scroll the cursor in the result set to a new position according
409410
to mode.
410-
411+
411412
If mode is 'relative' (default), value is taken as offset to
412413
the current position in the result set, if set to 'absolute',
413414
value states an absolute target position."""
@@ -427,7 +428,7 @@ def __iter__(self):
427428
self._check_executed()
428429
result = self.rownumber and self._rows[self.rownumber:] or self._rows
429430
return iter(result)
430-
431+
431432

432433
class CursorUseResultMixIn(object):
433434

@@ -438,7 +439,7 @@ class CursorUseResultMixIn(object):
438439
the connection."""
439440

440441
_defer_warnings = True
441-
442+
442443
def _get_result(self): return self._get_db().use_result()
443444

444445
def fetchone(self):
@@ -450,7 +451,7 @@ def fetchone(self):
450451
return None
451452
self.rownumber = self.rownumber + 1
452453
return r[0]
453-
454+
454455
def fetchmany(self, size=None):
455456
"""Fetch up to size rows from the cursor. Result set may be smaller
456457
than size. If size is not defined, cursor.arraysize is used."""
@@ -460,7 +461,7 @@ def fetchmany(self, size=None):
460461
if not r:
461462
self._warning_check()
462463
return r
463-
464+
464465
def fetchall(self):
465466
"""Fetchs all available rows from the cursor."""
466467
self._check_executed()
@@ -477,18 +478,18 @@ def next(self):
477478
if row is None:
478479
raise StopIteration
479480
return row
480-
481481

482-
class CursorTupleRowsMixIn(object):
482+
__next__ = next
483+
483484

485+
class CursorTupleRowsMixIn(object):
484486
"""This is a MixIn class that causes all rows to be returned as tuples,
485487
which is the standard form required by DB API."""
486488

487489
_fetch_type = 0
488490

489491

490492
class CursorDictRowsMixIn(object):
491-
492493
"""This is a MixIn class that causes all rows to be returned as
493494
dictionaries. This is a non-standard feature."""
494495

@@ -520,7 +521,6 @@ def fetchallDict(self):
520521

521522

522523
class CursorOldDictRowsMixIn(CursorDictRowsMixIn):
523-
524524
"""This is a MixIn class that returns rows as dictionaries with
525525
the same key convention as the old Mysqldb (MySQLmodule). Don't
526526
use this."""
@@ -530,28 +530,24 @@ class CursorOldDictRowsMixIn(CursorDictRowsMixIn):
530530

531531
class Cursor(CursorStoreResultMixIn, CursorTupleRowsMixIn,
532532
BaseCursor):
533-
534533
"""This is the standard Cursor class that returns rows as tuples
535534
and stores the result set in the client."""
536535

537536

538537
class DictCursor(CursorStoreResultMixIn, CursorDictRowsMixIn,
539538
BaseCursor):
540-
541539
"""This is a Cursor class that returns rows as dictionaries and
542540
stores the result set in the client."""
543-
541+
544542

545543
class SSCursor(CursorUseResultMixIn, CursorTupleRowsMixIn,
546544
BaseCursor):
547-
548545
"""This is a Cursor class that returns rows as tuples and stores
549546
the result set in the server."""
550547

551548

552549
class SSDictCursor(CursorUseResultMixIn, CursorDictRowsMixIn,
553550
BaseCursor):
554-
555551
"""This is a Cursor class that returns rows as dictionaries and
556552
stores the result set in the server."""
557553

0 commit comments

Comments
 (0)