[Twisted-Python] mapped resultsets for adbapi:
Dave Peticolas
dave at krondo.com
Fri Jun 4 10:04:13 MDT 2004
Would you mind posting this patch to the tracker?
http://www.twistedmatrix.com/users/roundup.twistd/twisted
thanks,
dave
---- Original Message ----
From: Stephen Waterbury
Date: Thu 6/3/04 23:43
To: twisted
Subject: [Twisted-Python] mapped resultsets for adbapi: "runQueryMapped"
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
_______________________________________________
Twisted-Python mailing list
Twisted-Python at twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
More information about the Twisted-Python
mailing list