[Zope] Re: dtml-Variablen in <dtml-in> loops?
Tino Wildenhain
tino@wildenhain.de
Sun, 27 May 2001 23:54:13 +0200
Hi Philipp,
--On Sonntag, 27. Mai 2001 23:20 +0200 Philipp Robbel=20
<philipp.robbel@eml.villa-bosch.de> wrote:
> Hi Tino,
>
> the problem I see with your (I agree: much cleaner) code is that for
> each group you issue a SQL statement. So if I have 1000 groups you'll
> end up with 1000 SQL queries.
you will hardly show 1000 Records at once ;)
> In my (ugly :-) code you'd only have 2 sql queries:
> - the first one: sqlCount (see previous post)
> - the second (cached) one outside the iterations: DATA=3DsqlListProjects
> (large list with
> 1000*Projects rows).
>
> About the caching: I read that in Dieter's Zope Book:
> http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html
Hm. So Dieter must be wrong since it is documented otherwise.
Even more, all database interactions are enclosed in a transaction
of the publishing process (if the database adaptor supports this -
and its supposed to do that)
>
> So my question remains: is there either DATA[1:a+b] (both a and b are
> dtml-Variables) possible or <dtml-in .. start=3Da+b..> (both a and b are
> dtml-Variables).
how about <dtml-in DATA start=3DGroupStart size=3DGroupCount orphan=3D0>
</dtml-in> ?
Another solution would be:
sqlProjectList:
SELECT GroupID,ProjectID,Project FROM Project ORDER BY GroupID,ProjectID
<dtml-call "REQUEST.set('marker',-1)">
<dtml-in sqlProjectList>
<dtml-if "marker!=3DGroupID"><dtml-call "REQUEST.set('marker',GroupID)">
Group <dtml-var GroupID>:
</dtml-if>
<dtml-var Project>
</dtml-in>
Regards
Tino
> Thanks again,
> Philipp
>
>
> -----Urspr=C3=BCngliche Nachricht-----
> Von: Tino Wildenhain
> Gesendet: So 27.5.2001 17:38
> An: Philipp Robbel
> Cc: zope@zope.org
> Betreff: Re: dtml-Variablen in <dtml-in> loops?
>
>
>
> First of all, you dont have to cache SQL results via dtml-let.
> Zope
> does this already for you.
>
> If you have 2 queries:
> sqlGroupList:
> SELECT DISTINCT GroupID FROM Projects
>
> and the other:
> sqlProjectList(arg_GroupID)
> SELECT ProjectID, Project FROM Projects WHERE
> GroupID=3D<dtml-arg_GroupID
> type=3Dint>
>
> so you can:
>
> <dtml-in sqlGroupList>
> GroupID &dtml-GroupID;:
> <dtml-in "sqlProjectList(arg_GroupID=3DGroupID)">
> <dtml-unless sequence-start>,</dtml-unless>
> <dtml-var Project>
> </dtml-in>
> </dtml-in>
>
> This looks a bit cleaner imho ;)
>
> Regards
> Tino Wildenhain
>