Author: phd
Date: 2007-04-17 10:28:32 -0600 (Tue, 17 Apr 2007)
New Revision: 2551
Modified:
SQLObject/branches/0.7/docs/News.txt
SQLObject/branches/0.7/sqlobject/sresults.py
SQLObject/branches/0.7/sqlobject/tests/test_select.py
Log:
Fixed a longstanding bug with .select() ignoring 'limit' parameter.
Modified: SQLObject/branches/0.7/docs/News.txt
===================================================================
--- SQLObject/branches/0.7/docs/News.txt 2007-04-17 16:28:11 UTC (rev 2550)
+++ SQLObject/branches/0.7/docs/News.txt 2007-04-17 16:28:32 UTC (rev 2551)
@@ -15,6 +15,8 @@
* Fixed a minor comparison problem in test_decimal.py.
+* Fixed a longstanding bug with .select() ignoring 'limit' parameter.
+
SQLObject 0.7.5
===============
Modified: SQLObject/branches/0.7/sqlobject/sresults.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/sresults.py 2007-04-17 16:28:11 UTC (rev 2550)
+++ SQLObject/branches/0.7/sqlobject/sresults.py 2007-04-17 16:28:32 UTC (rev 2551)
@@ -20,16 +20,21 @@
self.clauseTables = clauseTables
self.tables = tablesDict.keys()
self.ops = ops
- if self.ops.get('orderBy', sqlbuilder.NoDefault) is sqlbuilder.NoDefault:
- self.ops['orderBy'] = sourceClass.sqlmeta.defaultOrder
- orderBy = self.ops['orderBy']
+ if ops.get('orderBy', sqlbuilder.NoDefault) is sqlbuilder.NoDefault:
+ ops['orderBy'] = sourceClass.sqlmeta.defaultOrder
+ orderBy = ops['orderBy']
if isinstance(orderBy, list) or isinstance(orderBy, tuple):
orderBy = map(self._mungeOrderBy, orderBy)
else:
orderBy = self._mungeOrderBy(orderBy)
- self.ops['dbOrderBy'] = orderBy
+ ops['dbOrderBy'] = orderBy
if ops.has_key('connection') and ops['connection'] is None:
del ops['connection']
+ if ops.get('limit', None):
+ assert not ops.get('start', None) and not ops.get('end', None), \
+ "'limit' cannot be used with 'start' or 'end'"
+ ops["start"] = 0
+ ops["end"] = ops["limit"]
def __repr__(self):
return "<%s at %x>" % (self.__class__.__name__, id(self))
@@ -140,13 +145,13 @@
if self.ops.get('end', None) is not None \
and self.ops['end'] < end:
end = self.ops['end']
- return self.clone(start=start, end=end)
+ return self.clone(limit=None, start=start, end=end)
else:
if value < 0:
return list(iter(self))[value]
else:
start = self.ops.get('start', 0) + value
- return list(self.clone(start=start, end=start+1))[0]
+ return list(self.clone(limit=None, start=start, end=start+1))[0]
def __iter__(self):
# @@: This could be optimized, using a simpler algorithm
@@ -173,6 +178,7 @@
def count(self):
""" Counting elements of current select results """
+ assert not self.ops.get('limit'), "'limit' is meaningless with 'distinct'"
assert not (self.ops.get('distinct') and (self.ops.get('start')
or self.ops.get('end'))), \
"distinct-counting of sliced objects is not supported"
Modified: SQLObject/branches/0.7/sqlobject/tests/test_select.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/tests/test_select.py 2007-04-17 16:28:11 UTC (rev 2550)
+++ SQLObject/branches/0.7/sqlobject/tests/test_select.py 2007-04-17 16:28:32 UTC (rev 2551)
@@ -1,6 +1,6 @@
from __future__ import generators # for enumerate
from sqlobject import *
-from sqlobject.tests.dbtest import *
+from dbtest import *
try:
enumerate
@@ -71,6 +71,12 @@
pass
assert count == len(names)
+def test_05_select_limit():
+ setupIter()
+ assert len(list(IterTest.select(limit=2))) == 2
+ raises(AssertionError, IterTest.select(limit=2).distinct)
+ raises(AssertionError, IterTest.select(limit=2).clone, start=1)
+
def test_selectBy():
setupClass(IterTest)
a = IterTest(name='a')
|