a ResultProxy is analgous to a result object sent directly from a DBAPI connection object and tries to implement the same interface with some enhancements to the targeting of columns. The reason result sets should never implement array-like index and length methods is because they represent a live stream of results being received from a database; as the loops are iterated, they can be processed and discarded from memory, thereby allowing arbitrarily large result sets to be processed. also, not all rows need to be iterated, which allows portions of result sets to be processed without having to pull all the data in at once, if at all.
for the result set to implement a count() method on result-holding cursor would require pulling the entire result set into memory all at once, making it impossible to process arbitrarily large result sets and making it impossible to "peek" at the first few rows in a result set without an enormous performance penalty. the database itself also does not necessarily know how many rows are in the result set either; if the results are not ordered, then the database should be giving you rows as it locates them, before it has even completed its task of finding them all. if you want the count of rows for a result set, execute a count() with the same criterion before ever getting the primary result set, i.e.: mytable.count(mytable.c.id==7) Jonathan Hayward http://JonathansCorner.com wrote: > I'll do that for now. It seems one of the things, though, of "If you're > doing it this way you're doing it the wrong way." > > On 4/2/06, Michael Bayer <[EMAIL PROTECTED]> wrote: >> >> >> you have to fetch all the rows into a list and then count how many items >> in the list. >> >> >> Jonathan Hayward http://JonathansCorner.com wrote: >> > I thought I had asked this question before and gotten an answer, but I >> > searched and didn't find it (I'm getting a little ragged): >> > >> > How do I tell how many rows are in a ResultProxy object? >> > >> > I have: number_of_slots = search_results.count() #search_results is a >> > ResultProxy >> > >> > which is getting: >> > >> > Traceback (most recent call last): >> > File >> > "/server1/users/jonathan/creations/inventions/software/insight/alchemy", >> > line 5876, in ? >> > multitasking.start_oracle() >> > File >> > "/server1/users/jonathan/creations/inventions/software/insight/alchemy", >> > line 3486, in start_oracle >> > self.run_oracle() >> > File >> > "/server1/users/jonathan/creations/inventions/software/insight/alchemy", >> > line 3447, in run_oracle >> > self.handle_oracle_query(newsocket, address) >> > File >> > "/server1/users/jonathan/creations/inventions/software/insight/alchemy", >> > line 3394, in handle_oracle_query >> > generate_output() >> > File >> > "/server1/users/jonathan/creations/inventions/software/insight/alchemy", >> > line 5175, in generate_output >> > current_frame.display() >> > File >> > "/server1/users/jonathan/creations/inventions/software/insight/alchemy", >> > line 2788, in display >> > build_output_for_appropriate_search_results() >> > File >> > "/server1/users/jonathan/creations/inventions/software/insight/alchemy", >> > line 4635, in build_output_for_appropriate_search_results >> > build_output_for_navigation(search_results) >> > File >> > "/server1/users/jonathan/creations/inventions/software/insight/alchemy", >> > line 4669, in build_output_for_navigation >> > number_of_slots = search_results.count() >> > AttributeError: ResultProxy instance has no attribute 'count' >> > >> > >> > -- >> > ++ Jonathan Hayward, [EMAIL PROTECTED] >> > ** To see an award-winning website with stories, essays, artwork, >> > ** games, and a four-dimensional maze, why not visit my home page? >> > ** All of this is waiting for you at http://JonathansCorner.com >> > >> > ** If you'd like a Google Mail (gmail.com) account, please tell me! >> > >> >> > > > -- > ++ Jonathan Hayward, [EMAIL PROTECTED] > ** To see an award-winning website with stories, essays, artwork, > ** games, and a four-dimensional maze, why not visit my home page? > ** All of this is waiting for you at http://JonathansCorner.com > > ** If you'd like a Google Mail (gmail.com) account, please tell me! > ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users