[Tutor] SQL headache with column

Bernard Lebel 3dbernard at gmail.com
Tue Jul 19 22:43:09 CEST 2005


Ah yeah I to mention that I indeed tried fetchall(), but Python would
raise an attribute error:

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 + "" )
	aRow = oResult.fetchall()
	print str( aRow )
	
	oCursor.close()
	oConnection.close()


Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "\\Linuxserver\prod\XSI\WORKGROUP_4.0\Data\Scripts\pipeline\sql.py",
line 153, in getTableColumns
    aRow = oResult.fetchall()
AttributeError: 'long' object has no attribute 'fetchall'



Thanks
Bernard



On 7/19/05, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
> >       oResult = oCursor.execute( "SHOW COLUMNS FROM " + sTableName + "" )
> 
> Hi Bernard,
> 
> Try using oCursor.fetchall() after the execution.  The return value of
> execute() are the number of rows affected, and you can then pull each
> fetched value by using either oCursor.fetchone() or oCursor.fetchall().
> 
> See:
> 
>     http://python.org/peps/pep-0249.html
> 
> for more details about this.  Hope this helps!
> 
>


More information about the Tutor mailing list