Skip to content

Commit 2f2f27f

Browse files
committed
Merge pull request pymssql#281 from pymssql/pr280
Fix some cases of cursor.rowcont having a -1 value after iterating over .fetch*() Refs pymssql#141
2 parents ab3424d + ed4ae13 commit 2f2f27f

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
@@ -507,8 +507,8 @@ cdef class Cursor:
507507

508508
try:
509509
return self.getrow()
510-
511510
except StopIteration:
511+
self._rownumber = self._source._conn.rows_affected
512512
return None
513513
except _mssql.MSSQLDatabaseException, e:
514514
raise OperationalError, e.args[0]
@@ -529,6 +529,7 @@ cdef class Cursor:
529529
try:
530530
rows.append(self.getrow())
531531
except StopIteration:
532+
self._rownumber = self._source._conn.rows_affected
532533
break
533534
return rows
534535
except _mssql.MSSQLDatabaseException, e:

tests/helpers.py

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

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

0 commit comments

Comments
 (0)