Re: limiting the amount of objects retrieved
Sebastien Bigaret <[email protected]> 07 Feb 2004 18:10:28 +0100
| Newsgroups | gmane.comp.python.modeling |
|---|---|
| Message-ID | <[email protected]> |
John Lenton <[email protected]> wrote: > On Fri, Feb 06, 2004 at 05:15:09PM +0100, Sebastien Bigaret wrote: > > > > John Lenton <[email protected]> wrote: > > > I need (or, rather, would like) to be able to use the 'splice > > > parameters' that I see commented out in Modeling.EditingContext to be > > > able to send feedback to the user as to how many objects have been > > > retrieved (and to let her cancel the operation if necessary). Is there > > > anything left to be done to be able to use these parameters? > > > > A patch was once made for using slice parameters; I was not able to > > find it on sf.net, however if you're interested in testing it I can > > make it available on sf tonite after I'm back home. > > I would be more than happy to do that, thank you. > > > If the goal is simply to control that not too much objects are fetched > > by a query, you may want to use ec.fetchCount() [same API as ec.fetch()] > > which returns the number of objects fetched (without actually fetching > > them). > > yes, but it's more than that: I want to give the user detailed > feedback as to the progress of the query, and the ability to cancel > it. The easyest way to do both is using fetchCount and then fetching > up to a number of objects. Fine, so the patch is for you! Sorry for the delay, it took me some time to retrieve it --it was hidden in a dark corner of my hard-disk :) It also required some work since it was made quite a long time ago and was completely out-of-sync. The patch #892454 should be applied to v0.9pre16. It adds fetch slices and, as an extra bonus, 'orderBy' parameter to ec.fetch(). It can be found at: https://sourceforge.net/tracker/index.php?func=detail&aid=892454&group_id=58935&atid=489337 Sort orderings are strings like '<attribute path> [<operator>]', where operator can be 'asc' (ascending, default), 'desc' (descending), and 'iasc' and 'idesc' (case-insensitive asc. and desc) Here are some examples: ec.fetch('Book', 'author.lastName != NULL', orderBy='author.lastName desc, price desc, title iasc') ec.fetch('Book', 'author.lastName != NULL', limit=2, offset=2) ec.fetch('Book', limit=2, page=1) Those examples are taken from test_EditingContext_Global.py (after patch has been applied), methods test_17_fetchSpecWithSortOrderings(), test_18/18b_fetchSpecWithFetchLimit() to which you can refer for further details (you'll find there the full API for slices and FetchSpecification as well). About fetch slices: 'offset' begins at zero (zero is the first record in the result set), while 'page' begins at one (page one is the first page). Current limitations are: - it is available/tested for Postgresql and MySQL only - parameter isDeep shouldn't be set w/ fetch slices and/or with sort orderings, - inserted (unsaved) objects will appear at the end of each result set when limit and/or orderBy is set. Last note, the patch contains all changes that have been made since 0.9pre16. This shouldn't be a problem, but I prefered to be explicit about that; see CHANGES and MIGRATION for the details. Enjoy ;) and thanks for your time testing this. -- Sébastien. PS: just before posting I wondered whether this hadn't been discussed once. And true! see here: https://sourceforge.net/mailarchive/forum.php?thread_id=1687932&forum_id=10674 https://sourceforge.net/mailarchive/forum.php?thread_id=1688402&forum_id=10674 https://sourceforge.net/mailarchive/forum.php?thread_id=1755269&forum_id=10674 The last url contains (at end) a post from me explaining the patch in more details (forget about the cvs branch however, it is now closed). Yes, this was one year ago... ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn