Re: [Zope] Simple, I think!
Generally speaking, when you do a query, you want the results of your query, not just the number of records. The original poster implies that this is what (s)he's looking for. It's inefficient to do two queries when one will suffice. So when you do the following, you get the number of records, as well as the result set that can be used in a dtml-in. <dtml-let results="SQL_Select()"> #Results returned = <dtml-var "_.len(results)"> </dtml-let> However, as somene has already pointed out, it's probably best/easiest to use the sequence-length variable defined by the dtml-in. However, if someone just wants a count of records from a db query, and not the records themselves, then you're right, just use SQL. Mark
True enough you could, but why?
SQL has the correct tools for the job!
----- Original Message ----- From: "Mark N. Gibson" <mark@kaivo.com> To: "Sheree Beaudette" <sheree@psouth.net> Cc: <zope@zope.org> Sent: Wednesday, July 25, 2001 10:16 PM Subject: Re: [Zope] Simple, I think!
You could do this:
<dtml-let results="SQL_Select()"> #Results returned = <dtml-var "_.len(results)"> </dtml-let>
Mark
I've looked everywhere and I think this should be simple but I'm not
getting
it
I simply want to count the number of records generated by an ZSQL Method (SQL query) within a DTML Method (something like get the record count of that certain query). I then want to refer to this number (could be zero if there are no records) and say if this number is zero then do something, else do something else.
Can anyone help??
_______________________________________________ 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 )
_______________________________________________ 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 )
OK I knew all that already, Since the original poster asked for only the number of records, then as you rightly say one simple SQL query which returns only one field and one row has to be better than getting all records that match the specific criteria and then counting those after the fact. If in fact you the intend to use the records then, sure, do it in one query that gets all records you need to act on. Obvious really eh! ----- Original Message ----- From: "Mark N. Gibson" <mark@kaivo.com> To: "Phil Harris" <phil.harris@zope.co.uk> Cc: "Mark N. Gibson" <mark@kaivo.com>; "Sheree Beaudette" <sheree@psouth.net>; <zope@zope.org> Sent: Wednesday, July 25, 2001 10:35 PM Subject: Re: [Zope] Simple, I think!
Generally speaking, when you do a query, you want the results of your query, not just the number of records. The original poster implies that this is what (s)he's looking for. It's inefficient to do two queries when one will suffice.
So when you do the following, you get the number of records, as well as the result set that can be used in a dtml-in.
<dtml-let results="SQL_Select()"> #Results returned = <dtml-var "_.len(results)"> </dtml-let>
However, as somene has already pointed out, it's probably best/easiest to use the sequence-length variable defined by the dtml-in.
However, if someone just wants a count of records from a db query, and not the records themselves, then you're right, just use SQL.
Mark
True enough you could, but why?
SQL has the correct tools for the job!
----- Original Message ----- From: "Mark N. Gibson" <mark@kaivo.com> To: "Sheree Beaudette" <sheree@psouth.net> Cc: <zope@zope.org> Sent: Wednesday, July 25, 2001 10:16 PM Subject: Re: [Zope] Simple, I think!
You could do this:
<dtml-let results="SQL_Select()"> #Results returned = <dtml-var "_.len(results)"> </dtml-let>
Mark
I've looked everywhere and I think this should be simple but I'm not
getting
it
I simply want to count the number of records generated by an ZSQL
Method
(SQL query) within a DTML Method (something like get the record count of that certain query). I then want to refer to this number (could be zero if there are no records) and say if this number is zero then do something, else do something else.
Can anyone help??
_______________________________________________ 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 )
_______________________________________________ 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 )
participants (2)
-
Mark N. Gibson -
Phil Harris