[Zope] Simple Count Method

Nick Garcia ngarcia@codeit.com
Thu, 09 Mar 2000 09:43:58 -0800


"Joseph A. Archer" wrote:
> 
> To all Zopist,
> 
> (I am new to the list, and yes I am going through the archives for the
> answer, but haven't found it yet.)
> 
> I have a simple two field table in MySQL, "whowhat", that pulls a user id
> from one table, and a class code from another.  (It tells you "who" has
> "what" classes)
> 
> I , being somewhat new to python & Zope, am having the darndest time trying
> to do a simple external method to do a count of how many times the class
> "so-and-so" is in the table. (That way, I know how many people have
> signed-up, and how close I am to the class max.)  I have tried different
> searches.  I have an SQL Method that does:
> 
> select * from whowhat
> 
> And I also have one that does:
> 
> ...
> select * from whatwhat where classcode = <dtml-sqlvar class_name type=nb>
> 
> I've been trying to create an External Method, but I just can't seem to get
> it to work. (yes, in the Extentions directory)
> 
> I need to try to stay away from doing a "select count(classcode)..." in an
> SQL Method if I can.
> 
> Any help to this tormented soul would be greatly appreciated.

Let's say in Zope you have SQLMethod whowhat and SQLMethod whatwhat.  In
your external method you should simply be able to do:

def countWhoWhat(self):
  return len(self.whowhat())

def countWhatWhat(self, class):
  return len(self.whatwhat(class=class))

These should return the result count for each SQLMethod.

-- 
Nick Garcia | ngarcia@codeit.com
CodeIt Computing | http://codeit.com