1
0
mirror of synced 2025-01-31 04:21:44 +03:00

[2.0] Moved Doctrine_Query to definite namespace Doctrine_ORM_Query.

Fixed paths that were referring wrong namespace resolution.
Implemented more Parser and AST classes: JoinVariableDeclaration and Join.
Fixed wrong semantical checks of IndexBy grammar rule. They should be in IdentificationVariableDeclaration and JoinVariableDeclaration.
This commit is contained in:
guilhermeblanco 2008-09-23 02:45:02 +00:00
parent 2aa542841f
commit 178f3fe5bb
109 changed files with 86 additions and 10733 deletions

View File

@ -755,7 +755,7 @@ final class Doctrine
/** /**
* isValidModelClass * isValidModelClass
* *
* Checks if what is passed is a valid Doctrine_Entity * Checks if what is passed is a valid Doctrine_ORM_Entity
* Will load class in to memory in order to inflect it and find out information about the class * Will load class in to memory in order to inflect it and find out information about the class
* *
* @param mixed $class Can be a string named after the class, an instance of the class, or an instance of the class reflected * @param mixed $class Can be a string named after the class, an instance of the class, or an instance of the class reflected
@ -763,7 +763,7 @@ final class Doctrine
*/ */
public static function isValidModelClass($class) public static function isValidModelClass($class)
{ {
if ($class instanceof Doctrine_Entity) { if ($class instanceof Doctrine_ORM_Entity) {
$class = get_class($class); $class = get_class($class);
} }
@ -774,10 +774,10 @@ final class Doctrine
if ($class instanceof ReflectionClass) { if ($class instanceof ReflectionClass) {
// Skip the following classes // Skip the following classes
// - abstract classes // - abstract classes
// - not a subclass of Doctrine_Entity // - not a subclass of Doctrine_ORM_Entity
// - don't have a setTableDefinition method // - don't have a setTableDefinition method
if (!$class->isAbstract() && if (!$class->isAbstract() &&
$class->isSubClassOf('Doctrine_Entity')) { $class->isSubClassOf('Doctrine_ORM_Entity')) {
return true; return true;
} }

View File

@ -243,7 +243,7 @@ class Doctrine_ORM_EntityManager
*/ */
public function createQuery($dql = "") public function createQuery($dql = "")
{ {
$query = new Doctrine_Query($this); $query = new Doctrine_ORM_Query($this);
if ( ! empty($dql)) { if ( ! empty($dql)) {
$query->setDql($dql); $query->setDql($dql);
} }

View File

@ -54,7 +54,7 @@ abstract class Doctrine_ORM_Internal_Hydration_AbstractHydrator
/** /**
* The current hydration mode. * The current hydration mode.
*/ */
protected $_hydrationMode = Doctrine_Query::HYDRATE_OBJECT; protected $_hydrationMode = Doctrine_ORM_Query::HYDRATE_OBJECT;
protected $_nullObject; protected $_nullObject;

View File

@ -89,14 +89,14 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte
$stmt = $parserResult->getDatabaseStatement(); $stmt = $parserResult->getDatabaseStatement();
if ($hydrationMode == Doctrine_Query::HYDRATE_NONE) { if ($hydrationMode == Doctrine_ORM_Query::HYDRATE_NONE) {
return $stmt->fetchAll(PDO::FETCH_NUM); return $stmt->fetchAll(PDO::FETCH_NUM);
} }
$this->_tableAliases = $parserResult->getTableToClassAliasMap(); $this->_tableAliases = $parserResult->getTableToClassAliasMap();
$this->_queryComponents = $parserResult->getQueryComponents(); $this->_queryComponents = $parserResult->getQueryComponents();
if ($hydrationMode == Doctrine_Query::HYDRATE_ARRAY) { if ($hydrationMode == Doctrine_ORM_Query::HYDRATE_ARRAY) {
$driver = new Doctrine_ORM_Internal_Hydration_ArrayDriver(); $driver = new Doctrine_ORM_Internal_Hydration_ArrayDriver();
} else { } else {
$driver = new Doctrine_ORM_Internal_Hydration_ObjectDriver($this->_em); $driver = new Doctrine_ORM_Internal_Hydration_ObjectDriver($this->_em);
@ -123,7 +123,7 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte
$idTemplate = array(); $idTemplate = array();
// Holds the resulting hydrated data structure // Holds the resulting hydrated data structure
if ($parserResult->isMixedQuery() || $hydrationMode == Doctrine_Query::HYDRATE_SCALAR) { if ($parserResult->isMixedQuery() || $hydrationMode == Doctrine_ORM_Query::HYDRATE_SCALAR) {
$result = array(); $result = array();
} else { } else {
$result = $driver->getElementCollection($rootEntityName); $result = $driver->getElementCollection($rootEntityName);
@ -145,7 +145,7 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte
$cache = array(); $cache = array();
// Evaluate HYDRATE_SINGLE_SCALAR // Evaluate HYDRATE_SINGLE_SCALAR
if ($hydrationMode == Doctrine_Query::HYDRATE_SINGLE_SCALAR) { if ($hydrationMode == Doctrine_ORM_Query::HYDRATE_SINGLE_SCALAR) {
$result = $stmt->fetchAll(PDO::FETCH_ASSOC); $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($result) > 1 || count($result[0]) > 1) { if (count($result) > 1 || count($result[0]) > 1) {
throw Doctrine_ORM_Exceptions_HydrationException::nonUniqueResult(); throw Doctrine_ORM_Exceptions_HydrationException::nonUniqueResult();
@ -157,7 +157,7 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte
// Process result set // Process result set
while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) { while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
// Evaluate HYDRATE_SCALAR // Evaluate HYDRATE_SCALAR
if ($hydrationMode == Doctrine_Query::HYDRATE_SCALAR) { if ($hydrationMode == Doctrine_ORM_Query::HYDRATE_SCALAR) {
$result[] = $this->_gatherScalarRowData($data, $cache); $result[] = $this->_gatherScalarRowData($data, $cache);
continue; continue;
} }
@ -246,7 +246,7 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte
$driver->getReferenceValue($baseElement, $relationAlias)); $driver->getReferenceValue($baseElement, $relationAlias));
} }
} else if ( ! isset($baseElement[$relationAlias])) { } else if ( ! isset($baseElement[$relationAlias])) {
if ($hydrationMode == Doctrine_Query::HYDRATE_ARRAY) { if ($hydrationMode == Doctrine_ORM_Query::HYDRATE_ARRAY) {
$baseElement[$relationAlias] = array(); $baseElement[$relationAlias] = array();
} else { } else {
$driver->setRelatedElement($baseElement, $relationAlias, $driver->setRelatedElement($baseElement, $relationAlias,
@ -266,7 +266,7 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte
} }
} }
if ($hydrationMode == Doctrine_Query::HYDRATE_ARRAY) { if ($hydrationMode == Doctrine_ORM_Query::HYDRATE_ARRAY) {
$coll =& $baseElement[$relationAlias]; $coll =& $baseElement[$relationAlias];
} else { } else {
$coll = $baseElement->_internalGetReference($relationAlias); $coll = $baseElement->_internalGetReference($relationAlias);
@ -359,10 +359,10 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte
if ($this->_isIgnoredName($key)) continue; if ($this->_isIgnoredName($key)) continue;
// Cache general information like the column name <-> field name mapping // Cache general information like the column name <-> field name mapping
$e = explode(Doctrine_Query_ParserRule::SQLALIAS_SEPARATOR, $key); $e = explode(Doctrine_ORM_Query_ParserRule::SQLALIAS_SEPARATOR, $key);
$columnName = array_pop($e); $columnName = array_pop($e);
$cache[$key]['dqlAlias'] = $this->_tableAliases[ $cache[$key]['dqlAlias'] = $this->_tableAliases[
implode(Doctrine_Query_ParserRule::SQLALIAS_SEPARATOR, $e) implode(Doctrine_ORM_Query_ParserRule::SQLALIAS_SEPARATOR, $e)
]; ];
$classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; $classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
// check whether it's an aggregate value or a regular field // check whether it's an aggregate value or a regular field
@ -444,10 +444,10 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte
if ($this->_isIgnoredName($key)) continue; if ($this->_isIgnoredName($key)) continue;
// cache general information like the column name <-> field name mapping // cache general information like the column name <-> field name mapping
$e = explode(Doctrine_Query_ParserRule::SQLALIAS_SEPARATOR, $key); $e = explode(Doctrine_ORM_Query_ParserRule::SQLALIAS_SEPARATOR, $key);
$columnName = array_pop($e); $columnName = array_pop($e);
$cache[$key]['dqlAlias'] = $this->_tableAliases[ $cache[$key]['dqlAlias'] = $this->_tableAliases[
implode(Doctrine_Query_ParserRule::SQLALIAS_SEPARATOR, $e) implode(Doctrine_ORM_Query_ParserRule::SQLALIAS_SEPARATOR, $e)
]; ];
$classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; $classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
// check whether it's an aggregate value or a regular field // check whether it's an aggregate value or a regular field

66
lib/Doctrine/Query.php → lib/Doctrine/ORM/Query.php Executable file → Normal file
View File

@ -23,12 +23,10 @@
#namespace Doctrine::ORM; #namespace Doctrine::ORM;
/** /**
* A Doctrine_Query object represents a DQL query. It is used to query databases for * A Doctrine_ORM_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 * data in an object-oriented fashion. A DQL query understands relations and inheritance
* and is dbms independant. * and is dbms independant.
* *
* @package Doctrine
* @subpackage Query
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org * @link www.phpdoctrine.org
* @since 1.0 * @since 1.0
@ -36,7 +34,7 @@
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Query extends Doctrine_Query_Abstract class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract
{ {
/* Hydration mode constants */ /* Hydration mode constants */
/** /**
@ -61,17 +59,17 @@ class Doctrine_Query extends Doctrine_Query_Abstract
const HYDRATE_NONE = 5; const HYDRATE_NONE = 5;
/** /**
* @var Doctrine_EntityManager The entity manager used by this query object. * @var Doctrine_ORM_EntityManager The entity manager used by this query object.
*/ */
protected $_entityManager; protected $_entityManager;
/** /**
* @var Doctrine_Hydrator The hydrator object used to hydrate query results. * @var Doctrine_ORM_Internal_Hydration The hydrator object used to hydrate query results.
*/ */
protected $_hydrator; protected $_hydrator;
/** /**
* @var Doctrine_Query_ParserResult The parser result that holds DQL => SQL information. * @var Doctrine_ORM_Query_ParserResult The parser result that holds DQL => SQL information.
*/ */
protected $_parserResult; protected $_parserResult;
@ -127,10 +125,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract
/** /**
* Returns a new Doctrine_Query object * Returns a new Doctrine_ORM_Query object
* *
* @param Doctrine_Connection $conn optional connection parameter * @param Doctrine_Connection $conn optional connection parameter
* @return Doctrine_Query * @return Doctrine_ORM_Query
*/ */
public static function create($conn = null) public static function create($conn = null)
{ {
@ -139,7 +137,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
/** /**
* Retrieves the assocated Doctrine_EntityManager to this Doctrine_Query * Retrieves the assocated Doctrine_EntityManager to this Doctrine_ORM_Query
* *
* @return Doctrine_EntityManager * @return Doctrine_EntityManager
*/ */
@ -152,7 +150,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
/** /**
* Returns the hydrator associated with this query object * Returns the hydrator associated with this query object
* *
* @return Doctrine_Hydrator The hydrator associated with this query object * @return Doctrine_ORM_Internal_Hydration The hydrator associated with this query object
*/ */
public function getHydrator() public function getHydrator()
{ {
@ -167,7 +165,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
* @return array * @return array
*/ */
public function fetchArray($params = array()) { public function fetchArray($params = array()) {
return $this->execute($params, Doctrine::HYDRATE_ARRAY); return $this->execute($params, self::HYDRATE_ARRAY);
} }
@ -187,7 +185,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
return false; return false;
} }
if ($collection instanceof Doctrine_Collection) { if ($collection instanceof Doctrine_ORM_Collection) {
return $collection->getFirst(); return $collection->getFirst();
} else if (is_array($collection)) { } else if (is_array($collection)) {
return array_shift($collection); return array_shift($collection);
@ -228,12 +226,12 @@ class Doctrine_Query extends Doctrine_Query_Abstract
/** /**
* Parses the DQL query, if necessary, and stores the parser result. * Parses the DQL query, if necessary, and stores the parser result.
* *
* @return Doctrine_Query_ParserResult * @return Doctrine_ORM_Query_ParserResult
*/ */
public function parse() public function parse()
{ {
if ($this->_state === self::STATE_DIRTY) { if ($this->_state === self::STATE_DIRTY) {
$parser = new Doctrine_Query_Parser($this); $parser = new Doctrine_ORM_Query_Parser($this);
$this->_parserResult = $parser->parse(); $this->_parserResult = $parser->parse();
$this->_state = self::STATE_CLEAN; $this->_state = self::STATE_CLEAN;
} }
@ -264,14 +262,14 @@ class Doctrine_Query extends Doctrine_Query_Abstract
if ($cached === false) { if ($cached === false) {
// Cache does not exist, we have to create it. // Cache does not exist, we have to create it.
$result = $this->_execute($params, Doctrine::HYDRATE_ARRAY); $result = $this->_execute($params, self::HYDRATE_ARRAY);
$queryResult = Doctrine_Query_CacheHandler::fromResultSet($this, $result); $queryResult = Doctrine_ORM_Query_CacheHandler::fromResultSet($this, $result);
$cacheDriver->save($hash, $queryResult->toCachedForm(), $this->_resultCacheTTL); $cacheDriver->save($hash, $queryResult->toCachedForm(), $this->_resultCacheTTL);
return $result; return $result;
} else { } else {
// Cache exists, recover it and return the results. // Cache exists, recover it and return the results.
$queryResult = Doctrine_Query_CacheHandler::fromCachedResult($this, $cached); $queryResult = Doctrine_ORM_Query_CacheHandler::fromCachedResult($this, $cached);
return $queryResult->getResultSet(); return $queryResult->getResultSet();
} }
@ -331,7 +329,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
$cacheDriver->save($hash, $this->_parserResult->toCachedForm(), $this->_queryCacheTTL); $cacheDriver->save($hash, $this->_parserResult->toCachedForm(), $this->_queryCacheTTL);
} else { } else {
// Cache exists, recover it and return the results. // Cache exists, recover it and return the results.
$this->_parserResult = Doctrine_Query_CacheHandler::fromCachedQuery($this, $cached); $this->_parserResult = Doctrine_ORM_Query_CacheHandler::fromCachedQuery($this, $cached);
$executor = $this->_parserResult->getSqlExecutor(); $executor = $this->_parserResult->getSqlExecutor();
} }
@ -348,7 +346,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
$params = $this->_prepareParams($params); $params = $this->_prepareParams($params);
// Double the params if we are using limit-subquery algorithm // Double the params if we are using limit-subquery algorithm
// We always have an instance of Doctrine_Query_ParserResult on hands... // We always have an instance of Doctrine_ORM_Query_ParserResult on hands...
if ($this->_parserResult->isLimitSubqueryUsed() && if ($this->_parserResult->isLimitSubqueryUsed() &&
$this->_entityManager->getConnection()->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') { $this->_entityManager->getConnection()->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') {
$params = array_merge($params, $params); $params = array_merge($params, $params);
@ -376,12 +374,12 @@ class Doctrine_Query extends Doctrine_Query_Abstract
* Defines a cache driver to be used for caching result sets. * Defines a cache driver to be used for caching result sets.
* *
* @param Doctrine_Cache_Interface|null $driver Cache driver * @param Doctrine_Cache_Interface|null $driver Cache driver
* @return Doctrine_Query * @return Doctrine_ORM_Query
*/ */
public function setResultCache($resultCache) public function setResultCache($resultCache)
{ {
if ($resultCache !== null && ! ($resultCache instanceof Doctrine_Cache_Interface)) { if ($resultCache !== null && ! ($resultCache instanceof Doctrine_Cache_Interface)) {
throw new Doctrine_Query_Exception( throw new Doctrine_ORM_Query_Exception(
'Method setResultCache() accepts only an instance of Doctrine_Cache_Interface or null.' 'Method setResultCache() accepts only an instance of Doctrine_Cache_Interface or null.'
); );
} }
@ -399,7 +397,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
*/ */
public function getResultCache() public function getResultCache()
{ {
if ($this->_resultCache instanceof Doctrine_Cache_Interface) { if ($this->_resultCache instanceof Doctrine_ORM_Cache_Interface) {
return $this->_resultCache; return $this->_resultCache;
} else { } else {
return $this->_entityManager->getConnection()->getResultCacheDriver(); return $this->_entityManager->getConnection()->getResultCacheDriver();
@ -411,7 +409,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
* Defines how long the result cache will be active before expire. * Defines how long the result cache will be active before expire.
* *
* @param integer $timeToLive How long the cache entry is valid * @param integer $timeToLive How long the cache entry is valid
* @return Doctrine_Query * @return Doctrine_ORM_Query
*/ */
public function setResultCacheLifetime($timeToLive) public function setResultCacheLifetime($timeToLive)
{ {
@ -440,7 +438,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
* Defines if the resultset cache is active or not. * Defines if the resultset cache is active or not.
* *
* @param boolean $expire Whether or not to force resultset cache expiration. * @param boolean $expire Whether or not to force resultset cache expiration.
* @return Doctrine_Query * @return Doctrine_ORM_Query
*/ */
public function setExpireResultCache($expire = true) public function setExpireResultCache($expire = true)
{ {
@ -465,13 +463,13 @@ class Doctrine_Query extends Doctrine_Query_Abstract
* Defines a cache driver to be used for caching queries. * Defines a cache driver to be used for caching queries.
* *
* @param Doctrine_Cache_Interface|null $driver Cache driver * @param Doctrine_Cache_Interface|null $driver Cache driver
* @return Doctrine_Query * @return Doctrine_ORM_Query
*/ */
public function setQueryCache($queryCache) public function setQueryCache($queryCache)
{ {
if ($queryCache !== null && ! ($queryCache instanceof Doctrine_Cache_Interface)) { if ($queryCache !== null && ! ($queryCache instanceof Doctrine_ORM_Cache_Interface)) {
throw new Doctrine_Query_Exception( throw new Doctrine_ORM_Query_Exception(
'Method setResultCache() accepts only an instance of Doctrine_Cache_Interface or null.' 'Method setResultCache() accepts only an instance of Doctrine_ORM_Cache_Interface or null.'
); );
} }
@ -488,7 +486,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
*/ */
public function getQueryCache() public function getQueryCache()
{ {
if ($this->_queryCache instanceof Doctrine_Cache_Interface) { if ($this->_queryCache instanceof Doctrine_ORM_Cache_Interface) {
return $this->_queryCache; return $this->_queryCache;
} else { } else {
return $this->_entityManager->getConnection()->getQueryCacheDriver(); return $this->_entityManager->getConnection()->getQueryCacheDriver();
@ -500,7 +498,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
* Defines how long the query cache will be active before expire. * Defines how long the query cache will be active before expire.
* *
* @param integer $timeToLive How long the cache entry is valid * @param integer $timeToLive How long the cache entry is valid
* @return Doctrine_Query * @return Doctrine_ORM_Query
*/ */
public function setQueryCacheLifetime($timeToLive) public function setQueryCacheLifetime($timeToLive)
{ {
@ -529,7 +527,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
* Defines if the query cache is active or not. * Defines if the query cache is active or not.
* *
* @param boolean $expire Whether or not to force query cache expiration. * @param boolean $expire Whether or not to force query cache expiration.
* @return Doctrine_Query * @return Doctrine_ORM_Query
*/ */
public function setExpireQueryCache($expire = true) public function setExpireQueryCache($expire = true)
{ {
@ -555,7 +553,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
* *
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process. * @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
* One of the Doctrine::HYDRATE_* constants. * One of the Doctrine::HYDRATE_* constants.
* @return Doctrine_Query * @return Doctrine_ORM_Query
*/ */
public function setHydrationMode($hydrationMode) public function setHydrationMode($hydrationMode)
{ {
@ -616,7 +614,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract
{ {
$result = $this->execute(array(), $hydrationMode); $result = $this->execute(array(), $hydrationMode);
if (count($result) > 1) { if (count($result) > 1) {
throw Doctrine_Query_Exception::nonUniqueResult(); throw Doctrine_ORM_Query_Exception::nonUniqueResult();
} }
return is_array($result) ? array_shift($result) : $result->getFirst(); return is_array($result) ? array_shift($result) : $result->getFirst();

View File

@ -1,43 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Abstract class of an AST node
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
abstract class Doctrine_Query_AST
{
protected $_parserResult = null;
public function __construct(Doctrine_Query_ParserResult $parserResult)
{
$this->_parserResult = $parserResult;
}
}

View File

@ -1,50 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* AbstractSchemaName ::= identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_AbstractSchemaName extends Doctrine_Query_AST
{
protected $_componentName;
/* Setters */
public function setComponentName($componentName)
{
$this->_componentName = $componentName;
}
/* Getters */
public function getComponentName()
{
return $this->_componentName;
}
}

View File

@ -1,50 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* AliasIdentificationVariable ::= identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_AliasIdentificationVariable extends Doctrine_Query_AST
{
protected $_componentAlias;
/* Setters */
public function setComponentAlias($componentAlias)
{
$this->_componentAlias = $componentAlias;
}
/* Getters */
public function getComponentAlias()
{
return $this->_componentAlias;
}
}

View File

@ -1,75 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* DeleteStatement = DeleteClause [WhereClause]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_DeleteStatement extends Doctrine_Query_AST
{
protected $_deleteClause;
protected $_whereClause;
/* Setters */
public function setDeleteClause($deleteClause)
{
$this->_deleteClause = $deleteClause;
}
public function setWhereClause($whereClause)
{
$this->_whereClause = $whereClause;
}
/* Getters */
public function getDeleteClause()
{
return $this->_deleteClause;
}
public function getWhereClause()
{
return $this->_whereClause;
}
/* REMOVE ME LATER. COPIED METHODS FROM SPLIT OF PRODUCTION INTO "AST" AND "PARSER" */
public function buildSql()
{
// The 1=1 is needed to workaround the affected_rows in MySQL.
// Simple "DELETE FROM table_name" gives 0 affected rows.
return $this->_deleteClause->buildSql() . (($this->_whereClause !== null)
? ' ' . $this->_whereClause->buildSql() : ' WHERE 1 = 1');
}
}

View File

@ -1,50 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* FieldIdentificationVariable ::= identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_FieldIdentificationVariable extends Doctrine_Query_AST
{
protected $_fieldName;
/* Setters */
public function setFieldName($fieldName)
{
$this->_fieldName = $fieldName;
}
/* Getters */
public function getFieldName()
{
return $this->_fieldName;
}
}

View File

@ -1,87 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* FromClause ::= "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_FromClause extends Doctrine_Query_AST
{
protected $_identificationVariableDeclarations = array();
/* Setters */
public function addIdentificationVariableDeclaration($identificationVariableDeclaration)
{
$this->_identificationVariableDeclarations[] = $identificationVariableDeclaration;
}
public function setIdentificationVariableDeclarations($identificationVariableDeclarations, $append = false)
{
$this->_selectExpressions = ($append === true)
? array_merge($this->_identificationVariableDeclarations, $identificationVariableDeclarations)
: $identificationVariableDeclarations;
}
/* Getters */
public function getIdentificationVariableDeclarations()
{
return $this->_identificationVariableDeclarations;
}
/* REMOVE ME LATER. COPIED METHODS FROM SPLIT OF PRODUCTION INTO "AST" AND "PARSER" */
public function buildSql()
{
//echo "FromClause:\n";
//for ($i = 0; $i < count($this->_identificationVariableDeclaration);$i++) {
// echo (($this->_identificationVariableDeclaration[$i] instanceof IdentificationVariableDeclaration)
// ? get_class($this->_identificationVariableDeclaration[$i])
// : get_class($this->_identificationVariableDeclaration[$i])) . "\n";
//}
return 'FROM ' . implode(', ', $this->_mapIdentificationVariableDeclarations());
}
protected function _mapIdentificationVariableDeclarations()
{
return array_map(
array(&$this, '_mapIdentificationVariableDeclaration'), $this->_identificationVariableDeclarations
);
}
protected function _mapIdentificationVariableDeclaration($value)
{
return $value->buildSql();
}
}

View File

@ -1,62 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* IdentificationVariable ::= identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_IdentificationVariable extends Doctrine_Query_AST
{
protected $_componentAlias;
/* Setters */
public function setComponentAlias($componentAlias)
{
$this->_componentAlias = $componentAlias;
}
/* Getters */
public function getComponentAlias()
{
return $this->_componentAlias;
}
/* REMOVE ME LATER. COPIED METHODS FROM SPLIT OF PRODUCTION INTO "AST" AND "PARSER" */
public function buildSql()
{
$conn = $this->_parserResult->getEntityManager()->getConnection();
return $conn->quoteIdentifier(
$this->_parserResult->getTableAliasFromComponentAlias($this->_componentAlias)
);
}
}

View File

@ -1,100 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* IdentificationVariableDeclaration ::= RangeVariableDeclaration [IndexBy] {JoinVariableDeclaration}*
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_IdentificationVariableDeclaration extends Doctrine_Query_AST
{
protected $_rangeVariableDeclaration = null;
protected $_indexBy = null;
protected $_joinVariableDeclarations = array();
/* Setters */
public function setRangeVariableDeclaration($rangeVariableDeclaration)
{
$this->_rangeVariableDeclaration = $rangeVariableDeclaration;
}
public function setIndexBy($indexBy)
{
$this->_indexBy = $indexBy;
}
public function addJoinVariableDeclaration($joinVariableDeclaration)
{
$this->_joinVariableDeclarations[] = $joinVariableDeclaration;
}
public function setJoinVariableDeclarations($joinVariableDeclarations, $append = false)
{
$this->_joinVariableDeclarations = ($append === true)
? array_merge($this->_joinVariableDeclarations, $joinVariableDeclarations)
: $joinVariableDeclarations;
}
/* Getters */
public function getRangeVariableDeclaration()
{
return $this->_rangeVariableDeclaration;
}
public function getIndexBy()
{
return $this->_indexBy;
}
public function getJoinVariableDeclarations()
{
return $this->_joinVariableDeclarations;
}
/* REMOVE ME LATER. COPIED METHODS FROM SPLIT OF PRODUCTION INTO "AST" AND "PARSER" */
public function buildSql()
{
$str = $this->_rangeVariableDeclaration->buildSql();
for ($i = 0, $l = count($this->_joinVariableDeclarations); $i < $l; $i++) {
$str .= ' ' . $this->_joinVariableDeclarations[$i]->buildSql();
}
return $str;
}
}

View File

@ -1,50 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* IndexBy ::= "INDEX" "BY" SimpleStateFieldPathExpression
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_IndexBy extends Doctrine_Query_AST
{
protected $_simpleStateFieldPathExpression = null;
/* Setters */
public function setSimpleStateFieldPathExpression($simpleStateFieldPathExpression)
{
$this->_simpleStateFieldPathExpression = $simpleStateFieldPathExpression;
}
/* Getters */
public function getSimpleStateFieldPathExpression()
{
return $this->_simpleStateFieldPathExpression;
}
}

View File

@ -1,89 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* RangeVariableDeclaration ::= AbstractSchemaName ["AS"] AliasIdentificationVariable
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_RangeVariableDeclaration extends Doctrine_Query_AST
{
protected $_abstractSchemaName = null;
protected $_aliasIdentificationVariable = null;
/* Setters */
public function setAbstractSchemaName($abstractSchemaName)
{
$this->_abstractSchemaName = $abstractSchemaName;
}
public function setAliasIdentificationVariable($aliasIdentificationVariable)
{
$this->_aliasIdentificationVariable = $aliasIdentificationVariable;
}
/* Getters */
public function getAbstractSchemaName()
{
return $this->_abstractSchemaName;
}
public function getAliasIdentificationVariable()
{
return $this->_aliasIdentificationVariable;
}
/* REMOVE ME LATER. COPIED METHODS FROM SPLIT OF PRODUCTION INTO "AST" AND "PARSER" */
public function buildSql()
{
// Retrieving connection
$conn = $this->_parserResult->getEntityManager()->getConnection();
// Component alias
$componentAlias = $this->_aliasIdentificationVariable->getComponentAlias();
// Retrieving required information
try {
$queryComponent = $this->_parserResult->getQueryComponent($componentAlias);
$classMetadata = $queryComponent['metadata'];
} catch (Doctrine_Exception $e) {
$this->_parser->semanticalError($e->getMessage());
return;
}
return $conn->quoteIdentifier($classMetadata->getTableName()) . ' '
. $conn->quoteIdentifier($this->_parserResult->getTableAliasFromComponentAlias($componentAlias));
}
}

View File

@ -1,93 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SelectClause = "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_SelectClause extends Doctrine_Query_AST
{
protected $_isDistinct;
protected $_selectExpressions = array();
/* Setters */
public function setIsDistinct($value)
{
$this->_isDistinct = $value;
}
public function addSelectExpression($expression)
{
$this->_selectExpressions[] = $expression;
}
public function setSelectExpressions($expressions, $append = false)
{
$this->_selectExpressions = ($append === true)
? array_merge($this->_selectExpressions, $expressions)
: $expressions;
}
/* Getters */
public function isDistinct()
{
return $this->_isDistinct;
}
public function getSelectExpressions()
{
return $this->_selectExpressions;
}
/* REMOVE ME LATER. COPIED METHODS FROM SPLIT OF PRODUCTION INTO "AST" AND "PARSER" */
public function buildSql()
{
return 'SELECT ' . (($this->_isDistinct) ? 'DISTINCT ' : '')
. implode(', ', $this->_mapSelectExpressions());
}
protected function _mapSelectExpressions()
{
return array_map(array(&$this, '_mapSelectExpression'), $this->_selectExpressions);
}
protected function _mapSelectExpression($value)
{
return $value->buildSql();
}
}

View File

@ -1,132 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SelectStatement = SelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_SelectStatement extends Doctrine_Query_AST
{
protected $_selectClause;
protected $_fromClause;
protected $_whereClause;
protected $_groupByClause;
protected $_havingClause;
protected $_orderByClause;
/* Setters */
public function setSelectClause($selectClause)
{
$this->_selectClause = $selectClause;
}
public function setFromClause($fromClause)
{
$this->_fromClause = $fromClause;
}
public function setWhereClause($whereClause)
{
$this->_whereClause = $whereClause;
}
public function setGroupByClause($groupByClause)
{
$this->_groupByClause = $groupByClause;
}
public function setHavingClause($havingClause)
{
$this->_havingClause = $havingClause;
}
public function setOrderByClause($orderByClause)
{
$this->_orderByClause = $orderByClause;
}
/* Getters */
public function getSelectClause()
{
return $this->_selectClause;
}
public function getFromClause()
{
return $this->_fromClause;
}
public function getWhereClause()
{
return $this->_whereClause;
}
public function getGroupByClause()
{
return $this->_groupByClause;
}
public function getHavingClause()
{
return $this->_havingClause;
}
public function getOrderByClause()
{
return $this->_orderByClause;
}
/* REMOVE ME LATER. COPIED METHODS FROM SPLIT OF PRODUCTION INTO "AST" AND "PARSER" */
public function buildSql()
{
return $this->_selectClause->buildSql() . ' ' . $this->_fromClause->buildSql()
. (($this->_whereClause !== null) ? ' ' . $this->_whereClause->buildSql() : ' WHERE 1 = 1')
. (($this->_groupByClause !== null) ? ' ' . $this->_groupByClause->buildSql() : '')
. (($this->_havingClause !== null) ? ' ' . $this->_havingClause->buildSql() : '')
. (($this->_orderByClause !== null) ? ' ' . $this->_orderByClause->buildSql() : '');
}
}

View File

@ -1,64 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SimpleStateFieldPathExpression ::= IdentificationVariable "." SimpleStateField
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_SimpleStateFieldPathExpression extends Doctrine_Query_AST
{
protected $_identificationVariable = null;
protected $_simpleStateField = null;
/* Setters */
public function setIdentificationVariable($identificationVariable)
{
$this->_identificationVariable = $identificationVariable;
}
public function setSimpleStateField($simpleStateField)
{
$this->_simpleStateField = $simpleStateField;
}
/* Getters */
public function getIdentificationVariable()
{
return $this->_identificationVariable;
}
public function getSimpleStateField()
{
return $this->_simpleStateField;
}
}

View File

@ -1,75 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* UpdateStatement = UpdateClause [WhereClause]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_AST_UpdateStatement extends Doctrine_Query_AST
{
protected $_updateClause;
protected $_whereClause;
/* Setters */
public function setUpdateClause($updateClause)
{
$this->_updateClause = $updateClause;
}
public function setWhereClause($whereClause)
{
$this->_whereClause = $whereClause;
}
/* Getters */
public function getUpdateClause()
{
return $this->_updateClause;
}
public function getWhereClause()
{
return $this->_whereClause;
}
/* REMOVE ME LATER. COPIED METHODS FROM SPLIT OF PRODUCTION INTO "AST" AND "PARSER" */
public function buildSql()
{
// The 1=1 is needed to workaround the affected_rows in MySQL.
// Simple "UPDATE table_name SET column_name = value" gives 0 affected rows.
return $this->_updateClause->buildSql() . (($this->_whereClause !== null)
? ' ' . $this->_whereClause->buildSql() : ' WHERE 1 = 1');
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,278 +0,0 @@
<?php
/*
* $Id: Cache.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>.
*/
/**
* Doctrine_Query_AbstractResult
*
* @package Doctrine
* @subpackage Query
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 2.0
* @version $Revision: 1393 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
abstract class Doctrine_Query_AbstractResult
{
/**
* @var mixed $_data The actual data to be stored. Can be an array, a string or an integer.
*/
protected $_data;
/**
* @var array $_queryComponents
*
* Two dimensional array containing the map for query aliases. Main keys are component aliases.
*
* table Table object associated with given alias.
* relation Relation object owned by the parent.
* parent Alias of the parent.
* agg Aggregates of this component.
* map Name of the column / aggregate value this component is mapped to a collection.
*/
protected $_queryComponents;
/**
* @var array Table alias map. Keys are SQL aliases and values DQL aliases.
*/
protected $_tableAliasMap;
/**
* @var array Enum params.
*/
protected $_enumParams;
/**
* Cannot be called directly, factory methods handle this job.
*
* @param mixed $data Data to be stored.
* @param array $queryComponents Query components.
* @param array $tableAliasMap Table aliases.
* @param array $enumParams Enum params.
* @return Doctrine_Query_CacheHandler
*/
public function __construct($data = '', $queryComponents = array(), $tableAliasMap = array(), $enumParams = array())
{
$this->_data = $data;
$this->_queryComponents = $queryComponents;
$this->_tableAliasMap = $tableAliasMap;
$this->_enumParams = $enumParams;
}
/**
* Defines the mapping components.
*
* @param array $queryComponents Query components.
*/
public function setQueryComponents(array $queryComponents)
{
$this->_queryComponents = $queryComponents;
}
/**
* Sets the declaration for given component alias.
*
* @param string $componentAlias The component alias to set the declaration to.
* @param string $queryComponent Alias declaration.
*/
public function setQueryComponent($componentAlias, array $queryComponent)
{
$this->_queryComponents[$componentAlias] = $queryComponent;
}
/**
* Gets the mapping components.
*
* @return array Query components.
*/
public function getQueryComponents()
{
return $this->_queryComponents;
}
/**
* Get the declaration for given component alias.
*
* @param string $componentAlias The component alias the retrieve the declaration from.
* @return array Alias declaration.
*/
public function getQueryComponent($componentAlias)
{
if ( ! array_key_exists($componentAlias, $this->_queryComponents)) {
throw new Doctrine_Query_Exception('Unknown query component ' . $componentAlias);
}
return $this->_queryComponents[$componentAlias];
}
/**
* Get the component alias for a given query component
*
* @param array $queryComponent The query component
* @param string Component alias
*/
public function getComponentAlias($queryComponent)
{
return array_search($queryComponent, $this->_queryComponents);;
}
/**
* Whether or not this object has a declaration for given component alias.
*
* @param string $componentAlias Component alias the retrieve the declaration from.
* @return boolean True if this object has given alias, otherwise false.
*/
public function hasQueryComponent($componentAlias)
{
return isset($this->_queryComponents[$componentAlias]);
}
/**
* Defines the table aliases.
*
* @param array $tableAliasMap Table aliases.
*/
public function setTableAliasMap(array $tableAliasMap)
{
$this->_tableAliasMap = $tableAliasMap;
}
/**
* Adds an SQL table alias and associates it a component alias
*
* @param string $tableAlias Table alias to be added.
* @param string $componentAlias Alias for the query component associated with given tableAlias.
*/
public function setTableAlias($tableAlias, $componentAlias)
{
$this->_tableAliasMap[$tableAlias] = $componentAlias;
}
/**
* Returns all table aliases.
*
* @return array Table aliases as an array.
*/
public function getTableAliasMap()
{
return $this->_tableAliasMap;
}
/**
* Get component alias associated with given table alias.
*
* @param string $tableAlias SQL table alias that identifies the component alias
* @return string Component alias
*/
public function getTableAlias($tableAlias)
{
if ( ! isset($this->_tableAliasMap[$tableAlias])) {
throw new Doctrine_Query_Exception('Unknown table alias ' . $tableAlias);
}
return $this->_tableAliasMap[$tableAlias];
}
/**
* Get table alias associated with given component alias.
*
* @param string $componentAlias Component alias that identifies the table alias
* @return string Component alias
*/
public function getTableAliasFromComponentAlias($componentAlias)
{
return array_search($componentAlias, $this->_tableAliasMap);
}
/**
* Whether or not this object has given tableAlias.
*
* @param string $tableAlias Table alias to be checked.
* @return boolean True if this object has given alias, otherwise false.
*/
public function hasTableAlias($tableAlias)
{
return (isset($this->_tableAliasMap[$tableAlias]));
}
/**
* Returns the enum parameters.
*
* @return mixed Enum parameters.
*/
public function getEnumParams()
{
return $this->_enumParams;
}
/**
* Sets input parameter as an enumerated parameter
*
* @param string $key The key of the input parameter
* @return Doctrine_Query_AbstractResult
*/
public function addEnumParam($key, $table = null, $column = null)
{
$array = (isset($table) || isset($column)) ? array($table, $column) : array();
if ($key === '?') {
$this->_enumParams[] = $array;
} else {
$this->_enumParams[$key] = $array;
}
return $this;
}
/**
* Returns this object in serialized format, revertable using fromCached*.
*
* @return string Serialized cached item.
*/
public function toCachedForm()
{
return serialize(array(
$this->_data,
$this->getQueryComponents(),
$this->getTableAliasMap(),
$this->getEnumParams()
));
}
}

View File

@ -1,152 +0,0 @@
<?php
/*
* $Id: Cache.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>.
*/
/**
* Doctrine_Query_CacheHandler
*
* @package Doctrine
* @subpackage Query
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1393 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*
* @todo Re-document this class
*/
abstract class Doctrine_Query_CacheHandler
{
/**
* Static factory method. Receives a Doctrine_Query object and generates
* the object after processing queryComponents. Table aliases are retrieved
* directly from Doctrine_Query_Parser.
*
* @param mixed $result Data to be stored.
* @param Doctrine_Query_ParserResult $parserResult Parser results that enables to have important data retrieved.
*/
public static function fromResultSet($result, $parserResult)
{
$queryComponents = array();
foreach ($parserResult->getQueryComponents() as $alias => $components) {
if ( ! isset($components['parent'])) {
$queryComponents[$alias][] = $components['mapper']->getComponentName();
//$queryComponents[$alias][] = $components['mapper']->getComponentName();
} else {
$queryComponents[$alias][] = $components['parent'] . '.' . $components['relation']->getAlias();
}
if (isset($components['agg'])) {
$queryComponents[$alias][] = $components['agg'];
}
if (isset($components['map'])) {
$queryComponents[$alias][] = $components['map'];
}
}
return new Doctrine_Query_QueryResult(
$result,
$queryComponents,
$parserResult->getTableAliasMap(),
$parserResult->getEnumParams()
);
}
/**
* Static factory method. Receives a Doctrine_Query object and a cached data.
* It handles the cache and generates the object after processing queryComponents.
* Table aliases are retrieved from cache.
*
* @param Doctrine_Query $query Doctrine_Query_Object related to this cache item.
* @param mixed $cached Cached data.
*/
public static function fromCachedResult($query, $cached = false)
{
$cached = unserialize($cached);
return new Doctrine_Query_QueryResult(
$cached[0],
self::_getQueryComponents($cached[1]),
$cached[2],
$cached[3]
);
}
/**
* Static factory method. Receives a Doctrine_Query object and a cached data.
* It handles the cache and generates the object after processing queryComponents.
* Table aliases are retrieved from cache.
*
* @param Doctrine_Query $query Doctrine_Query_Object related to this cache item.
* @param mixed $cached Cached data.
*/
public static function fromCachedQuery($query, $cached = false)
{
$cached = unserialize($cached);
return new Doctrine_Query_ParserResult(
$cached[0],
self::_getQueryComponents($cached[1]),
$cached[2],
$cached[3]
);
}
/**
* @nodoc
*/
protected static function _getQueryComponents($query, $cachedQueryComponents)
{
$queryComponents = array();
foreach ($cachedQueryComponents as $alias => $components) {
$e = explode('.', $components[0]);
if (count($e) === 1) {
$queryComponents[$alias]['mapper'] = $query->getConnection()->getMapper($e[0]);
$queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getTable();
} else {
$queryComponents[$alias]['parent'] = $e[0];
$queryComponents[$alias]['relation'] = $queryComponents[$e[0]]['table']->getAssociation($e[1]);
$queryComponents[$alias]['mapper'] = $query->getConnection()->getMapper($queryComponents[$alias]['relation']->getTargetEntityName());
$queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getTable();
}
if (isset($v[1])) {
$queryComponents[$alias]['agg'] = $components[1];
}
if (isset($v[2])) {
$queryComponents[$alias]['map'] = $components[2];
}
}
return $queryComponents;
}
}

View File

@ -1,39 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Doctrine_Query_Exception
*
* @package Doctrine
* @subpackage Query
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Query_Exception extends Doctrine_Exception
{
public static function nonUniqueResult()
{
return new self("The query contains more than one result.");
}
}

View File

@ -1,380 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* An LL(k) parser for the context-free grammar of Doctrine Query Language.
* Parses a DQL query, reports any errors in it, and generates the corresponding
* SQL.
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser
{
/**
* The minimum number of tokens read after last detected error before
* another error can be reported.
*
* @var int
*/
const MIN_ERROR_DISTANCE = 2;
/**
* The Sql Builder object.
*
* @var Doctrine_Query_SqlBuilder
*/
protected $_sqlbuilder;
/**
* DQL string.
*
* @var string
*/
protected $_input;
/**
* A scanner object.
*
* @var Doctrine_Query_Scanner
*/
protected $_scanner;
/**
* The Parser Result object.
*
* @var Doctrine_Query_ParserResult
*/
protected $_parserResult;
/**
* Keyword symbol table
*
* @var Doctrine_Query_Token
*/
protected $_keywordTable;
// Scanner Stuff
/**
* @var array The next token in the query string.
*/
public $lookahead;
/**
* @var array The last matched token.
*/
public $token;
// End of Scanner Stuff
// Error management stuff
/**
* Array containing errors detected in the query string during parsing process.
*
* @var array
*/
protected $_errors;
/**
* @var int The number of tokens read since last error in the input string.
*/
protected $_errorDistance;
/**
* The EntityManager.
*
* @var EnityManager
*/
protected $_em;
// End of Error management stuff
/**
* Creates a new query parser object.
*
* @param string $dql DQL to be parsed.
* @param Doctrine_Connection $connection The connection to use
*/
public function __construct(Doctrine_Query $query)
{
$this->_em = $query->getEntityManager();
$this->_input = $query->getDql();
$this->_scanner = new Doctrine_Query_Scanner($this->_input);
$this->_sqlBuilder = new Doctrine_Query_SqlBuilder($this->_em);
$this->_keywordTable = new Doctrine_Query_Token();
$this->_parserResult = new Doctrine_Query_ParserResult(
'',
array( // queryComponent
'dctrn' => array(
'metadata' => null,
'parent' => null,
'relation' => null,
'map' => null,
'scalar' => null,
),
),
array( // tableAliasMap
'dctrn' => 'dctrn',
)
);
$this->_parserResult->setEntityManager($this->_em);
$this->free(true);
}
/**
* Attempts to match the given token with the current lookahead token.
*
* If they match, updates the lookahead token; otherwise raises a syntax
* error.
*
* @param int|string token type or value
* @return bool True, if tokens match; false otherwise.
*/
public function match($token)
{
if (is_string($token)) {
$isMatch = ($this->lookahead['value'] === $token);
} else {
$isMatch = ($this->lookahead['type'] === $token);
}
if ( ! $isMatch) {
// No definition for value checking.
$this->syntaxError($this->_keywordTable->getLiteral($token));
}
$this->next();
return true;
}
/**
* Moves the parser scanner to next token
*
* @return void
*/
public function next()
{
$this->token = $this->lookahead;
$this->lookahead = $this->_scanner->next();
$this->_errorDistance++;
}
public function isA($value, $token)
{
return $this->_scanner->isA($value, $token);
}
/**
* Free this parser enabling it to be reused
*
* @param boolean $deep Whether to clean peek and reset errors
* @param integer $position Position to reset
* @return void
*/
public function free($deep = false, $position = 0)
{
// WARNING! Use this method with care. It resets the scanner!
$this->_scanner->resetPosition($position);
// Deep = true cleans peek and also any previously defined errors
if ($deep) {
$this->_scanner->resetPeek();
$this->_errors = array();
}
$this->token = null;
$this->lookahead = null;
$this->_errorDistance = self::MIN_ERROR_DISTANCE;
}
/**
* Parses a query string.
*/
public function parse()
{
$this->lookahead = $this->_scanner->next();
// Building the Abstract Syntax Tree
// We have to double the call of QueryLanguage to allow it to work correctly... =\
$DQL = new Doctrine_Query_Parser_QueryLanguage($this);
$AST = $DQL->parse('QueryLanguage', Doctrine_Query_ParserParamHolder::create());
// Check for end of string
if ($this->lookahead !== null) {
$this->syntaxError('end of string');
}
// Check for semantical errors
if (count($this->_errors) > 0) {
throw new Doctrine_Query_Parser_Exception(implode("\r\n", $this->_errors));
}
// Assign the executor in parser result
$this->_parserResult->setSqlExecutor(Doctrine_Query_SqlExecutor_Abstract::create($AST));
return $this->_parserResult;
}
/**
* Retrieves the assocated Doctrine_Query_SqlBuilder to this object.
*
* @return Doctrine_Query_SqlBuilder
*/
public function getSqlBuilder()
{
return $this->_sqlBuilder;
}
/**
* Returns the scanner object associated with this object.
*
* @return Doctrine_Query_Scanner
*/
public function getScanner()
{
return $this->_scanner;
}
/**
* Returns the parser result associated with this object.
*
* @return Doctrine_Query_ParserResult
*/
public function getParserResult()
{
return $this->_parserResult;
}
/**
* Generates a new syntax error.
*
* @param string $expected Optional expected string.
* @param array $token Optional token.
*/
public function syntaxError($expected = '', $token = null)
{
if ($token === null) {
$token = $this->lookahead;
}
// Formatting message
$message = 'line 0, col ' . (isset($token['position']) ? $token['position'] : '-1') . ': Error: ';
if ($expected !== '') {
$message .= "Expected '$expected', got ";
} else {
$message .= 'Unexpected ';
}
if ($this->lookahead === null) {
$message .= 'end of string.';
} else {
$message .= "'{$this->lookahead['value']}'";
}
throw new Doctrine_Query_Parser_Exception($message);
}
/**
* Generates a new semantical error.
*
* @param string $message Optional message.
* @param array $token Optional token.
*/
public function semanticalError($message = '', $token = null)
{
$this->_semanticalErrorCount++;
if ($token === null) {
$token = $this->token;
}
$this->_logError('Warning: ' . $message, $token);
}
/**
* Logs new error entry.
*
* @param string $message Message to log.
* @param array $token Token that it was processing.
*/
protected function _logError($message = '', $token)
{
if ($this->_errorDistance >= self::MIN_ERROR_DISTANCE) {
$message = 'line 0, col ' . $token['position'] . ': ' . $message;
$this->_errors[] = $message;
}
$this->_errorDistance = 0;
}
/**
* Gets the EntityManager used by the parser.
*
* @return EntityManager
*/
public function getEntityManager()
{
return $this->_em;
}
/**
* Retrieve the piece of DQL string given the token position
*
* @param array $token Token that it was processing.
* @return string Piece of DQL string.
*/
public function getQueryPiece($token, $previousChars = 10, $nextChars = 10)
{
$start = max(0, $token['position'] - $previousChars);
$end = max($token['position'] + $nextChars, strlen($this->_input));
return substr($this->_input, $start, $end);
}
}

View File

@ -1,69 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* AbstractSchemaName ::= identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_AbstractSchemaName extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// AbstractSchemaName ::= identifier
$this->_AST = $this->AST('AbstractSchemaName');
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_AST->setComponentName($this->_parser->token['value']);
}
public function semantical($paramHolder)
{
$componentName = $this->_AST->getComponentName();
// Check if we are dealing with a real Doctrine_Entity or not
if ( ! $this->_isDoctrineEntity($componentName)) {
$this->_parser->semanticalError(
"Defined entity '" . $companyName . "' is not a valid Doctrine_Entity."
);
}
// Return AST node
return $this->_AST;
}
protected function _isDoctrineEntity($componentName)
{
return class_exists($componentName) && is_subclass_of($componentName, 'Doctrine_ORM_Entity');
}
}

View File

@ -1,66 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* AliasIdentificationVariable = identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_AliasIdentificationVariable extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// AliasIdentificationVariable = identifier
$this->_AST = $this->AST('AliasIdentificationVariable');
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_AST->setComponentAlias($this->_parser->token['value']);
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
if ($parserResult->hasQueryComponent($this->_AST->getComponentAlias())) {
// We should throw semantical error if there's already a component for this alias
$queryComponent = $parserResult->getQueryComponent($this->_AST->getComponentAlias());
$componentName = $queryComponent['metadata']->getClassName();
$message = "Cannot re-declare component alias '" . $this->_AST->getComponentAlias() . "'. "
. "It was already declared for component '" . $componentName . "'.";
$this->_parser->semanticalError($message);
}
return $this->_AST;
}
}

View File

@ -1,53 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* DeleteStatement ::= DeleteClause [WhereClause]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_DeleteStatement extends Doctrine_Query_Parser
{
protected $_AST = null;
public function syntax($paramHolder)
{
// DeleteStatement ::= DeleteClause [WhereClause]
$this->_AST = $this->AST('DeleteStatement');
$this->_AST->setDeleteClause($this->parse('DeleteClause', $paramHolder));
if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) {
$this->_AST->setWhereClause($this->parse('WhereClause', $paramHolder));
}
// Return AST node
return $this->_AST;
}
}

View File

@ -1,35 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Doctrine_Query_Parser_Exception
*
* @package Doctrine
* @subpackage Query
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
class Doctrine_Query_Parser_Exception extends Doctrine_Exception
{
}

View File

@ -1,61 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* FieldIdentificationVariable ::= identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_FieldIdentificationVariable extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// FieldIdentificationVariable ::= identifier
$this->_AST = $this->AST('FieldIdentificationVariable');
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_AST->setFieldName($this->_parser->token['value']);
// Return AST node
return $this->_AST;
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
// [TODO] Check for field existance somewhere
// Return AST node
return $this->_AST;
}
}

View File

@ -1,61 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* FromClause ::= "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
class Doctrine_Query_Parser_FromClause extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// FromClause ::= "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration}
$this->_AST = $this->AST('FromClause');
$this->_parser->match(Doctrine_Query_Token::T_FROM);
$this->_AST->addIdentificationVariableDeclaration(
$this->parse('IdentificationVariableDeclaration', $paramHolder)
);
while ($this->_isNextToken(',')) {
$this->_parser->match(',');
$this->_AST->addIdentificationVariableDeclaration(
$this->parse('IdentificationVariableDeclaration', $paramHolder)
);
}
// Return AST node
return $this->_AST;
}
}

View File

@ -1,64 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* IdentificationVariable ::= identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_IdentificationVariable extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// IdentificationVariable ::= identifier
$this->_AST = $this->AST('IdentificationVariable');
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_AST->setComponentAlias($this->_parser->token['value']);
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
if ( ! $parserResult->hasQueryComponent($this->_AST->getComponentAlias())) {
// We should throw semantical error if we cannot find the component alias
$message = "No entity related to declared alias '" . $this->_AST->getComponentAlias()
. "' near '" . $this->_parser->getQueryPiece($this->_parser->token) . "'.";
$this->_parser->semanticalError($message);
}
// Return AST node
return $this->_AST;
}
}

View File

@ -1,68 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* IdentificationVariableDeclaration ::= RangeVariableDeclaration [IndexBy] {JoinVariableDeclaration}*
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
class Doctrine_Query_Parser_IdentificationVariableDeclaration extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// IdentificationVariableDeclaration ::= RangeVariableDeclaration [IndexBy] {JoinVariableDeclaration}*
$this->_AST = $this->AST('IdentificationVariableDeclaration');
$this->_AST->setRangeVariableDeclaration($this->parse('RangeVariableDeclaration', $paramHolder));
if ($this->_isNextToken(Doctrine_Query_Token::T_INDEX)) {
$paramHolder->set(
'componentAlias',
$this->_AST->getRangeVariableDeclaration()->getAliasIdentificationVariable()->getComponentAlias()
);
$this->_AST->setIndexBy($this->parse('IndexBy', $paramHolder));
$paramHolder->remove('componentAlias');
}
while (
$this->_isNextToken(Doctrine_Query_Token::T_LEFT) ||
$this->_isNextToken(Doctrine_Query_Token::T_INNER) ||
$this->_isNextToken(Doctrine_Query_Token::T_JOIN)
) {
$this->_AST->addJoinVariableDeclaration($this->parse('JoinVariableDeclaration', $paramHolder));
}
// Return AST node
return $this->_AST;
}
}

View File

@ -1,106 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* IndexBy ::= "INDEX" "BY" SimpleStateFieldPathExpression
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_IndexBy extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// IndexBy ::= "INDEX" "BY" SimpleStateFieldPathExpression
$this->_AST = $this->AST('IndexBy');
$this->_parser->match(Doctrine_Query_Token::T_INDEX);
$this->_parser->match(Doctrine_Query_Token::T_BY);
$this->_AST->setSimpleStateFieldPathExpression($this->parse('SimpleStateFieldPathExpression', $paramHolder));
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
$componentAlias = $this->_AST->getSimpleStateFieldPathExpression()
->getIdentificationVariable()->getComponentAlias();
$componentFieldName = $this->_AST->getSimpleStateFieldPathExpression()
->getSimpleStateField()->getFieldName();
// Check if we have same component being used in index
if ($componentAlias !== $paramHolder->get('componentAlias')) {
$message = "Invalid alising. Cannot index by '" . $paramHolder->get('componentAlias')
. "' inside '" . $componentAlias . "' scope.";
$this->_parser->semanticalError($message);
}
// Retrieving required information
try {
$queryComponent = $parserResult->getQueryComponent($componentAlias);
$classMetadata = $queryComponent['metadata'];
} catch (Doctrine_Exception $e) {
$this->_parser->semanticalError($e->getMessage());
return;
}
// The INDEXBY field must be either the (primary && not part of composite pk) || (unique && notnull)
$columnMapping = $classMetadata->getFieldMapping($componentFieldName);
if (
! $classMetadata->isIdentifier($componentFieldName) &&
! $classMetadata->isUniqueField($componentFieldName) &&
! $classMetadata->isNotNull($componentFieldName)
) {
$this->_parser->semanticalError(
"Field '" . $componentFieldName . "' of component '" . $classMetadata->getClassName() .
"' must be unique and notnull to be used as index.",
$this->_parser->token
);
}
if ($classMetadata->isIdentifier($componentFieldName) && $classMetadata->isIdentifierComposite()) {
$this->_parser->semanticalError(
"Field '" . $componentFieldName . "' of component '" . $classMetadata->getClassName() .
"' must be primary and not part of a composite primary key to be used as index.",
$this->_parser->token
);
}
$queryComponent['map'] = $componentFieldName;
$parserResult->setQueryComponent($componentAlias, $queryComponent);
// Return AST node
return $this->_AST;
}
}

View File

@ -1,57 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* QueryLanguage ::= SelectStatement | UpdateStatement | DeleteStatement
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_QueryLanguage extends Doctrine_Query_ParserRule
{
public function syntax($paramHolder)
{
// QueryLanguage ::= SelectStatement | UpdateStatement | DeleteStatement
switch ($this->_parser->lookahead['type']) {
case Doctrine_Query_Token::T_SELECT:
return $this->parse('SelectStatement', $paramHolder);
break;
case Doctrine_Query_Token::T_UPDATE:
return $this->parse('UpdateStatement', $paramHolder);
break;
case Doctrine_Query_Token::T_DELETE:
return $this->parse('DeleteStatement', $paramHolder);
break;
default:
$this->_parser->syntaxError('SELECT, UPDATE or DELETE');
break;
}
}
}

View File

@ -1,98 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* RangeVariableDeclaration ::= AbstractSchemaName ["AS"] AliasIdentificationVariable
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
class Doctrine_Query_Parser_RangeVariableDeclaration extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// RangeVariableDeclaration ::= AbstractSchemaName ["AS"] AliasIdentificationVariable
$this->_AST = $this->AST('RangeVariableDeclaration');
$this->_AST->setAbstractSchemaName($this->parse('AbstractSchemaName', $paramHolder));
if ($this->_isNextToken(Doctrine_Query_Token::T_AS)) {
$this->_parser->match(Doctrine_Query_Token::T_AS);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_IDENTIFIER)) {
$this->_AST->setAliasIdentificationVariable($this->parse('AliasIdentificationVariable', $paramHolder));
}
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
$componentName = $this->_AST->getAbstractSchemaName()->getComponentName();
$componentAlias = $this->_AST->getAliasIdentificationVariable()->getComponentAlias();
// Check if we already have a component defined without an alias
if ($componentAlias === null && $parserResult->hasQueryComponent($componentName)) {
$this->_parser->semanticalError(
"Cannot re-declare component '{$componentName}'. Please assign an alias to it."
);
// Define new queryComponent since it does not exist yet
} else {
// Retrieving ClassMetadata and Mapper
try {
$classMetadata = $this->_em->getClassMetadata($componentName);
// Building queryComponent
$queryComponent = array(
'metadata' => $classMetadata,
'parent' => null,
'relation' => null,
'map' => null,
'scalar' => null,
);
} catch (Doctrine_Exception $e) {
$this->_parser->semanticalError($e->getMessage());
}
// Inspect for possible non-aliasing
if ($componentAlias === null) {
$componentAlias = $componentName;
}
$tableAlias = $parserResult->generateTableAlias($classMetadata->getClassName());
$parserResult->setQueryComponent($componentAlias, $queryComponent);
$parserResult->setTableAlias($tableAlias, $componentAlias);
}
// Return AST node
return $this->_AST;
}
}

View File

@ -1,76 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SelectClause ::= "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_SelectClause extends Doctrine_Query_ParserRule
{
protected $_AST = null;
protected $_selectExpressions = array();
public function syntax($paramHolder)
{
// SelectClause ::= "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression}
$this->_AST = $this->AST('SelectClause');
$this->_parser->match(Doctrine_Query_Token::T_SELECT);
// Inspecting if we are in a DISTINCT query
if ($this->_isNextToken(Doctrine_Query_Token::T_DISTINCT)) {
$this->_parser->match(Doctrine_Query_Token::T_DISTINCT);
$this->_AST->setIsDistinct(true);
}
// Process SelectExpressions (1..N)
$this->_selectExpressions[] = $this->parse('SelectExpression', $paramHolder);
while ($this->_isNextToken(',')) {
$this->_parser->match(',');
$this->_selectExpressions[] = $this->parse('SelectExpression', $paramHolder);
}
}
public function semantical($paramHolder)
{
// We need to validate each SelectExpression
for ($i = 0, $l = count($this->_selectExpressions); $i < $l; $i++) {
$this->_AST->addSelectExpression($this->_selectExpressions[$i]->semantical($paramHolder));
}
// Return AST node
return $this->_AST;
}
}

View File

@ -1,82 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SelectExpression ::= IdentificationVariable ["." "*"] |
* (StateFieldPathExpression | AggregateExpression | "(" Subselect ")" )
* [["AS"] FieldIdentificationVariable]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
class Doctrine_Query_Parser_SelectExpression extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// SelectExpression ::= IdentificationVariable ["." "*"] |
// (StateFieldPathExpression | AggregateExpression | "(" Subselect ")" )
// [["AS"] FieldIdentificationVariable]
// First we recognize for an IdentificationVariable (Component alias)
if ($this->_isIdentificationVariable()) {
$identificationVariable = $this->parse('IdentificationVariable', $paramHolder);
// Inspecting if we are in a ["." "*"]
if ($this->_isNextToken('.')) {
$this->_parser->match('.');
$this->_parser->match('*');
}
return $identificationVariable;
}
}
protected function _isIdentificationVariable()
{
// Retrying to recoginize this grammar: IdentificationVariable ["." "*"]
$token = $this->_parser->lookahead;
$this->_parser->getScanner()->resetPeek();
// We have an identifier here
if ($token['type'] === Doctrine_Query_Token::T_IDENTIFIER) {
$token = $this->_parser->getScanner()->peek();
// If we have a dot ".", then next char must be the "*"
if ($token['value'] === '.') {
$token = $this->_parser->getScanner()->peek();
return $token['value'] === '*';
}
}
return false;
}
}

View File

@ -1,83 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SelectStatement ::= SelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_SelectStatement extends Doctrine_Query_ParserRule
{
protected $_AST = null;
protected $_selectClause = null;
public function syntax($paramHolder)
{
// SelectStatement ::= SelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
$this->_AST = $this->AST('SelectStatement');
// Disable the semantical check for SelectClause now. This is needed
// since we dont know the query components yet (will be known only
// when the FROM and WHERE clause are processed).
$paramHolder->set('semanticalCheck', false);
$this->_selectClause = $this->parse('SelectClause', $paramHolder);
$paramHolder->remove('semanticalCheck');
$this->_AST->setFromClause($this->parse('FromClause', $paramHolder));
if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) {
$this->_AST->setWhereClause($this->parse('WhereClause', $paramHolder));
}
if ($this->_isNextToken(Doctrine_Query_Token::T_GROUP)) {
$this->_AST->setGroupByClause($this->parse('GroupByClause', $paramHolder));
}
if ($this->_isNextToken(Doctrine_Query_Token::T_HAVING)) {
$this->_AST->setHavingClause($this->parse('HavingClause', $paramHolder));
}
if ($this->_isNextToken(Doctrine_Query_Token::T_ORDER)) {
$this->_AST->setOrderByClause($this->parse('OrderByClause', $paramHolder));
}
}
public function semantical($paramHolder)
{
// We need to invoke the semantical check of SelectClause here, since
// it was not yet checked.
// The semantical checks will be forwarded to all SelectClause dependant grammar rules
$this->_AST->setSelectClause($this->_selectClause->semantical($paramHolder));
// Return AST node
return $this->_AST;
}
}

View File

@ -1,44 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SimpleStateField ::= FieldIdentificationVariable
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_SimpleStateField extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// SimpleStateField ::= FieldIdentificationVariable
return $this->parse('FieldIdentificationVariable', $paramHolder);
}
}

View File

@ -1,79 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SimpleStateFieldPathExpression ::= IdentificationVariable "." SimpleStateField
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_SimpleStateFieldPathExpression extends Doctrine_Query_ParserRule
{
protected $_AST = null;
public function syntax($paramHolder)
{
// SimpleStateFieldPathExpression ::= IdentificationVariable "." SimpleStateField
$this->_AST = $this->AST('SimpleStateFieldPathExpression');
$this->_AST->setIdentificationVariable($this->parse('IdentificationVariable', $paramHolder));
$this->_parser->match('.');
$this->_AST->setSimpleStateField($this->parse('SimpleStateField', $paramHolder));
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
$componentAlias = $this->_AST->getIdentificationVariable()->getComponentAlias();
$componentFieldName = $this->_AST->getSimpleStateField()->getFieldName();
// We need to make sure field exists
try {
$queryComponent = $parserResult->getQueryComponent($componentAlias);
$classMetadata = $queryComponent['metadata'];
} catch (Doctrine_Exception $e) {
$this->_parser->semanticalError($e->getMessage());
return;
}
if ($classMetadata instanceof Doctrine_ClassMetadata && ! $classMetadata->hasField($componentFieldName)) {
$this->_parser->semanticalError(
"Cannot use key mapping. Field '" . $componentFieldName . "' " .
"does not exist in component '" . $classMetadata->getClassName() . "'.",
$this->_parser->token
);
}
// Return AST node
return $this->_AST;
}
}

View File

@ -1,53 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* UpdateStatement ::= UpdateClause [WhereClause]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser_UpdateStatement extends Doctrine_Query_Parser
{
protected $_AST = null;
public function syntax($paramHolder)
{
// UpdateStatement ::= UpdateClause [WhereClause]
$this->_AST = $this->AST('UpdateStatement');
$this->_AST->setUpdateClause($this->parse('UpdateClause', $paramHolder));
if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) {
$this->_AST->setWhereClause($this->parse('WhereClause', $paramHolder));
}
// Return AST node
return $this->_AST;
}
}

View File

@ -1,89 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Production variables holder
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_ParserParamHolder
{
protected static $_instance;
protected $_data;
protected function __construct()
{
$this->free();
}
public static function create()
{
if ( ! isset(self::$_instance)) {
self::$_instance = new self;
}
return self::$_instance;
}
public function free()
{
$this->_data = array();
}
public function set($offset, $value)
{
$this->_data[$offset] = $value;
}
public function get($offset)
{
return isset($this->_data[$offset]) ? $this->_data[$offset] : null;
}
public function has($offset)
{
return isset($this->_data[$offset]);
}
public function remove($offset)
{
if ($this->has($offset)) {
$this->_data[$offset] = null;
unset($this->_data[$offset]);
}
}
}

View File

@ -1,188 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Doctrine_Query_ParserResult
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_ParserResult extends Doctrine_Query_AbstractResult
{
/**
* The EntityManager.
*
* @var Doctrine_EntityManager
*/
protected $_em;
/**
* A simple array keys representing table aliases and values table alias
* seeds. The seeds are used for generating short table aliases.
*
* @var array $_tableAliasSeeds
*/
protected $_tableAliasSeeds = array();
/**
* Simple array of keys representing the fields used in query.
*
* @var array $_queryFields
*/
protected $_queryFields = array();
/**
* Sets the Entity Manager.
*
* @param Doctrine_EntityManager $em The Entity Manager.
*/
public function setEntityManager($em)
{
$this->_em = $em;
}
/**
* Gets the Entity Manager.
*
* @return Doctrine_EntityManager
*/
public function getEntityManager()
{
return $this->_em;
}
/**
* @nodoc
*/
public function setSqlExecutor(Doctrine_Query_SqlExecutor_Abstract $executor)
{
$this->_data = $executor;
}
/**
* @nodoc
*/
public function getSqlExecutor()
{
return $this->_data;
}
/**
* Defines the mapping fields.
*
* @param array $queryFields Query fields.
*/
public function setQueryFields(array $queryFields)
{
$this->_queryFields = $queryFields;
}
/**
* Sets the declaration for given field alias.
*
* @param string $fieldAlias The field alias to set the declaration to.
* @param string $queryField Alias declaration.
*/
public function setQueryField($fieldAlias, $queryField)
{
$this->_queryFields[$fieldAlias] = $queryField;
}
/**
* Gets the mapping fields.
*
* @return array Query fields.
*/
public function getQueryFields()
{
return $this->_queryFields;
}
/**
* Get the declaration for given field alias.
*
* @param string $fieldAlias The field alias the retrieve the declaration from.
* @return array Alias declaration.
*/
public function getQueryField($fieldAlias)
{
if ( ! isset($this->_queryFields[$fieldAlias])) {
throw new Doctrine_Query_Exception('Unknown query field ' . $fieldAlias);
}
return $this->_queryFields[$fieldAlias];
}
/**
* Whether or not this object has a declaration for given field alias.
*
* @param string $fieldAlias Field alias the retrieve the declaration from.
* @return boolean True if this object has given alias, otherwise false.
*/
public function hasQueryField($fieldAlias)
{
return isset($this->_queryFields[$fieldAlias]);
}
/**
* Generates a table alias from given table name and associates
* it with given component alias
*
* @param string $componentName Component name to be associated with generated table alias
* @return string Generated table alias
*/
public function generateTableAlias($componentName)
{
$baseAlias = strtolower(preg_replace('/[^A-Z]/', '\\1', $componentName));
// We may have a situation where we have all chars are lowercased
if ( $baseAlias == '' ) {
// We simply grab the first 2 chars of component name
$baseAlias = substr($componentNam, 0, 2);
}
$alias = $baseAlias;
if ( ! isset($this->_tableAliasSeeds[$baseAlias])) {
$this->_tableAliasSeeds[$baseAlias] = 1;
} else {
$alias .= $this->_tableAliasSeeds[$baseAlias]++;
}
return $alias;
}
}

View File

@ -1,75 +0,0 @@
<?php
/**
* This class is just an intermediate implementation for refactoring purposes
* and will be replaced by the ParserResult class of the new DQL parser branch.
*
*/
class Doctrine_Query_ParserResultDummy
{
private $_isMixedQuery;
private $_dbStatement;
private $_isIdentityQuery;
private $_hydrationMode;
private $_tableToClassAliasMap;
private $_queryComponents;
public function isMixedQuery()
{
return $this->_isMixedQuery;
}
public function isIdentityQuery()
{
return $this->_isIdentityQuery;
}
public function setMixedQuery($bool)
{
$this->_isMixedQuery = (bool) $bool;
}
public function getDatabaseStatement()
{
return $this->_dbStatement;
}
public function setDatabaseStatement($stmt)
{
$this->_dbStatement = $stmt;
}
public function getHydrationMode()
{
return $this->_hydrationMode;
}
public function setHydrationMode($hydrationMode)
{
$this->_hydrationMode = $hydrationMode;
}
public function getTableToClassAliasMap()
{
return $this->_tableToClassAliasMap;
}
public function setTableToClassAliasMap(array $map)
{
$this->_tableToClassAliasMap = $map;
}
public function setQueryComponents(array $queryComponents)
{
$this->_queryComponents = $queryComponents;
}
public function getQueryComponents()
{
return $this->_queryComponents;
}
}
?>

View File

@ -1,204 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* An abstract base class for the productions of the Doctrine Query Language
* context-free grammar.
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
abstract class Doctrine_Query_ParserRule
{
/**
* @nodoc
*/
const SQLALIAS_SEPARATOR = '__';
/**
* @nodoc
*/
const DEFAULT_QUERYCOMPONENT = 'dctrn';
/**
* Parser object
*
* @var Doctrine_Query_Parser
*/
protected $_parser;
/**
* The EntityManager.
*
* @var EntityManager
*/
protected $_em;
/**
* Creates a new production object.
*
* @param Doctrine_Query_Parser $parser a parser object
*/
public function __construct(Doctrine_Query_Parser $parser)
{
$this->_parser = $parser;
$this->_em = $this->_parser->getEntityManager();
}
protected function _isNextToken($token)
{
$la = $this->_parser->lookahead;
return ($la['type'] === $token || $la['value'] === $token);
}
protected function _isFunction()
{
$la = $this->_parser->lookahead;
$next = $this->_parser->getScanner()->peek();
return ($la['type'] === Doctrine_Query_Token::T_IDENTIFIER && $next['value'] === '(');
}
protected function _isSubselect()
{
$la = $this->_parser->lookahead;
$next = $this->_parser->getScanner()->peek();
return ($la['value'] === '(' && $next['type'] === Doctrine_Query_Token::T_SELECT);
}
/**
* Executes the grammar rule using the specified parameters.
*
* @param string $RuleName BNF Grammar Rule name
* @param array $paramHolder Production parameter holder
* @return Doctrine_Query_ParserRule
*/
public function parse($RuleName, $paramHolder)
{
$BNFGrammarRule = $this->_getGrammarRule($RuleName);
//echo "Processing class: " . get_class($BNFGrammarRule) . "...\n";
//echo "Params: " . var_export($paramHolder, true) . "\n";
// Syntax check
if ( ! $paramHolder->has('syntaxCheck') || $paramHolder->get('syntaxCheck') === true) {
//echo "Processing syntax checks of " . $RuleName . "...\n";
$return = $BNFGrammarRule->syntax($paramHolder);
if ($return !== null) {
//echo "Returning Gramma Rule class: " . (is_object($return) ? get_class($return) : $return) . "...\n";
return $return;
}
}
// Semantical check
if ( ! $paramHolder->has('semanticalCheck') || $paramHolder->get('semanticalCheck') === true) {
//echo "Processing semantical checks of " . $RuleName . "...\n";
$return = $BNFGrammarRule->semantical($paramHolder);
if ($return !== null) {
//echo "Returning Gramma Rule class: " . (is_object($return) ? get_class($return) : $return) . "...\n";
return $return;
}
}
return $BNFGrammarRule;
}
/**
* Returns a grammar rule object with the given name.
*
* @param string $name grammar rule name
* @return Doctrine_Query_ParserRule
*/
protected function _getGrammarRule($name)
{
$class = 'Doctrine_Query_Parser_' . $name;
//echo $class . "\r\n";
//TODO: This expensive check is not necessary. Should be removed at the end.
// "new $class" will throw an error anyway if the class is not found.
if ( ! class_exists($class)) {
throw new Doctrine_Query_Parser_Exception(
"Unknown Grammar Rule '$name'. Could not find related compiler class."
);
}
return new $class($this->_parser);
}
/**
* Creates an AST node with the given name.
*
* @param string $AstName AST node name
* @return Doctrine_Query_AST
*/
public function AST($AstName)
{
$class = 'Doctrine_Query_AST_' . $AstName;
//echo $class . "\r\n";
if ( ! class_exists($class)) {
throw new Doctrine_Query_Parser_Exception(
"Unknown AST node '" . $AstName . "'. Could not find related compiler class."
);
}
return new $class($this->_parser->getParserResult());
}
/**
* @nodoc
*/
abstract public function syntax($paramHolder);
/**
* @nodoc
*/
public function semantical($paramHolder)
{
}
public function getParser()
{
return $this->_parser;
}
}

View File

@ -1,95 +0,0 @@
<?php
/*
* $Id$
*
* 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 parse tree printer for Doctrine Query Language parser.
*
* @package Doctrine
* @subpackage Query
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Printer
{
/**
* Current indentation level
*
* @var int
*/
protected $_indent = 0;
/**
* Defines whether parse tree is printed (default, false) or not (true).
*
* @var bool
*/
protected $_silent;
/**
* Constructs a new parse tree printer.
*
* @param bool $silent Parse tree will not be printed if true.
*/
public function __construct($silent = false)
{
$this->_silent = $silent;
}
/**
* Prints an opening parenthesis followed by production name and increases
* indentation level by one.
*
* This method is called before executing a production.
*
* @param string $name production name
*/
public function startProduction($name)
{
$this->println('(' . $name);
$this->_indent++;
}
/**
* Decreases indentation level by one and prints a closing parenthesis.
*
* This method is called after executing a production.
*/
public function endProduction()
{
$this->_indent--;
$this->println(')');
}
/**
* Prints text indented with spaces depending on current indentation level.
*
* @param string $str text
*/
public function println($str)
{
if ( ! $this->_silent) {
echo str_repeat(' ', $this->_indent), $str, "\n";
}
}
}

View File

@ -1,118 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* AggregateExpression = ("AVG" | "MAX" | "MIN" | "SUM" | "COUNT") "(" ["DISTINCT"] Expression ")"
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_AggregateExpression extends Doctrine_Query_Production
{
protected $_functionName;
protected $_isDistinct;
protected $_expression;
public function syntax($paramHolder)
{
// AggregateExpression = ("AVG" | "MAX" | "MIN" | "SUM" | "COUNT") "(" ["DISTINCT"] Expression ")"
$this->_isDistinct = false;
$token = $this->_parser->lookahead;
switch ($token['type']) {
case Doctrine_Query_Token::T_AVG:
case Doctrine_Query_Token::T_MAX:
case Doctrine_Query_Token::T_MIN:
case Doctrine_Query_Token::T_SUM:
case Doctrine_Query_Token::T_COUNT:
$this->_parser->match($token['type']);
$this->_functionName = strtoupper($token['value']);
break;
default:
$this->_parser->logError('AVG, MAX, MIN, SUM or COUNT');
break;
}
$this->_parser->match('(');
if ($this->_isNextToken(Doctrine_Query_Token::T_DISTINCT)) {
$this->_parser->match(Doctrine_Query_Token::T_DISTINCT);
$this->_isDistinct = true;
}
$this->_expression = $this->AST('Expression', $paramHolder);
$this->_parser->match(')');
}
public function semantical($paramHolder)
{
$this->_expression->semantical($paramHolder);
}
public function buildSql()
{
return $this->_functionName
. '(' . (($this->_isDistinct) ? 'DISTINCT ' : '')
. $this->_expression->buildSql()
. ')';
}
/**
* Visitor support.
*
* @param object $visitor
*/
public function accept($visitor)
{
$this->_expression->accept($visitor);
$visitor->visitAggregateExpression($this);
}
/* Getters */
public function getExpression()
{
return $this->_expression;
}
public function getFunctionName()
{
return $this->_functionName;
}
public function isDistinct()
{
return $this->_isDistinct;
}
}

View File

@ -1,119 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Atom = string | integer | float | input_parameter
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
class Doctrine_Query_Production_Atom extends Doctrine_Query_Production
{
protected $_type;
protected $_value;
public function syntax($paramHolder)
{
// Atom = string | integer | float | input_parameter
switch ($this->_parser->lookahead['type']) {
case Doctrine_Query_Token::T_STRING:
$this->_parser->match(Doctrine_Query_Token::T_STRING);
$this->_type = 'string';
break;
case Doctrine_Query_Token::T_INTEGER:
$this->_parser->match(Doctrine_Query_Token::T_INTEGER);
$this->_type = 'integer';
break;
case Doctrine_Query_Token::T_FLOAT:
$this->_parser->match(Doctrine_Query_Token::T_FLOAT);
$this->_type = 'float';
break;
case Doctrine_Query_Token::T_INPUT_PARAMETER:
$this->_parser->match(Doctrine_Query_Token::T_INPUT_PARAMETER);
$this->_type = 'param';
break;
default:
$this->_parser->syntaxError('string, number or parameter (? or :)');
break;
}
$this->_value = $this->_parser->token['value'];
}
public function buildSql()
{
$conn = $this->_em->getConnection();
switch ($this->_type) {
case 'param':
return $this->_value;
case 'string':
//FIXME: Remove the quotes from _value! Should the scanner do that or where?
// 'mystring' => mystring. Otherwise 'mystring' is the content (with quotes)!
// Eg: select ... from ... where f.foo = 'bar'
// => $conn->quote('bar',...), CURRENTLY: $conn->quote("'bar'",...)
// This fix looks a bit ugly or ... ? Should this happen earlier? Syntax?
// Scanner?
if (strpos($this->_value, "'") === 0) {
$this->_value = substr($this->_value, 1, strlen($this->_value) - 2);
}
return $conn->quote($this->_value, $this->_type);
default:
return $conn->quote($this->_value, $this->_type);
}
}
/**
* Visitor support.
*
* @param object $visitor
*/
public function accept($visitor)
{
$visitor->visitAtom($this);
}
/* Getters */
public function getType()
{
return $this->_type;
}
public function getValue()
{
return $this->_value;
}
}

View File

@ -1,87 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* BetweenExpression = ["NOT"] "BETWEEN" Expression "AND" Expression
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_BetweenExpression extends Doctrine_Query_Production
{
protected $_not;
protected $_fromExpression;
protected $_toExpression;
public function syntax($paramHolder)
{
// BetweenExpression = ["NOT"] "BETWEEN" Expression "AND" Expression
$this->_not = false;
if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) {
$this->_parser->match(Doctrine_Query_Token::T_NOT);
$this->_not = true;
}
$this->_parser->match(Doctrine_Query_Token::T_BETWEEN);
$this->_fromExpression = $this->AST('Expression', $paramHolder);
$this->_parser->match(Doctrine_Query_Token::T_AND);
$this->_toExpression = $this->AST('Expression', $paramHolder);
}
public function buildSql()
{
return (($this->_not) ? 'NOT ' : '') . 'BETWEEN '
. $this->_fromExpression->buildSql() . ' AND ' . $this->_toExpression->buildSql();
}
/* Getters */
public function isNot()
{
return $this->_not;
}
public function getFromExpression()
{
return $this->_fromExpression;
}
public function getToExpression()
{
return $this->_toExpression;
}
}

View File

@ -1,94 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* ComparisonExpression = ComparisonOperator ( QuantifiedExpression | Expression | "(" Subselect ")" )
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_ComparisonExpression extends Doctrine_Query_Production
{
protected $_operator;
protected $_expression;
protected $_isSubselect;
public function syntax($paramHolder)
{
// ComparisonExpression = ComparisonOperator ( QuantifiedExpression | Expression | "(" Subselect ")" )
$this->_operator = $this->AST('ComparisonOperator', $paramHolder);
if (($this->_isSubselect = $this->_isSubselect()) === true) {
$this->_parser->match('(');
$this->_expression = $this->AST('Subselect', $paramHolder);
$this->_parser->match(')');
$this->_isSubselect = true;
} else {
switch ($this->_parser->lookahead['type']) {
case Doctrine_Query_Token::T_ALL:
case Doctrine_Query_Token::T_ANY:
case Doctrine_Query_Token::T_SOME:
$this->_expression = $this->AST('QuantifiedExpression', $paramHolder);
break;
default:
$this->_expression = $this->AST('Expression', $paramHolder);
break;
}
}
}
public function buildSql()
{
return $this->_operator . ' ' . (($this->_isSubselect) ?
'(' . $this->_expression->buildSql() . ')' : $this->_expression->buildSql()
);
}
/* Getters */
public function getOperator()
{
return $this->_operator;
}
public function getExpression()
{
return $this->_expression;
}
public function isSubselect()
{
return $this->_isSubselect;
}
}

View File

@ -1,82 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* ComparisonOperator = "=" | "<" | "<=" | "<>" | ">" | ">=" | "!="
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_ComparisonOperator extends Doctrine_Query_Production
{
public function syntax($paramHolder)
{
switch ($this->_parser->lookahead['value']) {
case '=':
$this->_parser->match('=');
return '=';
break;
case '<':
$this->_parser->match('<');
$operator = '<';
if ($this->_isNextToken('=')) {
$this->_parser->match('=');
$operator .= '=';
} elseif ($this->_isNextToken('>')) {
$this->_parser->match('>');
$operator .= '>';
}
return $operator;
break;
case '>':
$this->_parser->match('>');
$operator = '>';
if ($this->_isNextToken('=')) {
$this->_parser->match('=');
$operator .= '=';
}
return $operator;
break;
case '!':
$this->_parser->match('!');
$this->_parser->match('=');
return '<>';
break;
default:
$this->_parser->syntaxError('=, <, <=, <>, >, >=, !=');
break;
}
}
}

View File

@ -1,79 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* ConditionalExpression = ConditionalTerm {"OR" ConditionalTerm}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_ConditionalExpression extends Doctrine_Query_Production
{
protected $_conditionalTerms = array();
public function syntax($paramHolder)
{
// ConditionalExpression = ConditionalTerm {"OR" ConditionalTerm}
$this->_conditionalTerms[] = $this->AST('ConditionalTerm', $paramHolder);
while ($this->_isNextToken(Doctrine_Query_Token::T_OR)) {
$this->_parser->match(Doctrine_Query_Token::T_OR);
$this->_conditionalTerms[] = $this->AST('ConditionalTerm', $paramHolder);
}
// Optimize depth instances in AST
if (count($this->_conditionalTerms) == 1) {
return $this->_conditionalTerms[0];
}
}
public function buildSql()
{
return implode(' OR ', $this->_mapConditionalTerms());
}
protected function _mapConditionalTerms()
{
return array_map(array(&$this, '_mapConditionalTerm'), $this->_conditionalTerms);
}
protected function _mapConditionalTerm($value)
{
return $value->buildSql();
}
/* Getters */
public function getConditionalTerms()
{
return $this->_conditionalTerms;
}
}

View File

@ -1,70 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* ConditionalFactor = ["NOT"] ConditionalPrimary
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_ConditionalFactor extends Doctrine_Query_Production
{
protected $_conditionalPrimary;
public function syntax($paramHolder)
{
// ConditionalFactor = ["NOT"] ConditionalPrimary
$notFactor = false;
if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) {
$this->_parser->match(Doctrine_Query_Token::T_NOT);
$notFactor = true;
}
$this->_conditionalPrimary = $this->AST('ConditionalPrimary', $paramHolder);
// Optimize depth instances in AST
if ( ! $notFactor) {
return $this->_conditionalPrimary;
}
}
public function buildSql()
{
// Do not need to check $notFactor. It'll be always present if we have this instance.
return 'NOT ' . $this->_conditionalPrimary->buildSql();
}
/* Getters */
public function getConditionalPrimary()
{
return $this->_conditionalPrimary;
}
}

View File

@ -1,108 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* ConditionalPrimary = SimpleConditionalExpression | "(" ConditionalExpression ")"
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_ConditionalPrimary extends Doctrine_Query_Production
{
protected $_conditionalExpression;
public function syntax($paramHolder)
{
// ConditionalPrimary = SimpleConditionalExpression | "(" ConditionalExpression ")"
if ( ! $this->_isConditionalExpression()) {
return $this->AST('SimpleConditionalExpression', $paramHolder);
}
$this->_parser->match('(');
$this->_conditionalExpression = $this->AST('ConditionalExpression', $paramHolder);
$this->_parser->match(')');
}
public function buildSql()
{
return '(' . $this->_conditionalExpression->buildSql() . ')';
}
protected function _isConditionalExpression()
{
$token = $this->_parser->lookahead;
$parenthesis = 0;
if ($token['value'] === '(') {
$parenthesis++;
}
while ($parenthesis > 0) {
$token = $this->_parser->getScanner()->peek();
if ($token['value'] === '(') {
$parenthesis++;
} elseif ($token['value'] === ')') {
$parenthesis--;
} else {
switch ($token['type']) {
case Doctrine_Query_Token::T_NOT:
case Doctrine_Query_Token::T_AND:
case Doctrine_Query_Token::T_OR:
case Doctrine_Query_Token::T_BETWEEN:
case Doctrine_Query_Token::T_LIKE:
case Doctrine_Query_Token::T_IN:
case Doctrine_Query_Token::T_IS:
case Doctrine_Query_Token::T_EXISTS:
return true;
case Doctrine_Query_Token::T_NONE:
switch ($token['value']) {
case '=':
case '<':
case '>':
case '!':
return true;
}
break;
}
}
}
return false;
}
/* Getters */
public function getConditionalExpression()
{
return $this->_conditionalExpression;
}
}

View File

@ -1,79 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* ConditionalTerm = ConditionalFactor {"AND" ConditionalFactor}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_ConditionalTerm extends Doctrine_Query_Production
{
protected $_conditionalFactors = array();
public function syntax($paramHolder)
{
// ConditionalTerm = ConditionalFactor {"AND" ConditionalFactor}
$this->_conditionalFactors[] = $this->AST('ConditionalFactor', $paramHolder);
while ($this->_isNextToken(Doctrine_Query_Token::T_AND)) {
$this->_parser->match(Doctrine_Query_Token::T_AND);
$this->_conditionalFactors[] = $this->AST('ConditionalFactor', $paramHolder);
}
// Optimize depth instances in AST
if (count($this->_conditionalFactors) == 1) {
return $this->_conditionalFactors[0];
}
}
public function buildSql()
{
return implode(' AND ', $this->_mapConditionalFactors());
}
protected function _mapConditionalFactors()
{
return array_map(array(&$this, '_mapConditionalFactor'), $this->_conditionalFactors);
}
protected function _mapConditionalFactor($value)
{
return $value->buildSql();
}
/* Getters */
public function getConditionalFactors()
{
return $this->_conditionalFactors;
}
}

View File

@ -1,73 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* DeleteClause = "DELETE" ["FROM"] VariableDeclaration
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_DeleteClause extends Doctrine_Query_Production
{
protected $_variableDeclaration;
public function syntax($paramHolder)
{
// DeleteClause = "DELETE" ["FROM"] VariableDeclaration
$this->_parser->match(Doctrine_Query_Token::T_DELETE);
if ($this->_isNextToken(Doctrine_Query_Token::T_FROM)) {
$this->_parser->match(Doctrine_Query_Token::T_FROM);
}
$this->_variableDeclaration = $this->AST('VariableDeclaration', $paramHolder);
}
public function buildSql()
{
return 'DELETE FROM ' . $this->_variableDeclaration->buildSql();
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$this->_variableDeclaration->accept($visitor);
$visitor->visitDeleteClause($this);
}
/* Getters */
public function getVariableDeclaration()
{
return $this->_variableDeclaration;
}
}

View File

@ -1,85 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* DeleteStatement = DeleteClause [WhereClause]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_DeleteStatement extends Doctrine_Query_Production
{
protected $_deleteClause;
protected $_whereClause;
public function syntax($paramHolder)
{
// DeleteStatement = DeleteClause [WhereClause]
$this->_deleteClause = $this->AST('DeleteClause', $paramHolder);
if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) {
$this->_whereClause = $this->AST('WhereClause', $paramHolder);
}
}
public function buildSql()
{
// The 1=1 is needed to workaround the affected_rows in MySQL.
// Simple "DELETE FROM table_name" gives 0 affected rows.
return $this->_deleteClause->buildSql() . (($this->_whereClause !== null)
? ' ' . $this->_whereClause->buildSql() : ' WHERE 1 = 1');
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$this->_deleteClause->accept($visitor);
if ($this->_whereClause) {
$this->_whereClause->accept($visitor);
}
$visitor->visitDeleteStatement($this);
}
/* Getters */
public function getDeleteClause()
{
return $this->_deleteClause;
}
public function getWhereClause()
{
return $this->_whereClause;
}
}

View File

@ -1,61 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* ExistsExpression = "EXISTS" "(" Subselect ")"
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_ExistsExpression extends Doctrine_Query_Production
{
protected $_subselect;
public function syntax($paramHolder)
{
// ExistsExpression = "EXISTS" "(" Subselect ")"
$this->_parser->match(Doctrine_Query_Token::T_EXISTS);
$this->_parser->match('(');
$this->_subselect = $this->AST('Subselect', $paramHolder);
$this->_parser->match(')');
}
public function buildSql()
{
return 'EXISTS (' . $this->_subselect->buildSql() . ')';
}
/* Getters */
public function getSubselect()
{
return $this->_subselect;
}
}

View File

@ -1,96 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Expression = Term {("+" | "-") Term}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_Expression extends Doctrine_Query_Production
{
protected $_terms = array();
public function syntax($paramHolder)
{
// Expression = Term {("+" | "-") Term}
$this->_terms[] = $this->AST('Term', $paramHolder);
while ($this->_isNextToken('+') || $this->_isNextToken('-')) {
if ($this->_isNextToken('+')) {
$this->_parser->match('+');
$this->_terms[] = '+';
} else{
$this->_parser->match('-');
$this->_terms[] = '-';
}
$this->_terms[] = $this->AST('Term', $paramHolder);
}
// Optimize depth instances in AST
if (count($this->_terms) == 1) {
return $this->_terms[0];
}
}
public function semantical($paramHolder)
{
for ($i = 0, $l = count($this->_terms); $i < $l; $i++) {
if ($this->_terms[$i] != '+' && $this->_terms[$i] != '-') {
$this->_terms[$i]->semantical($paramHolder);
}
}
}
public function buildSql()
{
return implode(' ', $this->_mapTerms());
}
protected function _mapTerms()
{
return array_map(array(&$this, '_mapTerm'), $this->_terms);
}
protected function _mapTerm($value)
{
return (is_string($value) ? $value : $value->buildSql());
}
/* Getters */
public function getTerms()
{
return $this->_terms;
}
}

View File

@ -1,94 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Factor = [("+" | "-")] Primary
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_Factor extends Doctrine_Query_Production
{
protected $_type;
protected $_primary;
public function syntax($paramHolder)
{
// Factor = [("+" | "-")] Primary
if ($this->_isNextToken('+')) {
$this->_parser->match('+');
$this->_type = '+';
} elseif ($this->_isNextToken('-')) {
$this->_parser->match('-');
$this->_type = '-';
}
$this->_primary = $this->AST('Primary', $paramHolder);
// Optimize depth instances in AST
if ($this->_type === null) {
return $this->_primary;
}
}
public function semantical($paramHolder)
{
$this->_primary->semantical($paramHolder);
}
public function buildSql()
{
return $this->_type . ' ' . $this->_primary->buildSql();
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$this->_primary->accept($visitor);
$visitor->visitFactor($this);
}
/* Getters */
public function getType()
{
return $this->_type;
}
public function getPrimary()
{
return $this->_primary;
}
}

View File

@ -1,91 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* FieldIdentificationVariable = identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_FieldIdentificationVariable extends Doctrine_Query_Production
{
protected $_fieldAlias;
protected $_columnAlias;
public function syntax($paramHolder)
{
// FieldIdentificationVariable = identifier
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_fieldAlias = $this->_parser->token['value'];
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
if ($parserResult->hasQueryField($this->_fieldAlias)) {
// We should throw semantical error if there's already a component for this alias
$fieldName = $parserResult->getQueryField($this->_fieldAlias);
$message = "Cannot re-declare field alias '{$this->_fieldAlias}'"
. "for '".$paramHolder->get('fieldName')."'.";
$this->_parser->semanticalError($message);
}
// Now we map it in queryComponent
$componentAlias = Doctrine_Query_Production::DEFAULT_QUERYCOMPONENT;
$queryComponent = $parserResult->getQueryComponent($componentAlias);
$idx = count($queryComponent['scalar']);
$queryComponent['scalar'][$idx] = $this->_fieldAlias;
$parserResult->setQueryComponent($componentAlias, $queryComponent);
// And also in field aliases
$parserResult->setQueryField($queryComponent['scalar'][$idx], $idx);
// Build the column alias
$this->_columnAlias = $parserResult->getTableAliasFromComponentAlias($componentAlias)
. Doctrine_Query_Production::SQLALIAS_SEPARATOR . $idx;
}
/* Getters */
public function getFieldAlias()
{
return $this->_fieldAlias;
}
public function getColumnAlias()
{
return $this->_columnAlias;
}
}

View File

@ -1,81 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* FromClause = "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_FromClause extends Doctrine_Query_Production
{
protected $_identificationVariableDeclaration = array();
public function syntax($paramHolder)
{
// FromClause = "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration}
$this->_parser->match(Doctrine_Query_Token::T_FROM);
$this->_identificationVariableDeclaration[] = $this->AST('IdentificationVariableDeclaration', $paramHolder);
while ($this->_isNextToken(',')) {
$this->_parser->match(',');
$this->_identificationVariableDeclaration[] = $this->AST('IdentificationVariableDeclaration', $paramHolder);
}
}
public function buildSql()
{
//echo "FromClause:\n";
//for ($i = 0; $i < count($this->_identificationVariableDeclaration);$i++) {
// echo (($this->_identificationVariableDeclaration[$i] instanceof IdentificationVariableDeclaration) ? get_class($this->_identificationVariableDeclaration[$i]) : get_class($this->_identificationVariableDeclaration[$i])) . "\n";
//}
return 'FROM ' . implode(', ', $this->_mapIdentificationVariableDeclarations());
}
protected function _mapIdentificationVariableDeclarations()
{
return array_map(array(&$this, '_mapIdentificationVariableDeclaration'), $this->_identificationVariableDeclaration);
}
protected function _mapIdentificationVariableDeclaration($value)
{
return $value->buildSql();
}
/* Getters */
public function getIdentificationVariableDeclarations()
{
return $this->_identificationVariableDeclaration;
}
}

View File

@ -1,104 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Function = identifier "(" [Expression {"," Expression}] ")"
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_Function extends Doctrine_Query_Production
{
protected $_functionName;
protected $_arguments = array();
public function syntax($paramHolder)
{
// Function = identifier "(" [Expression {"," Expression}] ")"
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_functionName = $this->_parser->token['value'];
$this->_parser->match('(');
if ( ! $this->_isNextToken(')')) {
$this->_arguments[] = $this->AST('Expression', $paramHolder);
while ($this->_isNextToken(',')) {
$this->_parser->match(',');
$this->_arguments[] = $this->AST('Expression', $paramHolder);
}
}
$this->_parser->match(')');
}
public function buildSql()
{
return $this->_functionName . '(' . implode(', ', $this->_mapArguments()) . ')';
}
protected function _mapArguments()
{
return array_map(array(&$this, '_mapArgument'), $this->_arguments);
}
protected function _mapArgument($value)
{
return $value->buildSql();
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
foreach ($this->_arguments as $argument) {
$argument->accept($visitor);
}
$visitor->visitFunction($this);
}
/* Getters */
public function getFunctionName()
{
return $this->_functionName;
}
public function getArguments()
{
return $this->_arguments;
}
}

View File

@ -1,89 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* GroupByClause = "GROUP" "BY" GroupByItem {"," GroupByItem}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_GroupByClause extends Doctrine_Query_Production
{
protected $_groupByItems = array();
public function syntax($paramHolder)
{
$this->_parser->match(Doctrine_Query_Token::T_GROUP);
$this->_parser->match(Doctrine_Query_Token::T_BY);
$this->_groupByItems[] = $this->AST('GroupByItem', $paramHolder);
while ($this->_isNextToken(',')) {
$this->_parser->match(',');
$this->_groupByItems[] = $this->AST('GroupByItem', $paramHolder);
}
}
public function buildSql()
{
return 'GROUP BY ' . implode(', ', $this->_mapGroupByItems());
}
protected function _mapGroupByItems()
{
return array_map(array(&$this, '_mapGroupByItem'), $this->_groupByItems);
}
protected function _mapGroupByItem($value)
{
return $value->buildSql();
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
foreach ($this->_groupByItems as $item) {
$item->accept($visitor);
}
$visitor->visitGroupByClause($this);
}
/* Getters */
public function getGroupByItems()
{
return $this->_groupByItems;
}
}

View File

@ -1,50 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* OrderByItem = PathExpression
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_GroupByItem extends Doctrine_Query_Production
{
public function syntax($paramHolder)
{
return $this->AST('PathExpression', $paramHolder);
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$visitor->visitGroupByItem($this);
}
}

View File

@ -1,70 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* HavingClause = "HAVING" ConditionalExpression
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_HavingClause extends Doctrine_Query_Production
{
protected $_conditionalExpression;
public function syntax($paramHolder)
{
// HavingClause = "HAVING" ConditionalExpression
$this->_parser->match(Doctrine_Query_Token::T_HAVING);
$this->_conditionalExpression = $this->AST('ConditionalExpression', $paramHolder);
}
public function buildSql()
{
return 'HAVING ' . $this->_conditionalExpression->buildSql();
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$this->_conditionalExpression->accept($visitor);
$visitor->visitHavingClause($this);
}
/* Getters */
public function getConditionalExpression()
{
return $this->_conditionalExpression;
}
}

View File

@ -1,65 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* IdentificationVariable = identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_IdentificationVariable extends Doctrine_Query_Production
{
protected $_componentAlias;
public function syntax($paramHolder)
{
// IdentificationVariable = identifier
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_componentAlias = $this->_parser->token['value'];
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
if ($parserResult->hasQueryComponent($this->_componentAlias)) {
// We should throw semantical error if there's already a component for this alias
$queryComponent = $parserResult->getQueryComponent($this->_componentAlias);
$componentName = $queryComponent['metadata']->getClassName();
$message = "Cannot re-declare component alias '{$this->_componentAlias}'"
. "for '".$paramHolder->get('componentName')."'. It was already declared for "
. "component '{$componentName}'.";
$this->_parser->semanticalError($message);
}
return $this->_componentAlias;
}
}

View File

@ -1,92 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* IdentificationVariableDeclaration = RangeVariableDeclaration [IndexBy] {JoinVariableDeclaration}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_IdentificationVariableDeclaration extends Doctrine_Query_Production
{
protected $_rangeVariableDeclaration;
protected $_indexBy;
protected $_joinVariableDeclarations = array();
public function syntax($paramHolder)
{
$this->_rangeVariableDeclaration = $this->AST('RangeVariableDeclaration', $paramHolder);
if ($this->_isNextToken(Doctrine_Query_Token::T_INDEX)) {
$paramHolder->set('componentAlias', $this->_rangeVariableDeclaration->getIdentificationVariable());
$this->_indexBy = $this->AST('IndexBy', $paramHolder);
$paramHolder->remove('componentAlias');
}
while (
$this->_isNextToken(Doctrine_Query_Token::T_LEFT) ||
$this->_isNextToken(Doctrine_Query_Token::T_INNER) ||
$this->_isNextToken(Doctrine_Query_Token::T_JOIN)
) {
$this->_joinVariableDeclarations[] = $this->AST('JoinVariableDeclaration', $paramHolder);
}
}
public function buildSql()
{
$str = $this->_rangeVariableDeclaration->buildSql();
for ($i = 0, $l = count($this->_joinVariableDeclarations); $i < $l; $i++) {
$str .= ' ' . $this->_joinVariableDeclarations[$i]->buildSql();
}
return $str;
}
/* Getters */
public function getRangeVariableDeclaration()
{
return $this->_rangeVariableDeclaration;
}
public function getIndexBy()
{
return $this->_indexBy;
}
public function getJoinVariableDeclarations()
{
return $this->_joinVariableDeclarations;
}
}

View File

@ -1,109 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* InExpression = ["NOT"] "IN" "(" (Atom {"," Atom} | Subselect) ")"
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_InExpression extends Doctrine_Query_Production
{
protected $_not;
protected $_subselect;
protected $_atoms = array();
public function syntax($paramHolder)
{
// InExpression = ["NOT"] "IN" "(" (Atom {"," Atom} | Subselect) ")"
$this->_not = false;
if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) {
$this->_parser->match(Doctrine_Query_Token::T_NOT);
$this->_not = true;
}
$this->_parser->match(Doctrine_Query_Token::T_IN);
$this->_parser->match('(');
if ($this->_isNextToken(Doctrine_Query_Token::T_SELECT)) {
$this->_subselect = $this->AST('Subselect', $paramHolder);
} else {
$this->_atoms[] = $this->AST('Atom', $paramHolder);
while ($this->_isNextToken(',')) {
$this->_parser->match(',');
$this->_atoms[] = $this->AST('Atom', $paramHolder);
}
}
$this->_parser->match(')');
}
public function buildSql()
{
return (($this->_not) ? 'NOT ' : '') . 'IN ('
. (($this->_subselect !== null) ? $this->_subselect->buildSql() : implode(', ', $this->_mapAtoms()))
. ')';
}
protected function _mapAtoms()
{
return array_map(array(&$this, '_mapAtom'), $this->_atoms);
}
protected function _mapAtom($value)
{
return $value->buildSql();
}
/* Getters */
public function isNot()
{
return $this->_not;
}
public function getSubselect()
{
return $this->_subselect;
}
public function getAtoms()
{
return $this->_atoms;
}
}

View File

@ -1,121 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* IndexBy = "INDEX" "BY" identifier
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_IndexBy extends Doctrine_Query_Production
{
protected $_componentAlias;
protected $_fieldName;
public function syntax($paramHolder)
{
$this->_componentAlias = $paramHolder->get('componentAlias');
$this->_parser->match(Doctrine_Query_Token::T_INDEX);
$this->_parser->match(Doctrine_Query_Token::T_BY);
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_fieldName = $this->_parser->token['value'];
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
//echo "Component alias: " . $this->_componentAlias . "\n";
//echo "Has query component: " . ($parserResult->hasQueryComponent($this->_componentAlias) ? "TRUE" : "FALSE") . "\n";
//$qc = $parserResult->getQueryComponents();
//$qc = array_keys($qc);
//echo "Query Components: " . var_export($qc, true) . "\n";
try {
$queryComponent = $parserResult->getQueryComponent($this->_componentAlias);
$classMetadata = $queryComponent['metadata'];
} catch (Doctrine_Exception $e) {
$this->_parser->semanticalError($e->getMessage());
return;
}
if ($classMetadata instanceof Doctrine_ClassMetadata && ! $classMetadata->hasField($this->_fieldName)) {
$this->_parser->semanticalError(
"Cannot use key mapping. Field '" . $this->_fieldName . "' " .
"does not exist in component '" . $classMetadata->getClassName() . "'.",
$this->_parser->token
);
}
// The INDEXBY field must be either the (primary && not part of composite pk) || (unique && notnull)
$columnMapping = $classMetadata->getFieldMapping($this->_fieldName);
if ( ! $classMetadata->isIdentifier($this->_fieldName) && ! $classMetadata->isUniqueField($this->_fieldName) && ! $classMetadata->isNotNull($this->_fieldName)) {
$this->_parser->semanticalError(
"Field '" . $this->_fieldName . "' of component '" . $classMetadata->getClassName() .
"' must be unique and notnull to be used as index.",
$this->_parser->token
);
}
if ($classMetadata->isIdentifier($this->_fieldName) && $classMetadata->isIdentifierComposite()) {
$this->_parser->semanticalError(
"Field '" . $this->_fieldName . "' of component '" . $classMetadata->getClassName() .
"' must be primary and not part of a composite primary key to be used as index.",
$this->_parser->token
);
}
$queryComponent['map'] = $this->_fieldName;
$parserResult->setQueryComponent($this->_componentAlias, $queryComponent);
}
public function buildSql()
{
return '';
}
/* Getters */
public function getComponentAlias()
{
return $this->_componentAlias;
}
public function getFieldName()
{
return $this->_fieldName;
}
}

View File

@ -1,162 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Join = ["LEFT" | "INNER"] "JOIN" RangeVariableDeclaration [("ON" | "WITH") ConditionalExpression]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_Join extends Doctrine_Query_Production
{
protected $_joinType;
protected $_rangeVariableDeclaration;
protected $_whereType;
protected $_conditionalExpression;
public function syntax($paramHolder)
{
$this->_joinType = 'INNER';
$this->_whereType = 'WITH';
if ($this->_isNextToken(Doctrine_Query_Token::T_LEFT)) {
$this->_parser->match(Doctrine_Query_Token::T_LEFT);
$this->_joinType = 'LEFT';
} else if ($this->_isNextToken(Doctrine_Query_Token::T_INNER)) {
$this->_parser->match(Doctrine_Query_Token::T_INNER);
}
$this->_parser->match(Doctrine_Query_Token::T_JOIN);
$this->_rangeVariableDeclaration = $this->AST('RangeVariableDeclaration', $paramHolder);
if ($this->_isNextToken(Doctrine_Query_Token::T_ON)) {
$this->_parser->match(Doctrine_Query_Token::T_ON);
$this->_whereType = 'ON';
$this->_conditionalExpression = $this->AST('ConditionalExpression', $paramHolder);
} else if ($this->_isNextToken(Doctrine_Query_Token::T_WITH)) {
$this->_parser->match(Doctrine_Query_Token::T_WITH);
$this->_conditionalExpression = $this->AST('ConditionalExpression', $paramHolder);
}
}
public function buildSql()
{
$parserResult = $this->_parser->getParserResult();
// Get the connection for the component
$conn = $this->_em->getConnection();
$sql = $this->_joinType . ' JOIN ' . $this->_rangeVariableDeclaration->buildSql();
$conditionExpression = isset($this->_conditionExpression)
? $this->_conditionExpression->buildSql() : '';
if ($this->_whereType == 'ON') {
return $sql . ' ON ' . $conditionExpression;
}
// We need to build the join conditions. Retrieving AssociationMapping
$queryComponent = $this->_rangeVariableDeclaration->getQueryComponent();
$association = $queryComponent['relation'];
$joinColumns = array();
if ($association->isOneToMany() || $association->isOneToOne()) {
if ($association->isInverseSide()) {
// joinColumns are found on the other (owning) side
$targetClass = $this->_em->getClassMetadata($association->getTargetEntityName());
$joinColumns = $targetClass->getAssociationMapping($association->getMappedByFieldName())
->getTargetToSourceKeyColumns();
} else {
$joinColumns = $association->getSourceToTargetKeyColumns();
}
} else {
//TODO: many-many
}
$relationConditionExpression = '';
// We have an array('localColumn' => 'foreignColumn', ...) here
foreach ($joinColumns as $localColumn => $foreignColumn) {
// leftExpression = rightExpression
// Defining leftExpression
$leftExpression = $conn->quoteIdentifier(
$parserResult->getTableAliasFromComponentAlias($queryComponent['parent']) . '.' . $localColumn
);
// Defining rightExpression
$rightExpression = $conn->quoteIdentifier(
$parserResult->getTableAliasFromComponentAlias(
$this->_rangeVariableDeclaration->getIdentificationVariable()
) . '.' . $foreignColumn
);
// Building the relation
$relationConditionExpression .= (($relationConditionExpression != '') ? ' AND ' : '')
. $leftExpression . ' = ' . $rightExpression;
}
$sql .= ' ON ' . $relationConditionExpression;
$sql .= empty($conditionExpression) ? '' : ' AND (' . $conditionExpression . ')';
return $sql;
}
/* Getters */
public function getJoinType()
{
return $this->_joinType;
}
public function getRangeVariableDeclaration()
{
return $this->_rangeVariableDeclaration;
}
public function getWhereType()
{
return $this->_whereType;
}
public function getConditionalExpression()
{
return $this->_conditionalExpression;
}
}

View File

@ -1,70 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* JoinVariableDeclaration = Join [IndexBy]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_JoinVariableDeclaration extends Doctrine_Query_Production
{
protected $_join;
protected $_indexBy;
public function syntax($paramHolder)
{
$this->_join = $this->AST('Join', $paramHolder);
if ($this->_isNextToken(Doctrine_Query_Token::T_INDEX)) {
$paramHolder->set('componentAlias', $this->_join->getRangeVariableDeclaration()->getIdentificationVariable());
$this->_indexBy = $this->AST('IndexBy', $paramHolder);
$paramHolder->remove('componentAlias');
}
}
public function buildSql()
{
return $this->_join->buildSql() . (isset($this->_indexby) ? $this->_indexby->buildSql() . ' ' : '');
}
/* Getters */
public function getJoin()
{
return $this->_join;
}
public function getIndexBy()
{
return $this->_indexBy;
}
}

View File

@ -1,91 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* LikeExpression = ["NOT"] "LIKE" Expression ["ESCAPE" string]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_LikeExpression extends Doctrine_Query_Production
{
protected $_not;
protected $_expression;
protected $_escapeString;
public function syntax($paramHolder)
{
// LikeExpression = ["NOT"] "LIKE" Expression ["ESCAPE" string]
$this->_escapeString = null;
$this->_not = false;
if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) {
$this->_parser->match(Doctrine_Query_Token::T_NOT);
$this->_not = true;
}
$this->_parser->match(Doctrine_Query_Token::T_LIKE);
$this->_expression = $this->AST('Expression', $paramHolder);
if ($this->_isNextToken(Doctrine_Query_Token::T_ESCAPE)) {
$this->_parser->match(Doctrine_Query_Token::T_ESCAPE);
$this->_parser->match(Doctrine_Query_Token::T_STRING);
$this->_escapeString = $this->_parser->token['value'];
}
}
public function buildSql()
{
return (($this->_not) ? 'NOT ' : '') . 'LIKE ' . $this->_expression->buildSql()
. (($this->_escapeString !== null) ? ' ESCAPE ' . $this->_escapeString : '');
}
/* Getters */
public function isNot()
{
return $this->_not;
}
public function getExpression()
{
return $this->_expression;
}
public function getEscapeString()
{
return $this->_escapeString;
}
}

View File

@ -1,65 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* LimitClause = "LIMIT" integer
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_LimitClause extends Doctrine_Query_Production
{
protected $_limit;
public function execute(array $params = array())
{
$this->_parser->match(Doctrine_Query_Token::T_LIMIT);
$this->_parser->match(Doctrine_Query_Token::T_INTEGER);
$this->_limit = $this->_parser->token['value'];
return $this;
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$visitor->visitLimitClause($this);
}
/* Getters */
public function getLimit()
{
return $this->_limit;
}
}

View File

@ -1,65 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* NullComparisonExpression = "IS" ["NOT"] "NULL"
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_NullComparisonExpression extends Doctrine_Query_Production
{
protected $_not;
public function syntax($paramHolder)
{
$this->_not = false;
$this->_parser->match(Doctrine_Query_Token::T_IS);
if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) {
$this->_parser->match(Doctrine_Query_Token::T_NOT);
$this->_not = true;
}
$this->_parser->match(Doctrine_Query_Token::T_NULL);
}
public function buildSql()
{
return 'IS ' . (($this->_not) ? 'NOT ' : '') . 'NULL';
}
/* Getters */
public function isNot()
{
return $this->_not;
}
}

View File

@ -1,74 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* OffsetClause = "OFFSET" integer
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_OffsetClause extends Doctrine_Query_Production
{
protected $_offset;
public function execute(array $params = array())
{
$this->_parser->match(Doctrine_Query_Token::T_OFFSET);
$this->_parser->match(Doctrine_Query_Token::T_INTEGER);
$this->_offset = $this->_parser->token['value'];
return $this;
}
public function buildSql()
{
// [TODO] How to deal with different DBMS here?
// The responsability to apply the limit-subquery is from
// SelectStatement, not this object's one.
return ' OFFSET ' . $this->_offset;
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$visitor->visitOffsetClause($this);
}
/* Getters */
public function getOffset()
{
return $this->_offset;
}
}

View File

@ -1,88 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* OrderByClause = "ORDER" "BY" OrderByItem {"," OrderByItem}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_OrderByClause extends Doctrine_Query_Production
{
protected $_orderByItems = array();
public function syntax($paramHolder)
{
$this->_parser->match(Doctrine_Query_Token::T_ORDER);
$this->_parser->match(Doctrine_Query_Token::T_BY);
$this->_orderByItems[] = $this->AST('OrderByItem', $paramHolder);
while ($this->_isNextToken(',')) {
$this->_parser->match(',');
$this->_orderByItems[] = $this->AST('OrderByItem', $paramHolder);
}
}
public function buildSql()
{
$str = 'ORDER BY ';
for ($i = 0, $l = count($this->_orderByItems); $i < $l; $i++) {
if ($i != 0) {
$str .= ', ';
}
$str .= ( $this->_orderByItems[$i] instanceof Doctrine_Query_Production ) ?
$this->_orderByItems[$i]->buildSql() : $this->_orderByItems[$i];
}
return $str;
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
foreach ($this->_orderByItems as $item) {
$item->accept($visitor);
}
$visitor->visitOrderByClause($this);
}
/* Getters */
public function getOrderByItems()
{
return $this->_orderByItems;
}
}

View File

@ -1,82 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* OrderByItem = Expression ["ASC" | "DESC"]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_OrderByItem extends Doctrine_Query_Production
{
protected $_expression;
protected $_orderType;
public function syntax($paramHolder)
{
$this->_expression = $this->AST('Expression', $paramHolder);
$this->_orderType = 'ASC';
if ($this->_isNextToken(Doctrine_Query_Token::T_ASC)) {
$this->_parser->match(Doctrine_Query_Token::T_ASC);
} elseif ($this->_isNextToken(Doctrine_Query_Token::T_DESC)) {
$this->_parser->match(Doctrine_Query_Token::T_DESC);
$this->_orderType = 'DESC';
}
}
public function buildSql()
{
return $this->_expression->buildSql() . ' ' . $this->_orderType;
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$this->_expression->accept($visitor);
$visitor->visitOrderByItem($this);
}
/* Getters */
public function getExpression()
{
return $this->_expression;
}
public function getOrderType()
{
return $this->_orderType;
}
}

View File

@ -1,171 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* PathExpression = identifier { "." identifier }
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_PathExpression extends Doctrine_Query_Production
{
protected $_identifiers = array();
protected $_fieldName;
protected $_componentAlias;
public function syntax($paramHolder)
{
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_identifiers[] = $this->_parser->token['value'];
while ($this->_isNextToken('.')) {
$this->_parser->match('.');
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_identifiers[] = $this->_parser->token['value'];
}
$this->_fieldName = array_pop($this->_identifiers);
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
$classMetadata = null;
if (($l = count($this->_identifiers)) == 0) {
// No metadata selection until now. We might need to deal with:
// DELETE FROM Obj alias WHERE field = X
$queryComponents = $parserResult->getQueryComponents();
// Check if we have more than one queryComponent defined
if (count($queryComponents) != 2) {
$this->_parser->semanticalError("Undefined component alias for field '{$this->_fieldName}'", $this->_parser->token);
}
// Retrieve ClassMetadata
$k = array_keys($queryComponents);
$this->_componentAlias = $k[1];
$classMetadata = $queryComponents[$this->_componentAlias]['metadata'];
} else {
$this->_componentAlias = $path = $this->_identifiers[0];
$queryComponent = $parserResult->getQueryComponent($path);
// We should have a semantical error if the queryComponent does not exists yet
if ($queryComponent === null) {
$this->_parser->semanticalError("Undefined component alias for '{$path}'", $this->_parser->token);
}
// Initializing ClassMetadata
$classMetadata = $queryComponent['metadata'];
// Looping through relations
for ($i = 1; $i < $l; $i++) {
$relationName = $this->_identifiers[$i];
$path .= '.' . $relationName;
if ( ! $classMetadata->hasAssociation($relationName)) {
$className = $classMetadata->getClassName();
$this->_parser->semanticalError(
"Relation '{$relationName}' does not exist in component '{$className}' when trying to get the path '{$path}'",
$this->_parser->token
);
}
// We inspect for queryComponent of relations, since we are using them
if ( ! $parserResult->hasQueryComponent($path)) {
$this->_parser->semanticalError("Cannot use the path '{$path}' without defining it in FROM.", $this->_parser->token);
}
// Assigning new componentAlias, queryComponent and classMetadata
$this->_componentAlias = $path;
$queryComponent = $parserResult->getQueryComponent($path);
$classMetadata = $queryComponent['metadata'];
}
}
// Now we inspect for field existance
if ( ! $classMetadata->hasField($this->_fieldName)) {
$className = $classMetadata->getClassName();
$this->_parser->semanticalError("Field '{$this->_fieldName}' does not exist in component '{$className}'", $this->_parser->token);
}
}
public function buildSql()
{
// Basic handy variables
$parserResult = $this->_parser->getParserResult();
// Retrieving connection
$conn = $this->_em->getConnection();
// Looking for queryComponent to fetch
$queryComponent = $parserResult->getQueryComponent($this->_componentAlias);
// Generating the SQL piece
$str = $parserResult->getTableAliasFromComponentAlias($this->_componentAlias) . '.'
. $queryComponent['metadata']->getColumnName($this->_fieldName);
return $conn->quoteIdentifier($str);
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$visitor->visitPathExpression($this);
}
/* Getters */
public function getIdentifiers()
{
return $this->_identifiers;
}
public function getFieldName()
{
return $this->_fieldName;
}
public function getComponentAlias()
{
return $this->_componentAlias;
}
}

View File

@ -1,169 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* PathExpressionEndingWithAsterisk = {identifier "."} "*"
*
* @package Doctrine
* @subpackage Query
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_PathExpressionEndingWithAsterisk extends Doctrine_Query_Production
{
protected $_identifiers = array();
protected $_queryComponent;
public function syntax($paramHolder)
{
// PathExpressionEndingWithAsterisk = {identifier "."} "*"
while ($this->_isNextToken(Doctrine_Query_Token::T_IDENTIFIER)) {
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_identifiers[] = $this->_parser->token['value'];
$this->_parser->match('.');
}
$this->_parser->match('*');
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
if (($l = count($this->_identifiers)) > 0) {
// We are dealing with component{.component}.*
$path = $this->_identifiers[0];
$this->_queryComponent = $parserResult->getQueryComponent($path);
// We should have a semantical error if the queryComponent does not exists yet
if ($this->_queryComponent === null) {
$this->_parser->semanticalError("Undefined component alias for '{$path}'", $this->_parser->token);
}
// Initializing ClassMetadata
$classMetadata = $this->_queryComponent['metadata'];
// Looping through relations
for ($i = 1; $i < $l; $i++) {
$relationName = $this->_identifiers[$i];
$path .= '.' . $relationName;
if ( ! $classMetadata->hasAssociation($relationName)) {
$className = $classMetadata->getClassName();
$this->_parser->semanticalError(
"Relation '{$relationName}' does not exist in component '{$className}' when trying to get the path '{$path}'",
$this->_parser->token
);
}
// We inspect for queryComponent of relations, since we are using them
if ( ! $parserResult->hasQueryComponent($path)) {
$this->_parser->semanticalError("Cannot use the path '{$path}' without defining it in FROM.", $this->_parser->token);
}
// Assigning new queryComponent and classMetadata
$this->_queryComponent = $parserResult->getQueryComponent($path);
$classMetadata = $this->_queryComponent['metadata'];
}
} else {
// We are dealing with a simple * as our PathExpression.
// We need to check if there's only one query component.
$queryComponents = $parserResult->getQueryComponents();
if (count($queryComponents) != 2) {
$this->_parser->semanticalError(
"Cannot use * as selector expression for multiple components."
);
}
// We simplify our life adding the component alias to our AST,
// since we have it on hands now.
$k = array_keys($queryComponents);
$componentAlias = $k[1];
$this->_queryComponent = $queryComponents[$componentAlias];
}
}
public function buildSql()
{
// Basic handy variables
$parserResult = $this->_parser->getParserResult();
// Retrieving connection
$conn = $this->_em->getConnection();
// Looking for componentAlias to fetch
$componentAlias = implode('.', $this->_identifiers);
if (count($this->_identifiers) == 0) {
$queryComponents = $parserResult->getQueryComponents();
// Retrieve ClassMetadata
$k = array_keys($queryComponents);
$componentAlias = $k[1];
}
// Generating the SQL piece
$fields = $this->_queryComponent['metadata']->getFieldMappings();
$tableAlias = $parserResult->getTableAliasFromComponentAlias($componentAlias);
$str = '';
foreach ($fields as $fieldName => $fieldMap) {
$str .= ($str != '') ? ', ' : '';
// DB Field name
$column = $tableAlias . '.' . $this->_queryComponent['metadata']->getColumnName($fieldName);
$column = $conn->quoteIdentifier($column);
// DB Field alias
$columnAlias = $tableAlias . '__' . $this->_queryComponent['metadata']->getColumnName($fieldName);
$columnAlias = $conn->quoteIdentifier($columnAlias);
$str .= $column . ' AS ' . $columnAlias;
}
return $str;
}
/* Getters */
public function getIdentifiers()
{
return $this->_identifiers;
}
public function getQueryComponent()
{
return $this->_queryComponent;
}
}

View File

@ -1,110 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Primary = PathExpression | Atom | "(" Expression ")" | Function | AggregateExpression
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_Primary extends Doctrine_Query_Production
{
protected $_expression;
public function syntax($paramHolder)
{
// Primary = PathExpression | Atom | "(" Expression ")" | Function | AggregateExpression
switch ($this->_parser->lookahead['type']) {
case Doctrine_Query_Token::T_IDENTIFIER:
if ($this->_isFunction()) {
return $this->AST('Function', $paramHolder);
} else {
return $this->AST('PathExpression', $paramHolder);
}
break;
case Doctrine_Query_Token::T_STRING:
case Doctrine_Query_Token::T_INTEGER:
case Doctrine_Query_Token::T_FLOAT:
case Doctrine_Query_Token::T_INPUT_PARAMETER:
return $this->AST('Atom', $paramHolder);
break;
case Doctrine_Query_Token::T_AVG:
case Doctrine_Query_Token::T_COUNT:
case Doctrine_Query_Token::T_MAX:
case Doctrine_Query_Token::T_MIN:
case Doctrine_Query_Token::T_SUM:
return $this->AST('AggregateExpression', $paramHolder);
break;
case Doctrine_Query_Token::T_NONE:
if ($this->_isNextToken('(')) {
$this->_parser->match('(');
$this->_expression = $this->AST('Expression', $paramHolder);
$this->_parser->match(')');
}
break;
default:
$this->_parser->syntaxError('Could not process primary type');
break;
}
}
public function semantical($paramHolder)
{
$this->_expression->semantical($paramHolder);
}
public function buildSql()
{
return '(' . $this->_expression->buildSql() . ')';
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$this->_expression->accept($visitor);
$visitor->visitPrimary($this);
}
/* Getters */
public function getExpression()
{
return $this->_expression;
}
}

View File

@ -1,85 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* QuantifiedExpression = ("ALL" | "ANY" | "SOME") "(" Subselect ")"
*
* @package Doctrine
* @subpackage Query
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_QuantifiedExpression extends Doctrine_Query_Production
{
protected $_type;
protected $_subselect;
public function syntax($paramHolder)
{
switch ($this->_parser->lookahead['type']) {
case Doctrine_Query_Token::T_ALL:
$this->_parser->match(Doctrine_Query_Token::T_ALL);
break;
case Doctrine_Query_Token::T_ANY:
$this->_parser->match(Doctrine_Query_Token::T_ANY);
break;
case Doctrine_Query_Token::T_SOME:
$this->_parser->match(Doctrine_Query_Token::T_SOME);
break;
default:
$this->_parser->logError('ALL, ANY or SOME');
break;
}
$this->_type = strtoupper($this->_parser->lookahead['value']);
$this->_parser->match('(');
$this->_subselect = $this->AST('Subselect', $paramHolder);
$this->_parser->match(')');
}
public function buildSql()
{
return $this->_type . ' (' . $this->_subselect->buildSql() . ')';
}
/* Getters */
public function getType()
{
return $this->_type;
}
public function getSubselect()
{
return $this->_subselect;
}
}

View File

@ -1,57 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* QueryLanguage = SelectStatement | UpdateStatement | DeleteStatement
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_QueryLanguage extends Doctrine_Query_Production
{
public function syntax($paramHolder)
{
// QueryLanguage = SelectStatement | UpdateStatement | DeleteStatement
switch ($this->_parser->lookahead['type']) {
case Doctrine_Query_Token::T_SELECT:
return $this->AST('SelectStatement', $paramHolder);
break;
case Doctrine_Query_Token::T_UPDATE:
return $this->AST('UpdateStatement', $paramHolder);
break;
case Doctrine_Query_Token::T_DELETE:
return $this->AST('DeleteStatement', $paramHolder);
break;
default:
$this->_parser->syntaxError('SELECT, UPDATE or DELETE');
break;
}
}
}

View File

@ -1,260 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* RangeVariableDeclaration = identifier {"." identifier} [["AS"] IdentificationVariable]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_RangeVariableDeclaration extends Doctrine_Query_Production
{
protected $_identifiers = array();
protected $_queryComponent;
protected $_identificationVariable;
public function syntax($paramHolder)
{
// RangeVariableDeclaration = identifier {"." identifier} [["AS"] IdentificationVariable]
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_identifiers[] = $this->_parser->token['value'];
while ($this->_isNextToken('.')) {
$this->_parser->match('.');
$this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER);
$this->_identifiers[] = $this->_parser->token['value'];
}
if ($this->_isNextToken(Doctrine_Query_Token::T_AS)) {
$this->_parser->match(Doctrine_Query_Token::T_AS);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_IDENTIFIER)) {
$paramHolder->set('componentName', implode('.', $this->_identifiers));
// Will return an identifier, with the semantical check already applied
$this->_identificationVariable = $this->AST('IdentificationVariable', $paramHolder);
$paramHolder->remove('componentName');
}
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
$componentName = implode('.', $this->_identifiers);
if ($parserResult->hasQueryComponent($componentName)) {
//echo "Entered in if of hasQueryComponent(".$componentName."): true\n";
// As long as name != alias, try to bring the queryComponent from name (already processed)
$queryComponent = $parserResult->getQueryComponent($componentName);
// Check if we defined _identificationVariable. We throw semantical error if not
if ($this->_identificationVariable === null) {
$componentName = $queryComponent['metadata']->getClassName();
$this->_parser->semanticalError(
"Cannot re-declare component '{$componentName}'. Please assign an alias to it."
);
return;
}
} else {
//echo "Entered in if hasQueryComponent(".$componentName."), alias ".var_export($this->_identificationVariable, true).": false\n";
// No queryComponent was found. We will have to build it for the first time
if (count($this->_identifiers) > 1) {
// We are in a multiple identifier declaration; we are dealing with relations here
$this->_semanticalWithMultipleIdentifier();
} else {
// We are in a single identifier declaration; our identifier is the class name
$this->_semanticalWithSingleIdentifier();
}
}
}
public function buildSql()
{
// We need to bring the queryComponent and get things from there.
$parserResult = $this->_parser->getParserResult();
// Retrieving connection
$conn = $this->_em->getConnection();
return $conn->quoteIdentifier($this->_queryComponent['metadata']->getTableName()) . ' '
. $conn->quoteIdentifier($parserResult->getTableAliasFromComponentAlias($this->_identificationVariable));
}
private function _semanticalWithSingleIdentifier()
{
$parserResult = $this->_parser->getParserResult();
// Get the connection for the component
$conn = $this->_em->getConnection();
$componentName = $this->_identifiers[0];
// Retrieving ClassMetadata and Mapper
try {
$classMetadata = $this->_em->getClassMetadata($componentName);
// Building queryComponent
$this->_queryComponent = array(
'metadata' => $classMetadata,
'parent' => null,
'relation' => null,
'map' => null,
'scalar' => null,
);
} catch (Doctrine_Exception $e) {
//echo "Tried to load class metadata from '".$componentName."': " . $e->getMessage() . "\n";
$this->_parser->semanticalError($e->getMessage());
return;
}
if ($this->_identificationVariable === null) {
$this->_identificationVariable = $componentName;
}
//echo "Identification Variable: " .$this->_identificationVariable . "\n";
$tableAlias = $parserResult->generateTableAlias($classMetadata->getClassName());
$parserResult->setQueryComponent($this->_identificationVariable, $this->_queryComponent);
$parserResult->setTableAlias($tableAlias, $this->_identificationVariable);
}
private function _semanticalWithMultipleIdentifier()
{
$parserResult = $this->_parser->getParserResult();
// Get the connection for the component
$conn = $this->_em->getConnection();
// Retrieve the base component
try {
$this->_queryComponent = $parserResult->getQueryComponent($this->_identifiers[0]);
$classMetadata = $this->_queryComponent['metadata'];
$className = $classMetadata->getClassName();
$parent = $path = $this->_identifiers[0];
} catch (Doctrine_Exception $e) {
$this->_parser->semanticalError($e->getMessage());
return;
}
// We loop into others identifier to build query components
for ($i = 1, $l = count($this->_identifiers); $i < $l; $i++) {
$relationName = $this->_identifiers[$i];
$path .= '.' . $relationName;
if ($parserResult->hasQueryComponent($path)) {
// We already have the query component on hands, get it
$this->_queryComponent = $parserResult->getQueryComponent($path);
$classMetadata = $this->_queryComponent['metadata'];
// If we are in our last check and identification variable is null, we throw semantical error
if ($i == $l - 1 && $this->_identificationVariable === null) {
$componentName = $classMetadata->getClassName();
$this->_parser->semanticalError(
"Cannot re-declare component '{$componentName}' in path '{$path}'. " .
"Please assign an alias to it."
);
return;
}
} else {
// We don't have the query component yet
if ( ! $classMetadata->hasAssociation($relationName)) {
$className = $classMetadata->getClassName();
$this->_parser->semanticalError("Relation '{$relationName}' does not exist in component '{$className}'");
return;
}
// Retrieving ClassMetadata
try {
$relation = $classMetadata->getAssociationMapping($relationName);
$targetClassMetadata = $this->_em->getClassMetadata($relation->getTargetEntityName());
$this->_queryComponent = array(
'metadata' => $targetClassMetadata,
'parent' => $parent,
'relation' => $relation,
'map' => null,
'scalar' => null,
);
$parent = $path;
} catch (Doctrine_Exception $e) {
//echo "Tried to load class metadata from '".$relationName."'\n";
$this->_parser->semanticalError($e->getMessage());
return;
}
}
}
if ($this->_identificationVariable === null) {
$this->_identificationVariable = $path;
}
$tableAlias = $parserResult->generateTableAlias($targetClassMetadata->getClassName());
$parserResult->setQueryComponent($this->_identificationVariable, $this->_queryComponent);
$parserResult->setTableAlias($tableAlias, $this->_identificationVariable);
}
/* Getters */
public function getIdentifiers()
{
return $this->_identifiers;
}
public function getQueryComponent()
{
return $this->_queryComponent;
}
public function getIdentificationVariable()
{
return $this->_identificationVariable;
}
}

View File

@ -1,101 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SelectClause = "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_SelectClause extends Doctrine_Query_Production
{
protected $_isDistinct;
protected $_selectExpressions = array();
public function syntax($paramHolder)
{
// SelectClause = "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression}
$this->_isDistinct = false;
$this->_parser->match(Doctrine_Query_Token::T_SELECT);
if ($this->_isNextToken(Doctrine_Query_Token::T_DISTINCT)) {
$this->_parser->match(Doctrine_Query_Token::T_DISTINCT);
$this->_isDistinct = true;
}
$this->_selectExpressions[] = $this->AST('SelectExpression', $paramHolder);
while ($this->_isNextToken(',')) {
$this->_parser->match(',');
$this->_selectExpressions[] = $this->AST('SelectExpression', $paramHolder);
}
}
public function semantical($paramHolder)
{
// We need to validate each SelectExpression
for ($i = 0, $l = count($this->_selectExpressions); $i < $l; $i++) {
$this->_selectExpressions[$i]->semantical($paramHolder);
}
}
public function buildSql()
{
return 'SELECT ' . (($this->_isDistinct) ? 'DISTINCT ' : '')
. implode(', ', $this->_mapSelectExpressions());
}
protected function _mapSelectExpressions()
{
return array_map(array(&$this, '_mapSelectExpression'), $this->_selectExpressions);
}
protected function _mapSelectExpression($value)
{
return $value->buildSql();
}
/* Getters */
public function isDistinct()
{
return $this->_isDistinct;
}
public function getSelectExpressions()
{
return $this->_selectExpressions;
}
}

View File

@ -1,212 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SelectExpression = (PathExpressionEndingWithAsterisk | Expression | "(" Subselect ")")
* [["AS"] IdentificationVariable]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
class Doctrine_Query_Production_SelectExpression extends Doctrine_Query_Production
{
protected $_leftExpression;
protected $_isSubselect;
protected $_fieldIdentificationVariable;
private $__columnAliasInSql;
public function syntax($paramHolder)
{
// SelectExpression = (PathExpressionEndingWithAsterisk | Expression | "(" Subselect ")")
// [["AS"] IdentificationVariable]
$this->_isSubselect = false;
if ($this->_isPathExpressionEndingWithAsterisk()) {
$this->_leftExpression = $this->AST('PathExpressionEndingWithAsterisk', $paramHolder);
$fieldName = implode('.', $this->_leftExpression->getIdentifiers()) . '.*';
} else if (($this->_isSubselect = $this->_isSubselect()) === true) {
$this->_parser->match('(');
$this->_leftExpression = $this->AST('Subselect', $paramHolder);
$this->_parser->match(')');
// [TODO] Any way to make it more fancy for user error?
$fieldName = '<Subselect>';
} else {
$this->_leftExpression = $this->AST('Expression', $paramHolder);
// [TODO] Any way to make it more fancy for user error?
$fieldName = '<Expression>';
}
if ($this->_isNextToken(Doctrine_Query_Token::T_AS)) {
$this->_parser->match(Doctrine_Query_Token::T_AS);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_IDENTIFIER)) {
$paramHolder->set('fieldName', $fieldName);
// Will return an identifier, with the semantical check already applied
$this->_fieldIdentificationVariable = $this->AST('FieldIdentificationVariable', $paramHolder);
$paramHolder->remove('fieldName');
}
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
// We cannot have aliases for foo.*
if ($this->_leftExpression instanceof Doctrine_Query_Production_PathExpressionEndingWithAsterisk
&& $this->_fieldIdentificationVariable !== null) {
$this->_parser->semanticalError(
"Cannot assign an identification variable to a path expression ending with asterisk (ie. foo.bar.* AS foobaz)."
);
}
// Also, we cannot have aliases for path expressions: foo.bar
if ($this->_leftExpression instanceof Doctrine_Query_Production_PathExpressionEndingWithAsterisk
&& $this->_fieldIdentificationVariable !== null) {
$this->_parser->semanticalError(
"Cannot assign an identification variable to a path expression (ie. foo.bar AS foobaz)."
);
}
// Make semantical checks
$this->_leftExpression->semantical($paramHolder);
if($this->_fieldIdentificationVariable !== null) {
$this->_fieldIdentificationVariable->semantical($paramHolder);
}
}
public function buildSql()
{
return $this->_leftExpression->buildSql() . $this->_buildColumnAliasInSql();
}
protected function _isPathExpressionEndingWithAsterisk()
{
$token = $this->_parser->lookahead;
$this->_parser->getScanner()->resetPeek();
while (($token['type'] === Doctrine_Query_Token::T_IDENTIFIER) || ($token['value'] === '.')) {
$token = $this->_parser->getScanner()->peek();
}
return $token['value'] === '*';
}
protected function _buildColumnAliasInSql()
{
// Retrieving parser result
$parserResult = $this->_parser->getParserResult();
// Retrieving connection
$conn = $this->_em->getConnection();
switch (get_class($this->_leftExpression)) {
case 'Doctrine_Query_Production_PathExpressionEndingWithAsterisk':
return '';
break;
case 'Doctrine_Query_Production_PathExpression':
// We bring the queryComponent from the class instance
$componentAlias = $this->_leftExpression->getComponentAlias();
$queryComponent = $parserResult->getQueryComponent($componentAlias);
$fieldName = $this->_leftExpression->getFieldName();
// Build the column alias now
$columnAlias = $parserResult->getTableAliasFromComponentAlias($componentAlias)
. Doctrine_Query_Production::SQLALIAS_SEPARATOR
. $queryComponent['metadata']->getColumnName($fieldName);
break;
default:
// We bring the default queryComponent
$componentAlias = Doctrine_Query_Production::DEFAULT_QUERYCOMPONENT;
$queryComponent = $parserResult->getQueryComponent($componentAlias);
// If we have FieldIdentificationVariable, we have to use the scalar map of it
if ($this->_fieldIdentificationVariable !== null) {
$columnAlias = $this->_fieldIdentificationVariable->getColumnAlias();
} else {
// We have to include the map now, since we don't have the scalar mapped
$queryFields = $parserResult->getQueryFields();
$itemIndex = 'item' . count(array_filter($queryFields, array($this, "_nonIdentifiedVariable")));
$idx = count($queryFields);
$queryComponent['scalar'][$idx] = $itemIndex;
$parserResult->setQueryComponent($componentAlias, $queryComponent);
// And also in field aliases
$parserResult->setQueryField($itemIndex, $idx);
// Build the column alias
$columnAlias = $parserResult->getTableAliasFromComponentAlias($componentAlias)
. Doctrine_Query_Production::SQLALIAS_SEPARATOR . $idx;
}
break;
}
return ' AS ' . $conn->quoteIdentifier($columnAlias);
}
protected function _nonIdentifiedVariable($value)
{
return ! is_string($value);
}
/* Getters */
public function getLeftExpression()
{
return $this->_leftExpression;
}
public function isSubselect()
{
return $this->_isSubselect;
}
public function getFieldIdentificationVariable()
{
return $this->_fieldIdentificationVariable;
}
}

View File

@ -1,133 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SelectStatement = SelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_SelectStatement extends Doctrine_Query_Production
{
protected $_selectClause;
protected $_fromClause;
protected $_whereClause;
protected $_groupByClause;
protected $_havingClause;
protected $_orderByClause;
public function syntax($paramHolder)
{
// SelectStatement = SelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
// Disable the semantical check for SelectClause now. This is needed
// since we dont know the query components yet (will be known only
// when the FROM clause be processed).
$paramHolder->set('semanticalCheck', false);
$this->_selectClause = $this->AST('SelectClause', $paramHolder);
$paramHolder->remove('semanticalCheck');
$this->_fromClause = $this->AST('FromClause', $paramHolder);
if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) {
$this->_whereClause = $this->AST('WhereClause', $paramHolder);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_GROUP)) {
$this->_groupByClause = $this->AST('GroupByClause', $paramHolder);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_HAVING)) {
$this->_havingClause = $this->AST('HavingClause', $paramHolder);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_ORDER)) {
$this->_orderByClause = $this->AST('OrderByClause', $paramHolder);
}
}
public function semantical($paramHolder)
{
// We need to invoke the semantical check of SelectClause here, since
// it was not yet checked.
$this->_selectClause->semantical($paramHolder);
}
public function buildSql()
{
return $this->_selectClause->buildSql() . ' ' . $this->_fromClause->buildSql()
. (($this->_whereClause !== null) ? ' ' . $this->_whereClause->buildSql() : ' WHERE 1 = 1')
. (($this->_groupByClause !== null) ? ' ' . $this->_groupByClause->buildSql() : '')
. (($this->_havingClause !== null) ? ' ' . $this->_havingClause->buildSql() : '')
. (($this->_orderByClause !== null) ? ' ' . $this->_orderByClause->buildSql() : '');
}
/* Getters */
public function getSelectClause()
{
return $this->_selectClause;
}
public function getFromClause()
{
return $this->_fromClause;
}
public function getWhereClause()
{
return $this->_whereClause;
}
public function getGroupByClause()
{
return $this->_groupByClause;
}
public function getHavingClause()
{
return $this->_havingClause;
}
public function getOrderByClause()
{
return $this->_orderByClause;
}
}

View File

@ -1,122 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SimpleConditionalExpression =
* ExistsExpression | Expression (ComparisonExpression | BetweenExpression |
* LikeExpression | InExpression | NullComparisonExpression | QuantifiedExpression)
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_SimpleConditionalExpression extends Doctrine_Query_Production
{
protected $_leftExpression;
protected $_rightExpression;
public function syntax($paramHolder)
{
// SimpleConditionalExpression =
// ExistsExpression | Expression (ComparisonExpression | BetweenExpression |
// LikeExpression | InExpression | NullComparisonExpression | QuantifiedExpression)
if ($this->_getExpressionType() === Doctrine_Query_Token::T_EXISTS) {
return $this->AST('ExistsExpression', $paramHolder);
}
$this->_leftExpression = $this->AST('Expression', $paramHolder);
switch ($this->_getExpressionType()) {
case Doctrine_Query_Token::T_BETWEEN:
$this->_rightExpression = $this->AST('BetweenExpression', $paramHolder);
break;
case Doctrine_Query_Token::T_LIKE:
$this->_rightExpression = $this->AST('LikeExpression', $paramHolder);
break;
case Doctrine_Query_Token::T_IN:
$this->_rightExpression = $this->AST('InExpression', $paramHolder);
break;
case Doctrine_Query_Token::T_IS:
$this->_rightExpression = $this->AST('NullComparisonExpression', $paramHolder);
break;
case Doctrine_Query_Token::T_ALL:
case Doctrine_Query_Token::T_ANY:
case Doctrine_Query_Token::T_SOME:
$this->_rightExpression = $this->AST('QuantifiedExpression', $paramHolder);
break;
case Doctrine_Query_Token::T_NONE:
// [TODO] Check out ticket #935 to understand what will be done with enumParams
$this->_rightExpression = $this->AST('ComparisonExpression', $paramHolder);
break;
default:
$message = "BETWEEN, LIKE, IN, IS, quantified (ALL, ANY or SOME) "
. "or comparison (=, <, <=, <>, >, >=, !=)";
$this->_parser->syntaxError($message);
break;
}
}
public function buildSql()
{
return $this->_leftExpression->buildSql() . ' ' . $this->_rightExpression->buildSql();
}
protected function _getExpressionType() {
if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) {
$scanner = $this->_parser->getScanner();
$token = $scanner->peek();
$scanner->resetPeek();
} else {
$token = $this->_parser->lookahead;
}
return $token['type'];
}
/* Getters */
public function getLeftExpression()
{
return $this->_leftExpression;
}
public function getRightExpression()
{
return $this->_rightExpression;
}
}

View File

@ -1,91 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* SimpleSelectClause = "SELECT" ["DISTINCT"] SelectExpression
*
* @package Doctrine
* @subpackage Query
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_SimpleSelectClause extends Doctrine_Query_Production
{
protected $_isDistinct;
protected $_selectExpression;
public function syntax($paramHolder)
{
// SimpleSelectClause = "SELECT" ["DISTINCT"] SelectExpression
$this->_isDistinct = false;
$this->_parser->match(Doctrine_Query_Token::T_SELECT);
if ($this->_isNextToken(Doctrine_Query_Token::T_DISTINCT)) {
$this->_parser->match(Doctrine_Query_Token::T_DISTINCT);
$this->_isDistinct = true;
}
$this->_selectExpression = $this->AST('SelectExpression', $paramHolder);
}
public function semantical($paramHolder)
{
// We need to validate the SelectExpression
$this->_selectExpression->semantical($paramHolder);
}
public function buildSql()
{
return 'SELECT ' . (($this->_isDistinct) ? 'DISTINCT ' : '')
. $this->_selectExpression->buildSql();
}
/**
* Visitor support
*
* @param object $visitor
*/
public function acccept($visitor)
{
$this->_selectExpression->accept($visitor);
$visitor->visitSimpleSelectClause($this);
}
/* Getters */
public function isDistinct()
{
return $this->_isDistinct;
}
public function getSelectExpression()
{
return $this->_selectExpression;
}
}

View File

@ -1,161 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Subselect = SimpleSelectClause FromClause [WhereClause] [GroupByClause]
* [HavingClause] [OrderByClause] [LimitClause] [OffsetClause]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_Subselect extends Doctrine_Query_Production
{
protected $_simpleSelectClause;
protected $_fromClause;
protected $_whereClause;
protected $_groupByClause;
protected $_havingClause;
protected $_orderByClause;
protected $_limitClause;
public function syntax($paramHolder)
{
// Subselect = SimpleSelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause] [LimitClause]
// Disable the semantical check for SelectClause now. This is needed
// since we dont know the query components yet (will be known only
// when the FROM clause be processed).
$paramHolder->set('semanticalCheck', false);
$this->_simpleSelectClause = $this->AST('SimpleSelectClause', $paramHolder);
$paramHolder->remove('semanticalCheck');
$this->_fromClause = $this->AST('FromClause', $paramHolder);
if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) {
$this->_whereClause = $this->AST('WhereClause', $paramHolder);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_GROUP)) {
$this->_groupByClause = $this->AST('GroupByClause', $paramHolder);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_HAVING)) {
$this->_havingClause = $this->AST('HavingClause', $paramHolder);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_ORDER)) {
$this->_orderByClause = $this->AST('OrderByClause', $paramHolder);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_LIMIT)) {
$this->_limitClause = $this->AST('LimitClause', $paramHolder);
}
}
public function semantical($paramHolder)
{
// We need to invoke the semantical check of SelectClause here, since
// it was not yet checked.
$this->_simpleSelectClause->semantical($paramHolder);
}
public function buildSql()
{
return $this->_simpleSelectClause->buildSql() . ' ' . $this->_fromClause->buildSql()
. (($this->_whereClause !== null) ? ' ' . $this->_whereClause->buildSql() : '')
. (($this->_groupByClause !== null) ? ' ' . $this->_groupByClause->buildSql() : '')
. (($this->_havingClause !== null) ? ' ' . $this->_havingClause->buildSql() : '')
. (($this->_orderByClause !== null) ? ' ' . $this->_orderByClause->buildSql() : '');
}
/**
* Visitor support
*
* @param object $visitor
*/
public function accept($visitor)
{
$this->_simpleSelectClause->accept($visitor);
$this->_fromClause->accept($visitor);
if ($this->_whereClause) {
$this->_whereClause->accept($visitor);
}
if ($this->_groupByClause) {
$this->_groupByClause->accept($visitor);
}
if ($this->_havingClause) {
$this->_havingClause->accept($visitor);
}
if ($this->_orderByClause) {
$this->_orderByClause->accept($visitor);
}
$visitor->visitSubselect($this);
}
/* Getters */
public function getSimpleSelectClause()
{
return $this->_simpleSelectClause;
}
public function getFromClause()
{
return $this->_fromClause;
}
public function getWhereClause()
{
return $this->_whereClause;
}
public function getGroupByClause()
{
return $this->_groupByClause;
}
public function getHavingClause()
{
return $this->_havingClause;
}
public function getOrderByClause()
{
return $this->_orderByClause;
}
}

View File

@ -1,107 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Term = Factor {("*" | "/") Factor}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_Term extends Doctrine_Query_Production
{
protected $_factors = array();
public function syntax($paramHolder)
{
// Term = Factor {("*" | "/") Factor}
$this->_factors[] = $this->AST('Factor', $paramHolder);
while ($this->_isNextToken('*') || $this->_isNextToken('/')) {
if ($this->_isNextToken('*')) {
$this->_parser->match('*');
$this->_factors[] = '*';
} else {
$this->_parser->match('/');
$this->_factors[] = '/';
}
$this->_factors[] = $this->AST('Factor', $paramHolder);
}
// Optimize depth instances in AST
if (count($this->_factors) == 1) {
return $this->_factors[0];
}
}
public function semantical($paramHolder)
{
for ($i = 0, $l = count($this->_factors); $i < $l; $i++) {
if ($this->_factors[$i] != '*' && $this->_factors[$i] != '/') {
$this->_factors[$i]->semantical($paramHolder);
}
}
}
public function buildSql()
{
return implode(' ', $this->_mapFactors());
}
protected function _mapFactors()
{
return array_map(array(&$this, '_mapFactor'), $this->_factors);
}
protected function _mapFactor($value)
{
return (is_string($value) ? $value : $value->buildSql());
}
/**
* Visitor support.
*/
public function accept($visitor)
{
foreach ($this->_factors as $factor) {
$factor->accept($visitor);
}
$visitor->visitTerm($this);
}
/* Getters */
public function getFactors()
{
return $this->_factors;
}
}

View File

@ -1,101 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* UpdateClause = "UPDATE" VariableDeclaration "SET" UpdateItem {"," UpdateItem}
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_UpdateClause extends Doctrine_Query_Production
{
protected $_variableDeclaration;
protected $_updateItems = array();
public function syntax($paramHolder)
{
// UpdateClause = "UPDATE" VariableDeclaration "SET" UpdateItem {"," UpdateItem}
$this->_parser->match(Doctrine_Query_Token::T_UPDATE);
$this->_variableDeclaration = $this->AST('VariableDeclaration', $paramHolder);
$this->_parser->match(Doctrine_Query_Token::T_SET);
$this->_updateItems[] = $this->AST('UpdateItem', $paramHolder);
while ($this->_isNextToken(',')) {
$this->_parser->match(',');
$this->_updateItems[] = $this->AST('UpdateItem', $paramHolder);
}
}
public function buildSql()
{
return 'UPDATE ' . $this->_variableDeclaration->buildSql()
. ' SET ' . implode(', ', $this->_mapUpdateItems());
}
protected function _mapUpdateItems()
{
return array_map(array(&$this, '_mapUpdateItem'), $this->_updateItems);
}
protected function _mapUpdateItem($value)
{
return $value->buildSql();
}
/**
* Visitor support.
*/
public function accept($visitor)
{
$this->_variableDeclaration->accept($visitor);
foreach ($this->_updateItems as $item) {
$item->accept($visitor);
}
$visitor->visitUpdateClause($this);
}
/* Getters */
public function getVariableDeclaration()
{
return $this->_variableDeclaration;
}
public function getUpdateItems()
{
return $this->_updateItems;
}
}

View File

@ -1,86 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* UpdateItem = PathExpression "=" (Expression | "NULL")
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_UpdateItem extends Doctrine_Query_Production
{
protected $_pathExpression;
protected $_expression;
public function syntax($paramHolder)
{
// UpdateItem = PathExpression "=" (Expression | "NULL")
$this->_pathExpression = $this->AST('PathExpression', $paramHolder);
$this->_parser->match('=');
if ($this->_isNextToken(Doctrine_Query_Token::T_NULL)) {
$this->_parser->match(Doctrine_Query_Token::T_NULL);
$this->_expression = null;
} else {
$this->_expression = $this->AST('Expression', $paramHolder);
}
}
public function buildSql()
{
return $this->_pathExpression->buildSql() . ' = '
. ($this->_expression === null ? 'NULL' : $this->_expression->buildSql());
}
/**
* Visitor support.
*/
public function accept($visitor)
{
$this->_pathExpression->accept($visitor);
if ($this->_expression) {
$this->_expression->accept($visitor);
}
$visitor->visitUpdateItem($this);
}
/* Getters */
public function getPathExpression()
{
return $this->_pathExpression;
}
public function getExpression()
{
return $this->_expression;
}
}

View File

@ -1,82 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* UpdateStatement = UpdateClause [WhereClause]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_UpdateStatement extends Doctrine_Query_Production
{
protected $_updateClause;
protected $_whereClause;
public function syntax($paramHolder)
{
// UpdateStatement = UpdateClause [WhereClause]
$this->_updateClause = $this->AST('UpdateClause', $paramHolder);
if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) {
$this->_whereClause = $this->AST('WhereClause', $paramHolder);
}
}
public function buildSql()
{
// The 1=1 is needed to workaround the affected_rows in MySQL.
// Simple "UPDATE table_name SET column_name = value" gives 0 affected rows.
return $this->_updateClause->buildSql() . (($this->_whereClause !== null)
? ' ' . $this->_whereClause->buildSql() : ' WHERE 1 = 1');
}
/**
* Visitor support.
*/
public function accept($visitor)
{
$this->_updateClause->accept($visitor);
if ($this->_whereClause) {
$this->_whereClause->accept($visitor);
}
$visitor->visitUpdateStatment($this);
}
/* Getters */
public function getUpdateClause()
{
return $this->_updateClause;
}
public function getWhereClause()
{
return $this->_whereClause;
}
}

View File

@ -1,151 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* VariableDeclaration = identifier [["AS"] IdentificationVariable]
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_VariableDeclaration extends Doctrine_Query_Production
{
protected $_componentName;
protected $_componentAlias;
public function syntax($paramHolder)
{
// VariableDeclaration = identifier [["AS"] IdentificationVariable]
if ($this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER)) {
// identifier
$this->_componentName = $this->_parser->token['value'];
}
if ($this->_isNextToken(Doctrine_Query_Token::T_AS)) {
$this->_parser->match(Doctrine_Query_Token::T_AS);
}
if ($this->_isNextToken(Doctrine_Query_Token::T_IDENTIFIER)) {
$paramHolder->set('componentName', $this->_componentName);
// Will return an identifier, with the semantical check already applied
$this->_componentAlias = $this->AST('IdentificationVariable', $paramHolder);
$paramHolder->remove('componentName');
}
}
public function semantical($paramHolder)
{
$parserResult = $this->_parser->getParserResult();
if ($parserResult->hasQueryComponent($this->_componentName)) {
// As long as name != alias, try to bring the queryComponent from name (already processed)
$queryComponent = $parserResult->getQueryComponent($this->_componentName);
// Check if we defined _componentAlias. We throw semantical error if not
if ($this->_componentAlias === null) {
$componentName = $queryComponent['metadata']->getClassName();
$this->_parser->semanticalError(
"Cannot re-declare component '{$this->_componentName}'. Please assign an alias to it."
);
return;
}
} else {
// No queryComponent was found. We will have to build it for the first time
// Get the connection for the component
$conn = $this->_em->getConnection();
// Retrieving ClassMetadata and Mapper
try {
$classMetadata = $this->_em->getMetadata($this->_componentName);
// Building queryComponent
$queryComponent = array(
'metadata' => $classMetadata,
'parent' => null,
'relation' => null,
'map' => null,
'scalar' => null,
);
} catch (Doctrine_Exception $e) {
$this->_parser->semanticalError($e->getMessage());
return;
}
}
// Define ParserResult assertions for later usage
$tableAlias = $this->_parser->getParserResult()->generateTableAlias($this->_componentName);
if ($this->_componentAlias === null) {
$this->_componentAlias = $this->_componentName;
}
$parserResult->setQueryComponent($this->_componentAlias, $queryComponent);
$parserResult->setTableAlias($tableAlias, $this->_componentAlias);
}
public function buildSql()
{
// Basic handy variables
$parserResult = $this->_parser->getParserResult();
$queryComponent = $parserResult->getQueryComponent($this->_componentAlias);
// Retrieving connection
$conn = $this->_em->getConnection();
return $conn->quoteIdentifier($queryComponent['metadata']->getTableName()) . ' '
. $conn->quoteIdentifier($parserResult->getTableAliasFromComponentAlias($this->_componentAlias));
}
/**
* Visitor support.
*/
public function accept($visitor)
{
$visitor->visitVariableDeclaration($this);
}
/* Getters */
public function getComponentName()
{
return $this->_componentName;
}
public function getComponentAlias()
{
return $this->_componentAlias;
}
}

View File

@ -1,59 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* WhereClause = "WHERE" ConditionalExpression
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_WhereClause extends Doctrine_Query_Production
{
protected $_conditionalExpression;
public function syntax($paramHolder)
{
// WhereClause = "WHERE" ConditionalExpression
$this->_parser->match(Doctrine_Query_Token::T_WHERE);
$this->_conditionalExpression = $this->AST('ConditionalExpression', $paramHolder);
}
public function buildSql()
{
return 'WHERE ' . $this->_conditionalExpression->buildSql();
}
/* Getters */
public function getConditionalExpression()
{
return $this->_conditionalExpression;
}
}

View File

@ -1,46 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Doctrine_Query_QueryResult
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_QueryResult extends Doctrine_Query_AbstractResult
{
/**
* Returns cached resultset.
*
* @return array Resultset.
*/
public function getResultSet()
{
return $this->_data;
}
}

View File

@ -1,231 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* Scans a DQL query for tokens.
*
* @package Doctrine
* @subpackage Query
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Scanner
{
/**
* Array of scanned tokens.
*
* @var array
*/
protected $_tokens = array();
/**
* @todo Doc
*/
protected $_position = 0;
/**
* @todo Doc
*/
protected $_peek = 0;
/**
* Creates a new query scanner object.
*
* @param string $input a query string
*/
public function __construct($input)
{
$this->_scan($input);
}
/**
* Checks if an identifier is a keyword and returns its correct type.
*
* @param string $identifier identifier name
* @return int token type
*/
public function _checkLiteral($identifier)
{
$name = 'Doctrine_Query_Token::T_' . strtoupper($identifier);
if (defined($name)) {
$type = constant($name);
if ($type > 100) {
return $type;
}
}
return Doctrine_Query_Token::T_IDENTIFIER;
}
/**
* Scans the input string for tokens.
*
* @param string $input a query string
*/
protected function _scan($input)
{
static $regex;
if ( ! isset($regex)) {
$patterns = array(
'[a-z_][a-z0-9_]*',
'(?:[0-9]+(?:[,\.][0-9]+)*)(?:e[+-]?[0-9]+)?',
"'(?:[^']|'')*'",
'\?|:[a-z]+'
);
$regex = '/(' . implode(')|(', $patterns) . ')|\s+|(.)/i';
}
$flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
$matches = preg_split($regex, $input, -1, $flags);
foreach ($matches as $match) {
$value = $match[0];
$type = $this->_getType($value);
$this->_tokens[] = array(
'value' => $value,
'type' => $type,
'position' => $match[1]
);
}
}
/**
* @todo Doc
*/
protected function _getType(&$value)
{
// $value is referenced because it can be changed if it is numeric.
// [TODO] Revisit the _isNumeric and _getNumeric methods to reduce overhead.
$type = Doctrine_Query_Token::T_NONE;
$newVal = $this->_getNumeric($value);
if ($newVal !== false){
$value = $newVal;
if (strpos($value, '.') !== false || stripos($value, 'e') !== false) {
$type = Doctrine_Query_Token::T_FLOAT;
} else {
$type = Doctrine_Query_Token::T_INTEGER;
}
}
if ($value[0] === "'" && $value[strlen($value) - 1] === "'") {
$type = Doctrine_Query_Token::T_STRING;
} else if (ctype_alpha($value[0]) || $value[0] === '_') {
$type = $this->_checkLiteral($value);
} else if ($value[0] === '?' || $value[0] === ':') {
$type = Doctrine_Query_Token::T_INPUT_PARAMETER;
}
return $type;
}
/**
* @todo Doc
*/
protected function _getNumeric($value)
{
if ( ! is_scalar($value)) {
return false;
}
// Checking for valid numeric numbers: 1.234, -1.234e-2
if (is_numeric($value)) {
return $value;
}
// World number: 1.000.000,02 or -1,234e-2
$worldnum = strtr($value, array('.' => '', ',' => '.'));
if (is_numeric($worldnum)) {
return $worldnum;
}
// American extensive number: 1,000,000.02
$american_en = strtr($value, array(',' => ''));
if (is_numeric($american_en)) {
return $american_en;
}
return false;
}
/**
* @todo Doc
*/
public function isA($value, $token)
{
$type = $this->_getType($value);
return $type === $token;
}
/**
* @todo Doc
*/
public function peek()
{
if (isset($this->_tokens[$this->_position + $this->_peek])) {
return $this->_tokens[$this->_position + $this->_peek++];
} else {
return null;
}
}
/**
* @todo Doc
*/
public function resetPeek()
{
$this->_peek = 0;
}
/**
* Returns the next token in the input string.
*
* A token is an associative array containing three items:
* - 'value' : the string value of the token in the input string
* - 'type' : the type of the token (identifier, numeric, string, input
* parameter, none)
* - 'position' : the position of the token in the input string
*
* @return array|null the next token; null if there is no more tokens left
*/
public function next()
{
$this->_peek = 0;
if (isset($this->_tokens[$this->_position])) {
return $this->_tokens[$this->_position++];
} else {
return null;
}
}
/**
* @todo Doc
*/
public function resetPosition($position = 0)
{
$this->_position = $position;
}
}

View File

@ -1,67 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* The SqlBuilder. Creates SQL out of an AST.
*
* INTERNAL: For platform-specific SQL, the platform of the connection should be used.
* ($this->_connection->getDatabasePlatform())
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_SqlBuilder
{
protected $_em;
protected $_conn;
public function __construct(Doctrine_ORM_EntityManager $em)
{
$this->_em = $em;
$this->_conn = $this->_em->getConnection();
}
/**
* Retrieves the assocated Doctrine_Connection to this object.
*
* @return Doctrine_Connection
*/
public function getConnection()
{
return $this->_connection;
}
/**
* @nodoc
*/
public function quoteIdentifier($identifier)
{
return $this->_conn->quoteIdentifier($identifier);
}
}

View File

@ -1,38 +0,0 @@
<?php
/*
* $Id$
*
* 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>.
*/
/**
* MySql class of Sql Builder object
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
class Doctrine_Query_SqlBuilder_Mysql extends Doctrine_Query_SqlBuilder
{
}

Some files were not shown because too many files have changed in this diff Show More