[Zope-dev] <dtml-in> how do I get count of records in sequence? (aka batch-size)

Brad Clements bkc@murkworks.com
Mon, 17 Apr 2000 11:25:44 -0500


I want to be able to do something like this:

<dtml-in "GetDB()[Table][Indice][Rec].fetchall()">
<dtml-with "_['sequence-item']">
<dtml-if "_['sequence-size'] == 1">
<dtml-var  "tableFromView(URL=URL0)">
<dtml-else>
<dtml-var  "tableFromView(viewName='DefaultLocatorView',URL=URL0)">
</dtml-if>
</dtml-with>
</dtml-in>

That is, produce different output depending on the number of items returned 
from dtml-in.  

There isn't a "sequence-size" variable. I thought "batch-size" would work, but 
that doesn't seem to exist either, even when I use "size=nn" in the dtml-in 
statement. 

I know I can use total-nnn, but then I need to know an attribute name. In this 
case, I do *not* know any of the attributes in the objects returned from 
fetchall().

Therefore I'm stuck doing something like this:

<dtml-if "_.len(GetDB()[Table][Indice][Rec].fetchall()) == 1">
<dtml-var "GetDB()[Table][Indice][Rec].fetchone().tableFromView(URL=URL0)">
<dtml-else>
<dtml-in "GetDB()[Table][Indice][Rec].fetchall()">
<dtml-with "_['sequence-item']">
<dtml-var "tableFromView(viewName='DefaultLocatorView',URL=URL0)">
</dtml-with>
</dtml-in>

This is ugly, and unlike SQLMethods, the value returned from fetchall() is not 
cached. (not sure if DTML caches the result of the call or not)

FYI, I'm using SQLDict.py here, and its very nice. Next step is to emulate a 
DB interface using Zope Database Adapters. This way I can test my core 
logic outside of Zope, but work with the transaction machinery inside zope.



Brad Clements,                bkc@murkworks.com   (315)268-1000
http://www.murkworks.com                          (315)268-9812 Fax
netmeeting: ils://ils.murkworks.com               AOL-IM: BKClements