[DB-SIG] Database API clarifications

M.-A. Lemburg lemburg@uni-duesseldorf.de
Mon, 02 Feb 1998 19:21:44 +0100


Tod Olson wrote:
> 
> [adding cursor.nextset()]
> 
> How about cursor.nextset() returns self.  Two
> benefits:
> 
> - Allows cursor.nextset().fetchall(), which is nice for interactive
>   typing.
> 
> - Works nicely if the database-API evolves to treat result sets as
>   objects.

That's a religous topic :-) just like many people would like to
see list.sort() return list and not None. We could specify it to
return a truth value (None is false, 1 and self are true). That leaves
enough space for future extensions. Objections ?

> Next question: should a programmer be able to do
> 
>         cursor.execute(big_query)
>         while cursor.nextset():
>                 cursor.fetchall()
> 
> to process all the rows of all the results, or must the programmer do
> 
>         cursor.execute(big_query)
>         cursor.fetchall()
>         while cursor.nextset():
>                 cursor.fetchall()

cursor.nextset() will have to switch to the next result set in any
case, so the latter is more appropriate. You can write it like this:

        cursor.execute(big_query)
	while 1:
	        cursor.fetchall()
        	if not cursor.nextset():
			break

without having to copy anything (Python's idiom for do {...} while (...)).

-- 
Marc-Andre Lemburg



_______________
DB-SIG  - SIG on Tabular Databases in Python

send messages to: db-sig@python.org
administrivia to: db-sig-request@python.org
_______________