[Zope] ZSQL, Python Script, number of records

Milos Prudek prudek@nembv.cz
Mon, 6 Aug 2001 08:19:57 +0200


Hi,

To check whether a record exists I'm using this:

exist (ZSQL method):
SELECT count(*) as I FROM ... WHERE ... ;

Python Script:
for x in exist(m_id=m_id):
  if x.i==0:
     print "no data"
  else:
     print "there are some data"

This works... but it's strange to use "for" for it... is there a simpler 
method? Just an "if", wthout "for"?


I tried to adapt the "exist" ZSQL to show a column from the table:
exist2 (ZSQL method):
SELECT count(*) as I, fname FROM ... WHERE ... ;

It fails and it recommends to put "fname" into GROUP BY. So:
exist3 (ZSQL method):
SELECT count(*) as I, fname FROM ... WHERE ... GROUP BY fname;

That works but IMHO it's a very ugly hack and it may breed trouble later on.

Is there a more elegant way to get both values and number of values using a 
single ZSQL method?

-- 
Milos Prudek