Re: [SQLObject] limit/offset question?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2009-05-17 01:22:49
|
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/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |