Opened 17 years ago

Closed 15 years ago

#632 enhancement closed wontfix (wontfix)

Mapped resultsets for adbapi

Reported by: Steve Waterbury Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Dave Peticolas, Steve Waterbury Branch:


Attachments (2)

adbapi.patch (1.4 KB) - added by Steve Waterbury 17 years ago.
test_enterprise.patch (3.5 KB) - added by Steve Waterbury 17 years ago.

Download all attachments as: .zip

Change History (7)

Changed 17 years ago by Steve Waterbury

Attachment: adbapi.patch added

comment:1 Changed 17 years ago by Steve Waterbury

This patch 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 and


* 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 or pyPgSQL's 'PgResultSet' attributes
  based on the cursor's column names.

* also, as James Knight points out, the same thing can be done with
  current adbapi functionality by using runInteraction -- to quote
  his message:

You would do something like:
def mapQuery(curs, *args, **kwargs):
 curs.execute(*args, **kwargs)
 result = curs.fetchall()
 columns = [d[0] for d in curs.description]
 return [dict(zip(columns, r)) for r in result]

dbpool.runInteraction(mapQuery, ...)

Changed 17 years ago by Steve Waterbury

Attachment: test_enterprise.patch added

comment:2 Changed 17 years ago by Steve Waterbury

... and the unit test patch.

comment:3 Changed 17 years ago by Dave Peticolas

Thanks, I'll take a close look at this over the weekend.

comment:4 Changed 15 years ago by Jean-Paul Calderone

Component: core
Resolution: wontfix
Status: newclosed

It looks like this is not going to be applied, since it can be done with runInteraction and t.e.adbapi should be even thinner than it is now, not growing even more functionality (plus it's basically unmaintained).

comment:5 Changed 11 years ago by <automation>

Owner: Dave Peticolas deleted
Note: See TracTickets for help on using tickets.