[Zope] Re: Result Set

Casey Duncan casey at zope.com
Wed Apr 14 11:51:14 EDT 2004


On Wed, 14 Apr 2004 10:14:56 -0400 (EDT)
Asad Habib <ahabib at engin.umich.edu> wrote:

> Hello. Does anyone know if there is a way to determine the number of
> rows retrieved in a result set without actually iterating over it? Any
> help would be greatly appreciated. Thanks.

What kind of result set? SQL or catalog?

for SQL it is probably best to perform a second "select count(*) from
foo" query to get the count, unless the where clause is complex, in
which case Python len() will be fine (and won't iterate).

For catalog results, len(results) is your only choice, unless you use
'sort_limit' in which case you can use results.actual_result_count.
len(results) may iterate in certain cases (like if you concatenated
results for example), but should be efficient for the most part.

hth,

-Casey




More information about the Zope mailing list