Skip to content

Fix SSCursor is not iterator on Python 3 #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 23 additions & 27 deletions MySQLdb/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@ def execute(self, query, args=None):

def executemany(self, query, args):
"""Execute a multi-row query.

query -- string, query to execute on server

args

Sequence of sequences or mappings, parameters to use with
query.

Returns long integer rows affected, if any.

This method improves performance on multiple-row INSERT and
REPLACE. Otherwise it is equivalent to looping over args with
execute().
Expand Down Expand Up @@ -279,11 +279,10 @@ def executemany(self, query, args):
r = self._query(qs)
if not self._defer_warnings: self._warning_check()
return r

def callproc(self, procname, args=()):

def callproc(self, procname, args=()):
"""Execute stored procedure procname with args

procname -- string, name of procedure to execute on server

args -- Sequence of parameters to use with procedure
Expand Down Expand Up @@ -318,26 +317,28 @@ def callproc(self, procname, args=()):
q = q.encode(db.unicode_literal.charset)
self._query(q)
self.nextset()

q = "CALL %s(%s)" % (procname,
','.join(['@_%s_%d' % (procname, i)
for i in range(len(args))]))
if isinstance(q, unicode):
q = q.encode(db.unicode_literal.charset)
self._query(q)
self._executed = q
if not self._defer_warnings: self._warning_check()
if not self._defer_warnings:
self._warning_check()
return args

def _do_query(self, q):
db = self._get_db()
self._last_executed = q
db.query(q)
self._do_get_result()
return self.rowcount

def _query(self, q): return self._do_query(q)

def _query(self, q):
return self._do_query(q)

def _fetch_row(self, size=1):
if not self._result:
return ()
Expand All @@ -356,7 +357,7 @@ def __iter__(self):
InternalError = InternalError
ProgrammingError = ProgrammingError
NotSupportedError = NotSupportedError


class CursorStoreResultMixIn(object):

Expand Down Expand Up @@ -403,11 +404,11 @@ def fetchall(self):
result = self._rows
self.rownumber = len(self._rows)
return result

def scroll(self, value, mode='relative'):
"""Scroll the cursor in the result set to a new position according
to mode.

If mode is 'relative' (default), value is taken as offset to
the current position in the result set, if set to 'absolute',
value states an absolute target position."""
Expand All @@ -427,7 +428,7 @@ def __iter__(self):
self._check_executed()
result = self.rownumber and self._rows[self.rownumber:] or self._rows
return iter(result)


class CursorUseResultMixIn(object):

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

_defer_warnings = True

def _get_result(self): return self._get_db().use_result()

def fetchone(self):
Expand All @@ -450,7 +451,7 @@ def fetchone(self):
return None
self.rownumber = self.rownumber + 1
return r[0]

def fetchmany(self, size=None):
"""Fetch up to size rows from the cursor. Result set may be smaller
than size. If size is not defined, cursor.arraysize is used."""
Expand All @@ -460,7 +461,7 @@ def fetchmany(self, size=None):
if not r:
self._warning_check()
return r

def fetchall(self):
"""Fetchs all available rows from the cursor."""
self._check_executed()
Expand All @@ -477,18 +478,18 @@ def next(self):
if row is None:
raise StopIteration
return row


class CursorTupleRowsMixIn(object):
__next__ = next


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

_fetch_type = 0


class CursorDictRowsMixIn(object):

"""This is a MixIn class that causes all rows to be returned as
dictionaries. This is a non-standard feature."""

Expand Down Expand Up @@ -520,7 +521,6 @@ def fetchallDict(self):


class CursorOldDictRowsMixIn(CursorDictRowsMixIn):

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

class Cursor(CursorStoreResultMixIn, CursorTupleRowsMixIn,
BaseCursor):

"""This is the standard Cursor class that returns rows as tuples
and stores the result set in the client."""


class DictCursor(CursorStoreResultMixIn, CursorDictRowsMixIn,
BaseCursor):

"""This is a Cursor class that returns rows as dictionaries and
stores the result set in the client."""


class SSCursor(CursorUseResultMixIn, CursorTupleRowsMixIn,
BaseCursor):

"""This is a Cursor class that returns rows as tuples and stores
the result set in the server."""


class SSDictCursor(CursorUseResultMixIn, CursorDictRowsMixIn,
BaseCursor):

"""This is a Cursor class that returns rows as dictionaries and
stores the result set in the server."""

Expand Down