[DB-SIG] There is a better way
Wed, 12 Jun 2002 08:01:28 +0100
-----BEGIN PGP SIGNED MESSAGE-----
On Wednesday 12 June 2002 7:22 am, Stuart Bishop wrote:
> On Friday, June 7, 2002, at 08:34 PM, Richard Taylor wrote:
> > if cr.description == None or cr.rowcount == 0 :
> > return 
> > try:
> > res = cr.fetchall()
> > I would welcome comments on whether this will work on all DB API
> > modules.
> Unfortunatly, rowcount may be undefined until all results have been
> retrieved (otherwise the DB may have to execute some massive query
> twice -
> once to determine the rowcount and once to actually retrieve the rows -
> in cases where the result cannot be cached in memory).
I am not sure that it matters. It would only matter if the rowcount was set to
zero when there really was some rows returned. That would appear to me to be
unlikely. If it is possible that cr.rowcount is not defined at all then I
guess the conditional could be:
if cr.description == None or (hasattr(cr,'rowcount') and cr.rowcount == 0):
This would assume that if a table description is set and rowcount is not yet
defined some rows have been returned from the database. Or at least that a
call to fetchXXX will not raise an exception.
Any of the db module maintainers want to comment on this? I believe that
psycopg would obey this condition because rowcount appears to be set to zero
when zero rows are returned.
B105 Woodward Building
St. Andrews Road
Worcs WR14 3PS
The Information contained in this E-Mail and any subsequent correspondence
is private and is intended solely for the intended recipient(s).
For those other than the recipient any disclosure, copying, distribution,
or any action taken or omitted to be taken in reliance on such information is
prohibited and may be unlawful.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
-----END PGP SIGNATURE-----