From 2efaa25b6570e5ff6da9dcf587e8e4e4e4fc89bc Mon Sep 17 00:00:00 2001 From: Bruce Feng <1269972275@qq.com> Date: Tue, 22 Oct 2019 16:47:02 +0800 Subject: [PATCH 1/2] fix CMySQLCursor.fetchmany bug Issue: When calling fetchmany iteratively and reaching end of rows in cursor, fetchmany does not updates self. _nextrow if there is no unread_result (only happens when the last batch is not a full batch). Fix: add an additional if/else where the self._nextrow is reset to (None, None) when unread_result is False. --- lib/mysql/connector/cursor_cext.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/mysql/connector/cursor_cext.py b/lib/mysql/connector/cursor_cext.py index 64f8c28..9fe871c 100644 --- a/lib/mysql/connector/cursor_cext.py +++ b/lib/mysql/connector/cursor_cext.py @@ -105,7 +105,7 @@ def reset(self, free=True): When free is True (default) the result will be freed. """ self._rowcount = -1 - self._nextrow = None + self._nextrow = (None, None) self._affected_rows = -1 self._insert_id = 0 self._warning_count = 0 @@ -511,11 +511,14 @@ def fetchmany(self, size=1): if size and self._cnx.unread_result: rows.extend(self._cnx.get_rows(size)[0]) - if size and self._cnx.unread_result: - self._nextrow = self._cnx.get_row() - if self._nextrow and not self._nextrow[0] and \ - not self._cnx.more_results: - self._cnx.free_result() + if size: + if self._cnx.unread_result: + self._nextrow = self._cnx.get_row() + if self._nextrow and not self._nextrow[0] and \ + not self._cnx.more_results: + self._cnx.free_result() + else: + self._nextrow = (None, None) if not rows: self._handle_eof() From e15f89302c05466cc49e06ce18230591d5dc5f42 Mon Sep 17 00:00:00 2001 From: Bruce Feng Date: Wed, 27 Nov 2019 17:42:41 +0800 Subject: [PATCH 2/2] self._nextrow = None --- lib/mysql/connector/cursor_cext.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mysql/connector/cursor_cext.py b/lib/mysql/connector/cursor_cext.py index 9fe871c..27fe883 100644 --- a/lib/mysql/connector/cursor_cext.py +++ b/lib/mysql/connector/cursor_cext.py @@ -105,7 +105,7 @@ def reset(self, free=True): When free is True (default) the result will be freed. """ self._rowcount = -1 - self._nextrow = (None, None) + self._nextrow = None self._affected_rows = -1 self._insert_id = 0 self._warning_count = 0