[DB-SIG] Use of record sets
Andy Dustman
andy@dustman.net
Fri, 6 Apr 2001 23:41:46 -0400 (EDT)
On Thu, 5 Apr 2001, Brad Clements wrote:
> On 3 Apr 2001, at 21:57, John Shafaee wrote:
>
> > The DBFactory module returns query results as a sequence of Records.
> > Records are Python UserDict objects that index field data by the
> > field(column) name. This is very convenient when interpolating results in a
> > string. The above example code would look like the following if written in
> > terms of lists of Records:
> >
> > print "Found id '%s', first name '%s' and last name
> > '%s'"%( result['id'], result['first_name'], result['last_name'] )
> >
> > I was wondering if this is something that you have considered. If not, I
> > was wondering what were the proper channels that I would need to go through
> > to make this suggestion open to the rest of the Python DB API community.
>
>
> Look for the module SQLDict.py which does exactly this (and much more)
Actually, SQLDict doesn't return dictionaries. It gives a dictionary
interface to your SQL database. It also has a facility for returning
records as real classes:
print "Found id '%s', first name '%s' and last name '%s'"%\
( result.id, result.first_name, result.last_name )
print result # better still, define __str__ to do this
> Much of my Zope/Python work is done with either SQLDict, or at the base db-api level. I
> use the db-api level when I need the maximum performance.
<boggle>I hardly ever hear of anyone using SQLDict...</boggle>
Also, as someone else pointed out, MySQLdb can return dictionaries instead
of tuples, if you use a DictCursor. This resulted from user-clamoring,
since the older MySQLmodule supported fetchDictxxx() methods. I suppose
derivative cursor classes could be added to other databases as well.
And just today I was wrestling a bit with _mysql (the low-level portion of
MySQLdb), since Zope ZMySQLDA uses that. Zope's DA interface is a database
API in itself, and making it play with _mysql is as easy or easier (and
probably a tad faster) than using MySQLdb.
--
Andy Dustman PGP: 0xC72F3F1D
@ .net http://dustman.net/andy
"Normally with carbonara you use eggs, but I used lobster brains instead."
-- Masahiko Kobe (Iron Chef Italian): 30-year-old Giant Lobster Battle