I love the functionality, but doesn't calling the function "where" conjure up the SQL WHERE clause? I might think it was doing something with SELECT...WHERE in the underlying DB.
-- Joe B. On Oct 27, 10:11 pm, "mr.freeze" <[email protected]> wrote: > Works! Would you be interested in these for sql.py Rows class?: > > def where(self,f): > if not self.response: > return None > rows = [] > for i in range(0,len(self)): > row = self[i] > if f(row): rows.append(self.response[i]) > return Rows(self._db,rows,*self.colnames) > > def filter(self,f): > if not self.response: > return None > rows = self.response > removed = [] > for i in range(0,len(self)): > row = self[i] > if f(row): > removed.append(rows[i]) > rows.remove(rows[i]) > return Rows(self._db,removed,*self.colnames) > > Example: > db.define_table('things',Field('category')) > rows = db(db.things.id>0).select() > tests = rows.where(lamdba row: row.category=="test") # returns matches > rows.filter(lamdba row: row.category=="test")# removes and returns > removed > > On Oct 27, 10:49 pm, mdipierro <[email protected]> wrote: > > > Thanks. Just fixed in trunk! > > > On Oct 27, 10:35 pm, "mr.freeze" <[email protected]> wrote: > > > > I get a syntax error when using this. I believe line 2926 of > > > Rows.__getitem__ needs to be changed from: > > > > if i >= len(self.response) or i < 0: > > > > ...to... > > > > if i >= len(self.response): > > > > since Rows.last() returns self[-1] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

