[DB-SIG] Python database API 2.0/returning Column names with data

David A McInnis david@dataovation.com
Sun, 4 Nov 2001 06:56:57 -0800


I found another one myself, for MySQLdb (I am using MySQL).

It appears that cursorclass= is undocumented as well.

If you set cursorclass=MySQLdb.cursors.DictCursor, a dictionary is returned
which contains the row names.

db1 = MySQLdb.connect(user = "username", passwd="password", host= "host", db
= "database", cursorclass=MySQLdb.cursors.DictCursor)

c1 = db1.cursor()
c1.execute("""SELECT * from table where email = %s""",
'david@topsites.net',)

row1 = c1.fetchone()
print row1['acctno']
print row1['email']
print row1['amt']


-----Original Message-----
From: db-sig-admin@python.org [mailto:db-sig-admin@python.org]On Behalf
Of Gary Maynard
Sent: Sunday, November 04, 2001 2:38 AM
To: db-sig@python.org
Subject: Re: [DB-SIG] Python database API 2.0/returning Column names
with data


Thanks everybody for your help with this. I got it working without too much
trouble after I read your messages.

As a Python Newbie though, may I suggest that this kind if information be
made more readily available? the Cursor.description function that is
required to do this is not listed in the API and thus seems almost to be an
undocumented feature.

Gary


_______________________________________________
DB-SIG maillist  -  DB-SIG@python.org
http://mail.python.org/mailman/listinfo/db-sig