[Twisted-Python] mapped resultsets for adbapi: "runQueryMapped"

Stephen Waterbury golux at comcast.net
Fri Jun 4 00:33:34 MDT 2004


Gang,

I don't know whether this is of interest to anyone else, but
I needed it for my stuff and I was hoping it might be suitable for
inclusion in adbapi:  it defines a new adbapi.ConnectionPool method
called 'runQueryMapped' (and corresponding '_runQueryMapped') whose
return value is a list of dicts that map column names to values
(rather than the list of lists of values that runQuery returns).

Attached are patches for adbapi.py and test_enterprise.py.

Pros:

* shouldn't break any existing code, as it is a completely separate
  method from runQuery and _runQuery.

* portable, should work with any DBAPI-conforming adaptor, since it
  builds the dictionaries from the cursor.description, which is part
  of the DBAPI spec.  The reason I needed to do this inside of adbapi
  is that adbapi doesn't expose cursor.description ... which is fine,
  as it seems cleaner to keep it inside adbapi anyway.

* unit test included (I've only run the test against SQLite, pyPgSQL,
  and psycopg, as I don't have the others installed on my machine).

Cons:

* only one I can think of is that it's unnecessary if you are using
  either reflector, which I'm not, or pyPgSQL's 'PgResultSet' attributes
  based on the cursor's column names, which I was but am not any more,
  since that is not portable and not part of the DBAPI spec.  While
  modifying my code to work with other backends (esp. psycopg and
  sqlite), I came up with this.

If it's decided not to include it, that's okay, I'll just keep patching
my Twisted source.  It's also fine if you want to name it something
else.  :)

Cheers,
Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: adbapi.patch
Type: text/x-patch
Size: 1388 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20040604/83ec0bbd/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_enterprise.patch
Type: text/x-patch
Size: 3617 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20040604/83ec0bbd/attachment-0005.bin>


More information about the Twisted-Python mailing list