How to get database metadata information (i.e. existing tables and columns in tables)
Luis M. González
luismgz at gmail.com
Tue Aug 22 13:25:36 EDT 2006
If you want to know the names of the fields on a recordset, you can use
cursor.description.
For example, lets say you have a connection to a MySQL database:
con = MySQLdb.connect('localhost','root','','mydb')
cur = con.cursor()
cur.execute('select * from customers')
result = cur.fetchall()
fields = [i[0] for i in cur.description]
...
Description gives a list with information about your recordset, being
the first item the name of the field.
Hope this helps...
Luis
Chris Brat wrote:
> Hi,
>
> Is it possible to retrieve details about the database, specifically a
> list of the tables in the database; and then to retrieve the columns
> and their types for the tables?
>
> Is this dependant on the database?
>
> Thanks
> Chris
More information about the Python-list
mailing list