Re: [Modeling-users] limiting the amount of objects retrieved
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2004-02-07 17:09:06
|
John Lenton <jo...@vi...> wrote: > On Fri, Feb 06, 2004 at 05:15:09PM +0100, Sebastien Bigaret wrote: > >=20 > > John Lenton <jo...@vi...> 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? > >=20 > > 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. >=20 > I would be more than happy to do that, thank you. >=20 > > 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). >=20 > 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=3Ddetail&aid=3D892454&group_= id=3D58935&atid=3D489337 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 !=3D NULL', orderBy=3D'author.lastName desc, price desc, title iasc') ec.fetch('Book', 'author.lastName !=3D NULL', limit=3D2, offset=3D2) ec.fetch('Book', limit=3D2, page=3D1) 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=E9bastien. 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=3D1687932&forum_id= =3D10674 https://sourceforge.net/mailarchive/forum.php?thread_id=3D1688402&forum_id= =3D10674 https://sourceforge.net/mailarchive/forum.php?thread_id=3D1755269&forum_id= =3D10674 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... |