[Zope] Referencing sql field in a direct traversal

Dieter Maurer dieter@handshake.de
Sun, 11 Jun 2000 19:59:59 +0200 (CEST)


Jones, David H writes:
 > I have set up a direct traversal sqlMethod which has as a DTML method
 > 
 > The zsql method, sqlModel,  is:
 > 
 > select *
 > from AP_MDL 
 > where <dtml-sqltest ap_mdl_no type=string>
 >  
 > The direct traversal url is:
 > 
 > http://e9999.rt.cs.boeing.com:8080/DB/sqlModel/777/asMeta
 > 
 > The first DTML method I wrote, asMeta, operated correctly with the following code:
 > 
 > <meta name="ap_mdl_no" content="<dtml-var ap_mdl_no>">
 > <meta name="ap_mdl_cd" content="<dtml-var ap_mdl_cd>">
 > <meta name="bus_no" content="<dtml-var bus_no>">
 > <meta name="ap_mdl_prod_ind" content="<dtml-var ap_mdl_prod_ind>">
 > 
 > Now I want to generalized the DTML method to work with any query.  I would like to reference the fields, but haven't figured out how to. Can someone tell me how to reference the fields and field names returned in a direct traversal.

The easiest way is to use a "brain" for your database records
and let one of its methods return the list of field names.
The information is contained in the attribute "__record_schema__"
(inaccessable from DTML!). "__record_schema__" is a dictionary
mapping field names to field indices (starting from 0).

Alternatively, you can use an external method, that accesses
"__record_schema__" for you and makes is accessable from
DTML.


Dieter