[Zope] Obtaining column names when using ZSQL method

Nerlich, Andrew ajn@sosos.com.au
Wed, 12 Jan 2000 07:33:00 +1100


Warning: Zope newbie alert

I would like to be able to take a ZSQL method like

select * from customer

and generate a table or form of column name/value pairs like

name         john smith
age            35
title           programmer

without having to feed Zope the column names explicitly. Such a facility
would IMHO be very useful for generation of prototype document templates
from RDBMS tables.

I thought something like (the SQL above is in a ZSQL method called
lookup_customer):

<table border>
<dtml-in lookup_customer size=50 start=query_start>
   <dtml-in sequence-item>
        <tr>
           <td><dtml-var sequence-key></td>
           <td><dtml-var sequence-item></td>
        <tr>
   </dtml-in>
</dtml-in>

might do the job, but it fails with a type error "unsubscriptable object" on
the sequence-key line. sequence-index will work instead of sequence-key. On
rereading the DTML Reference (and using a good deal of guesswork) it appears
that sequence-key may only apply to "pure" Zope objects and not extend to
SQL-type objects.

Can anyone help me with this?

Also, is there a way through DTML or Python to find out the type (varchar,
number, etc) of each column? Zope has access to at least some of this info,
otherwise search interfaces would not work on select * queries. 

TIA.

Andrew Nerlich
Strategic Operating Solutions Pty Ltd
(02) 9966 8707       0418 407 833
ajn@sosos.com.au