Beispiel #1
0
 /**
  * @param Select $select
  * @param Pagination $pagination
  * @throws Exception\RuntimeException
  * @return array
  */
 protected function executeSelect(Select $select, Pagination $pagination = null)
 {
     $selectState = $select->getRawState();
     if ((string) $selectState['table'] != (string) $this->table) {
         throw new Exception\RuntimeException('The table name of the provided select object must match that of the table');
     }
     if ($pagination) {
         $counter = clone $select;
         $counter->reset(Select::COLUMNS)->reset(Select::ORDER)->reset(Select::LIMIT)->reset(Select::OFFSET);
         if (strtoupper($select->getRawState($select::QUANTIFIER)) == Select::QUANTIFIER_DISTINCT) {
             $columns = $select->getRawState(Select::COLUMNS);
             $counter->columns("COUNT({$select->getRawState(Select::QUANTIFIER)} {$columns[0]}) as total");
         } else {
             $counter->columns('COUNT(*) as total');
         }
         $row = $this->sql->prepareStatement($counter)->execute()->current();
         $pagination->setRecordCount($row['total']);
         $size = $pagination->getPageSize();
         $currentPage = $pagination->getCurrentPage();
         $select->limit($size)->offset(($currentPage - 1) * $size);
     }
     // prepare and execute
     $statement = $this->sql->prepareStatement($select);
     $rowset = array();
     foreach ($statement->execute() as $row) {
         $rowset[] = $row;
     }
     return $rowset;
 }
Beispiel #2
0
 protected function processSubSelect(Select $subselect, PlatformInterface $platform, Driver\DriverInterface $driver = null, Parameters $parameters = null)
 {
     if ($driver) {
         // Track subselect prefix and count for parameters
         $this->processInfo['subselectCount']++;
         $subselect->processInfo['subselectCount'] = $this->processInfo['subselectCount'];
         $subselect->processInfo['paramPrefix'] = 'subselect' . $subselect->processInfo['subselectCount'];
         // call subselect
         $stmt = $subselect->prepareStatement($platform, $driver);
         // copy count
         $this->processInfo['subselectCount'] = $subselect->processInfo['subselectCount'];
         if ($parameters) {
             $parameters->merge($stmt->getParameters());
         }
         $sql = $stmt->getSql();
     } else {
         $sql = $subselect->getSqlString($platform);
     }
     return $sql;
 }