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

Stephen Waterbury golux at comcast.net
Fri Jun 4 02:33:34 EDT 2004


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.


* 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).


* 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.  :)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: adbapi.patch
Type: text/x-patch
Size: 1388 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20040604/83ec0bbd/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_enterprise.patch
Type: text/x-patch
Size: 3617 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20040604/83ec0bbd/attachment-0001.bin 

More information about the Twisted-Python mailing list