Mapping Column Names to results using DBI

Emile van Sebille emile at fenx.com
Wed Jan 19 22:57:53 EST 2000


I normally end up cut and pasting the column names ala:

    select namefield, addressfields, emailfield from contacts

then:

    namefield, addressfields, emailfield = returned_record

This gets the values into the named fields, and is a lot easier than
dealing with index numbers, but you've got to remember to change both
places when you change things around (or get the unpack error ;-).

I've been meaning to ask this as well, or play with other structures,
but haven't had the time yet.

Emile van Sebille
emile at fenx.com
-------------------


----- Original Message -----
From: Timothy Grant <tjg at avalongroup.net>
To: Python People <python-list at python.org>
Sent: Wednesday, January 19, 2000 2:34 PM
Subject: Mapping Column Names to results using DBI


> Hi again,
>
> Right now I have an app that works ok, but I forsee a problem in the
> future.
>
> As you know, the results from a database query are returned in a
tuple.
> I can access those results by position just fine, is it possible to
map
> the column names onto the results, so I can access columns by name
> rather than by number?
>
> While indexing by number works, it is incredibly fragile and will
start
> failing the minute the underlying DB changes.
>
> Once again, it appears to me from the DBI spec that there should be a
> way to do this, I just can't figure it out from the spec.
>
> I'm using mxODBC if that helps.
>
> Thanks.
> --
> Stand Fast,
>     tjg.
>
> Chief Technology Officer              tjg at exceptionalminds.com
> Red Hat Certified Engineer            www.exceptionalminds.com
> Avalon Technology Group, Inc.                   (503) 246-3630
> >>>>>>>>>>>>EXCEPTIONAL MINDS, INNOVATIVE PRODUCTS<<<<<<<<<<<<
>
> --
> http://www.python.org/mailman/listinfo/python-list
>






More information about the Python-list mailing list