[Zope] Finding out how many rows is selected in database

Spicklemire, Jerry Jerry.Spicklemire@IFLYATA.COM
Thu, 5 Apr 2001 16:20:52 -0500


Gitte said:

> need to do one thing if there are
> records returned and another if no records are returned

To test for no rows returned, this works:

<dtml-if sql_query_name>
<dtml-else>
 <dtml-call process_no_matching_records>
</dtml-if>

In other words, do nothing unless you get a response that 
tests "true". An empty set is interpretted as "false".

Of course, you can call a "process_matching_records" 
by sticking it between the "if" and the "else". Also, by 
setting the cache value of the query you can "call" it again, 
but in fact the result set will just be re-used

For Example:

<dtml-if sql_query_name>
 <dtml-call "REQUEST.set('result_set', sql_query_name)">
There are <dtml-var "_.len(_['result_set'])"> matching rows.
 <dtml-in sql_query_name>
  <dtml-call process_matching_records> 
 </dtml-in>
<dtml-else>
There are no matching rows. 
 <dtml-call process_no_matching_records>
</dtml-if>

It looks like the same query is being called three times, 
but the cache setting allows the result set to be re-cycled, 
much to the relief of your RDBMS!

If I simply don't get your problem, please ignore.

Later,
Jerry S.