Changeset 1007

Show
Ignore:
Timestamp:
07/08/08 14:35:17 (1 month ago)
Author:
laurentj
Message:

ticket #580: jDaoFactoryBase::countBy : allowing to do count on distinct fields. p=Thomas

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/CREDITS

    r1006 r1007  
    163163Thomas 
    164164 - fixed bugs in jDao (#576, #643) 
     165 - jDaoFactoryBase::countBy : allowing to do count on distinct fields (#580) 
    165166 
    166167Christian Tritten 
  • trunk/lib/jelix/dao/jDaoFactoryBase.class.php

    r1006 r1007  
    263263     * @return int the count 
    264264     */ 
    265     final public function countBy($searchcond) { 
    266         $query = 'SELECT COUNT(*) as c '.$this->_fromClause.$this->_whereClause; 
     265    final public function countBy($searchcond, $distinct=null) { 
     266        $count = '*'; 
     267        if ($distinct !== null) { 
     268            $props = $this->getProperties(); 
     269            if (isset($props[$distinct])) 
     270                $count = 'DISTINCT '.$this->_tables[$props[$distinct]['table']]['realname'].'.'.$props[$distinct]['fieldName']; 
     271        } 
     272         
     273        $query = 'SELECT COUNT('.$count.') as c '.$this->_fromClause.$this->_whereClause; 
    267274        if ($searchcond->hasConditions ()){ 
    268275            $query .= ($this->_whereClause !='' ? ' AND ' : ' WHERE '); 
Download in other formats: Unified Diff Zip Archive