equal
deleted
inserted
replaced
19 |
19 |
20 __docformat__ = "restructuredtext en" |
20 __docformat__ = "restructuredtext en" |
21 |
21 |
22 from warnings import warn |
22 from warnings import warn |
23 |
23 |
|
24 from six.moves import range |
|
25 |
24 from logilab.common import nullobject |
26 from logilab.common import nullobject |
25 from logilab.common.decorators import cached, clear_cache, copy_cache |
27 from logilab.common.decorators import cached, clear_cache, copy_cache |
26 from rql import nodes, stmts |
28 from rql import nodes, stmts |
27 |
29 |
28 from cubicweb import NotAnEntity, NoResultError, MultipleResultsError |
30 from cubicweb import NotAnEntity, NoResultError, MultipleResultsError |
184 |
186 |
185 :rtype: `ResultSet` |
187 :rtype: `ResultSet` |
186 """ |
188 """ |
187 rows, descr = [], [] |
189 rows, descr = [], [] |
188 rset = self.copy(rows, descr) |
190 rset = self.copy(rows, descr) |
189 for i in xrange(len(self)): |
191 for i in range(len(self)): |
190 if not filtercb(self.get_entity(i, col)): |
192 if not filtercb(self.get_entity(i, col)): |
191 continue |
193 continue |
192 rows.append(self.rows[i]) |
194 rows.append(self.rows[i]) |
193 descr.append(self.description[i]) |
195 descr.append(self.description[i]) |
194 rset.rowcount = len(rows) |
196 rset.rowcount = len(rows) |
309 else: |
311 else: |
310 newselect = stmts.Select() |
312 newselect = stmts.Select() |
311 newselect.limit = limit |
313 newselect.limit = limit |
312 newselect.offset = offset |
314 newselect.offset = offset |
313 aliases = [nodes.VariableRef(newselect.get_variable(chr(65+i), i)) |
315 aliases = [nodes.VariableRef(newselect.get_variable(chr(65+i), i)) |
314 for i in xrange(len(rqlst.children[0].selection))] |
316 for i in range(len(rqlst.children[0].selection))] |
315 for vref in aliases: |
317 for vref in aliases: |
316 newselect.append_selected(nodes.VariableRef(vref.variable)) |
318 newselect.append_selected(nodes.VariableRef(vref.variable)) |
317 newselect.set_with([nodes.SubQuery(aliases, rqlst)], check=False) |
319 newselect.set_with([nodes.SubQuery(aliases, rqlst)], check=False) |
318 newunion = stmts.Union() |
320 newunion = stmts.Union() |
319 newunion.append(newselect) |
321 newunion.append(newselect) |
385 |
387 |
386 # client helper methods ################################################### |
388 # client helper methods ################################################### |
387 |
389 |
388 def entities(self, col=0): |
390 def entities(self, col=0): |
389 """iter on entities with eid in the `col` column of the result set""" |
391 """iter on entities with eid in the `col` column of the result set""" |
390 for i in xrange(len(self)): |
392 for i in range(len(self)): |
391 # may have None values in case of outer join (or aggregat on eid |
393 # may have None values in case of outer join (or aggregat on eid |
392 # hacks) |
394 # hacks) |
393 if self.rows[i][col] is not None: |
395 if self.rows[i][col] is not None: |
394 yield self.get_entity(i, col) |
396 yield self.get_entity(i, col) |
395 |
397 |
604 try: |
606 try: |
605 myvar = select.selection[col].variable |
607 myvar = select.selection[col].variable |
606 except AttributeError: |
608 except AttributeError: |
607 # not a variable |
609 # not a variable |
608 continue |
610 continue |
609 for i in xrange(len(select.selection)): |
611 for i in range(len(select.selection)): |
610 if i == col: |
612 if i == col: |
611 continue |
613 continue |
612 coletype = self.description[row][i] |
614 coletype = self.description[row][i] |
613 # None description possible on column resulting from an |
615 # None description possible on column resulting from an |
614 # outer join |
616 # outer join |