/**
     * Returns contents of the table.
     *
     * @param string $table_name Table name.
     *
     * @return array
     */
    private function _dumpTable($table_name)
    {
        $profiler = $this->database->getProfiler();
        if (is_object($profiler)) {
            $profiler->setActive(false);
        }
        $sql = 'SELECT *
				FROM ' . $table_name;
        $table_content = $this->database->fetchAll($sql);
        if (is_object($profiler)) {
            $profiler->setActive(true);
        }
        return $table_content;
    }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function attachRelationships(Collection $collection, $include = null, ServerRequestInterface $request = null)
 {
     if (count($collection) === 0) {
         return;
     }
     if (is_null($include)) {
         return;
     }
     $rels = $collection->getIterator()->current()->getRelationshipMap();
     $rules = $request instanceof ServerRequestInterface ? $this->parseQueryString($request->getUri()->getQuery()) : [];
     foreach ($this->getRelationshipMap() as $key => $map) {
         if (is_array($include) && !in_array($key, $include)) {
             continue;
         }
         $binds = $this->getRelationshipBinds($collection, $key, $map['defined_in']['entity']);
         if (empty($binds)) {
             continue;
         }
         $query = sprintf('SELECT * FROM %s LEFT JOIN %s ON %s.%s = %s.%s WHERE %s.%s IN (:relationships)', $map['defined_in']['table'], $map['target']['table'], $map['target']['table'], $map['target']['primary'], $map['defined_in']['table'], $map['target']['relationship'], $map['defined_in']['table'], $map['defined_in']['primary']);
         // @todo allow for further filtering of rels via request
         if (array_key_exists('sort', $rules)) {
             $whitelist = [];
             if (array_key_exists($key, $rels)) {
                 $entity = $rels[$key];
                 $entity = new $entity();
                 $mapping = $entity->getMapping();
                 $whitelist = array_keys($mapping);
             }
             $query .= $this->buildSortPart($rules['sort'], $map['target']['table'], $whitelist);
         }
         $result = $this->dbal->fetchAll($query, ['relationships' => $binds]);
         $this->attachRelationshipsToCollection($collection, $key, $result);
     }
 }
 public function fetchAllQuery($sQuery, array $aParameters = [])
 {
     try {
         $aAllRecords = $this->oPdo->fetchAll($sQuery, $aParameters) ?: [];
     } catch (\PDOException $oException) {
         $sErrMsg = $oException->getMessage() . "\n  Entity: " . $this->get('entity') . "\n  Query: {$sQuery}" . "\n  Parameters: " . print_r($aParameters, true);
         throw new \RuntimeException($sErrMsg);
     }
     // Format:
     foreach ($aAllRecords as $iIndex => $aRecord) {
         $this->formatFromDb($aAllRecords[$iIndex]);
     }
     return $aAllRecords;
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function attachRelationships(Collection $collection, $include = null, ServerRequestInterface $request = null)
 {
     if (count($collection) === 0 || is_null($include)) {
         return;
     }
     $bind = [];
     $rels = $collection->getIterator()->current()->getRelationshipMap();
     $rules = $request instanceof ServerRequestInterface ? $this->parseQueryString($request->getUri()->getQuery()) : [];
     foreach ($this->getRelationshipMap() as $key => $map) {
         if (!array_key_exists('include', $rules) || array_key_exists('include', $rules) && !array_key_exists($key, $rules['include'])) {
             continue;
         }
         $binds = $this->getRelationshipBinds($collection, $key, $map['defined_in']['entity']);
         if (empty($binds)) {
             continue;
         }
         $query = sprintf('SELECT * FROM %s LEFT JOIN %s ON %s.%s = %s.%s WHERE %s.%s IN (:relationships)', $map['defined_in']['table'], $map['target']['table'], $map['target']['table'], $map['target']['primary'], $map['defined_in']['table'], $map['target']['relationship'], $map['defined_in']['table'], $map['defined_in']['primary']);
         $options = array_key_exists('include', $rules) ? $rules['include'][$key] : [];
         if (!empty($options['filter'])) {
             $query .= $this->buildRelationshipFilterQueryPart($map, $options['filter']);
             foreach ($options['filter'] as $filter) {
                 $bind[$filter['binding']] = $filter['value'];
             }
         }
         if (array_key_exists('sort', $rules)) {
             $whitelist = [];
             if (array_key_exists($key, $rels)) {
                 $entity = $rels[$key];
                 $whitelist = array_keys((new $entity())->getMapping());
             }
             $query .= $this->buildSortPart($rules['sort'], $map['target']['table'], $whitelist);
         }
         if (array_key_exists('limit', $options) && !is_null($options['limit'])) {
             $query .= ' LIMIT ' . (int) $options['limit'];
         }
         $bind['relationships'] = $binds;
         $result = $this->dbal->fetchAll($query, $bind);
         $this->attachRelationshipsToCollection($collection, $key, $result);
     }
 }
 /**
  *
  * Fetches a sequential array of rows from the database; the rows
  * are represented as associative arrays.
  *
  * @param string $statement The SQL statement to prepare and execute.
  *
  * @param array $values Values to bind to the query.
  *
  * @param callable $callable A callable to be applied to each of the rows
  * to be returned.
  *
  * @return array
  *
  */
 public function fetchAll($statement, array $values = array(), $callable = null)
 {
     $result = $this->pdo->fetchAll($statement, $values, $callable);
     $this->logProfiles(__FUNCTION__);
     return $result;
 }