Ejemplo n.º 1
0
 public function hydrate(Statement $statement)
 {
     $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
     if (!$rows) {
         return array();
     }
     if ($this->normalize) {
         foreach ($rows as $key => $row) {
             $rows[$key] = $statement->normalizeRow($row);
         }
     }
     $keys = array_keys((array) reset($rows));
     if (!count($keys)) {
         throw new \LogicException('Result set does not contain any column.');
     } elseif ($this->key === NULL && $this->value === NULL) {
         if (count($keys) === 1) {
             list($this->value) = $keys;
         } else {
             list($this->key, $this->value) = $keys;
         }
     }
     $return = array();
     if ($this->key === NULL) {
         foreach ($rows as $row) {
             $return[] = $this->value === NULL ? $row : $row[$this->value];
         }
     } else {
         foreach ($rows as $row) {
             $return[is_object($row[$this->key]) ? (string) $row[$this->key] : $row[$this->key]] = $this->value === NULL ? $row : $row[$this->value];
         }
     }
     return $return;
 }
Ejemplo n.º 2
0
 public function hydrate(Statement $statement)
 {
     $res = $statement->fetch(PDO::FETCH_BOTH);
     if ($res !== false && $this->normalize) {
         $value = $statement->normalizeRow(array($this->columnIndex => $res[$this->columnIndex]));
         $res = $value;
     }
     return isset($res[$this->columnIndex]) ? $res[$this->columnIndex] : false;
 }
Ejemplo n.º 3
0
 public function hydrate(Statement $statement)
 {
     $res = $statement->fetchAll(PDO::FETCH_ASSOC);
     if (false !== $res) {
         if ($this->normalize) {
             foreach ($res as $key => $row) {
                 $res[$key] = ArrayHash::from($statement->normalizeRow($row));
             }
         } else {
             foreach ($res as $key => $row) {
                 $res[$key] = ArrayHash::from($row);
             }
         }
     }
     return $res;
 }
Ejemplo n.º 4
0
 public function logQuery(Statement $result, array $params = NULL)
 {
     if ($this->disabled) {
         return;
     }
     $source = NULL;
     foreach (debug_backtrace(FALSE) as $row) {
         if (isset($row['file']) && is_file($row['file']) && !$this->isIgnoredPath($row['file'])) {
             if (isset($row['function']) && strpos($row['function'], 'call_user_func') === 0) {
                 continue;
             }
             $source = array($row['file'], (int) $row['line']);
             break;
         }
     }
     $this->count++;
     $this->totalTime += $result->getTime();
     if ($this->count < $this->maxQueries) {
         $this->queries[] = array($result->queryString, $params, $result->getTime(), $result->rowCount(), $result->getConnection(), $source);
     }
 }
Ejemplo n.º 5
0
 public function hydrate(Statement $statement)
 {
     $columnIndex = $this->columnIndex;
     if (is_string($columnIndex)) {
         $columnCount = $statement->getColumnCount();
         for ($i = 0; $i < $columnCount; $i++) {
             $meta = $statement->getColumnMeta($i);
             if ($meta['name'] == $columnIndex) {
                 $columnIndex = $i;
                 break;
             }
         }
     }
     $res = $statement->fetchAll(PDO::FETCH_COLUMN, $columnIndex);
     if ($res !== false && $this->normalize) {
         foreach ($res as $key => $value) {
             $value = $statement->normalizeRow(array($columnIndex => $value));
             $res[$key] = $value[$columnIndex];
         }
     }
     return $res;
 }
Ejemplo n.º 6
0
 function __construct(Statement $statement)
 {
     foreach ($statement->normalizeRow($this) as $key => $value) {
         $this->{$key} = $value;
     }
 }
Ejemplo n.º 7
0
 /**
  * Common column type detection.
  * @return array
  */
 public static function detectTypes(Statement $statement)
 {
     $types = array();
     $count = $statement->columnCount();
     // driver must be meta-aware, see PHP bugs #53782, #54695
     for ($col = 0; $col < $count; $col++) {
         $meta = $statement->getColumnMeta($col);
         if (isset($meta['native_type'])) {
             $types[$meta['name']] = self::detectType($meta['native_type']);
         }
     }
     return $types;
 }