[DB-SIG] Python database API 2.0/returning Column names with data
M.-A. Lemburg
mal@lemburg.com
Sun, 04 Nov 2001 13:37:19 +0100
Gary Maynard wrote:
>
> Thanks everybody for your help with this. I got it working without too much
> trouble after I read your messages.
>
> As a Python Newbie though, may I suggest that this kind if information be
> made more readily available? the Cursor.description function that is
> required to do this is not listed in the API and thus seems almost to be an
> undocumented feature.
Oh, it is:
"""
Cursor Objects should respond to the following methods and
attributes:
description
This read-only attribute is a sequence of 7-item
sequences. Each of these sequences contains information
describing one result column: (name, type_code,
display_size, internal_size, precision, scale,
null_ok). The first two items (name and type_code) are
mandatory, the other five are optional and must be set to
None if meaningfull values are not provided.
This attribute will be None for operations that
do not return rows or if the cursor has not had an
operation invoked via the executeXXX() method yet.
The type_code can be interpreted by comparing it to the
Type Objects specified in the section below.
"""
But you're right in that this question often comes up and
there's no hint to the solution in the DB API. I'll fix that with
the next revision of the 2.0 API.
--
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company: http://www.egenix.com/
Python Software: http://www.lemburg.com/python/