odbc and accessing database results by field
Robert Brewer
fumanchu at amor.org
Tue Oct 28 13:58:37 EST 2003
My answer was incomplete, since 'description' returns a sequence (not
just the name). So for the line "fieldNames = c.description",
substitute:
fieldNames = [eachColumn[0] for eachColumn in c.description]
FuManChu
> -----Original Message-----
> From: Robert Brewer
> Sent: Tuesday, October 28, 2003 9:54 AM
> To: 'python-list at python.org'
> Subject: RE: odbc and accessing database results by field
>
>
> You can write:
>
> c.execute('SELECT TOP 10 field1, field2 FROM TABLE')
> fieldNames = c.description
> rows = c.fetchall()
> c.close()
> datadict = dict(zip(fieldNames, rows))
> print datadict['field1']
>
>
> Robert Brewer
> MIS
> Amor Ministries
> fumanchu at amor.org
>
> > -----Original Message-----
> > From: JZ [mailto:jroznfgre at jngpugbjreQBGbet.cy]
> > Sent: Tuesday, October 28, 2003 7:26 AM
> > To: python-list at python.org
> > Subject: odbc and accessing database results by field
> >
> >
> > 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 :(
> >
> > --
> > JZ ICQ:6712522
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
More information about the Python-list
mailing list