Fix infinite loop in find method

If a _limit is not given, the query limit should
be given by eit
This commit is contained in:
Stefan Wehrmeyer 2014-01-25 21:20:18 +01:00
parent 5a7cafd4e2
commit eff6925af9
2 changed files with 8 additions and 3 deletions

View File

@ -337,6 +337,9 @@ class Table(object):
rp = self.database.executable.execute(count_query) rp = self.database.executable.execute(count_query)
total_row_count = rp.fetchone()[0] total_row_count = rp.fetchone()[0]
if _limit is None:
_limit = total_row_count
if _step is None or _step is False or _step == 0: if _step is None or _step is False or _step == 0:
_step = total_row_count _step = total_row_count
@ -348,8 +351,6 @@ class Table(object):
for i in count(): for i in count():
qoffset = _offset + (_step * i) qoffset = _offset + (_step * i)
qlimit = _step
if _limit is not None:
qlimit = min(_limit - (_step * i), _step) qlimit = min(_limit - (_step * i), _step)
if qlimit <= 0: if qlimit <= 0:
break break

View File

@ -194,6 +194,10 @@ class TableTestCase(unittest.TestCase):
assert len(ds) == 3, ds assert len(ds) == 3, ds
ds = list(self.tbl.find(place=TEST_CITY_1, _limit=2)) ds = list(self.tbl.find(place=TEST_CITY_1, _limit=2))
assert len(ds) == 2, ds assert len(ds) == 2, ds
ds = list(self.tbl.find(place=TEST_CITY_1, _limit=2, _step=1))
assert len(ds) == 2, ds
ds = list(self.tbl.find(place=TEST_CITY_1, _limit=1, _step=2))
assert len(ds) == 1, ds
def test_distinct(self): def test_distinct(self):
x = list(self.tbl.distinct('place')) x = list(self.tbl.distinct('place'))