[Zope] Get Column Names from SQL Query?

Casey Duncan cduncan@kaivo.com
Wed, 04 Apr 2001 10:24:39 -0600


"Thomas B. Passin" wrote:
> 
> I want to run an SQL query, like
> 
> select * from person
> 
> Then I want to extract the column names from the returned data.  In other
> words, I don't want to hand-code them into the result page.
> 
> I know how to do this in Cold Fusion, but I don't know how in Zope.
> 
> I'm using a ZSQL method, of course, to query the database.
> 
> Anyone know how to do this without running an external method?
> 
> Tom P
> 

I think you should be able to do something like this (untested):

<dtml-with name="sqlMethod">
    <dtml-in name="dictionaries">
        <dtml-in name="sequence-item" mapping>
            <dtml-var name="sequence-key">:
            <dtml-var name="sequence-item"><br />
        </dtml-in>
    </dtml-in>
</dtml-in>

or as a python script:

rows = context.sqlMethod(REQUEST).dictionaries()
for row in rows:
    for field = row.keys():
        ...whatever you want to do here (field name = field, value =
row[field])...
        
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>