public function count() { if ($this->count === null) { if ($this->countQuery) { try { $res = $this->countQuery->execute(); $this->count = $res[0]['c']; } catch (NoResultException $e) { $this->count = 0; } } else { $this->count = parent::count(); } } return $this->count; }
/** * Executes query and saving query SQL to list (if needed) * * @access public * @param boolean $noResults returns no results, if TRUE * @return array * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function execute($noResults = FALSE) { if (!$noResults) { static::$mResult = $this->oQuery->getResult(); } else { static::$mResult = $this->oQuery->execute(); } return static::$mResult; }
/** * @param DBALQueryBuilder|Query $queryBuilder * * @return int[] */ private function getPostIds($queryBuilder) { $ids = []; if ($queryBuilder instanceof DBALQueryBuilder) { foreach ($queryBuilder->execute()->fetchAll() as $post) { $ids[] = (int) $post['id']; } } elseif ($queryBuilder instanceof Query) { foreach ($queryBuilder->getResult() as $post) { $ids[] = $post->getId(); } } return array_unique($ids); }
/** * _performQuery() - This method accepts a Doctrine\ORM\Query object and * performs a query against the database with that object. * * @param Doctrine\ORM\Query $query * @throws \Zend\Authentication\Adapter\Exception\RuntimeException - when a invalid select object is encoutered * @return array */ protected function _performQuery(\Doctrine\ORM\Query $query) { try { $resultIdentities = $query->execute(); } catch (Exception $e) { /** * @see \Zend\Authentication\Adapter\Exception\RuntimeException */ require_once 'Zend/Auth/Adapter/Exception.php'; throw new \Zend\Authentication\Adapter\Exception\RuntimeException('The supplied parameters to \\Doctrine\\ORM\\EntityManager failed to ' . 'produce a valid sql statement, please check entity and column names ' . 'for validity.'); } return $resultIdentities; }
public function fetch(Query $query, $mode = self::FETCH_ALL) { if ($mode == self::FETCH_ALL) { if ($query->getMaxResults() !== null && $query->getHydrationMode() != self::HYDRATE_SINGLE_SCALAR) { return (new Paginator($query))->getIterator()->getArrayCopy(); } else { return $query->execute(); } } else { if ($mode == self::FETCH_ALL_PAGED) { return new Paginator($query); } else { if ($mode == self::FETCH_ONE) { $query->setMaxResults(1); if ($query->getHydrationMode() != self::HYDRATE_SINGLE_SCALAR) { return (new Paginator($query))->getIterator()->current(); } else { return $query->getOneOrNullResult(); } } else { if ($mode == self::FETCH_ONE_UNIQUE) { return $query->getOneOrNullResult(); } } } } }