developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #580: 580-jDaoConditions-countBy-distinct.diff

File 580-jDaoConditions-countBy-distinct.diff, 1.1 KB (added by thomas, 13 years ago)
  • lib/jelix/dao/jDaoFactoryBase.class.php

     
    262262     * @param jDaoConditions $searchcond
    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 ');
    269276            $query .= $this->_createConditionsClause($searchcond);