[Tutor] SQL headache with column
Bernard Lebel
3dbernard at gmail.com
Tue Jul 19 22:13:53 CEST 2005
Hello,
Not sure if it's a Python thing, but...
When sending command to the MySQL server by command line, I can use
SHOW COLUMNS FROM <tablename>, the list of all columns with a bunch of
properties is printed.
However, when I run the same command from Python and I store the
result, the result is an integer that only tell the number of columns.
I would like to get the column names!
def getTableColumns( sTableName ):
""" Lists and returns the list of columns from a given table. """
oConnection = connect2db()
oCursor = oConnection.cursor()
oResult = oCursor.execute( "SHOW COLUMNS FROM " + sTableName + "" )
print str( oResult )
oCursor.close()
oConnection.close()
Prints "33" (I have 33 columns)
Thanks
Bernard
More information about the Tutor
mailing list