BartlebyScrivener wrote:
> Gau,
> 
> This prints the names of the columns in my database.
> 
> # Modification of
> # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/389535
> # Instructions for customizing are at:
> # http://www.egenix.com/files/python/mxODBC.html
> 
> import mx.ODBC.Windows as odbc
> 
> driv='DRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:/Access
> Databases/Quotations2005'
> 
> conn = odbc.DriverConnect(driv)
> c = conn.cursor()
> 
> # get the column names from Table1
> c.execute ("SELECT * FROM Table1")
> 
> # get column names
> cols= [ i[0] for i in c.description ]
> print '\n\ncols=',cols
> 
Note that there's no requirement that the SELECT actually retrieve any 
data, son the normal technique is to use a query guaranteed to return no 
rows, such as

     SELECT * FROM Table1 WHERE 1=0

See also

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189

for an algorithm that will show data fron an arbitrary query in a 
reasonably tidy display.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd                 www.holdenweb.com
Love me, love my blog         holdenweb.blogspot.com

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to