Exemplo n.º 1
0
 /**
  * Gives the number of rows in the result set.
  *
  * Part of the Countable interface.
  *
  * @return int
  */
 public function count()
 {
     if ($this->_count !== null) {
         return $this->_count;
     }
     if ($this->_statement) {
         return $this->_count = $this->_statement->rowCount();
     }
     return $this->_count = count($this->_results);
 }
Exemplo n.º 2
0
 /**
  * Helper function to fetch the next result from the statement or
  * seeded results.
  *
  * @return mixed
  */
 protected function _fetchResult()
 {
     if (!$this->_statement) {
         return false;
     }
     $row = $this->_statement->fetch('assoc');
     if ($row === false) {
         return $row;
     }
     return $this->_groupResult($row);
 }
Exemplo n.º 3
0
 /**
  * Helper function used to iterate a statement and extract the columns
  * defined in $collectKeys
  *
  * @param \Cake\Database\StatementInterface $statement The statement to read from.
  * @param array $collectKeys The keys to collect
  * @return array
  */
 protected function _groupKeys($statement, $collectKeys)
 {
     $keys = [];
     while ($result = $statement->fetch('assoc')) {
         foreach ($collectKeys as $nestKey => $parts) {
             // Missed joins will have null in the results.
             if ($parts[2] === true && !isset($result[$parts[1][0]])) {
                 continue;
             }
             if ($parts[2] === true) {
                 $value = $result[$parts[1][0]];
                 $keys[$nestKey][$parts[0]][$value] = $value;
                 continue;
             }
             // Handle composite keys.
             $collected = [];
             foreach ($parts[1] as $key) {
                 $collected[] = $result[$key];
             }
             $keys[$nestKey][$parts[0]][implode(';', $collected)] = $collected;
         }
     }
     $statement->rewind();
     return $keys;
 }
Exemplo n.º 4
0
 /**
  * Binds all the stored values in this object to the passed statement.
  *
  * @param \Cake\Database\StatementInterface $statement The statement to add parameters to.
  * @return void
  */
 public function attachTo($statement)
 {
     $bindings = $this->bindings();
     if (empty($bindings)) {
         return;
     }
     $params = $types = [];
     foreach ($bindings as $b) {
         $params[$b['placeholder']] = $b['value'];
         $types[$b['placeholder']] = $b['type'];
     }
     $statement->bind($params, $types);
 }
Exemplo n.º 5
0
 /**
  * Helper function used to iterate a statement and extract the columns
  * defined in $collectKeys
  *
  * @param \Cake\Database\StatementInterface $statement The statement to read from.
  * @param array $collectKeys The keys to collect
  * @return array
  */
 protected function _groupKeys($statement, $collectKeys)
 {
     $keys = [];
     while ($result = $statement->fetch('assoc')) {
         foreach ($collectKeys as $parts) {
             // Missed joins will have null in the results.
             if ($parts[2] && !isset($result[$parts[1][0]])) {
                 continue;
             }
             if ($parts[2]) {
                 $keys[$parts[0]][] = $result[$parts[1][0]];
                 continue;
             }
             $collected = [];
             foreach ($parts[1] as $key) {
                 $collected[] = $result[$key];
             }
             $keys[$parts[0]][] = $collected;
         }
     }
     $statement->rewind();
     return $keys;
 }
Exemplo n.º 6
0
 /**
  * Binds all the stored values in this object to the passed statement.
  *
  * @param \Cake\Database\StatementInterface $statement The statement to add parameters to.
  * @return void
  */
 public function attachTo($statement)
 {
     $bindings = $this->bindings();
     if (empty($bindings)) {
         return;
     }
     $params = $types = [];
     foreach ($bindings as $b) {
         $statement->bindValue($b['placeholder'], $b['value'], $b['type']);
     }
 }
Exemplo n.º 7
0
 /**
  * Binds all the stored values in this object to the passed statement.
  *
  * @param \Cake\Database\StatementInterface $statement The statement to add parameters to.
  * @return void
  */
 public function attachTo($statement)
 {
     $properties = $this->_properties;
     if (empty($properties)) {
         return;
     }
     foreach ($properties as $name => $value) {
         $parameter = $this->_repository->schema()->parameter($name);
         if ($parameter === null) {
             continue;
         }
         if ($name === ':result') {
             $paramName = $name;
         } else {
             $paramName = ':' . $name;
         }
         if ($parameter !== null) {
             $type = $parameter['type'];
             list($value, $type) = $this->cast($this->_properties[$name], $type);
             $this->_castedProperties[$name] = $value;
             if ($parameter['in']) {
                 if ($parameter['out']) {
                     $this->_properties[$name] = $value;
                 }
             }
             if ($parameter['out']) {
                 $statement->bindParam($paramName, $this->_properties[$name], $type);
             } else {
                 $statement->bindParam($paramName, $this->_castedProperties[$name], $type);
             }
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Helper function used to iterate an statement and extract the columns
  * defined in $collectKeys
  *
  * @param \Cake\Database\StatementInterface $statement
  * @param array $collectKeys
  * @return array
  */
 protected function _groupKeys($statement, $collectKeys)
 {
     $keys = [];
     while ($result = $statement->fetch('assoc')) {
         foreach ($collectKeys as $parts) {
             if ($parts[2]) {
                 $keys[$parts[0]][] = $result[$parts[1][0]];
                 continue;
             }
             $collected = [];
             foreach ($parts[1] as $key) {
                 $collected[] = $result[$key];
             }
             $keys[$parts[0]][] = $collected;
         }
     }
     $statement->rewind();
     return $keys;
 }