[DB-SIG] Use of record sets

John Shafaee pshafaee@hostway.com
Mon, 09 Apr 2001 09:54:54 -0500


This may be a stupid question, but is the dtuple.py specs. part of the Python
DB API? I do not have access to the older SIGs, but looking over the current
API interface docs I did not see anything mentioned about such a class.

Actually, the concept of viewing DB results as records has been around for much
longer than Python itself, no argument there. I am certain that at this time
there are a number of Python implementations out there; all equally good and
useful. Just in the past DB-SIG posts there were two different implementations
mentioned (Record and SQLDict).

However, I think there is a need to standardize on this concept (if it has not
already been done and/or I just missed it). I believe that the most appropriate
definition for this concept would be in the Python DB API. It would be great if
all implementations of the DB API would provide a facility for treating results
as record sets.

So, as there are many different implementations of converting fetchall() results
into records sets, there isn't a standard one that we can expect when working
with a Python DB module.

Best,
John S.

Greg Stein wrote:

> Euh... there is already a module to handle result sets as tuple,
> dictionaries, or attributed objects. It was written over five years ago :-)
>
> http://www.lyra.org/greg/python/
>
> Right around the middle of the page: dtuple.py
>
> Cheers,
> -g
>
> On Wed, Apr 04, 2001 at 06:11:37PM +0200, Dittmar, Daniel wrote:
> > > result = curs.fetchone()
> > > print "Found id '%s', first name '%s' and last name '%s'"%( result[0],
> > result[1], result[2] )
> >
> > vs.
> >
> > > print "Found id '%s', first name '%s' and last name '%s'"%( result['id'],
> > result['first_name'],
> > >   result['last_name'] )
> >
> > How about
> >
> > id, first_name, last_name = curs.fetchone ()
> > print "Found id '%s', first name '%s' and last name '%s'"%( id, first_name,
> > last_name)
> >
> > or better still
> >
> > for id, first_name, last_name in curs:
> >     print "Found id '%s', first name '%s' and last name '%s'"%( id,
> > first_name, last_name)
> >
> > This is of couse not directly an argument against using strings as a column
> > index (DBI has them, JDBC has them).
> >
> > There is one annoying property of SQL in this context: identifier are
> > converted to uppercase unless quoted. Should the UserDict mimic this
> > behaviour by trying both the actual string and the uppercase version?
> >
> > And how about returning row objects. That would allow .dot notation (if the
> > column names are valid Python identifier):
> > print "Found id '%s', first name '%s' and last name '%s'"%( result.id,
> > result.first_name, result.last_name)
> >
> > My personal preference: 'for id, first_name, last_name in curs:'
> >
> > Daniel
> >
> > --
> > Daniel Dittmar
> > daniel.dittmar@sap.com
> > SAP DB, SAP Labs Berlin
> > http://www.sapdb.org/
> >
> > _______________________________________________
> > DB-SIG maillist  -  DB-SIG@python.org
> > http://mail.python.org/mailman/listinfo/db-sig
>
> --
> Greg Stein, http://www.lyra.org/