[Zope] Re: how do I get field names from a query

Dieter Maurer dieter@handshake.de
Wed, 31 May 2000 23:22:51 +0200 (CEST)


Adam Molyneaux writes:
 > still trying to get field names from a query of the form
 > SELECT * FROM MYTABLE
 > 
 > 
 > 
 > ><dtml-in "sqlListTable(table_name='personnel')">
 > >   <dtml-in sequence-item>
 > >      <P><dtml-var sequence_key>
 > ></dtml-in >

If "sqlListTable" is a SQLMethod, you get the sequence of result column
names by:

	"sqlListTable(table_name='personnel').names()"

If, e.g., you want list the first column of your
result set, this could be done as follows:

<dtml-let q="sqlListTable(table_name='personnel')"
          field1= "q.names()[0]">
<dtml-in q>
  <dtml-with sequence-item>
    <dtml-var field1>: <dtml-var "_[field1]"><br>
  </dtml-with>
</dtml-in>
</dtml-let>


Dieter