thanks, committed this to 1471 in the 0.2 branch and 1472 in the trunk.
On May 16, 2006, at 10:20 PM, Claudio MartÃnez wrote:
SelectResults has a little bug, the slices of slices are returning
the wrong results.
For example:
results = Person.mapper.select()
slice = results[10:20]
slice[5] should be equal to results[15], instead it's equal to
results[5].
Included a patch with a couple of fixes and added the corresponding
test to test/selectresults.py (runs ok!).
--
Claudio
Index: lib/sqlalchemy/ext/selectresults.py
===================================================================
--- lib/sqlalchemy/ext/selectresults.py (revision 1466)
+++ lib/sqlalchemy/ext/selectresults.py (working copy)
@@ -66,11 +66,11 @@
else:
res = self.clone()
if start is not None and stop is not None:
- res._ops.update(dict(offset=start, limit=stop-
start))
+ res._ops.update(dict(offset=self._ops.get
('offset', 0)+start, limit=stop-start))
elif start is None and stop is not None:
res._ops.update(dict(limit=stop))
elif start is not None and stop is None:
- res._ops.update(dict(offset=start))
+ res._ops.update(dict(offset=self._ops.get
('offset', 0)+start))
if item.step is not None:
return list(res)[None:None:item.step]
else:
Index: lib/sqlalchemy/mods/selectresults.py
===================================================================
--- lib/sqlalchemy/mods/selectresults.py (revision 1466)
+++ lib/sqlalchemy/mods/selectresults.py (working copy)
@@ -1,6 +1,7 @@
from sqlalchemy.ext.selectresults import *
+from sqlalchemy.orm.mapper import global_extensions
def install_plugin():
- orm.global_extensions.append(SelectResultsExt)
+ global_extensions.append(SelectResultsExt)
install_plugin()
Index: test/selectresults.py
===================================================================
--- test/selectresults.py (revision 1466)
+++ test/selectresults.py (working copy)
@@ -46,6 +46,7 @@
assert list(self.res[:10]) == self.orig[:10]
assert list(self.res[10:40:3]) == self.orig[10:40:3]
assert list(self.res[-5:]) == self.orig[-5:]
+ assert self.res[10:20][5] == self.orig[10:20][5]
def test_aggregate(self):
assert self.res.count() == 100
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users