[Zope] Get Column Names from SQL Query?

Thomas B. Passin tpassin@mitretek.org
Tue, 10 Apr 2001 10:16:45 -0400


Here is my version of dtml code to display an arbitrary database query
including column headers.  It doesn't use Casey Duncan's fancy entities and
dictionaries.  This code is about as lean and clean as I can make it, except
for comments I have added for explanation.

Your ZSQL query is named "theQuery".  It gets executed (once only) when the
<dtml-let> is evaluated.

<dtml-let results=theQuery>
<table border='1'>
<!-- Headers -->
<tr>
   <dtml-in "results.names()"><!-- Loop over column names -->
      <th><dtml-var sequence-item></th>
   </dtml-in>
</tr>
<!-- Data-->
<dtml-in results><!-- Loop over rows-->
   <tr>
      <dtml-in sequence-item> <!-- Loop over columns-->
         <td><dtml-var sequence-item></td>
      </dtml-in>
   </tr>
</dtml-in>
</table>
Total of <dtml-var "_.len(results)"> Rows
</dtml-let>

Cheers,

Tom P