[DB-SIG] about dictfetch

M.-A. Lemburg mal@lemburg.com
Fri, 01 Feb 2002 12:19:04 +0100


"zammon@libero.it" wrote:
> 
> Hi all,
> 
> I see psycopg has  thre very useful cursor methods; dictfetchone(),
> dictfetchmany() and dictfetchall()
> I find not those methods defined on Python Database API Specification 2.0
> Someone can tell me  why those methods are not considered  neccessaries ?

Please see the archives of this mailing list. This is a FAQ (even though
there's no FAQ entry yet ;-).

"""
    A very common question on the DB-SIG mailing list is how to
    construct a dictionary out of the tuples returned by .fetchxxx().

    There are several existing tools available which provide helpers
    for this task. Most of them use the approach of using the column
    names defined in the cursor attribute .description as basis for
    the keys in the row dictionary.

    Note that the reason for not extending the DB API specification
    to also support dictionary return values for the .fetchxxx() methods
    is that this approach has several drawbacks:

    * Some databases don't support case-sensitive column names or
      auto-convert them to all lowercase or all uppercase characters.

    * Columns in the result set which are generated by the query (e.g.
      using SQL functions) don't map to table column names and databases
      usually generate names for these columns in a very database
      specific way.

    As a result, accessing the columns through dictionary keys varies
    between databases and makes writing portable code impossible.
"""

This text will go into the DB API 2.0 update which I'll prepare later
today.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/