Skip to content

Commit df3a74e

Browse files
committed
fix cursor_cext rowcount error
1 parent 90eaeca commit df3a74e

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lib/mysql/connector/cursor_cext.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _handle_result(self, result):
168168
"""Handles the result after statement execution"""
169169
if 'columns' in result:
170170
self._description = result['columns']
171-
self._rowcount = 0
171+
self._rowcount = -1
172172
self._handle_resultset()
173173
else:
174174
self._insert_id = result['insert_id']
@@ -515,7 +515,10 @@ def fetchall(self):
515515
self._handle_eof()
516516
return []
517517

518-
self._rowcount += len(rows[0])
518+
rowcount = len(rows[0])
519+
if rowcount >= 0 and self._rowcount == -1:
520+
self._rowcount = 0
521+
self._rowcount += rowcount
519522
self._handle_eof()
520523
#self._cnx.handle_unread_result()
521524
return rows[0]
@@ -545,7 +548,10 @@ def fetchmany(self, size=1):
545548
self._handle_eof()
546549
return []
547550

548-
self._rowcount += len(rows)
551+
rowcount = len(rows)
552+
if rowcount >= 0 and self._rowcount == -1:
553+
self._rowcount = 0
554+
self._rowcount += rowcount
549555
return rows
550556

551557
def fetchone(self):
@@ -562,7 +568,10 @@ def fetchone(self):
562568
else:
563569
self._handle_eof()
564570
return None
565-
self._rowcount += 1
571+
if self._rowcount == -1:
572+
self._rowcount = 1
573+
else:
574+
self._rowcount += 1
566575
return row[0]
567576

568577
def __iter__(self):
@@ -839,7 +848,7 @@ class CMySQLCursorPrepared(CMySQLCursor):
839848
def __init__(self, connection):
840849
super(CMySQLCursorPrepared, self).__init__(connection)
841850
self._rows = None
842-
self._rowcount = 0
851+
self._rowcount = -1
843852
self._next_row = 0
844853
self._binary = True
845854
self._stmt = None
@@ -1041,6 +1050,9 @@ def fetchall(self):
10411050
self._handle_eof()
10421051
return []
10431052

1044-
self._rowcount += len(rows[0])
1053+
rowcount = len(rows[0])
1054+
if rowcount >= 0 and self._rowcount == -1:
1055+
self._rowcount = 0
1056+
self._rowcount += rowcount
10451057
self._handle_eof()
10461058
return rows[0]

0 commit comments

Comments
 (0)