mxODBC question

Emile van Sebille emile at
Mon Feb 12 00:12:35 CET 2001


I've put together a class to handle this.  I'm only using it
at one site, so it probably won't scale well, but it allows
me to work with the data by using the database column names.
It's geared to handle only sql statements of the form
"select colA, colB, colC from tablename where conditions",
which in my case is about 90% of my usage.  It works by
parsing the sql select statement, mapping the retrieved cols
to class instance attributes with those names,
then returning a list of thoses instances.

--sample usage:

import SQLdata

all_open_ar = SQLdata.cache(('',),
    from RECEIVABLE \
    where INVOICE_DATE < %s",1)

open_ar = all_open_ar('09/30/2000')

for openInvoice in open_ar:
    bal = openInvoice.TOTAL_AMOUNT - openInvoice.PAID_AMOUNT

If you're interested, E-mail me, and I'll send it to you.

Emile van Sebille
emile at

"Scott Hathaway" <slhath at> wrote in message
news:nTDh6.66287$bb.1038987 at
> I am using mxODBC to access db's with no problem, but I
have a question.  If
> I use a sql call as follows:
> select username from users;
> Then, I make a call as follows:
> data = c.fetchall()
> Then, to access the first value of the first (and only)
field, I have to
> use:
> theValue = data[0][0]
> This is ugly.  Is there a way to do something like:
> theValue = data[0]['firstname']
> Or anything more easy to discern for code readability?
> Thanks,
> Scott

More information about the Python-list mailing list