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

Andy Dustman andy@dustman.net
04 Nov 2001 10:54:28 -0500


On Sun, 2001-11-04 at 09:56, David A McInnis wrote:
> 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']

MySQLdb's cursorclass is not documented in the DB API because it is a
non-standard extension. It is, however, well-documented in the MySQLdb
documentation.

-- 
Andy Dustman         PGP: 0x930B8AB6
    @       .net     http://dustman.net/andy
You can have my keys when you pry them from my dead, cold neurons.