From: Marcin W. <wo...@un...> - 2004-09-10 10:01:27
|
Hi, I needed to answer question like this: -- How many people have at least one address with given zip SELECT COUNT(DISTINCT person.id) FROM person, address WHERE address.person_id =3D person.id AND address.zip =3D 50482 I modified main.py with applied distinct patch and it worked (with MySQL)= . Perhaps someone will find it useful or will find an error in it: def count(self): """ Counting elements of current select results """ - count =3D self.accumulate('COUNT(*)') + if self.ops.get('distinct'): + count =3D self.accumulate('COUNT(DISTINCT %s.%s)' % ( + self.sourceClass._table, + self.sourceClass._idName)) + else: + count =3D self.accumulate('COUNT(*)') if self.ops.get('start'): count -=3D self.ops['start'] BTW, are there any plans to include distinct and index patches to SQLObje= ct? BTW 2, in docs/News.txt it is written about cascade: The constraints are only implemented in the DBMS, not in SQLObject (i.e., they will not work in databases like MySQL and SQLite). but they seem to be implemented also in SQLObject and they work in MySQL. At least I hope so :-). I rely on it. Marcin --=20 Marcin Wojdyr | http://www.unipress.waw.pl/~wojdyr |