[Zope-DB] ZSQL Result Set: How to find out column's names?
Mon, 03 Feb 2003 19:52:24 +0100
Stephan Herschel wrote:
> M.-A. Lemburg wrote:
>> Stephan Herschel wrote:
>>> Hi group,
>>> I'm testing a ZSQL Method which uses a dynamically constructed
>>> sql-statement. Thus i don't know the column names of the result set.
>>> How can I get the column names to display them in a dtml-method?
>>> The only thing I found was a reference to the 'Searchable Object
>>> Interface' in the Zope-book and a hint to a method called
>>> _searchable_result_columns() which cannot be called as it starts with
>>> a '_'
>> The usual way to query for result columns is by adding a "and 1=0"
>> to the WHERE clause, e.g. SELECT * FROM MyTable WHERE 1=0 will
>> give you an empty result set.
>> You should then be able to call the .name() method on the Results
This should be ".names()".
>> object which will give you the column names.
>> Not tested, but should work this way,
> Thanks for the fast answer, but I just tried it and for me it doesn't work:
> <dtml-let result="query()">
> <dtml-var expr="result.name()">
> <dtml-in result size=20 start=query_start>
> <dtml-if sequence-start>
> Error Type: AttributeError
> Error Value: name
CEO eGenix.com Software GmbH
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting: http://www.egenix.com/
Python Software: http://www.egenix.com/files/python/