DB-API: how can I find the column names in a cursor?

Fredrik Lundh fredrik at pythonware.com
Thu Jun 1 08:54:16 EDT 2006


"A.M" wrote:

> The problem is I don't know how to find out what are the column name and type that comes out of 
> query (each row in cursor).
>
> Is there any possibility that my Python code can find out the column name and type in each row in 
> cursor?

>From "cursor objects" in the DB-API documentation:

    .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."

The full spec is available here: http://www.python.org/dev/peps/pep-0249/

</F> 






More information about the Python-list mailing list