Interested in these? Handy for paging through stuff you've already
pulled from the db (otherwise limitby is best):

rows = db().select(db.things.ALL)

skip - bypass the specified number of elements and return the rest
take - return the specified number of elements from the beginning

>page = rows.skip(pagenum * pagesize).take((pagesize+1)


On Oct 28, 12:50 pm, mdipierro <[email protected]> wrote:
> deal! uploading.
>
> On Oct 28, 12:42 pm, Alex Fanjul <[email protected]> wrote:
>
> > I agree with Jonathan, (find) and (exclude) are the best.
> > Filter is like "let me this in the result" (just the opposite sense),
> > and remove is like "real remove this from my database"
>
> > So... '*Find*' this in my rows, BUT also *Exclude *this from my results!
>
> > Alex F
>
> > El 28/10/2009 18:23, Jonathan Lundell escribió:
>
> > > On Oct 28, 2009, at 9:58 AM, mdipierro wrote:
>
> > >> On a third thougth. Mr Freeze original names are better (find and
> > >> filter it is).
>
> > > Your use of 'filter' (or my confusion about it) for both cases
> > > illustrates its ambiguity. How about 'find' and 'exclude'?
>
> > >> I added slices too. Here is an example:
>
> > >> b=DAL('sqlite://storage')
> > >> db.define_table('a',Field('b'))
> > >> db.a.insert(b='aaa')
> > >> db.a.insert(b='aab')
> > >> db.a.insert(b='abb')
> > >> db.a.insert(b='bbb')
>
> > >> ### return rows that match condition
> > >> rows=db(db.a.id>0).select().find(lambda row: row.b>0)
>
> > >> #### sort rows
> > >> rows0 = rows.sort(lambda row: row.b.upper()):
>
> > >> rows1=db(db.a.id>0).select()
> > >> ### move matching rows from rows1 to rows2
> > >> rows2=rows1.filter(lambda row: row.b>'b')
>
> > >> ### get a slice of the rows
> > >> rows3=rows[1:3]
>
> > >> They can be mixed and matched
>
> > >> rows=(rows1|rows2|rows3).find(..)[:].filter(..).sort(..)
>
> > >> Now one implement at DAL level most functions missing on GAE like OR,
> > >> LIKE, BELONGS.
>
> > >> Massimo
>
> > >> On Oct 28, 11:17 am, mdipierro<[email protected]>  wrote:
>
> > >>> Ok, I am going with filter (same as your find) and extract (same as
> > >>> your filter with some changes to make it faster and issue that caused
> > >>> it to skip some rows). In trunk now.
>
> > >>> Massimo
>
> > >>> On Oct 28, 10:51 am, "mr.freeze"<[email protected]>  wrote:
>
> > >>>> Now I'm confused :)  What if you just changed the 'where' to 'find'
> > >>>> and kept both.  Filter should reduce the actual set, returning the
> > >>>> removed rows.  Find should just return the matched rows.
>
> > >>>> On Oct 28, 10:15 am, mdipierro<[email protected]>  wrote:
>
> > >>>>> OK I just put the where function in trunk but renamed it filter
> > >>>>> (sorry
> > >>>>> for the confusion).
>
> > >>>>> On Oct 28, 10:11 am, Joe Barnhart<[email protected]>  wrote:
>
> > >>>>>> I know, that's what I'm saying.... the word "where" suggests it
> > >>>>>> is an SQL
> > >>>>>> verb but it has nothing to do with SQL.  I was just thinking it
> > >>>>>> might be
> > >>>>>> confusing to new users of w2p.
>
> > >>>>>> On Wed, Oct 28, 2009 at 6:32 AM, mr.freeze
> > >>>>>> <[email protected]>  wrote:
>
> > >>>>>>> No, anything post 'select' is done after the db call, including
> > >>>>>>> first
> > >>>>>>> () and last().
>
> > >>>>>>> On Oct 28, 2:51 am, Joe  Barnhart<[email protected]>  wrote:
>
> > >>>>>>>> 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]
>
> > --
> > Alejandro Fanjul Fdez.
> > [email protected]
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to