On Sat, May 16, 2009 at 03:52:28PM -0400, inhahe wrote:
> Hi, i have a question about limit/offset.  i read something that says if
> you're doing something like pages of results with next/previous buttons, you
> should do the query once and then cache the results for a certain period of
> time, but then my friend says you can do limit(x,y) where, i guess, one
> variable is the starting point and the other is the number of records.  then
> i found out about the "offset" keyword on the web, so i guess the proper way
> is to use limit and offset.  either way, this seems more efficient than
> caching the whole query--is it?  and how do i do this in sqlobject?  or
> should i just store a query and use slicing on it?  or just do the same
> query each time and use slicing on it since sqlobject caches certain things
> anyway?  thanks.

   In SQLObject, MyTable.select() doesn't return a list of rows - the call
returns an instance of SelectResult class which maps slicing to
limit/offset. This is how you should do it:

for row in MyTable.select(query)[offset:offset+limit]:
   process(row)

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            p...@phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to