1
0
mirror of synced 2024-12-14 15:16:04 +03:00
doctrine2/lib/Doctrine/Query.php

622 lines
18 KiB
PHP
Raw Normal View History

<?php
2008-05-24 22:18:37 +04:00
/*
2008-05-24 22:18:37 +04:00
* $Id: Query.php 3938 2008-03-06 19:36:50Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
/**
* A Doctrine_Query object represents a DQL query. It is used to query databases for
* data in an object-oriented fashion. A DQL query understands relations and inheritance
* and is dbms independant.
*
* @package Doctrine
* @subpackage Query
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
2008-05-24 22:18:37 +04:00
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
2008-05-24 22:18:37 +04:00
class Doctrine_Query extends Doctrine_Query_Abstract
2007-05-16 23:20:55 +04:00
{
/**
* @var Doctrine_EntityManager The entity manager used by this query object.
*/
protected $_entityManager;
/**
2008-05-24 22:18:37 +04:00
* @var Doctrine_Hydrator The hydrator object used to hydrate query results.
*/
2008-05-24 22:18:37 +04:00
protected $_hydrator;
/**
2008-05-24 22:18:37 +04:00
* @var Doctrine_Query_ParserResult The parser result that holds DQL => SQL information.
*/
2008-05-24 22:18:37 +04:00
protected $_parserResult;
2007-05-26 23:50:40 +04:00
/**
2008-05-24 22:18:37 +04:00
* @var string $_sql Cached SQL query.
2007-05-26 23:50:40 +04:00
*/
2008-05-24 22:18:37 +04:00
protected $_sql = null;
2008-05-24 22:18:37 +04:00
// Caching Stuff
2007-05-19 22:29:29 +04:00
/**
2008-05-24 22:18:37 +04:00
* @var Doctrine_Cache_Interface The cache driver used for caching result sets.
2007-05-16 23:20:55 +04:00
*/
2008-05-24 22:18:37 +04:00
protected $_resultCache;
2007-05-27 15:38:16 +04:00
/**
2008-05-24 22:18:37 +04:00
* @var boolean Boolean value that indicates whether or not expire the result cache.
*/
2008-05-24 22:18:37 +04:00
protected $_expireResultCache = false;
/**
2008-05-24 22:18:37 +04:00
* @var int Result Cache lifetime.
*/
2008-05-24 22:18:37 +04:00
protected $_resultCacheTTL;
/**
2008-05-24 22:18:37 +04:00
* @var Doctrine_Cache_Interface The cache driver used for caching queries.
*/
2008-05-24 22:18:37 +04:00
protected $_queryCache;
/**
2008-05-24 22:18:37 +04:00
* @var boolean Boolean value that indicates whether or not expire the query cache.
*/
2008-05-24 22:18:37 +04:00
protected $_expireQueryCache = false;
2007-05-24 20:13:50 +04:00
/**
2008-05-24 22:18:37 +04:00
* @var int Query Cache lifetime.
2007-05-24 20:13:50 +04:00
*/
2008-05-24 22:18:37 +04:00
protected $_queryCacheTTL;
// End of Caching Stuff
public function __construct(Doctrine_EntityManager $entityManager)
2007-05-24 20:13:50 +04:00
{
$this->_entityManager = $entityManager;
2008-09-12 13:58:02 +04:00
$this->_hydrator = new Doctrine_ORM_Internal_Hydration_StandardHydrator($entityManager);
2008-05-24 22:18:37 +04:00
$this->free();
}
/**
2008-05-24 22:18:37 +04:00
* Returns a new Doctrine_Query object
2007-05-18 03:13:58 +04:00
*
2008-05-24 22:18:37 +04:00
* @param Doctrine_Connection $conn optional connection parameter
2007-05-18 03:13:58 +04:00
* @return Doctrine_Query
*/
2008-05-24 22:18:37 +04:00
public static function create($conn = null)
2007-05-18 03:13:58 +04:00
{
2008-05-24 22:18:37 +04:00
return new self($conn);
2007-05-18 03:13:58 +04:00
}
2008-05-24 22:18:37 +04:00
2007-05-18 03:13:58 +04:00
/**
* Retrieves the assocated Doctrine_EntityManager to this Doctrine_Query
*
* @return Doctrine_EntityManager
*/
public function getEntityManager()
{
return $this->_entityManager;
}
2008-05-24 22:18:37 +04:00
2007-05-24 18:19:44 +04:00
/**
2008-05-24 22:18:37 +04:00
* Returns the hydrator associated with this query object
2007-05-24 18:19:44 +04:00
*
2008-05-24 22:18:37 +04:00
* @return Doctrine_Hydrator The hydrator associated with this query object
2007-05-24 18:19:44 +04:00
*/
2008-05-24 22:18:37 +04:00
public function getHydrator()
2007-05-24 18:19:44 +04:00
{
2008-05-24 22:18:37 +04:00
return $this->_hydrator;
2007-05-24 18:19:44 +04:00
}
2008-05-24 22:18:37 +04:00
/**
* Convenience method to execute using array fetching as hydration mode.
*
* @param string $params
* @return array
*/
public function fetchArray($params = array()) {
return $this->execute($params, Doctrine::HYDRATE_ARRAY);
}
2008-05-24 22:18:37 +04:00
/**
* Convenience method to execute the query and return the first item
* of the collection.
*
* @param string $params Parameters
* @param int $hydrationMode Hydration mode
* @return mixed Array or Doctrine_Collection or false if no result.
*/
public function fetchOne($params = array(), $hydrationMode = null)
{
2008-07-01 09:57:19 +04:00
$collection = $this->limit(1)->execute($params, $hydrationMode);
if (count($collection) === 0) {
return false;
}
if ($collection instanceof Doctrine_Collection) {
return $collection->getFirst();
} else if (is_array($collection)) {
return array_shift($collection);
}
return false;
2007-05-18 03:13:58 +04:00
}
/**
2008-05-24 22:18:37 +04:00
* Query the database with DQL (Doctrine Query Language).
*
2008-05-24 22:18:37 +04:00
* @param string $query DQL query
* @param array $params prepared statement parameters
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
* @see Doctrine::FETCH_* constants
* @return mixed
*/
2008-05-24 22:18:37 +04:00
public function query($query, $params = array(), $hydrationMode = null)
{
2008-05-24 22:18:37 +04:00
$this->setDql($query);
return $this->execute($params, $hydrationMode);
}
2007-07-09 00:18:50 +04:00
/**
2008-05-24 22:18:37 +04:00
* Builds the sql query from the given parameters and applies things such as
* column aggregation inheritance and limit subqueries if needed
2007-07-09 00:18:50 +04:00
*
2008-05-24 22:18:37 +04:00
* @return mixed The built sql query or an array of all sql queries.
2007-07-09 00:18:50 +04:00
*/
2008-05-24 22:18:37 +04:00
public function getSql()
2007-07-09 00:18:50 +04:00
{
2008-05-24 22:18:37 +04:00
return $this->parse()->getSqlExecutor()->getSqlStatements();
2007-07-09 00:18:50 +04:00
}
2007-05-16 23:20:55 +04:00
/**
2008-05-24 22:18:37 +04:00
* Parses the DQL query, if necessary, and stores the parser result.
2007-05-16 23:20:55 +04:00
*
2008-05-24 22:18:37 +04:00
* @return Doctrine_Query_ParserResult
2007-05-16 23:20:55 +04:00
*/
2008-05-24 22:18:37 +04:00
public function parse()
2007-05-16 23:20:55 +04:00
{
2008-05-24 22:18:37 +04:00
if ($this->_state === self::STATE_DIRTY) {
$parser = new Doctrine_Query_Parser($this);
2008-05-24 22:18:37 +04:00
$this->_parserResult = $parser->parse();
$this->_state = self::STATE_CLEAN;
2007-11-19 20:55:23 +03:00
}
2008-05-24 22:18:37 +04:00
return $this->_parserResult;
2007-09-13 01:42:42 +04:00
}
2008-05-24 22:18:37 +04:00
2007-09-13 01:42:42 +04:00
/**
2008-05-24 22:18:37 +04:00
* Executes the query and populates the data set.
2007-09-13 01:42:42 +04:00
*
2008-05-24 22:18:37 +04:00
* @param string $params Parameters to be sent to query.
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
* One of the Doctrine::HYDRATE_* constants.
* @return Doctrine_Collection The root collection
2007-09-13 01:42:42 +04:00
*/
2008-05-24 22:18:37 +04:00
public function execute($params = array(), $hydrationMode = null)
2007-09-13 01:42:42 +04:00
{
2008-05-24 22:18:37 +04:00
$params = $this->getParams($params);
2008-05-24 22:18:37 +04:00
// If there is a CacheDriver associated to cache resultsets...
if ($this->_resultCache && $this->_type === self::SELECT) { // Only executes if "SELECT"
$cacheDriver = $this->getResultCacheDriver();
2007-09-13 01:42:42 +04:00
2008-05-24 22:18:37 +04:00
// Calculate hash for dql query.
$hash = md5($this->getDql() . var_export($params, true));
$cached = ($this->_expireResultCache) ? false : $cacheDriver->fetch($hash);
2007-09-13 01:42:42 +04:00
2008-05-24 22:18:37 +04:00
if ($cached === false) {
// Cache does not exist, we have to create it.
$result = $this->_execute($params, Doctrine::HYDRATE_ARRAY);
$queryResult = Doctrine_Query_CacheHandler::fromResultSet($this, $result);
$cacheDriver->save($hash, $queryResult->toCachedForm(), $this->_resultCacheTTL);
2007-09-13 01:42:42 +04:00
2008-05-24 22:18:37 +04:00
return $result;
} else {
// Cache exists, recover it and return the results.
$queryResult = Doctrine_Query_CacheHandler::fromCachedResult($this, $cached);
2007-09-13 01:42:42 +04:00
2008-05-24 22:18:37 +04:00
return $queryResult->getResultSet();
2007-09-13 01:42:42 +04:00
}
}
2008-05-24 22:18:37 +04:00
return $this->_execute($params, $hydrationMode);
2007-09-13 01:42:42 +04:00
}
2008-05-24 22:18:37 +04:00
2007-09-13 01:42:42 +04:00
/**
2008-05-24 22:18:37 +04:00
* _execute
2007-09-13 01:42:42 +04:00
*
2008-05-24 22:18:37 +04:00
* @param string $params Parameters to be sent to query.
* @param int $hydrationMode Method of hydration to be used.
* @return Doctrine_Collection The root collection
2007-09-13 01:42:42 +04:00
*/
2008-05-24 22:18:37 +04:00
protected function _execute($params, $hydrationMode)
2007-09-13 01:42:42 +04:00
{
2008-05-24 22:18:37 +04:00
// preQuery invoking
$this->preQuery();
2008-05-24 22:18:37 +04:00
// Query execution
$stmt = $this->_execute2($params);
2008-05-24 22:18:37 +04:00
// postQuery invoking
$this->postQuery();
2008-05-24 22:18:37 +04:00
if (is_integer($stmt)) {
return $stmt;
2007-09-13 01:42:42 +04:00
}
2008-05-24 22:18:37 +04:00
return $this->_hydrator->hydrateResultSet($stmt, $hydrationMode);
}
2007-08-08 00:41:33 +04:00
/**
2008-05-24 22:18:37 +04:00
* _execute2
2007-08-08 00:41:33 +04:00
*
2008-05-24 22:18:37 +04:00
* @param array $params
* @return PDOStatement The executed PDOStatement.
2007-08-08 00:41:33 +04:00
*/
2008-05-24 22:18:37 +04:00
protected function _execute2($params)
2007-08-08 00:41:33 +04:00
{
2008-05-24 22:18:37 +04:00
// If there is a CacheDriver associated to cache queries...
if ($this->_queryCache || $this->_entityManager->getConnection()->getAttribute(Doctrine::ATTR_QUERY_CACHE)) {
2008-05-24 22:18:37 +04:00
$queryCacheDriver = $this->getQueryCacheDriver();
2008-05-24 22:18:37 +04:00
// Calculate hash for dql query.
$hash = md5($this->getDql() . 'DOCTRINE_QUERY_CACHE_SALT');
$cached = ($this->_expireQueryCache) ? false : $queryCacheDriver->fetch($hash);
2007-08-08 00:41:33 +04:00
2008-05-24 22:18:37 +04:00
if ($cached === false) {
// Cache does not exist, we have to create it.
$executor = $this->parse()->getSqlExecutor();
2007-12-10 21:59:12 +03:00
2008-05-24 22:18:37 +04:00
// To-be cached item is parserResult
$cacheDriver->save($hash, $this->_parserResult->toCachedForm(), $this->_queryCacheTTL);
2007-08-08 00:41:33 +04:00
} else {
2008-05-24 22:18:37 +04:00
// Cache exists, recover it and return the results.
$this->_parserResult = Doctrine_Query_CacheHandler::fromCachedQuery($this, $cached);
2007-12-10 21:59:12 +03:00
2008-05-24 22:18:37 +04:00
$executor = $this->_parserResult->getSqlExecutor();
}
} else {
$executor = $this->parse()->getSqlExecutor();
2007-12-10 21:59:12 +03:00
}
2008-05-24 22:18:37 +04:00
// Assignments for Hydrator and Enums
$this->_hydrator->setQueryComponents($this->_parserResult->getQueryComponents());
$this->_hydrator->setTableAliasMap($this->_parserResult->getTableAliasMap());
$this->_setEnumParams($this->_parserResult->getEnumParams());
2007-12-10 21:59:12 +03:00
2008-05-24 22:18:37 +04:00
// Converting parameters
$params = $this->_prepareParams($params);
2007-12-10 21:59:12 +03:00
2008-05-24 22:18:37 +04:00
// Double the params if we are using limit-subquery algorithm
// We always have an instance of Doctrine_Query_ParserResult on hands...
if ($this->_parserResult->isLimitSubqueryUsed() &&
$this->_entityManager->getConnection()->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') {
2008-05-24 22:18:37 +04:00
$params = array_merge($params, $params);
2007-12-10 21:59:12 +03:00
}
2008-05-24 22:18:37 +04:00
// Executing the query and assigning PDOStatement
return $executor->execute($this->_conn, $params);
2007-12-10 21:59:12 +03:00
}
2007-12-10 21:51:22 +03:00
2007-05-26 23:50:40 +04:00
/**
2008-05-24 22:18:37 +04:00
* @nodoc
2007-05-26 23:50:40 +04:00
*/
2008-05-24 22:18:37 +04:00
protected function _prepareParams(array $params)
2007-04-14 20:28:09 +04:00
{
2008-05-24 22:18:37 +04:00
// Convert boolean params
$params = $this->_entityManager->getConnection()->convertBooleans($params);
2007-04-14 20:28:09 +04:00
2008-05-24 22:18:37 +04:00
// Convert enum params
return $this->convertEnums($params);
2007-04-14 20:28:09 +04:00
}
2008-05-24 22:18:37 +04:00
/**
2008-05-24 22:18:37 +04:00
* Defines a cache driver to be used for caching result sets.
2007-05-26 23:50:40 +04:00
*
2008-05-24 22:18:37 +04:00
* @param Doctrine_Cache_Interface|null $driver Cache driver
* @return Doctrine_Query
2007-05-26 23:50:40 +04:00
*/
2008-05-24 22:18:37 +04:00
public function setResultCache($resultCache)
{
2008-05-24 22:18:37 +04:00
if ($resultCache !== null && ! ($resultCache instanceof Doctrine_Cache_Interface)) {
throw new Doctrine_Query_Exception(
'Method setResultCache() accepts only an instance of Doctrine_Cache_Interface or null.'
);
}
2007-06-01 14:17:50 +04:00
2008-05-24 22:18:37 +04:00
$this->_resultCache = $resultCache;
2007-05-26 23:50:40 +04:00
2008-05-24 22:18:37 +04:00
return $this;
}
2008-05-24 22:18:37 +04:00
/**
2008-05-24 22:18:37 +04:00
* Returns the cache driver used for caching result sets.
*
2008-05-24 22:18:37 +04:00
* @return Doctrine_Cache_Interface Cache driver
*/
2008-05-24 22:18:37 +04:00
public function getResultCache()
{
2008-05-24 22:18:37 +04:00
if ($this->_resultCache instanceof Doctrine_Cache_Interface) {
return $this->_resultCache;
} else {
return $this->_entityManager->getConnection()->getResultCacheDriver();
}
}
2008-05-24 22:18:37 +04:00
/**
2008-05-24 22:18:37 +04:00
* Defines how long the result cache will be active before expire.
*
2008-05-24 22:18:37 +04:00
* @param integer $timeToLive How long the cache entry is valid
* @return Doctrine_Query
*/
2008-05-24 22:18:37 +04:00
public function setResultCacheLifetime($timeToLive)
{
2008-05-24 22:18:37 +04:00
if ($timeToLive !== null) {
$timeToLive = (int) $timeToLive;
}
2008-05-24 22:18:37 +04:00
$this->_resultCacheTTL = $timeToLive;
2008-05-24 22:18:37 +04:00
return $this;
2007-06-19 14:43:19 +04:00
}
2008-05-24 22:18:37 +04:00
2007-06-19 14:43:19 +04:00
/**
2008-05-24 22:18:37 +04:00
* Retrieves the lifetime of resultset cache.
2007-06-19 14:43:19 +04:00
*
2008-05-24 22:18:37 +04:00
* @return int
2007-06-19 14:43:19 +04:00
*/
2008-05-24 22:18:37 +04:00
public function getResultCacheLifetime()
2007-06-19 14:43:19 +04:00
{
2008-05-24 22:18:37 +04:00
return $this->_resultCacheTTL;
2007-06-19 22:53:46 +04:00
}
2008-05-24 22:18:37 +04:00
2007-06-19 22:53:46 +04:00
/**
2008-05-24 22:18:37 +04:00
* Defines if the resultset cache is active or not.
2007-06-19 22:53:46 +04:00
*
2008-05-24 22:18:37 +04:00
* @param boolean $expire Whether or not to force resultset cache expiration.
* @return Doctrine_Query
2007-06-19 22:53:46 +04:00
*/
2008-05-24 22:18:37 +04:00
public function setExpireResultCache($expire = true)
2007-06-19 22:53:46 +04:00
{
2008-05-24 22:18:37 +04:00
$this->_expireResultCache = (bool) $expire;
2007-06-19 22:53:46 +04:00
2008-05-24 22:18:37 +04:00
return $this;
2007-09-13 01:42:42 +04:00
}
2008-05-24 22:18:37 +04:00
/**
2008-05-24 22:18:37 +04:00
* Retrieves if the resultset cache is active or not.
*
2008-05-24 22:18:37 +04:00
* @return bool
*/
2008-05-24 22:18:37 +04:00
public function getExpireResultCache()
{
2008-05-24 22:18:37 +04:00
return $this->_expireResultCache;
}
2008-05-24 22:18:37 +04:00
/**
2008-05-24 22:18:37 +04:00
* Defines a cache driver to be used for caching queries.
*
2008-05-24 22:18:37 +04:00
* @param Doctrine_Cache_Interface|null $driver Cache driver
* @return Doctrine_Query
*/
2008-05-24 22:18:37 +04:00
public function setQueryCache($queryCache)
{
2008-05-24 22:18:37 +04:00
if ($queryCache !== null && ! ($queryCache instanceof Doctrine_Cache_Interface)) {
throw new Doctrine_Query_Exception(
'Method setResultCache() accepts only an instance of Doctrine_Cache_Interface or null.'
);
}
2008-05-24 22:18:37 +04:00
$this->_queryCache = $queryCache;
2007-06-28 02:29:57 +04:00
2008-05-24 22:18:37 +04:00
return $this;
}
2008-05-24 22:18:37 +04:00
/**
* Returns the cache driver used for caching queries.
*
* @return Doctrine_Cache_Interface Cache driver
*/
public function getQueryCache()
{
if ($this->_queryCache instanceof Doctrine_Cache_Interface) {
return $this->_queryCache;
} else {
return $this->_entityManager->getConnection()->getQueryCacheDriver();
2007-06-28 02:29:57 +04:00
}
}
2008-05-24 22:18:37 +04:00
/**
2008-05-24 22:18:37 +04:00
* Defines how long the query cache will be active before expire.
*
2008-05-24 22:18:37 +04:00
* @param integer $timeToLive How long the cache entry is valid
* @return Doctrine_Query
*/
2008-05-24 22:18:37 +04:00
public function setQueryCacheLifetime($timeToLive)
{
2008-05-24 22:18:37 +04:00
if ($timeToLive !== null) {
$timeToLive = (int) $timeToLive;
2007-05-16 23:20:55 +04:00
}
2008-05-24 22:18:37 +04:00
$this->_queryCacheTTL = $timeToLive;
return $this;
}
2008-05-24 22:18:37 +04:00
/**
2008-05-24 22:18:37 +04:00
* Retrieves the lifetime of resultset cache.
*
* @return int
*/
2008-05-24 22:18:37 +04:00
public function getQueryCacheLifetime()
{
2008-05-24 22:18:37 +04:00
return $this->_queryCacheTTL;
2007-07-09 15:23:44 +04:00
}
2008-05-24 22:18:37 +04:00
2007-05-16 23:20:55 +04:00
/**
2008-05-24 22:18:37 +04:00
* Defines if the query cache is active or not.
2007-05-16 23:20:55 +04:00
*
2008-05-24 22:18:37 +04:00
* @param boolean $expire Whether or not to force query cache expiration.
* @return Doctrine_Query
2007-05-16 23:20:55 +04:00
*/
2008-05-24 22:18:37 +04:00
public function setExpireQueryCache($expire = true)
2007-05-16 23:20:55 +04:00
{
2008-05-24 22:18:37 +04:00
$this->_expireQueryCache = (bool) $expire;
2008-05-24 22:18:37 +04:00
return $this;
}
2008-05-24 22:18:37 +04:00
2007-06-19 02:30:15 +04:00
/**
2008-05-24 22:18:37 +04:00
* Retrieves if the query cache is active or not.
*
2008-05-24 22:18:37 +04:00
* @return bool
*/
2008-05-24 22:18:37 +04:00
public function getExpireQueryCache()
{
2008-05-24 22:18:37 +04:00
return $this->_expireQueryCache;
}
2008-05-24 22:18:37 +04:00
2007-05-16 23:20:55 +04:00
/**
2008-05-24 22:18:37 +04:00
* Defines the processing mode to be used during hydration process.
2007-05-16 23:20:55 +04:00
*
2008-05-24 22:18:37 +04:00
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
* One of the Doctrine::HYDRATE_* constants.
* @return Doctrine_Query
2007-05-16 23:20:55 +04:00
*/
2008-05-24 22:18:37 +04:00
public function setHydrationMode($hydrationMode)
2007-05-16 23:20:55 +04:00
{
2008-05-24 22:18:37 +04:00
$this->_hydrator->setHydrationMode($hydrationMode);
return $this;
2007-05-16 23:20:55 +04:00
}
/**
2008-05-24 22:18:37 +04:00
* Empty template method to provide Query subclasses with the possibility
* to hook into the query building procedure, doing any custom / specialized
* query building procedures that are neccessary.
*
2008-05-24 22:18:37 +04:00
* @return void
* @deprecated Should be removed. Extending Query is no good solution. Should
* Things like this should be done through listeners.
*/
2008-05-24 22:18:37 +04:00
public function preQuery()
{
}
/**
2008-05-24 22:18:37 +04:00
* Empty template method to provide Query subclasses with the possibility
* to hook into the query building procedure, doing any custom / specialized
* post query procedures (for example logging) that are neccessary.
2007-08-30 01:36:36 +04:00
*
2008-05-24 22:18:37 +04:00
* @return void
* @deprecated Should be removed. Extending Query is no good solution. Should
* Things like this should be done through listeners.
*/
2008-05-24 22:18:37 +04:00
public function postQuery()
2007-08-30 01:36:36 +04:00
{
2008-05-24 22:18:37 +04:00
}
/**
* Gets the list of results for the query.
*
* @param integer $hydrationMode
* @return mixed
*/
public function getResultList($hydrationMode = null)
{
return $this->execute(array(), $hydrationMode);
}
/**
* Gets the single result of the query.
* Enforces the uniqueness of the result. If the result is not unique,
* a QueryException is thrown.
*
* @param integer $hydrationMode
* @return mixed
* @throws QueryException If the query result is not unique.
*/
public function getSingleResult($hydrationMode = null)
{
$result = $this->execute(array(), $hydrationMode);
if (count($result) > 1) {
throw Doctrine_Query_Exception::nonUniqueResult();
}
return is_array($result) ? array_shift($result) : $result->getFirst();
}
2008-05-24 22:18:37 +04:00
/**
2008-05-24 22:18:37 +04:00
* This method is automatically called when this Doctrine_Hydrate is serialized.
*
2008-05-24 22:18:37 +04:00
* @return array An array of serialized properties
*/
public function serialize()
{
$vars = get_object_vars($this);
}
/**
2008-05-24 22:18:37 +04:00
* This method is automatically called everytime a Doctrine_Hydrate object is unserialized.
*
2008-05-24 22:18:37 +04:00
* @param string $serialized Doctrine_Record as serialized string
* @return void
*/
public function unserialize($serialized)
{
}
}