예제 #1
0
 /**
  * return the number of records corresponding to the conditions stored into the
  * jDaoConditions object.
  * @author Loic Mathaud
  * @copyright 2007 Loic Mathaud
  * @since 1.0b2
  * @param jDaoConditions $searchcond
  * @return int the count
  */
 public final function countBy($searchcond, $distinct = null)
 {
     $count = '*';
     if ($distinct !== null) {
         $props = $this->getProperties();
         if (isset($props[$distinct])) {
             $count = 'DISTINCT ' . $this->_tables[$props[$distinct]['table']]['name'] . '.' . $props[$distinct]['fieldName'];
         }
     }
     $query = 'SELECT COUNT(' . $count . ') as c ' . $this->_fromClause . $this->_whereClause;
     if ($searchcond->hasConditions()) {
         $query .= $this->_whereClause != '' ? ' AND ' : ' WHERE ';
         $query .= $this->_createConditionsClause($searchcond);
     }
     $rs = $this->_conn->query($query);
     $res = $rs->fetch();
     return intval($res->c);
 }
예제 #2
0
 /**
  * return the number of records corresponding to the conditions stored into the
  * jDaoConditions object.
  * @author Loic Mathaud
  * @contributor Steven Jehannet
  * @copyright 2007 Loic Mathaud
  * @since 1.0b2
  * @param jDaoConditions $searchcond
  * @return int the count
  */
 public final function countBy($searchcond, $distinct = null)
 {
     $count = '*';
     $sqlite = false;
     if ($distinct !== null) {
         $props = static::$_properties;
         if (isset($props[$distinct])) {
             $count = 'DISTINCT ' . $this->_tables[$props[$distinct]['table']]['name'] . '.' . $props[$distinct]['fieldName'];
         }
         $sqlite = $this->_conn->dbms == 'sqlite';
     }
     if (!$sqlite) {
         $query = 'SELECT COUNT(' . $count . ') as c ' . $this->_fromClause . $this->_whereClause;
     } else {
         // specific query for sqlite, which doesn't support COUNT+DISTINCT
         $query = 'SELECT COUNT(*) as c FROM (SELECT ' . $count . ' ' . $this->_fromClause . $this->_whereClause;
     }
     if ($searchcond->hasConditions()) {
         $query .= $this->_whereClause != '' ? ' AND ' : ' WHERE ';
         $query .= $this->_createConditionsClause($searchcond);
     }
     if ($sqlite) {
         $query .= ')';
     }
     $rs = $this->_conn->query($query);
     $res = $rs->fetch();
     return intval($res->c);
 }
예제 #3
0
 function testNonEmptyRecursive()
 {
     $cond = new jDaoConditions();
     $cond->startGroup();
     $cond->startGroup('OR');
     $cond->addCondition('test', '=', 1);
     $cond->endGroup();
     $cond->endGroup();
     $this->assertTrue($cond->hasConditions());
     $this->assertFalse($cond->isEmpty());
 }