From cf213e5b341b58dd4186898b99a3a719fd378336 Mon Sep 17 00:00:00 2001 From: mkmoisen Date: Wed, 27 Apr 2016 21:27:28 -0700 Subject: [PATCH] Modify cursor.fetchmany() to break after no results Currently, if you call `cur.fetchmany(1000)` while there is only 1 row left to fetch, the loop will call `self.fetchone()` 1000 times and will return an array of size 1000, where 999 values are None. This file change breaks out of the loop if `self.fetchone()` returns None to prevent this behavior, exactly what `fetchall()` does. --- pyhs2/cursor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyhs2/cursor.py b/pyhs2/cursor.py index 32dc76a..053129d 100644 --- a/pyhs2/cursor.py +++ b/pyhs2/cursor.py @@ -153,7 +153,10 @@ def fetchmany(self,size=-1): size = self.arraysize recs = [] for i in range(0,size): - recs.append(self.fetchone()) + rec = self.fetchone() + if rec is None: + break + recs.append(rec) self._cursorLock.release() return recs