[Zope] help with dtml and sql---counting database rows with sql method

Passin, Tom tpassin@mitretek.org
Mon, 21 Apr 2003 17:21:47 -0400


You are looking at the result object returned from the query - it is not =
an error - and it contains the info you want.  But you have to extract =
your result from it.  To see the count, remember that you are getting =
back a set of rows, even though there is only one row.  So you treat it =
like any other database return -

You can display the count this way (here, count_test() is your zsql =
method)-

<dtml-in "count_test()">
   &dtml-p2_count;
</dtml-in>

or

<dtml-in "count_test()">
   <dtml-var p2_count>
</dtml-in>

Cheers,

Tom P

[Sean Kelley]

Thanks- I tried this and get the error:
<Shared.DC.ZRDB.Results.Results instance at 0x9fc69cc>
Any ideas what this means?


----- Original Message -----
From: "Kelley, Sean" <SKelley@ci.santa-rosa.ca.us>
To: <zope@zope.org>
Cc: <sean@horse101.com>
Sent: Friday, April 18, 2003 12:55 AM
Subject: [Zope] help with dtml and sql---counting database rows with sql
method

...snip...
 =20
assigned to the value.  So I name to the resultant column:

SELECT count(*) as p2_count
FROM IWPLNCHK
   =20

Use this query, but call it with <dtml-var counter>. That will give you
access to the value of p2_count, like this (assuming there are 123 =
records
in the db):

There are <dtml-var counter> records in the database

will give you

There are 123 records in the database


HTH,

/dario


 =20