Skip to content

Commit ed4ae13

Browse files
bladamsramiro
authored andcommitted
Set rowcount correctly after retrieving all rows through fetchall or fetchmany
ref pymssql#141
1 parent 461519b commit ed4ae13

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

pymssql.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ cdef class Cursor:
505505

506506
try:
507507
return self.getrow()
508-
509508
except StopIteration:
509+
self._rownumber = self._source._conn.rows_affected
510510
return None
511511
except _mssql.MSSQLDatabaseException, e:
512512
raise OperationalError, e.args[0]
@@ -527,6 +527,7 @@ cdef class Cursor:
527527
try:
528528
rows.append(self.getrow())
529529
except StopIteration:
530+
self._rownumber = self._source._conn.rows_affected
530531
break
531532
return rows
532533
except _mssql.MSSQLDatabaseException, e:

tests/helpers.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,24 @@ def test_select_rowcount(self):
285285
cur.fetchall()
286286
eq_(cur.rowcount, 5)
287287

288+
def test_fetchone_rowcount(self):
289+
cur = self.execute('select * from test')
290+
eq_(cur.rowcount, -1)
291+
292+
for _ in iter(cur.fetchone, None):
293+
eq_(cur.rowcount, -1)
294+
295+
eq_(cur.rowcount, 5)
296+
297+
def test_fetchmany_rowcount(self):
298+
cur = self.execute('select * from test')
299+
eq_(cur.rowcount, -1)
300+
301+
for _ in iter(cur.fetchmany, []):
302+
eq_(cur.rowcount, -1)
303+
304+
eq_(cur.rowcount, 5)
305+
288306
def test_as_dict(self):
289307
# test for http://code.google.com/p/pymssql/issues/detail?id=92
290308
cur = self.conn.cursor(as_dict=True)

0 commit comments

Comments
 (0)