odbc and accessing database results by field

J

JZ

import odbc
conn = odbc.odbc('mydsn')
c = conn.cursor()
c.execute('SELECT TOP 10 field1, field2 FROM TABLE')
rows = c.fetchall()
c.close()
conn.close()

I am using MSSQL2000. My problem is:
Instead of row[0], rows[1]
I would like to use row['field1], row['field']
Is it possible for odbc module?
I cannot find any comprehensive documentation :(
 
G

George Kinney

JZ said:
import odbc
conn = odbc.odbc('mydsn')
c = conn.cursor()
c.execute('SELECT TOP 10 field1, field2 FROM TABLE')
rows = c.fetchall()
c.close()
conn.close()

I am using MSSQL2000. My problem is:
Instead of row[0], rows[1]
I would like to use row['field1], row['field']
Is it possible for odbc module?
I cannot find any comprehensive documentation :(

Well, I've been using oledb, but it should be fairly similar.

I just wrote a small wrapper class for the ADODB.Recordset object, that when
its Open() method is called, (as well as MoveNext, MovePrev, etc.) it copies
the current field names and their values into self.__dict__, so I can access
them via r.Field1, r.Field2, etc.

Another route I've gone (since OS/400 allows field names like TEST#REC@,
which python pukes on, is to over-ride __call__ to handle field data. (i.e.
c('test') = somevalue, etc.).

Anyways, a couple of ideas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top