field names from MySQLdb
Dennis Lee Bieber
wlfraed at ix.netcom.com
Fri Nov 8 21:45:34 EST 2002
les fed this fish to the penguins on Friday 08 November 2002 02:29 pm:
> Hi,
> how do i get field names for a table in MySQLdb?
> thanks
> (i looked into pydoc MySQLdb but did not find it there)
One of my assorted books mentions: cursor.description
Not sure what all the data represents, but the first entry in each
sub-tuple is the field name...
>>> db = MySQLdb.connect(db="mysql")
>>> c = db.cursor()
>>> c.execute("select * from db")
2L
>>> c.description
(('Host', 254, 1, 60, 60, 0, 0), ('Db', 254, 7, 64, 64, 0, 0), ('User',
254, 0, 16, 16, 0, 0), ('Select_priv', 254, 1, 1, 1, 0, 0),
('Insert_priv', 254, 1, 1, 1, 0, 0), ('Update_priv', 254, 1, 1, 1, 0,
0), ('Delete_priv', 254, 1, 1, 1, 0, 0), ('Create_priv', 254, 1, 1, 1,
0, 0), ('Drop_priv', 254, 1, 1, 1, 0, 0), ('Grant_priv', 254, 1, 1, 1,
0, 0), ('References_priv', 254, 1, 1, 1, 0, 0), ('Index_priv', 254, 1,
1, 1, 0, 0), ('Alter_priv', 254, 1, 1, 1, 0, 0))
>>> for fld in c.description:
... print fld[0],
...
Host Db User Select_priv Insert_priv Update_priv Delete_priv
Create_priv Drop_priv Grant_priv References_priv Index_priv Alter_priv
--
--
> ============================================================== <
> wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed at dm.net | Bestiaria Support Staff <
> ============================================================== <
> Bestiaria Home Page: http://www.beastie.dm.net/ <
> Home Page: http://www.dm.net/~wulfraed/ <
More information about the Python-list
mailing list