Skip to content

Commit

Permalink
Clear cursor._query before query() (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane authored Nov 5, 2018
1 parent abcc468 commit e7fddae
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions MySQLdb/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self, connection):
self._result = None
self._warnings = None
self.rownumber = None
self._rows = None

def close(self):
"""Close the cursor. No further queries will be possible."""
Expand Down Expand Up @@ -172,23 +173,27 @@ def nextset(self):
nr = db.next_result()
if nr == -1:
return None
self._do_get_result()
self._do_get_result(db)
self._post_get_result()
self._warning_check()
return 1

def _post_get_result(self): pass
def _do_get_result(self, db):
self._result = result = self._get_result()
if result is None:
self.description = self.description_flags = None
else:
self.description = result.describe()
self.description_flags = result.field_flags()

def _do_get_result(self):
db = self._get_db()
self._result = self._get_result()
self.rowcount = db.affected_rows()
self.rownumber = 0
self.description = self._result and self._result.describe() or None
self.description_flags = self._result and self._result.field_flags() or None
self.lastrowid = db.insert_id()
self._warnings = None

def _post_get_result(self):
pass

def setinputsizes(self, *args):
"""Does nothing, required by DB API."""

Expand Down Expand Up @@ -248,7 +253,6 @@ def execute(self, query, args=None):
except Exception:
exc, value = sys.exc_info()[:2]
self.errorhandler(self, exc, value)
self._executed = query
if not self._defer_warnings:
self._warning_check()
return res
Expand Down Expand Up @@ -364,21 +368,19 @@ def callproc(self, procname, args=()):
if isinstance(q, unicode):
q = q.encode(db.encoding, 'surrogateescape')
self._query(q)
self._executed = q
if not self._defer_warnings:
self._warning_check()
return args

def _do_query(self, q):
def _query(self, q):
db = self._get_db()
self._last_executed = q
self._result = None
db.query(q)
self._do_get_result()
self._do_get_result(db)
self._post_get_result()
self._executed = q
return self.rowcount

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

def _fetch_row(self, size=1):
if not self._result:
return ()
Expand Down Expand Up @@ -408,11 +410,6 @@ class CursorStoreResultMixIn(object):
def _get_result(self):
return self._get_db().store_result()

def _query(self, q):
rowcount = self._do_query(q)
self._post_get_result()
return rowcount

def _post_get_result(self):
self._rows = self._fetch_row(0)
self._result = None
Expand Down Expand Up @@ -481,7 +478,8 @@ class CursorUseResultMixIn(object):

_defer_warnings = True

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

def fetchone(self):
"""Fetches a single row from the cursor."""
Expand Down

0 comments on commit e7fddae

Please sign in to comment.