[Zope-DB] ZSQL Result Set: How to find out column's names?

Stephan Herschel stephan.herschel@proceryon.at
Mon, 03 Feb 2003 17:27:02 +0100


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
> object which will give you the column names.
> 
> Not tested, but should work this way,

Hi,

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[0].name()">

<dtml-in result size=20 start=query_start>

    <dtml-if sequence-start>
....

==>

Error Type: AttributeError
Error Value: name

-- 


Stephan