[Zope] Iteration over Z SQL Method resultset using fieldnames from TinyTable ??? A proposal for new DTML? (see end for that)

Petri Savolainen petri.savolainen@lut.fi
Fri, 19 Nov 1999 12:37:30 +0200


(anyone think this would be worth a how-to or hint? Too easy maybe- I will
then post it to Jeff Shelton's weblog at Userland? Comments?)

Well- sleeping over it helps. Plus checking the "Advanced DTML how-to".

The following snippet accomplishes what I wanted- it's a <dtml-in> within
another <dtml-in>. I tried this at first but could not make it work,
initially, for some reason. Probably because I did not have the  <dtml-var
expr="_[fieldname]"> right.

This lists the db table fieldnames in QueryFields which is a one-column
TinyTable...

<dtml-in QueryFields>
           <dtml-var fieldname>
</dtml-in>

In the above, "fieldname" is the name of the column variable that lists the
db field names stored in the TinyTable.

<dtml-in QueryGetData sort=name>
  <dtml-in QueryFields>
     <dtml-var expr="_[fieldname]">
  </dtml-in>
</dtml-in>

Ok this was the hard part. QueryGetData is a Z SQL Method that looks up the
field names to query from the same abovementioned TinyTable.

Anyway, so, it is possible to run loops within loops, but how do you put a
lookup in the inner loop, to get the data the fieldnames in the TinyTable
refer to? Rather than hardcoding fieldnames into multiple  <dtml-var ...>
statements to show that data? Well, that is what the expr= + underscore +
square brackets combination does. In my opinion, while Zope is beautifully
simple, easy and nice to start with, this is where things come to a
screeching halt for a newbie... for me, it happened, anyway. More examples
are needed to illustrate this underscore indirect variable referral stuff...
even better if there was a regular dtml statement for this.
<dtml-indirect-var ...> or something? Or does something like this exist?

 Petri

-----Original Message-----
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Petri
Savolainen
Sent: Friday, November 19, 1999 2:48 AM
To: zope@zope.org
Subject: [Zope] Iteration over Z SQL Method resultset using fieldnames
from TinyTable ??? Cannot figure this...


Hello,

I am wondering how do I get an iteration over all the SQL fields that a Z
SQL Method returns- simultaneously picking up the field names from a
Tinytable that same Z SQL Method uses to get the data in the first place?

I've got a SQL Connection to Postgres all set up, a TinyTable containing
fields I want to query, and a Z SQL method called "GetCompanies" containing:

SELECT
<dtml-in QueryFields>
"<dtml-var fieldname>"
 <dtml-if sequence-end>
 <dtml-else>,
 </dtml-if>
</dtml-in>
FROM companies;

In which, fieldname is the variable containing the fieldnames I want, in the
TinyTable. Great this far- it returns a nice table. But- if I want to format
this, by iterating over "GetCompanies" (in a separate DTML Method), and
adding some formatting there, I know just a "hardwired" way, as in:

<dtml-in GetCompanies>
                ...formatting stuff...
<dtml-var myfieldname>
               ...more formatting...
</dtml-in>

Because I know "myfieldname" is a name of a database field I know exists,
and thus ends up in the namespace of "GetCompanies", as an attribute
(correct???)

Now, the problem is, what if I want to iterate over the data in
GetCompanies, but don't know any fieldnames, I just know I can get them from
the same old Tinytable??????

Would much appreciate- embarrassingly, I've spent hours trying to figure
this simple thing out... I guess I have to list all that exists in the
namespace of GetCompanies  Z SQL Method (all the attributes?), then filter
out the standard stuff ---> what is left is a collection of field names it
has data for??? But how??

Thanks!

 Petri


_______________________________________________
Zope maillist  -  Zope@zope.org
http://lists.zope.org/mailman/listinfo/zope
          No cross posts or HTML encoding!
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )