[Twisted-Python] Testing with trial, adbapi questions

Brendon Colby brendoncolby at gmail.com
Mon Jun 25 15:35:23 EDT 2007

On 6/25/07, Karl Bartel <karlb at gmx.net> wrote:
> Brendon Colby wrote:
> > 4. I was digging through the adbapi code, and it appears that the only
> > type of result set I can get is a tuple (because only cursors are
> > used...). Is there a way I can get a dictionary returned, keys are
> > column names? i.e. a MySqlDB.fetch_row(how=1). I'm just not seeing how
> > I can do this with adbapi or, rather, how I can pass through to the
> > MySqlDB module to get this type of result set.
> This depends on your DBAPI implementation. psycopg2 and pysqlite have
> optional support for this. I don't know about you mysql, though. Using
> any of these is not DBAPI2 compliant, but it's extremely useful.

Aha! This got me thinking...so I dug into the MySQLdb README file
(again). To be able to get a tuple of dictionaries returned while
using adbabi/MySQLdb, you simply have to do:

    self.dbPool = adbapi.ConnectionPool("MySQLdb",host=host,port=port,
                                        cursorclass=DictCursor) #<-----

Since MySQLdb implements cursors in Python, one can subclass the base
cursor class or use one of the several others provided - in this case
DictCursor. This just wasn't obvious to me (never was) in the README!


More information about the Twisted-Python mailing list