[Zope] Getting SQL record names in python script?

Thomas B. Passin tpassin@mitretek.org
Tue, 13 Nov 2001 13:25:38 -0500


[<azbok@yahoo.com>]


> I call a ZSQL method in python and successfully retrieve the results I 
> want.  Then I want to get a list of the field names.
> 
> I try
>   MyRec = context.GetRecord()
>   print MyRec[0].keys()
> 
> I get 
>   Error Type: AttributeError
>   Error Value: keys
> 
> I can cycle through the values no problem.  I thought the records 
> returned were each a dictionary.  Is keys one of those functions that 
> is restricted?
> 
> How would I get field names?
> 


To repeat a post from last April:

I remember posting this before, but something seems to have eaten it.
Laurie Nason nailed it for me, many thanks Laurie.

Here is a summary of the result:

Given a ZSQL query named "query1", this DTML will execute the query and
display a list of the column names:

  <dtml-let results=query1>
   <dtml-var "results.names()">
  </dtml-let>

And here it is using dtml-with:

<dtml-with query1>
   <dtml-var "names()">
</dtml-with>

Thanks to all for the help.

Regards,

Tom P