/**
  * 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);
 }
示例#2
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);
 }
示例#3
0
 public function execSQLScript($file)
 {
     $lines = file($file);
     $cmdSQL = '';
     $nbCmd = 0;
     $style = $this->dbmsStyle;
     foreach ((array) $lines as $key => $line) {
         if (!preg_match($style[0], $line) && strlen(trim($line)) > 0) {
             // la ligne n'est ni vide ni commentaire
             //$line = str_replace("\\'","''",$line);
             //$line = str_replace($this->scriptReplaceFrom, $this->scriptReplaceBy,$line);
             $cmdSQL .= $line;
             if (preg_match($style[1], $line)) {
                 //Si on est à la ligne de fin de la commande on l'execute
                 // On nettoie la commande du ";" de fin et on l'execute
                 $cmdSQL = preg_replace($style[1], '', $cmdSQL);
                 $this->_connector->query($cmdSQL);
                 $nbCmd++;
                 $cmdSQL = '';
             }
         }
     }
     return $nbCmd;
 }