diff --git a/draft/Doctrine/Query/Abstract.php b/draft/Doctrine/Query/Abstract.php deleted file mode 100644 index 08a9e2bf9..000000000 --- a/draft/Doctrine/Query/Abstract.php +++ /dev/null @@ -1,1565 +0,0 @@ -. - */ - -/** - * Doctrine_Query_Abstract - * - * @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 Konsta Vesterinen - * @todo See {@link Doctrine_Query} - */ -abstract class Doctrine_Query_Abstract -{ - /** - * QUERY TYPE CONSTANTS - */ - - /** - * constant for SELECT queries - */ - const SELECT = 0; - - /** - * constant for DELETE queries - */ - const DELETE = 1; - - /** - * constant for UPDATE queries - */ - const UPDATE = 2; - - /** - * constant for INSERT queries - */ - const INSERT = 3; - - /** - * constant for CREATE queries - */ - const CREATE = 4; - - /** @todo document the query states (and the transitions between them). */ - /** - * A query object is in CLEAN state when it has NO unparsed/unprocessed DQL parts. - */ - const STATE_CLEAN = 1; - - /** - * A query object is in state DIRTY when it has DQL parts that have not yet been - * parsed/processed. - */ - const STATE_DIRTY = 2; - - /** - * A query is in DIRECT state when ... ? - */ - const STATE_DIRECT = 3; - - /** - * A query object is on LOCKED state when ... ? - */ - const STATE_LOCKED = 4; - - /** - * @var array Table alias map. Keys are SQL aliases and values DQL aliases. - */ - protected $_tableAliasMap = array(); - - /** - * @var Doctrine_View The view object used by this query, if any. - */ - protected $_view; - - /** - * @var integer $_state The current state of this query. - */ - protected $_state = Doctrine_Query::STATE_CLEAN; - - /** - * @var array $params The parameters of this query. - */ - protected $_params = array('join' => array(), - 'where' => array(), - 'set' => array(), - 'having' => array()); - - /* Caching properties */ - /** - * @var Doctrine_Cache_Interface The cache driver used for caching result sets. - */ - protected $_resultCache; - /** - * @var boolean $_expireResultCache A boolean value that indicates whether or not - * expire the result cache. - */ - protected $_expireResultCache = false; - protected $_resultCacheTTL; - - /** - * @var Doctrine_Cache_Interface The cache driver used for caching queries. - */ - protected $_queryCache; - protected $_expireQueryCache = false; - protected $_queryCacheTTL; - - - /** - * @var Doctrine_Connection The connection used by this query object. - */ - protected $_conn; - - - /** - * @var array $_sqlParts The SQL query string parts. Filled during the DQL parsing process. - */ - protected $_sqlParts = array( - 'select' => array(), - 'distinct' => false, - 'forUpdate' => false, - 'from' => array(), - 'set' => array(), - 'join' => array(), - 'where' => array(), - 'groupby' => array(), - 'having' => array(), - 'orderby' => array(), - 'limit' => false, - 'offset' => false, - ); - - /** - * @var array $_dqlParts An array containing all DQL query parts. - */ - protected $_dqlParts = array( - 'from' => array(), - 'select' => array(), - 'forUpdate' => false, - 'set' => array(), - 'join' => array(), - 'where' => array(), - 'groupby' => array(), - 'having' => array(), - 'orderby' => array(), - 'limit' => array(), - 'offset' => array(), - ); - - /** - * @var integer $type the query type - * - * @see Doctrine_Query::* constants - */ - protected $_type = self::SELECT; - - /** - * @var Doctrine_Hydrator The hydrator object used to hydrate query results. - */ - protected $_hydrator; - - /** - * @var Doctrine_Query_Parser The parser that is used for query parsing. - */ - protected $_parser; - - /** - * @var array $_tableAliasSeeds A simple array keys representing table aliases and values - * table alias seeds. The seeds are used for generating short table - * aliases. - */ - protected $_tableAliasSeeds = array(); - - /** - * @var array $_enumParams an array containing the keys of the parameters that should be enumerated - */ - protected $_enumParams = array(); - - /** - * @var boolean - */ - protected $_isLimitSubqueryUsed = false; - - - /** - * Constructor. - * - * @param Doctrine_Connection The connection object the query will use. - * @param Doctrine_Hydrator_Abstract The hydrator that will be used for generating result sets. - */ - public function __construct(Doctrine_Connection $connection = null, - Doctrine_Hydrator_Abstract $hydrator = null) - { - if ($connection === null) { - $connection = Doctrine_Manager::getInstance()->getCurrentConnection(); - } - if ($hydrator === null) { - $hydrator = new Doctrine_Hydrator(); - } - $this->_conn = $connection; - $this->_hydrator = $hydrator; - $this->_tokenizer = new Doctrine_Query_Tokenizer(); - } - - /** - * setOption - * - * @param string $name option name - * @param string $value option value - * @return Doctrine_Query this object - */ - public function setOption($name, $value) - { - if ( ! isset($this->_options[$name])) { - throw new Doctrine_Query_Exception('Unknown option ' . $name); - } - $this->_options[$name] = $value; - } - - /** - * hasSqlTableAlias - * whether or not this object has given tableAlias - * - * @param string $tableAlias the table alias to be checked - * @return boolean true if this object has given alias, otherwise false - */ - public function hasSqlTableAlias($sqlTableAlias) - { - return (isset($this->_tableAliasMap[$sqlTableAlias])); - } - - /** - * getTableAliasMap - * returns all table aliases - * - * @return array table aliases as an array - */ - public function getTableAliasMap() - { - return $this->_tableAliasMap; - } - - /** - * getSqlQueryPart - * gets an SQL query part from the SQL query part array - * - * @param string $name the name of the query part to be set - * @param string $part query part string - * @throws Doctrine_Query_Exception if trying to set unknown query part - * @return Doctrine_Hydrate this object - */ - public function getSqlQueryPart($part) - { - if ( ! isset($this->_sqlParts[$part])) { - throw new Doctrine_Query_Exception('Unknown SQL query part ' . $part); - } - return $this->_sqlParts[$part]; - } - - /** - * setSqlQueryPart - * sets an SQL query part in the SQL query part array - * - * @param string $name the name of the query part to be set - * @param string $part query part string - * @throws Doctrine_Query_Exception if trying to set unknown query part - * @return Doctrine_Hydrate this object - */ - public function setSqlQueryPart($name, $part) - { - if ( ! isset($this->_sqlParts[$name])) { - throw new Doctrine_Query_Exception('Unknown query part ' . $name); - } - - if ($name !== 'limit' && $name !== 'offset') { - if (is_array($part)) { - $this->_sqlParts[$name] = $part; - } else { - $this->_sqlParts[$name] = array($part); - } - } else { - $this->_sqlParts[$name] = $part; - } - - return $this; - } - - /** - * addSqlQueryPart - * adds an SQL query part to the SQL query part array - * - * @param string $name the name of the query part to be added - * @param string $part query part string - * @throws Doctrine_Query_Exception if trying to add unknown query part - * @return Doctrine_Hydrate this object - */ - public function addSqlQueryPart($name, $part) - { - if ( ! isset($this->_sqlParts[$name])) { - throw new Doctrine_Query_Exception('Unknown query part ' . $name); - } - if (is_array($part)) { - $this->_sqlParts[$name] = array_merge($this->_sqlParts[$name], $part); - } else { - $this->_sqlParts[$name][] = $part; - } - return $this; - } - - /** - * removeSqlQueryPart - * removes a query part from the query part array - * - * @param string $name the name of the query part to be removed - * @throws Doctrine_Query_Exception if trying to remove unknown query part - * @return Doctrine_Hydrate this object - */ - public function removeSqlQueryPart($name) - { - if ( ! isset($this->_sqlParts[$name])) { - throw new Doctrine_Query_Exception('Unknown query part ' . $name); - } - - if ($name == 'limit' || $name == 'offset') { - $this->_sqlParts[$name] = false; - } else { - $this->_sqlParts[$name] = array(); - } - return $this; - } - - /** - * setView - * sets a database view this query object uses - * this method should only be called internally by doctrine - * - * @param Doctrine_View $view database view - * @return void - */ - public function setView(Doctrine_View $view) - { - $this->_view = $view; - } - - /** - * getView - * returns the view associated with this query object (if any) - * - * @return Doctrine_View the view associated with this query object - */ - public function getView() - { - return $this->_view; - } - - /** - * limitSubqueryUsed - * - * @return boolean - */ - public function isLimitSubqueryUsed() - { - return $this->_isLimitSubqueryUsed; - } - - /** - * convertEnums - * convert enum parameters to their integer equivalents - * - * @return array converted parameter array - */ - public function convertEnums($params) - { - foreach ($this->_enumParams as $key => $values) { - if (isset($params[$key])) { - if ( ! empty($values)) { - $params[$key] = $values[0]->enumIndex($values[1], $params[$key]); - } - } - } - return $params; - } - - /** - * Creates the SQL snippet for additional joins. - * - * @return string The created SQL snippet. - */ - protected function _createCustomJoinSql($componentName, $componentAlias) - { - $table = $this->_conn->getTable($componentName); - $tableAlias = $this->getSqlTableAlias($componentAlias, $table->getTableName()); - $customJoins = $this->_conn->getMapper($componentName)->getCustomJoins(); - $sql = ''; - foreach ($customJoins as $componentName => $joinType) { - $joinedTable = $this->_conn->getTable($componentName); - $joinedAlias = $componentAlias . '.' . $componentName; - $joinedTableAlias = $this->getSqlTableAlias($joinedAlias, $joinedTable->getTableName()); - $sql .= ' ' - . $joinType - . ' JOIN ' - . $this->_conn->quoteIdentifier($joinedTable->getTableName()) - . ' ' - . $this->_conn->quoteIdentifier($joinedTableAlias) . ' ON '; - - foreach ($table->getIdentifierColumnNames() as $column) { - $sql .= $this->_conn->quoteIdentifier($tableAlias) - . '.' . $this->_conn->quoteIdentifier($column) - . ' = ' . $this->_conn->quoteIdentifier($joinedTableAlias) - . '.' . $this->_conn->quoteIdentifier($column); - } - } - - return $sql; - } - - /** - * Creates the SQL snippet for the WHERE part that contains the discriminator - * column conditions. - * - * @return string The created SQL snippet. - */ - protected function _createDiscriminatorConditionSql() - { - $array = array(); - foreach ($this->_queryComponents as $componentAlias => $data) { - $sqlTableAlias = $this->getSqlTableAlias($componentAlias); - if ( ! $data['mapper'] instanceof Doctrine_Mapper_SingleTable) { - $array[$sqlTableAlias][] = array(); - } else { - $array[$sqlTableAlias][] = $data['mapper']->getDiscriminatorColumn(); - } - } - //var_dump($array); - // apply inheritance maps - $str = ''; - $c = array(); - - $index = 0; - foreach ($array as $tableAlias => $maps) { - $a = array(); - - // don't use table aliases if the query isn't a select query - if ($this->_type !== Doctrine_Query::SELECT) { - $tableAlias = ''; - } else { - $tableAlias .= '.'; - } - - foreach ($maps as $map) { - $b = array(); - foreach ($map as $field => $value) { - $identifier = $this->_conn->quoteIdentifier($tableAlias . $field); - - if ($index > 0) { - $b[] = '(' . $identifier . ' = ' . $this->_conn->quote($value) - . ' OR ' . $identifier . ' IS NULL)'; - } else { - $b[] = $identifier . ' = ' . $this->_conn->quote($value); - } - } - - if ( ! empty($b)) { - $a[] = implode(' AND ', $b); - } - } - - if ( ! empty($a)) { - $c[] = implode(' AND ', $a); - } - $index++; - } - - $str .= implode(' AND ', $c); - - return $str; - } - - /** - * getSqlTableAlias - * some database such as Oracle need the identifier lengths to be < ~30 chars - * hence Doctrine creates as short identifier aliases as possible - * - * this method is used for the creation of short table aliases, its also - * smart enough to check if an alias already exists for given component (componentAlias) - * - * @param string $componentAlias the alias for the query component to search table alias for - * @param string $tableName the table name from which the table alias is being created - * @return string the generated / fetched short alias - */ - public function getSqlTableAlias($componentAlias, $tableName = null) - { - $alias = array_search($componentAlias, $this->_tableAliasMap); - - if ($alias !== false) { - return $alias; - } - - if ($tableName === null) { - throw new Doctrine_Query_Exception("Couldn't get short alias for " . $componentAlias); - } - - return $this->generateTableAlias($componentAlias, $tableName); - } - - /** - * generateNewSqlTableAlias - * generates a new alias from given table alias - * - * @param string $tableAlias table alias from which to generate the new alias from - * @return string the created table alias - */ - public function generateNewSqlTableAlias($oldAlias) - { - if (isset($this->_tableAliasMap[$oldAlias])) { - // generate a new alias - $name = substr($oldAlias, 0, 1); - $i = ((int) substr($oldAlias, 1)); - - if ($i == 0) { - $i = 1; - } - - $newIndex = ($this->_tableAliasSeeds[$name] + $i); - - return $name . $newIndex; - } - - return $oldAlias; - } - - /** - * getSqlTableAliasSeed - * returns the alias seed for given table alias - * - * @param string $tableAlias table alias that identifies the alias seed - * @return integer table alias seed - */ - public function getSqlTableAliasSeed($sqlTableAlias) - { - if ( ! isset($this->_tableAliasSeeds[$sqlTableAlias])) { - return 0; - } - return $this->_tableAliasSeeds[$sqlTableAlias]; - } - - - /** - * copyAliases - * copy aliases from another Hydrate object - * - * this method is needed by DQL subqueries which need the aliases - * of the parent query - * - * @param Doctrine_Hydrate $query the query object from which the - * aliases are copied from - * @return Doctrine_Hydrate this object - */ - public function copyAliases(Doctrine_Query_Abstract $query) - { - $this->_tableAliasMap = $query->_tableAliasMap; - $this->_queryComponents = $query->_queryComponents; - $this->_tableAliasSeeds = $query->_tableAliasSeeds; - return $this; - } - - /** - * getRootAlias - * returns the alias of the the root component - * - * @return array - */ - public function getRootAlias() - { - if ( ! $this->_queryComponents) { - $this->getSql(); - } - reset($this->_queryComponents); - - return key($this->_queryComponents); - } - - /** - * getRootDeclaration - * returns the root declaration - * - * @return array - */ - public function getRootDeclaration() - { - $map = reset($this->_queryComponents); - return $map; - } - - /** - * getRoot - * returns the root component for this object - * - * @return Doctrine_Table root components table - */ - public function getRoot() - { - $map = reset($this->_queryComponents); - - if ( ! isset($map['table'])) { - throw new Doctrine_Query_Exception('Root component not initialized.'); - } - - return $map['table']; - } - - /** - * generateTableAlias - * generates a table alias from given table name and associates - * it with given component alias - * - * @param string $componentAlias the component alias to be associated with generated table alias - * @param string $tableName the table name from which to generate the table alias - * @return string the generated table alias - * @deprecated - */ - public function generateTableAlias($componentAlias, $tableName) - { - return $this->generateSqlTableAlias($componentAlias, $tableName); - } - - /** - * generateSqlTableAlias - * generates a table alias from given table name and associates - * it with given component alias - * - * @param string $componentAlias the component alias to be associated with generated table alias - * @param string $tableName the table name from which to generate the table alias - * @return string the generated table alias - */ - public function generateSqlTableAlias($componentAlias, $tableName) - { - $char = strtolower(substr($tableName, 0, 1)); - - $alias = $char; - - if ( ! isset($this->_tableAliasSeeds[$alias])) { - $this->_tableAliasSeeds[$alias] = 1; - } - - while (isset($this->_tableAliasMap[$alias])) { - if ( ! isset($this->_tableAliasSeeds[$alias])) { - $this->_tableAliasSeeds[$alias] = 1; - } - $alias = $char . ++$this->_tableAliasSeeds[$alias]; - } - - $this->_tableAliasMap[$alias] = $componentAlias; - - return $alias; - } - - /** - * getComponentAlias - * get component alias associated with given table alias - * - * @param string $sqlTableAlias the SQL table alias that identifies the component alias - * @return string component alias - */ - public function getComponentAlias($sqlTableAlias) - { - if ( ! isset($this->_tableAliasMap[$sqlTableAlias])) { - throw new Doctrine_Query_Exception('Unknown table alias ' . $sqlTableAlias); - } - return $this->_tableAliasMap[$sqlTableAlias]; - } - - /** - * _execute - * - * @param array $params - * @return PDOStatement The executed PDOStatement. - */ - protected function _execute($params) - { - $params = $this->_conn->convertBooleans($params); - - if ( ! $this->_view) { - if ($this->_queryCache || $this->_conn->getAttribute(Doctrine::ATTR_QUERY_CACHE)) { - $queryCacheDriver = $this->getQueryCacheDriver(); - // calculate hash for dql query - $dql = $this->getDql(); - $hash = md5($dql . 'DOCTRINE_QUERY_CACHE_SALT'); - $cached = $queryCacheDriver->fetch($hash); - if ($cached) { - $query = $this->_constructQueryFromCache($cached); - } else { - $query = $this->getSqlQuery($params); - $serializedQuery = $this->getCachedForm($query); - $queryCacheDriver->save($hash, $serializedQuery, $this->_queryCacheTTL); - } - } else { - $query = $this->getSqlQuery($params); - } - } else { - $query = $this->_view->getSelectSql(); - } - - $params = $this->convertEnums($params); - - if ($this->isLimitSubqueryUsed() && - $this->_conn->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') { - $params = array_merge($params, $params); - } - - if ($this->_type !== self::SELECT) { - return $this->_conn->exec($query, $params); - } - - $stmt = $this->_conn->execute($query, $params); - - return $stmt; - } - - /** - * execute - * executes the query and populates the data set - * - * @param string $params - * @return Doctrine_Collection the root collection - */ - public function execute($params = array(), $hydrationMode = null) - { - $params = array_merge($this->_params['join'], - $this->_params['set'], - $this->_params['where'], - $this->_params['having'], - $params); - - if ($this->_resultCache) { - $cacheDriver = $this->getResultCacheDriver(); - - $dql = $this->getDql(); - // calculate hash for dql query - $hash = md5($dql . var_export($params, true)); - - $cached = ($this->_expireResultCache) ? false : $cacheDriver->fetch($hash); - - if ($cached === false) { - // cache miss - $stmt = $this->_execute($params); - $this->_hydrator->setQueryComponents($this->_queryComponents); - $result = $this->_hydrator->hydrateResultSet($stmt, $this->_tableAliasMap, - Doctrine::HYDRATE_ARRAY); - - $cached = $this->getCachedForm($result); - $cacheDriver->save($hash, $cached, $this->_resultCacheTTL); - return $result; - } else { - return $this->_constructQueryFromCache($cached); - } - } else { - $stmt = $this->_execute($params); - - if (is_integer($stmt)) { - return $stmt; - } - - $this->_hydrator->setQueryComponents($this->_queryComponents); - return $this->_hydrator->hydrateResultSet($stmt, $this->_tableAliasMap, $hydrationMode); - } - } - - /** - * Constructs the query from the cached form. - * - * @param string The cached query, in a serialized form. - * @return array The custom component that was cached together with the essential - * query data. This can be either a result set (result caching) - * or an SQL query string (query caching). - */ - protected function _constructQueryFromCache($cached) - { - $cached = unserialize($cached); - $this->_tableAliasMap = $cached[2]; - $customComponent = $cached[0]; - - $queryComponents = array(); - $cachedComponents = $cached[1]; - foreach ($cachedComponents as $alias => $components) { - $e = explode('.', $components[0]); - if (count($e) === 1) { - $queryComponents[$alias]['mapper'] = $this->_conn->getMapper($e[0]); - $queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getTable(); - } else { - $queryComponents[$alias]['parent'] = $e[0]; - $queryComponents[$alias]['relation'] = $queryComponents[$e[0]]['table']->getRelation($e[1]); - $queryComponents[$alias]['mapper'] = $this->_conn->getMapper($queryComponents[$alias]['relation']->getForeignComponentName()); - $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]; - } - } - $this->_queryComponents = $queryComponents; - - return $customComponent; - } - - /** - * getCachedForm - * returns the cached form of this query for given resultSet - * - * @param array $resultSet - * @return string serialized string representation of this query - */ - public function getCachedForm($customComponent = null) - { - $componentInfo = array(); - - foreach ($this->getQueryComponents() as $alias => $components) { - if ( ! isset($components['parent'])) { - $componentInfo[$alias][] = $components['mapper']->getComponentName(); - //$componentInfo[$alias][] = $components['mapper']->getComponentName(); - } else { - $componentInfo[$alias][] = $components['parent'] . '.' . $components['relation']->getAlias(); - } - if (isset($components['agg'])) { - $componentInfo[$alias][] = $components['agg']; - } - if (isset($components['map'])) { - $componentInfo[$alias][] = $components['map']; - } - } - - return serialize(array($customComponent, $componentInfo, $this->getTableAliasMap())); - } - - /** - * addSelect - * adds fields to the SELECT part of the query - * - * @param string $select Query SELECT part - * @return Doctrine_Query - */ - public function addSelect($select) - { - return $this->_addDqlQueryPart('select', $select, true); - } - - /** - * addTableAlias - * adds an alias for table and associates it with given component alias - * - * @param string $componentAlias the alias for the query component associated with given tableAlias - * @param string $tableAlias the table alias to be added - * @return Doctrine_Hydrate - * @deprecated - */ - public function addTableAlias($tableAlias, $componentAlias) - { - return $this->addSqlTableAlias($tableAlias, $componentAlias); - } - - /** - * addSqlTableAlias - * adds an SQL table alias and associates it a component alias - * - * @param string $componentAlias the alias for the query component associated with given tableAlias - * @param string $tableAlias the table alias to be added - * @return Doctrine_Query_Abstract - */ - public function addSqlTableAlias($sqlTableAlias, $componentAlias) - { - $this->_tableAliasMap[$sqlTableAlias] = $componentAlias; - return $this; - } - - /** - * addFrom - * adds fields to the FROM part of the query - * - * @param string $from Query FROM part - * @return Doctrine_Query - */ - public function addFrom($from) - { - return $this->_addDqlQueryPart('from', $from, true); - } - - /** - * addWhere - * adds conditions to the WHERE part of the query - * - * @param string $where Query WHERE part - * @param mixed $params an array of parameters or a simple scalar - * @return Doctrine_Query - */ - public function addWhere($where, $params = array()) - { - if (is_array($params)) { - $this->_params['where'] = array_merge($this->_params['where'], $params); - } else { - $this->_params['where'][] = $params; - } - return $this->_addDqlQueryPart('where', $where, true); - } - - /** - * whereIn - * adds IN condition to the query WHERE part - * - * @param string $expr the operand of the IN - * @param mixed $params an array of parameters or a simple scalar - * @param boolean $not whether or not to use NOT in front of IN - * @return Doctrine_Query - */ - public function whereIn($expr, $params = array(), $not = false) - { - $params = (array) $params; - $a = array(); - foreach ($params as $k => $value) { - if ($value instanceof Doctrine_Expression) { - $value = $value->getSql(); - unset($params[$k]); - } else { - $value = '?'; - } - $a[] = $value; - } - - $this->_params['where'] = array_merge($this->_params['where'], $params); - - $where = $expr . ($not === true ? ' NOT ':'') . ' IN (' . implode(', ', $a) . ')'; - - return $this->_addDqlQueryPart('where', $where, true); - } - - /** - * whereNotIn - * adds NOT IN condition to the query WHERE part - * - * @param string $expr the operand of the NOT IN - * @param mixed $params an array of parameters or a simple scalar - * @return Doctrine_Query - */ - public function whereNotIn($expr, $params = array()) - { - return $this->whereIn($expr, $params, true); - } - - /** - * addGroupBy - * adds fields to the GROUP BY part of the query - * - * @param string $groupby Query GROUP BY part - * @return Doctrine_Query - */ - public function addGroupBy($groupby) - { - return $this->_addDqlQueryPart('groupby', $groupby, true); - } - - /** - * addHaving - * adds conditions to the HAVING part of the query - * - * @param string $having Query HAVING part - * @param mixed $params an array of parameters or a simple scalar - * @return Doctrine_Query - */ - public function addHaving($having, $params = array()) - { - if (is_array($params)) { - $this->_params['having'] = array_merge($this->_params['having'], $params); - } else { - $this->_params['having'][] = $params; - } - return $this->_addDqlQueryPart('having', $having, true); - } - - /** - * addOrderBy - * adds fields to the ORDER BY part of the query - * - * @param string $orderby Query ORDER BY part - * @return Doctrine_Query - */ - public function addOrderBy($orderby) - { - return $this->_addDqlQueryPart('orderby', $orderby, true); - } - - /** - * select - * sets the SELECT part of the query - * - * @param string $select Query SELECT part - * @return Doctrine_Query - */ - public function select($select) - { - return $this->_addDqlQueryPart('select', $select); - } - - /** - * distinct - * Makes the query SELECT DISTINCT. - * - * @param bool $flag Whether or not the SELECT is DISTINCT (default true). - * @return Doctrine_Query - */ - public function distinct($flag = true) - { - $this->_sqlParts['distinct'] = (bool) $flag; - return $this; - } - - /** - * forUpdate - * Makes the query SELECT FOR UPDATE. - * - * @param bool $flag Whether or not the SELECT is FOR UPDATE (default true). - * @return Doctrine_Query - */ - public function forUpdate($flag = true) - { - $this->_sqlParts[self::FOR_UPDATE] = (bool) $flag; - return $this; - } - - /** - * delete - * sets the query type to DELETE - * - * @return Doctrine_Query - */ - public function delete() - { - $this->_type = self::DELETE; - return $this; - } - - /** - * update - * sets the UPDATE part of the query - * - * @param string $update Query UPDATE part - * @return Doctrine_Query - */ - public function update($update) - { - $this->_type = self::UPDATE; - return $this->_addDqlQueryPart('from', $update); - } - - /** - * set - * sets the SET part of the query - * - * @param string $update Query UPDATE part - * @return Doctrine_Query - */ - public function set($key, $value, $params = null) - { - if (is_array($key)) { - foreach ($key as $k => $v) { - $this->set($k, '?', array($v)); - } - return $this; - } else { - if ($params !== null) { - if (is_array($params)) { - $this->_params['set'] = array_merge($this->_params['set'], $params); - } else { - $this->_params['set'][] = $params; - } - } - return $this->_addDqlQueryPart('set', $key . ' = ' . $value, true); - } - } - - /** - * from - * sets the FROM part of the query - * - * @param string $from Query FROM part - * @return Doctrine_Query - */ - public function from($from) - { - return $this->_addDqlQueryPart('from', $from); - } - - /** - * innerJoin - * appends an INNER JOIN to the FROM part of the query - * - * @param string $join Query INNER JOIN - * @return Doctrine_Query - */ - public function innerJoin($join, $params = array()) - { - if (is_array($params)) { - $this->_params['join'] = array_merge($this->_params['join'], $params); - } else { - $this->_params['join'][] = $params; - } - - return $this->_addDqlQueryPart('from', 'INNER JOIN ' . $join, true); - } - - /** - * leftJoin - * appends a LEFT JOIN to the FROM part of the query - * - * @param string $join Query LEFT JOIN - * @return Doctrine_Query - */ - public function leftJoin($join, $params = array()) - { - if (is_array($params)) { - $this->_params['join'] = array_merge($this->_params['join'], $params); - } else { - $this->_params['join'][] = $params; - } - - return $this->_addDqlQueryPart('from', 'LEFT JOIN ' . $join, true); - } - - /** - * groupBy - * sets the GROUP BY part of the query - * - * @param string $groupby Query GROUP BY part - * @return Doctrine_Query - */ - public function groupBy($groupby) - { - return $this->_addDqlQueryPart('groupby', $groupby); - } - - /** - * where - * sets the WHERE part of the query - * - * @param string $join Query WHERE part - * @param mixed $params an array of parameters or a simple scalar - * @return Doctrine_Query - */ - public function where($where, $params = array()) - { - $this->_params['where'] = array(); - if (is_array($params)) { - $this->_params['where'] = $params; - } else { - $this->_params['where'][] = $params; - } - - return $this->_addDqlQueryPart('where', $where); - } - - /** - * having - * sets the HAVING part of the query - * - * @param string $having Query HAVING part - * @param mixed $params an array of parameters or a simple scalar - * @return Doctrine_Query - */ - public function having($having, $params = array()) - { - $this->_params['having'] = array(); - if (is_array($params)) { - $this->_params['having'] = $params; - } else { - $this->_params['having'][] = $params; - } - - return $this->_addDqlQueryPart('having', $having); - } - - /** - * orderBy - * sets the ORDER BY part of the query - * - * @param string $orderby Query ORDER BY part - * @return Doctrine_Query - */ - public function orderBy($orderby) - { - return $this->_addDqlQueryPart('orderby', $orderby); - } - - /** - * limit - * sets the Query query limit - * - * @param integer $limit limit to be used for limiting the query results - * @return Doctrine_Query - */ - public function limit($limit) - { - return $this->_addDqlQueryPart('limit', $limit); - } - - /** - * offset - * sets the Query query offset - * - * @param integer $offset offset to be used for paginating the query - * @return Doctrine_Query - */ - public function offset($offset) - { - return $this->_addDqlQueryPart('offset', $offset); - } - - /** - * getSql - * shortcut for {@link getSqlQuery()}. - * - * @return string sql query string - */ - public function getSql() - { - return $this->getSqlQuery(); - } - - /** - * clear - * resets all the variables - * - * @return void - */ - protected function clear() - { - $this->_sqlParts = array( - 'select' => array(), - 'distinct' => false, - 'forUpdate' => false, - 'from' => array(), - 'set' => array(), - 'join' => array(), - 'where' => array(), - 'groupby' => array(), - 'having' => array(), - 'orderby' => array(), - 'limit' => false, - 'offset' => false, - ); - } - - public function setHydrationMode($hydrationMode) - { - $this->_hydrator->setHydrationMode($hydrationMode); - return $this; - } - - /** - * @deprecated - */ - public function getAliasMap() - { - return $this->_queryComponents; - } - - /** - * Gets the components of this query. - */ - public function getQueryComponents() - { - return $this->_queryComponents; - } - - /** - * Return the SQL parts. - * - * @return array The parts - * @deprecated - */ - public function getParts() - { - return $this->getSqlParts(); - } - - /** - * Return the SQL parts. - * - * @return array The parts - */ - public function getSqlParts() - { - return $this->_sqlParts; - } - - /** - * getType - * - * returns the type of this query object - * by default the type is Doctrine_Query_Abstract::SELECT but if update() or delete() - * are being called the type is Doctrine_Query_Abstract::UPDATE and Doctrine_Query_Abstract::DELETE, - * respectively - * - * @see Doctrine_Query_Abstract::SELECT - * @see Doctrine_Query_Abstract::UPDATE - * @see Doctrine_Query_Abstract::DELETE - * - * @return integer return the query type - */ - public function getType() - { - return $this->_type; - } - - /** - * useCache - * - * @param Doctrine_Cache_Interface|bool $driver cache driver - * @param integer $timeToLive how long the cache entry is valid - * @return Doctrine_Hydrate this object - * @deprecated Use useResultCache() - */ - public function useCache($driver = true, $timeToLive = null) - { - return $this->useResultCache($driver, $timeToLive); - } - - /** - * useResultCache - * - * @param Doctrine_Cache_Interface|bool $driver cache driver - * @param integer $timeToLive how long the cache entry is valid - * @return Doctrine_Hydrate this object - */ - public function useResultCache($driver = true, $timeToLive = null) - { - if ($driver !== null && $driver !== true && ! ($driver instanceOf Doctrine_Cache_Interface)){ - $msg = 'First argument should be instance of Doctrine_Cache_Interface or null.'; - throw new Doctrine_Query_Exception($msg); - } - $this->_resultCache = $driver; - - return $this->setResultCacheLifeSpan($timeToLive); - } - - /** - * useQueryCache - * - * @param Doctrine_Cache_Interface|bool $driver cache driver - * @param integer $timeToLive how long the cache entry is valid - * @return Doctrine_Hydrate this object - */ - public function useQueryCache(Doctrine_Cache_Interface $driver, $timeToLive = null) - { - $this->_queryCache = $driver; - return $this->setQueryCacheLifeSpan($timeToLive); - } - - /** - * expireCache - * - * @param boolean $expire whether or not to force cache expiration - * @return Doctrine_Hydrate this object - * @deprecated Use expireResultCache() - */ - public function expireCache($expire = true) - { - return $this->expireResultCache($expire); - } - - /** - * expireCache - * - * @param boolean $expire whether or not to force cache expiration - * @return Doctrine_Hydrate this object - */ - public function expireResultCache($expire = true) - { - $this->_expireResultCache = true; - return $this; - } - - /** - * expireQueryCache - * - * @param boolean $expire whether or not to force cache expiration - * @return Doctrine_Hydrate this object - */ - public function expireQueryCache($expire = true) - { - $this->_expireQueryCache = true; - return $this; - } - - /** - * setCacheLifeSpan - * - * @param integer $timeToLive how long the cache entry is valid - * @return Doctrine_Hydrate this object - * @deprecated Use setResultCacheLifeSpan() - */ - public function setCacheLifeSpan($timeToLive) - { - return $this->setResultCacheLifeSpan($timeToLive); - } - - /** - * setResultCacheLifeSpan - * - * @param integer $timeToLive how long the cache entry is valid - * @return Doctrine_Hydrate this object - */ - public function setResultCacheLifeSpan($timeToLive) - { - if ($timeToLive !== null) { - $timeToLive = (int) $timeToLive; - } - $this->_resultCacheTTL = $timeToLive; - - return $this; - } - - /** - * setQueryCacheLifeSpan - * - * @param integer $timeToLive how long the cache entry is valid - * @return Doctrine_Hydrate this object - */ - public function setQueryCacheLifeSpan($timeToLive) - { - if ($timeToLive !== null) { - $timeToLive = (int) $timeToLive; - } - $this->_queryCacheTTL = $timeToLive; - - return $this; - } - - /** - * getCacheDriver - * returns the cache driver associated with this object - * - * @return Doctrine_Cache_Interface|boolean|null cache driver - * @deprecated Use getResultCacheDriver() - */ - public function getCacheDriver() - { - return $this->getResultCacheDriver(); - } - - /** - * getResultCacheDriver - * returns the cache driver used for caching result sets - * - * @return Doctrine_Cache_Interface|boolean|null cache driver - */ - public function getResultCacheDriver() - { - if ($this->_resultCache instanceof Doctrine_Cache_Interface) { - return $this->_resultCache; - } else { - return $this->_conn->getResultCacheDriver(); - } - } - - /** - * getQueryCacheDriver - * returns the cache driver used for caching queries - * - * @return Doctrine_Cache_Interface|boolean|null cache driver - */ - public function getQueryCacheDriver() - { - if ($this->_queryCache instanceof Doctrine_Cache_Interface) { - return $this->_queryCache; - } else { - return $this->_conn->getQueryCacheDriver(); - } - } - - /** - * getConnection - * - * @return Doctrine_Connection - */ - public function getConnection() - { - return $this->_conn; - } - - /** - * Adds a DQL part to the internal parts collection. - * - * @param string $queryPartName The name of the query part. - * @param string $queryPart The actual query part to add. - * @param boolean $append Whether to append $queryPart to already existing - * parts under the same $queryPartName. Defaults to FALSE - * (previously added parts with the same name get overridden). - */ - protected function _addDqlQueryPart($queryPartName, $queryPart, $append = false) - { - if ($append) { - $this->_dqlParts[$queryPartName][] = $queryPart; - } else { - $this->_dqlParts[$queryPartName] = array($queryPart); - } - - $this->_state = Doctrine_Query::STATE_DIRTY; - return $this; - } - - /** - * Gets the SQL query that corresponds to this query object. - * The returned SQL syntax depends on the connection driver that is used - * by this query object at the time of this method call. - * - * @param array $params - */ - abstract public function getSqlQuery($params = array()); - - /** - * parseDqlQuery - * parses a dql query - * - * @param string $query query to be parsed - * @return Doctrine_Query_Abstract this object - */ - abstract public function parseDqlQuery($query); - - /** - * @deprecated - */ - public function parseQuery($query) - { - return $this->parseDqlQuery($query); - } - - /** - * @deprecated - */ - public function getQuery($params = array()) - { - return $this->getSqlQuery($params); - } -} diff --git a/draft/Doctrine/Query/Parser.php b/draft/Doctrine/Query/Parser.php deleted file mode 100644 index 94e4abdc5..000000000 --- a/draft/Doctrine/Query/Parser.php +++ /dev/null @@ -1,226 +0,0 @@ -. - */ - -/** - * 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 Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.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; - - /** - * A scanner object. - * - * @var Doctrine_Query_Scanner - */ - protected $_scanner; - - /** - * An array of production objects with their names as keys. - * - * @var array - */ - protected $_productions = array(); - - /** - * The next token in the query string. - * - * @var Doctrine_Query_Token - */ - public $lookahead; - - /** - * Array containing syntax and semantical errors detected in the query - * string during parsing process. - * - * @var array - */ - protected $_errors = array(); - - /** - * The number of tokens read since last error in the input string - * - * @var int - */ - protected $_errorDistance = self::MIN_ERROR_DISTANCE; - - /** - * A query printer object used to print a parse tree from the input string - * for debugging purposes. - * - * @var Doctrine_Query_Printer - */ - protected $_printer; - - /** - * The connection object used by this query. - * - * @var Doctrine_Connection - */ - protected $_conn; - - /** - * Creates a new query parser object. - * - * @param string $input query string to be parsed - * @param Doctrine_Connection The connection object the query will use. - */ - public function __construct($input, Doctrine_Connection $conn = null) - { - $this->_scanner = new Doctrine_Query_Scanner($input); - $this->_printer = new Doctrine_Query_Printer(true); - - if ($conn === null) { - $conn = Doctrine_Manager::getInstance()->getCurrentConnection(); - } - - $this->_conn = $conn; - } - - /** - * Returns the connection object used by the query. - * - * @return Doctrine_Connection - */ - public function getConnection() - { - return $this->_conn; - } - - /** - * Returns a production object with the given name. - * - * @param string $name production name - * @return Doctrine_Query_Production - */ - public function getProduction($name) - { - if ( ! isset($this->_productions[$name])) { - $class = 'Doctrine_Query_Production_' . $name; - $this->_productions[$name] = new $class($this); - } - - return $this->_productions[$name]; - } - - /** - * 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 - */ - public function match($token) - { - if (is_string($token)) { - $isMatch = ($this->lookahead['value'] === $token); - } else { - $isMatch = ($this->lookahead['type'] === $token); - } - - if ($isMatch) { - $this->_printer->println($this->lookahead['value']); - $this->lookahead = $this->_scanner->next(); - $this->_errorDistance++; - } else { - $this->logError(); - } - } - - public function logError($message = '') - { - if ($message === '') { - if ($this->lookahead === null) { - $message = 'Unexpected end of string.'; - } else { - $message = 'Unexpected "' . $this->lookahead['value'] . '"'; - } - } - - if ($this->_errorDistance >= self::MIN_ERROR_DISTANCE) { - if ($this->lookahead !== null) { - $message .= ' at position ' . $this->lookahead['position']; - } - $this->_errors[] = $message; - } - - $this->_errorDistance = 0; - } - - /** - * Returns the scanner object associated with this object. - * - * @return Doctrine_Query_Scanner - */ - public function getScanner() - { - return $this->_scanner; - } - - /** - * Returns the parse tree printer object associated with this object. - * - * @return Doctrine_Query_Printer - */ - public function getPrinter() - { - return $this->_printer; - } - - /** - * Parses a query string. - * - * @throws Doctrine_Query_Parser_Exception if errors were detected in the query string - */ - public function parse() - { - $this->lookahead = $this->_scanner->next(); - - $this->getProduction('QueryLanguage')->execute(); - - if ($this->lookahead !== null) { - $this->logError('End of string expected'); - } - - if (count($this->_errors)) { - $msg = 'Errors were detected during the query parsing (' - . implode('; ', $this->_errors) . ').'; - throw new Doctrine_Query_Parser_Exception($msg); - } - } -} diff --git a/draft/Doctrine/Query/Parser/Exception.php b/draft/Doctrine/Query/Parser/Exception.php deleted file mode 100644 index 9e5c449a3..000000000 --- a/draft/Doctrine/Query/Parser/Exception.php +++ /dev/null @@ -1,35 +0,0 @@ -. - */ - -/** - * Doctrine_Query_Parser_Exception - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @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 -{ -} diff --git a/draft/Doctrine/Query/Printer.php b/draft/Doctrine/Query/Printer.php deleted file mode 100644 index d68cc5fc6..000000000 --- a/draft/Doctrine/Query/Printer.php +++ /dev/null @@ -1,95 +0,0 @@ -. - */ - -/** - * A parse tree printer for Doctrine Query Language parser. - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.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"; - } - } -} diff --git a/draft/Doctrine/Query/Production.php b/draft/Doctrine/Query/Production.php deleted file mode 100644 index 5f3dcd43f..000000000 --- a/draft/Doctrine/Query/Production.php +++ /dev/null @@ -1,98 +0,0 @@ -. - */ - -/** - * An abstract base class for the productions of the Doctrine Query Language - * context-free grammar. - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -abstract class Doctrine_Query_Production -{ - /** - * a parser object - * - * @var Doctrine_Query_Parser - */ - protected $_parser; - - /** - * Creates a new production object. - * - * @param Doctrine_Query_Parser $parser a parser object - */ - public function __construct(Doctrine_Query_Parser $parser) - { - $this->_parser = $parser; - } - - 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 a production with specified name and parameters. - * - * @param string $name production name - * @param array $params an associative array containing parameter names and - * their values - * @return mixed - */ - public function __call($method, $args) - { - $this->_parser->getPrinter()->startProduction($method); - $retval = $this->_parser->getProduction($method)->execute($args); - $this->_parser->getPrinter()->endProduction(); - - return $retval; - } - - /** - * Executes this production using the specified parameters. - * - * @param array $params an associative array containing parameter names and - * their values - * @return mixed - */ - abstract public function execute(array $params = array()); -} diff --git a/draft/Doctrine/Query/Production/AggregateExpression.php b/draft/Doctrine/Query/Production/AggregateExpression.php deleted file mode 100644 index 03394294b..000000000 --- a/draft/Doctrine/Query/Production/AggregateExpression.php +++ /dev/null @@ -1,63 +0,0 @@ -. - */ - -/** - * AggregateExpression = - * ("AVG" | "MAX" | "MIN" | "SUM" | "COUNT") "(" ["DISTINCT"] Expression ")" - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_AggregateExpression extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $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']); - break; - - default: - $this->_parser->logError(); - } - - $this->_parser->match('('); - - if ($this->_isNextToken(Doctrine_Query_Token::T_DISTINCT)) { - $this->_parser->match(Doctrine_Query_Token::T_DISTINCT); - } - - $this->Expression(); - - $this->_parser->match(')'); - } -} diff --git a/draft/Doctrine/Query/Production/Atom.php b/draft/Doctrine/Query/Production/Atom.php deleted file mode 100644 index 68e30e617..000000000 --- a/draft/Doctrine/Query/Production/Atom.php +++ /dev/null @@ -1,54 +0,0 @@ -. - */ - -/** - * Atom = string | integer | float | input_parameter - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @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 -{ - public function execute(array $params = array()) - { - switch ($this->_parser->lookahead['type']) { - case Doctrine_Query_Token::T_STRING: - $this->_parser->match(Doctrine_Query_Token::T_STRING); - break; - case Doctrine_Query_Token::T_INTEGER: - $this->_parser->match(Doctrine_Query_Token::T_INTEGER); - break; - case Doctrine_Query_Token::T_FLOAT: - $this->_parser->match(Doctrine_Query_Token::T_FLOAT); - break; - case Doctrine_Query_Token::T_INPUT_PARAMETER: - $this->_parser->match(Doctrine_Query_Token::T_INPUT_PARAMETER); - break; - default: - $this->_parser->syntaxError(); - } - } -} diff --git a/draft/Doctrine/Query/Production/BetweenExpression.php b/draft/Doctrine/Query/Production/BetweenExpression.php deleted file mode 100644 index 50c1c9bf6..000000000 --- a/draft/Doctrine/Query/Production/BetweenExpression.php +++ /dev/null @@ -1,46 +0,0 @@ -. - */ - -/** - * BetweenExpression = ["NOT"] "BETWEEN" Expression "AND" Expression - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_BetweenExpression extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) { - $this->_parser->match(Doctrine_Query_Token::T_NOT); - } - - $this->_parser->match(Doctrine_Query_Token::T_BETWEEN); - $this->Expression(); - $this->_parser->match(Doctrine_Query_Token::T_AND); - $this->Expression(); - } -} diff --git a/draft/Doctrine/Query/Production/ComparisonExpression.php b/draft/Doctrine/Query/Production/ComparisonExpression.php deleted file mode 100644 index b7462149d..000000000 --- a/draft/Doctrine/Query/Production/ComparisonExpression.php +++ /dev/null @@ -1,55 +0,0 @@ -. - */ - -/** - * ComparisonExpression = ComparisonOperator ( QuantifiedExpression | Expression | "(" Subselect ")" ) - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_ComparisonExpression extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->ComparisonOperator(); - - if ($this->_isSubselect()) { - $this->_parser->match('('); - $this->Subselect(); - $this->_parser->match(')'); - } 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->QuantifiedExpression(); - break; - default: - $this->Expression(); - } - } - } -} diff --git a/draft/Doctrine/Query/Production/ComparisonOperator.php b/draft/Doctrine/Query/Production/ComparisonOperator.php deleted file mode 100644 index 4cd60f82e..000000000 --- a/draft/Doctrine/Query/Production/ComparisonOperator.php +++ /dev/null @@ -1,59 +0,0 @@ -. - */ - -/** - * ComparisonOperator = "=" | "<" | "<=" | "<>" | ">" | ">=" - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_ComparisonOperator extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - switch ($this->_parser->lookahead['value']) { - case '=': - $this->_parser->match('='); - break; - case '<': - $this->_parser->match('<'); - if ($this->_isNextToken('=')) { - $this->_parser->match('='); - } elseif ($this->_isNextToken('>')) { - $this->_parser->match('>'); - } - break; - case '>': - $this->_parser->match('>'); - if ($this->_isNextToken('=')) { - $this->_parser->match('='); - } - break; - default: - $this->_parser->logError(); - } - } -} diff --git a/draft/Doctrine/Query/Production/ConditionalExpression.php b/draft/Doctrine/Query/Production/ConditionalExpression.php deleted file mode 100644 index ac1246164..000000000 --- a/draft/Doctrine/Query/Production/ConditionalExpression.php +++ /dev/null @@ -1,44 +0,0 @@ -. - */ - -/** - * ConditionalExpression = ConditionalTerm {"OR" ConditionalTerm} - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_ConditionalExpression extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->ConditionalTerm(); - - while ($this->_isNextToken(Doctrine_Query_Token::T_OR)) { - $this->_parser->match(Doctrine_Query_Token::T_OR); - $this->ConditionalTerm(); - } - } -} diff --git a/draft/Doctrine/Query/Production/ConditionalFactor.php b/draft/Doctrine/Query/Production/ConditionalFactor.php deleted file mode 100644 index 464867b08..000000000 --- a/draft/Doctrine/Query/Production/ConditionalFactor.php +++ /dev/null @@ -1,43 +0,0 @@ -. - */ - -/** - * ConditionalFactor = ["NOT"] ConditionalPrimary - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_ConditionalFactor extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) { - $this->_parser->match(Doctrine_Query_Token::T_NOT); - } - - $this->ConditionalPrimary(); - } -} diff --git a/draft/Doctrine/Query/Production/ConditionalPrimary.php b/draft/Doctrine/Query/Production/ConditionalPrimary.php deleted file mode 100644 index 9cde387ab..000000000 --- a/draft/Doctrine/Query/Production/ConditionalPrimary.php +++ /dev/null @@ -1,88 +0,0 @@ -. - */ - -/** - * ConditionalPrimary = SimpleConditionalExpression | "(" ConditionalExpression ")" - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_ConditionalPrimary extends Doctrine_Query_Production -{ - private 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 '>': - return true; - } - break; - } - } - } - - return false; - } - - public function execute(array $params = array()) - { - if ($this->_isConditionalExpression()) { - $this->_parser->match('('); - $this->ConditionalExpression(); - $this->_parser->match(')'); - } else { - $this->SimpleConditionalExpression(); - } - } -} diff --git a/draft/Doctrine/Query/Production/ConditionalTerm.php b/draft/Doctrine/Query/Production/ConditionalTerm.php deleted file mode 100644 index 88312ddf7..000000000 --- a/draft/Doctrine/Query/Production/ConditionalTerm.php +++ /dev/null @@ -1,44 +0,0 @@ -. - */ - -/** - * ConditionalTerm = ConditionalFactor {"AND" ConditionalFactor} - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_ConditionalTerm extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->ConditionalFactor(); - - while ($this->_isNextToken(Doctrine_Query_Token::T_AND)) { - $this->_parser->match(Doctrine_Query_Token::T_AND); - $this->ConditionalFactor(); - } - } -} diff --git a/draft/Doctrine/Query/Production/DeleteClause.php b/draft/Doctrine/Query/Production/DeleteClause.php deleted file mode 100644 index 3542a6dc7..000000000 --- a/draft/Doctrine/Query/Production/DeleteClause.php +++ /dev/null @@ -1,41 +0,0 @@ -. - */ - -/** - * DeleteClause = "DELETE" "FROM" RangeVariableDeclaration - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_DeleteClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_DELETE); - $this->_parser->match(Doctrine_Query_Token::T_FROM); - $this->RangeVariableDeclaration(); - } -} diff --git a/draft/Doctrine/Query/Production/DeleteStatement.php b/draft/Doctrine/Query/Production/DeleteStatement.php deleted file mode 100644 index 71f60490b..000000000 --- a/draft/Doctrine/Query/Production/DeleteStatement.php +++ /dev/null @@ -1,55 +0,0 @@ -. - */ - -/** - * DeleteStatement = DeleteClause [WhereClause] [OrderByClause] [LimitClause] [OffsetClause] - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_DeleteStatement extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->DeleteClause(); - - if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) { - $this->WhereClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_ORDER)) { - $this->OrderByClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_LIMIT)) { - $this->LimitClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_OFFSET)) { - $this->OffsetClause(); - } - } -} diff --git a/draft/Doctrine/Query/Production/ExistsExpression.php b/draft/Doctrine/Query/Production/ExistsExpression.php deleted file mode 100644 index 0bc715c2e..000000000 --- a/draft/Doctrine/Query/Production/ExistsExpression.php +++ /dev/null @@ -1,43 +0,0 @@ -. - */ - -/** - * ExistsExpression = "EXISTS" "(" Subselect ")" - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_ExistsExpression extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_EXISTS); - - $this->_parser->match('('); - $this->Subselect(); - $this->_parser->match(')'); - } -} diff --git a/draft/Doctrine/Query/Production/Expression.php b/draft/Doctrine/Query/Production/Expression.php deleted file mode 100644 index ee309f4a7..000000000 --- a/draft/Doctrine/Query/Production/Expression.php +++ /dev/null @@ -1,48 +0,0 @@ -. - */ - -/** - * Expression = Term {("+" | "-") Term} - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_Expression extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->Term(); - - while ($this->_isNextToken('+') || $this->_isNextToken('-')) { - if ($this->_isNextToken('+')) { - $this->_parser->match('+'); - } else{ - $this->_parser->match('-'); - } - $this->Term(); - } - } -} diff --git a/draft/Doctrine/Query/Production/Factor.php b/draft/Doctrine/Query/Production/Factor.php deleted file mode 100644 index 7beb75a40..000000000 --- a/draft/Doctrine/Query/Production/Factor.php +++ /dev/null @@ -1,45 +0,0 @@ -. - */ - -/** - * Factor = [("+" | "-")] Primary - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_Factor extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - if ($this->_isNextToken('+')) { - $this->_parser->match('+'); - } elseif ($this->_isNextToken('-')) { - $this->_parser->match('-'); - } - - $this->Primary(); - } -} diff --git a/draft/Doctrine/Query/Production/FromClause.php b/draft/Doctrine/Query/Production/FromClause.php deleted file mode 100644 index 384a5123f..000000000 --- a/draft/Doctrine/Query/Production/FromClause.php +++ /dev/null @@ -1,46 +0,0 @@ -. - */ - -/** - * FromClause = "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration} - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_FromClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_FROM); - - $this->IdentificationVariableDeclaration(); - - while ($this->_isNextToken(',')) { - $this->_parser->match(','); - $this->IdentificationVariableDeclaration(); - } - } -} diff --git a/draft/Doctrine/Query/Production/Function.php b/draft/Doctrine/Query/Production/Function.php deleted file mode 100644 index 883b8d2b4..000000000 --- a/draft/Doctrine/Query/Production/Function.php +++ /dev/null @@ -1,51 +0,0 @@ -. - */ - -/** - * Function = identifier "(" [Expression {"," Expression}] ")" - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_Function extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER); - - $this->_parser->match('('); - - if ( ! $this->_isNextToken(')')) { - $this->Expression(); - while ($this->_isNextToken(',')) { - $this->_parser->match(','); - $this->Expression(); - } - } - - $this->_parser->match(')'); - } -} diff --git a/draft/Doctrine/Query/Production/GroupByClause.php b/draft/Doctrine/Query/Production/GroupByClause.php deleted file mode 100644 index 64d72e429..000000000 --- a/draft/Doctrine/Query/Production/GroupByClause.php +++ /dev/null @@ -1,47 +0,0 @@ -. - */ - -/** - * GroupByClause = "GROUP" "BY" GroupByItem {"," GroupByItem} - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_GroupByClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_GROUP); - $this->_parser->match(Doctrine_Query_Token::T_BY); - - $this->GroupByItem(); - - while ($this->_isNextToken(',')) { - $this->_parser->match(','); - $this->GroupByItem(); - } - } -} diff --git a/draft/Doctrine/Query/Production/GroupByItem.php b/draft/Doctrine/Query/Production/GroupByItem.php deleted file mode 100644 index 336d8f493..000000000 --- a/draft/Doctrine/Query/Production/GroupByItem.php +++ /dev/null @@ -1,39 +0,0 @@ -. - */ - -/** - * OrderByItem = PathExpression - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_GroupByItem extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->PathExpression(); - } -} diff --git a/draft/Doctrine/Query/Production/HavingClause.php b/draft/Doctrine/Query/Production/HavingClause.php deleted file mode 100644 index b28df6837..000000000 --- a/draft/Doctrine/Query/Production/HavingClause.php +++ /dev/null @@ -1,41 +0,0 @@ -. - */ - -/** - * HavingClause = "HAVING" ConditionalExpression - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_HavingClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_HAVING); - - $this->ConditionalExpression(); - } -} diff --git a/draft/Doctrine/Query/Production/IdentificationVariable.php b/draft/Doctrine/Query/Production/IdentificationVariable.php deleted file mode 100644 index b92865d1e..000000000 --- a/draft/Doctrine/Query/Production/IdentificationVariable.php +++ /dev/null @@ -1,48 +0,0 @@ -. - */ - -/** - * IdentificationVariable = identifier - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_IdentificationVariable extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $token = $this->_parser->lookahead; - - $this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER); - - /* - if ( ! isValidIdentificationVariable($token['value'])) { - $this->error('"' . $name . '" is not a identification variable.'); - } - */ - return $token; - } -} diff --git a/draft/Doctrine/Query/Production/IdentificationVariableDeclaration.php b/draft/Doctrine/Query/Production/IdentificationVariableDeclaration.php deleted file mode 100644 index df093c542..000000000 --- a/draft/Doctrine/Query/Production/IdentificationVariableDeclaration.php +++ /dev/null @@ -1,54 +0,0 @@ -. - */ - -/** - * IdentificationVariableDeclaration = RangeVariableDeclaration {Join} - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_IdentificationVariableDeclaration extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $rangeVarDecl = $this->RangeVariableDeclaration(); - - if ($this->_isNextToken(Doctrine_Query_Token::T_INDEX)) { - $this->IndexBy(); - } - - while ($this->_isNextToken(Doctrine_Query_Token::T_LEFT) || - $this->_isNextToken(Doctrine_Query_Token::T_INNER) || - $this->_isNextToken(Doctrine_Query_Token::T_JOIN)) { - - $this->Join(); - - if ($this->_isNextToken(Doctrine_Query_Token::T_INDEX)) { - $this->IndexBy(); - } - } - } -} diff --git a/draft/Doctrine/Query/Production/InExpression.php b/draft/Doctrine/Query/Production/InExpression.php deleted file mode 100644 index 20ac38c93..000000000 --- a/draft/Doctrine/Query/Production/InExpression.php +++ /dev/null @@ -1,57 +0,0 @@ -. - */ - -/** - * InExpression = ["NOT"] "IN" "(" (Atom {"," Atom} | Subselect) ")" - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_InExpression extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) { - $this->_parser->match(Doctrine_Query_Token::T_NOT); - } - - $this->_parser->match(Doctrine_Query_Token::T_IN); - - $this->_parser->match('('); - - if ($this->_isNextToken(Doctrine_Query_Token::T_SELECT)) { - $this->Subselect(); - } else { - $this->Atom(); - while ($this->_isNextToken(',')) { - $this->_parser->match(','); - $this->Atom(); - } - } - - $this->_parser->match(')'); - } -} diff --git a/draft/Doctrine/Query/Production/IndexBy.php b/draft/Doctrine/Query/Production/IndexBy.php deleted file mode 100644 index 3c5f13ee6..000000000 --- a/draft/Doctrine/Query/Production/IndexBy.php +++ /dev/null @@ -1,41 +0,0 @@ -. - */ - -/** - * IndexBy = "INDEX" "BY" PathExpression - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_IndexBy extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_INDEX); - $this->_parser->match(Doctrine_Query_Token::T_BY); - $this->PathExpression(); - } -} diff --git a/draft/Doctrine/Query/Production/Join.php b/draft/Doctrine/Query/Production/Join.php deleted file mode 100644 index 1d70f7aeb..000000000 --- a/draft/Doctrine/Query/Production/Join.php +++ /dev/null @@ -1,55 +0,0 @@ -. - */ - -/** - * Join = ["LEFT" | "INNER"] "JOIN" RangeVariableDeclaration [("ON" | "WITH") ConditionalExpression] - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_Join extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - if ($this->_isNextToken(Doctrine_Query_Token::T_LEFT)) { - $this->_parser->match(Doctrine_Query_Token::T_LEFT); - } elseif ($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(); - - if ($this->_isNextToken(Doctrine_Query_Token::T_ON)) { - $this->_parser->match(Doctrine_Query_Token::T_ON); - $this->ConditionalExpression(); - } elseif ($this->_isNextToken(Doctrine_Query_Token::T_WITH)) { - $this->_parser->match(Doctrine_Query_Token::T_WITH); - $this->ConditionalExpression(); - } - } -} diff --git a/draft/Doctrine/Query/Production/LimitClause.php b/draft/Doctrine/Query/Production/LimitClause.php deleted file mode 100644 index f680ecb6b..000000000 --- a/draft/Doctrine/Query/Production/LimitClause.php +++ /dev/null @@ -1,40 +0,0 @@ -. - */ - -/** - * LimitClause = "LIMIT" integer - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_LimitClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_LIMIT); - $this->_parser->match(Doctrine_Query_Token::T_INTEGER); - } -} diff --git a/draft/Doctrine/Query/Production/OffsetClause.php b/draft/Doctrine/Query/Production/OffsetClause.php deleted file mode 100644 index 3b894ce90..000000000 --- a/draft/Doctrine/Query/Production/OffsetClause.php +++ /dev/null @@ -1,40 +0,0 @@ -. - */ - -/** - * OffsetClause = "OFFSET" integer - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_OffsetClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_OFFSET); - $this->_parser->match(Doctrine_Query_Token::T_INTEGER); - } -} diff --git a/draft/Doctrine/Query/Production/OrderByClause.php b/draft/Doctrine/Query/Production/OrderByClause.php deleted file mode 100644 index 63b72c5b1..000000000 --- a/draft/Doctrine/Query/Production/OrderByClause.php +++ /dev/null @@ -1,47 +0,0 @@ -. - */ - -/** - * OrderByClause = "ORDER" "BY" OrderByItem {"," OrderByItem} - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_OrderByClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_ORDER); - $this->_parser->match(Doctrine_Query_Token::T_BY); - - $this->OrderByItem(); - - while ($this->_isNextToken(',')) { - $this->_parser->match(','); - $this->OrderByItem(); - } - } -} diff --git a/draft/Doctrine/Query/Production/OrderByItem.php b/draft/Doctrine/Query/Production/OrderByItem.php deleted file mode 100644 index ff2b6fca4..000000000 --- a/draft/Doctrine/Query/Production/OrderByItem.php +++ /dev/null @@ -1,45 +0,0 @@ -. - */ - -/** - * OrderByItem = Expression ["ASC" | "DESC"] - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_OrderByItem extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->Expression(); - - 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); - } - } -} diff --git a/draft/Doctrine/Query/Production/PathExpression.php b/draft/Doctrine/Query/Production/PathExpression.php deleted file mode 100644 index 282ac0e71..000000000 --- a/draft/Doctrine/Query/Production/PathExpression.php +++ /dev/null @@ -1,44 +0,0 @@ -. - */ - -/** - * PathExpression = identifier { "." identifier } - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_PathExpression extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER); - - while ($this->_isNextToken('.')) { - $this->_parser->match('.'); - $this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER); - } - } -} diff --git a/draft/Doctrine/Query/Production/PathExpressionEndingWithAsterisk.php b/draft/Doctrine/Query/Production/PathExpressionEndingWithAsterisk.php deleted file mode 100644 index 9744bb74d..000000000 --- a/draft/Doctrine/Query/Production/PathExpressionEndingWithAsterisk.php +++ /dev/null @@ -1,44 +0,0 @@ -. - */ - -/** - * PathExpressionEndingWithAsterisk = {identifier "."} "*" - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_PathExpressionEndingWithAsterisk extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - while ($this->_isNextToken(Doctrine_Query_Token::T_IDENTIFIER)) { - $this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER); - $this->_parser->match('.'); - } - - $this->_parser->match('*'); - } -} diff --git a/draft/Doctrine/Query/Production/Primary.php b/draft/Doctrine/Query/Production/Primary.php deleted file mode 100644 index 0a755ef98..000000000 --- a/draft/Doctrine/Query/Production/Primary.php +++ /dev/null @@ -1,70 +0,0 @@ -. - */ - -/** - * Primary = PathExpression | Atom | "(" Expression ")" | Function | - * AggregateExpression - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_Primary extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - switch ($this->_parser->lookahead['type']) { - case Doctrine_Query_Token::T_IDENTIFIER: - if ($this->_isFunction()) { - $this->Function(); - } else { - $this->PathExpression(); - } - 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: - $this->Atom(); - 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: - $this->AggregateExpression(); - break; - case Doctrine_Query_Token::T_NONE: - if ($this->_isNextToken('(')) { - $this->_parser->match('('); - $this->Expression(); - $this->_parser->match(')'); - break; - } - default: - $this->_parser->logError(); - } - } -} diff --git a/draft/Doctrine/Query/Production/QuantifiedExpression.php b/draft/Doctrine/Query/Production/QuantifiedExpression.php deleted file mode 100644 index a7cfdb927..000000000 --- a/draft/Doctrine/Query/Production/QuantifiedExpression.php +++ /dev/null @@ -1,55 +0,0 @@ -. - */ - -/** - * QuantifiedExpression = ("ALL" | "ANY" | "SOME") "(" Subselect ")" - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_QuantifiedExpression extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - 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(); - } - - $this->_parser->match('('); - $this->Subselect(); - $this->_parser->match(')'); - } -} diff --git a/draft/Doctrine/Query/Production/QueryLanguage.php b/draft/Doctrine/Query/Production/QueryLanguage.php deleted file mode 100644 index f5565a5cf..000000000 --- a/draft/Doctrine/Query/Production/QueryLanguage.php +++ /dev/null @@ -1,52 +0,0 @@ -. - */ - -/** - * QueryLanguage = SelectStatement | UpdateStatement | DeleteStatement - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_QueryLanguage extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - switch ($this->_parser->lookahead['type']) { - case Doctrine_Query_Token::T_SELECT: - case Doctrine_Query_Token::T_FROM: - $this->SelectStatement(); - break; - case Doctrine_Query_Token::T_UPDATE: - $this->UpdateStatement(); - break; - case Doctrine_Query_Token::T_DELETE: - $this->DeleteStatement(); - break; - default: - $this->_parser->logError(); - } - } -} diff --git a/draft/Doctrine/Query/Production/RangeVariableDeclaration.php b/draft/Doctrine/Query/Production/RangeVariableDeclaration.php deleted file mode 100644 index a54df966e..000000000 --- a/draft/Doctrine/Query/Production/RangeVariableDeclaration.php +++ /dev/null @@ -1,46 +0,0 @@ -. - */ - -/** - * RangeVariableDeclaration = PathExpression [["AS"] IdentificationVariable] - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_RangeVariableDeclaration extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->PathExpression(); - - if ($this->_isNextToken(Doctrine_Query_Token::T_AS)) { - $this->_parser->match(Doctrine_Query_Token::T_AS); - $this->IdentificationVariable(); - } elseif ($this->_isNextToken(Doctrine_Query_Token::T_IDENTIFIER)) { - $this->IdentificationVariable(); - } - } -} diff --git a/draft/Doctrine/Query/Production/SelectClause.php b/draft/Doctrine/Query/Production/SelectClause.php deleted file mode 100644 index f6b0b535b..000000000 --- a/draft/Doctrine/Query/Production/SelectClause.php +++ /dev/null @@ -1,50 +0,0 @@ -. - */ - -/** - * SelectClause = "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression} - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_SelectClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $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->SelectExpression(); - - while ($this->_isNextToken(',')) { - $this->_parser->match(','); - $this->SelectExpression(); - } - } -} diff --git a/draft/Doctrine/Query/Production/SelectExpression.php b/draft/Doctrine/Query/Production/SelectExpression.php deleted file mode 100644 index 27d63a876..000000000 --- a/draft/Doctrine/Query/Production/SelectExpression.php +++ /dev/null @@ -1,67 +0,0 @@ -. - */ - -/** - * SelectExpression = (PathExpressionEndingWithAsterisk | Expression | "(" Subselect ")") - * [["AS"] IdentificationVariable] - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @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 -{ - private 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'] === '*'; - } - - public function execute(array $params = array()) - { - if ($this->_isPathExpressionEndingWithAsterisk()) { - $this->PathExpressionEndingWithAsterisk(); - } elseif ($this->_isSubselect()) { - $this->_parser->match('('); - $this->Subselect(); - $this->_parser->match(')'); - } else { - $this->Expression(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_AS)) { - $this->_parser->match(Doctrine_Query_Token::T_AS); - $this->_parser->match(Doctrine_Query_Token::T_IDENTIFIER); - } elseif ($this->_isNextToken(Doctrine_Query_Token::T_IDENTIFIER)) { - $this->IdentificationVariable(); - } - } -} diff --git a/draft/Doctrine/Query/Production/SelectStatement.php b/draft/Doctrine/Query/Production/SelectStatement.php deleted file mode 100644 index 3c9e2a7a9..000000000 --- a/draft/Doctrine/Query/Production/SelectStatement.php +++ /dev/null @@ -1,64 +0,0 @@ -. - */ - -/** - * SelectStatement = [SelectClause] FromClause [WhereClause] [GroupByClause] - * [HavingClause] [OrderByClause] [LimitClause] - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_SelectStatement extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - if ($this->_isNextToken(Doctrine_Query_Token::T_SELECT)) { - $this->SelectClause(); - } - - $this->FromClause(); - - if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) { - $this->WhereClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_GROUP)) { - $this->GroupByClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_HAVING)) { - $this->HavingClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_ORDER)) { - $this->OrderByClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_LIMIT)) { - $this->LimitClause(); - } - } -} diff --git a/draft/Doctrine/Query/Production/SimpleConditionalExpression.php b/draft/Doctrine/Query/Production/SimpleConditionalExpression.php deleted file mode 100644 index aa13536be..000000000 --- a/draft/Doctrine/Query/Production/SimpleConditionalExpression.php +++ /dev/null @@ -1,78 +0,0 @@ -. - */ - -/** - * SimpleConditionalExpression = - * Expression (ComparisonExpression | BetweenExpression | LikeExpression | - * InExpression | NullComparisonExpression | QuantifiedExpression) | - * ExistsExpression - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_SimpleConditionalExpression extends Doctrine_Query_Production -{ - protected function _getExpressionType() { - if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) { - $token = $this->_parser->getScanner()->peek(); - $this->_parser->getScanner()->resetPeek(); - } else { - $token = $this->_parser->lookahead; - } - - return $token['type']; - } - - public function execute(array $params = array()) - { - if ($this->_getExpressionType() === Doctrine_Query_Token::T_EXISTS) { - $this->ExistsExpression(); - } else { - $this->Expression(); - - switch ($this->_getExpressionType()) { - case Doctrine_Query_Token::T_BETWEEN: - $this->BetweenExpression(); - break; - case Doctrine_Query_Token::T_LIKE: - $this->LikeExpression(); - break; - case Doctrine_Query_Token::T_IN: - $this->InExpression(); - break; - case Doctrine_Query_Token::T_IS: - $this->NullComparisonExpression(); - break; - case Doctrine_Query_Token::T_NONE: - $this->ComparisonExpression(); - break; - default: - $this->_parser->logError(); - } - } - - } -} diff --git a/draft/Doctrine/Query/Production/SimpleSelectClause.php b/draft/Doctrine/Query/Production/SimpleSelectClause.php deleted file mode 100644 index a19487895..000000000 --- a/draft/Doctrine/Query/Production/SimpleSelectClause.php +++ /dev/null @@ -1,45 +0,0 @@ -. - */ - -/** - * SimpleSelectClause = "SELECT" ["DISTINCT"] SelectExpression - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_SimpleSelectClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $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->SelectExpression(); - } -} diff --git a/draft/Doctrine/Query/Production/Subselect.php b/draft/Doctrine/Query/Production/Subselect.php deleted file mode 100644 index 834958a58..000000000 --- a/draft/Doctrine/Query/Production/Subselect.php +++ /dev/null @@ -1,62 +0,0 @@ -. - */ - -/** - * Subselect = SimpleSelectClause FromClause [WhereClause] [GroupByClause] - * [HavingClause] [OrderByClause] [LimitClause] [OffsetClause] - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_Subselect extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->SimpleSelectClause(); - - $this->FromClause(); - - if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) { - $this->WhereClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_GROUP)) { - $this->GroupByClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_HAVING)) { - $this->HavingClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_ORDER)) { - $this->OrderByClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_LIMIT)) { - $this->LimitClause(); - } - } -} diff --git a/draft/Doctrine/Query/Production/Term.php b/draft/Doctrine/Query/Production/Term.php deleted file mode 100644 index 707c8e14c..000000000 --- a/draft/Doctrine/Query/Production/Term.php +++ /dev/null @@ -1,48 +0,0 @@ -. - */ - -/** - * Term = Factor {("*" | "/") Factor} - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_Term extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->Factor(); - - while ($this->_isNextToken('*') || $this->_isNextToken('/')) { - if ($this->_isNextToken('*')) { - $this->_parser->match('*'); - } else { - $this->_parser->match('/'); - } - $this->Factor(); - } - } -} diff --git a/draft/Doctrine/Query/Production/UpdateClause.php b/draft/Doctrine/Query/Production/UpdateClause.php deleted file mode 100644 index c2b8f9b1b..000000000 --- a/draft/Doctrine/Query/Production/UpdateClause.php +++ /dev/null @@ -1,47 +0,0 @@ -. - */ - -/** - * UpdateClause = "UPDATE" RangeVariableDeclaration "SET" UpdateItem {"," UpdateItem} - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_UpdateClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_UPDATE); - $this->RangeVariableDeclaration(); - $this->_parser->match(Doctrine_Query_Token::T_SET); - - $this->UpdateItem(); - while ($this->_isNextToken(',')) { - $this->_parser->match(','); - $this->UpdateItem(); - } - } -} diff --git a/draft/Doctrine/Query/Production/UpdateItem.php b/draft/Doctrine/Query/Production/UpdateItem.php deleted file mode 100644 index 29974d40c..000000000 --- a/draft/Doctrine/Query/Production/UpdateItem.php +++ /dev/null @@ -1,47 +0,0 @@ -. - */ - -/** - * UpdateItem = PathExpression "=" (Expression | "NULL") - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_UpdateItem extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->PathExpression(); - - $this->_parser->match('='); - - if ($this->_isNextToken(Doctrine_Query_Token::T_NULL)) { - $this->_parser->match(Doctrine_Query_Token::T_NULL); - } else { - $this->Expression(); - } - } -} diff --git a/draft/Doctrine/Query/Production/UpdateStatement.php b/draft/Doctrine/Query/Production/UpdateStatement.php deleted file mode 100644 index 27d53783c..000000000 --- a/draft/Doctrine/Query/Production/UpdateStatement.php +++ /dev/null @@ -1,51 +0,0 @@ -. - */ - -/** - * UpdateStatement = UpdateClause [WhereClause] [OrderByClause] [LimitClause] - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_UpdateStatement extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->UpdateClause(); - - if ($this->_isNextToken(Doctrine_Query_Token::T_WHERE)) { - $this->WhereClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_ORDER)) { - $this->OrderByClause(); - } - - if ($this->_isNextToken(Doctrine_Query_Token::T_LIMIT)) { - $this->LimitClause(); - } - } -} diff --git a/draft/Doctrine/Query/Production/WhereClause.php b/draft/Doctrine/Query/Production/WhereClause.php deleted file mode 100644 index 4ad76e9cb..000000000 --- a/draft/Doctrine/Query/Production/WhereClause.php +++ /dev/null @@ -1,41 +0,0 @@ -. - */ - -/** - * WhereClause = "WHERE" ConditionalExpression - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Production_WhereClause extends Doctrine_Query_Production -{ - public function execute(array $params = array()) - { - $this->_parser->match(Doctrine_Query_Token::T_WHERE); - - $this->ConditionalExpression(); - } -} diff --git a/draft/Doctrine/Query/Registry.php b/draft/Doctrine/Query/Registry.php deleted file mode 100644 index fc48d68c3..000000000 --- a/draft/Doctrine/Query/Registry.php +++ /dev/null @@ -1,70 +0,0 @@ -. - */ - -/** - * Doctrine_Query_Registry - * - * @package Doctrine - * @subpackage Query - * @author Konsta Vesterinen - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.com - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Registry -{ - protected $_queries = array(); - - public function add($key, $query) - { - if (strpos($key, '/') === false) { - $this->_queries[$key] = $query; - } else { - // namespace found - - $e = explode('/', $key); - - $this->_queries[$e[0]][$e[1]] = $query; - } - } - - public function get($key, $namespace = null) - { - if (isset($namespace)) { - if ( ! isset($this->_queries[$namespace][$key])) { - throw new Doctrine_Query_Registry_Exception('A query with the name ' . $namespace . '/' . $key . ' does not exist.'); - } - $query = $this->_queries[$namespace][$key]; - } else { - if ( ! isset($this->_queries[$key])) { - throw new Doctrine_Query_Registry_Exception('A query with the name ' . $key . ' does not exist.'); - } - $query = $this->_queries[$key]; - } - - if ( ! ($query instanceof Doctrine_Query)) { - $query = Doctrine_Query::create()->parseQuery($query); - } - - return $query; - } -} \ No newline at end of file diff --git a/draft/Doctrine/Query/Scanner.php b/draft/Doctrine/Query/Scanner.php deleted file mode 100644 index 4af887375..000000000 --- a/draft/Doctrine/Query/Scanner.php +++ /dev/null @@ -1,164 +0,0 @@ -. - */ - -/** - * Scans a DQL query for tokens. - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Query_Scanner -{ - /** - * Array of scanned tokens - * - * @var array - */ - protected $_tokens = array(); - - protected $_position = 0; - - 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]; - - if (is_numeric($value)) { - if (strpos($value, '.') !== false || stripos($value, 'e') !== false) { - $type = Doctrine_Query_Token::T_FLOAT; - } else { - $type = Doctrine_Query_Token::T_INTEGER; - } - } elseif ($value[0] === "'" && $value[strlen($value) - 1] === "'") { - $type = Doctrine_Query_Token::T_STRING; - } elseif (ctype_alpha($value[0]) || $value[0] === '_') { - $type = $this->_checkLiteral($value); - } elseif ($value[0] === '?' || $value[0] === ':') { - $type = Doctrine_Query_Token::T_INPUT_PARAMETER; - } else { - $type = Doctrine_Query_Token::T_NONE; - } - - $this->_tokens[] = array( - 'value' => $value, - 'type' => $type, - 'position' => $match[1] - ); - } - } - - public function peek() - { - if (isset($this->_tokens[$this->_position + $this->_peek])) { - return $this->_tokens[$this->_position + $this->_peek++]; - } else { - return null; - } - } - - 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; - } - } - - -} diff --git a/draft/Doctrine/Query/Token.php b/draft/Doctrine/Query/Token.php deleted file mode 100644 index dbde9be11..000000000 --- a/draft/Doctrine/Query/Token.php +++ /dev/null @@ -1,88 +0,0 @@ -. - */ - -/** - * Container for token type constants of Doctrine Query Language. - * - * @package Doctrine - * @subpackage Query - * @author Janne Vanhala - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -final class Doctrine_Query_Token -{ - const T_NONE = 1; - const T_IDENTIFIER = 2; - const T_INTEGER = 3; - const T_STRING = 4; - const T_INPUT_PARAMETER = 5; - const T_FLOAT = 6; - - const T_ALL = 101; - const T_AND = 102; - const T_ANY = 103; - const T_AS = 104; - const T_ASC = 105; - const T_AVG = 106; - const T_BETWEEN = 107; - const T_BY = 108; - const T_COUNT = 109; - const T_DELETE = 110; - const T_DESC = 111; - const T_DISTINCT = 112; - const T_ESCAPE = 113; - const T_EXISTS = 114; - const T_FROM = 115; - const T_GROUP = 116; - const T_HAVING = 117; - const T_IN = 118; - const T_INDEX = 119; - const T_INNER = 120; - const T_IS = 121; - const T_JOIN = 122; - const T_LEFT = 123; - const T_LIKE = 124; - const T_LIMIT = 125; - const T_MAX = 126; - const T_MIN = 127; - const T_MOD = 128; - const T_NOT = 129; - const T_NULL = 130; - const T_OFFSET = 131; - const T_ON = 132; - const T_OR = 133; - const T_ORDER = 134; - const T_SELECT = 135; - const T_SET = 136; - const T_SIZE = 137; - const T_SOME = 138; - const T_SUM = 139; - const T_UPDATE = 140; - const T_WHERE = 141; - const T_WITH = 142; - const T_TRUE = 143; - const T_FALSE = 144; - - private function __construct() {} -} diff --git a/draft/query-language.txt b/draft/query-language.txt deleted file mode 100644 index 2d8100c96..000000000 --- a/draft/query-language.txt +++ /dev/null @@ -1,73 +0,0 @@ -/* Context-free grammar for Doctrine Query Language - * - * Document syntax: - * - non-terminals begin with an upper case character - * - terminals begin with a lower case character - * - parentheses (...) are used for grouping - * - square brackets [...] are used for defining an optional part, eg. zero or - * one time time - * - curly brackets {...} are used for repetion, eg. zero or more times - * - double quotation marks "..." define a terminal string - * - a vertical bar represents an alternative - */ - -QueryLanguage = SelectStatement | UpdateStatement | DeleteStatement - -SelectStatement = [SelectClause] FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause] [LimitClause] [OffsetClause] -UpdateStatement = UpdateClause [WhereClause] [OrderByClause] [LimitClause] [OffsetClause] -DeleteStatement = DeleteClause [WhereClause] [OrderByClause] [LimitClause] [OffsetClause] - -Subselect = SimpleSelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause] [LimitClause] [OffsetClause] -SelectClause = "SELECT" ["ALL" | "DISTINCT"] SelectExpression {"," SelectExpression} -SimpleSelectClause = "SELECT" ["ALL" | "DISTINCT"] SelectExpression -DeleteClause = "DELETE" "FROM" RangeVariableDeclaration -WhereClause = "WHERE" ConditionalExpression -FromClause = "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration} -HavingClause = "HAVING" ConditionalExpression -GroupByClause = "GROUP" "BY" GroupByItem {"," GroupByItem} -OrderByClause = "ORDER" "BY" OrderByItem {"," OrderByItem} -LimitClause = "LIMIT" integer -OffsetClause = "OFFSET" integer -UpdateClause = "UPDATE" RangeVariableDeclaration "SET" UpdateItem {"," UpdateItem} - -OrderByItem = Expression ["ASC" | "DESC"] -GroupByItem = PathExpression -UpdateItem = PathExpression "=" (Expression | "NULL") - -IdentificationVariableDeclaration = RangeVariableDeclaration [IndexBy] {Join [IndexBy]} -RangeVariableDeclaration = PathExpression [["AS"] IdentificationVariable] - -Join = ["LEFT" | "INNER"] "JOIN" RangeVariableDeclaration [("ON" | "WITH") ConditionalExpression] -IndexBy = "INDEX" "BY" PathExpression - -ConditionalExpression = ConditionalTerm {"OR" ConditionalTerm} -ConditionalTerm = ConditionalFactor {"AND" ConditionalFactor} -ConditionalFactor = ["NOT"] ConditionalPrimary -ConditionalPrimary = SimpleConditionalExpression | "(" ConditionalExpression ")" -SimpleConditionalExpression - = Expression (ComparisonExpression | BetweenExpression | LikeExpression - | InExpression | NullComparisonExpression) | ExistsExpression - -Atom = string | integer | float | boolean | input_parameter - -Expression = Term {("+" | "-") Term} -Term = Factor {("*" | "/") Factor} -Factor = [("+" | "-")] Primary -Primary = PathExpression | Atom | "(" Expression ")" | Function | AggregateExpression - -SelectExpression = (PathExpressionEndingWithAsterisk | Expression | "(" Subselect ")" ) [["AS"] IdentificationVariable] -PathExpression = identifier {"." identifier} -PathExpressionEndingWithAsterisk = {identifier "."} "*" - -AggregateExpression = ("AVG" | "MAX" | "MIN" | "SUM") "(" ["DISTINCT"] Expression ")" - | "COUNT" "(" ["DISTINCT"] (Expression | "*") ")" - -QuantifiedExpression = ("ALL" | "ANY" | "SOME") "(" Subselect ")" -BetweenExpression = ["NOT"] "BETWEEN" Expression "AND" Expression -ComparisonExpression = ComparisonOperator ( QuantifiedExpression | Expression | "(" Subselect ")" ) -InExpression = ["NOT"] "IN" "(" (Atom {"," Atom} | Subselect) ")" -LikeExpression = ["NOT"] "LIKE" Expression ["ESCAPE" string] -NullComparisonExpression = "IS" ["NOT"] "NULL" -ExistsExpression = "EXISTS" "(" Subselect ")" - -Function = identifier "(" [Expression {"," Expression}] ")" diff --git a/draft/test.php b/draft/test.php deleted file mode 100644 index 5f183b078..000000000 --- a/draft/test.php +++ /dev/null @@ -1,31 +0,0 @@ -parse(); -} -$end = microtime(true); - -printf("Parsed %d queries: %.3f ms per query\n", $n, ($end - $start) / $n * 1000); diff --git a/draft/tests/Query/LanguageRecognitionTestCase.php b/draft/tests/Query/LanguageRecognitionTestCase.php deleted file mode 100644 index f0621e18d..000000000 --- a/draft/tests/Query/LanguageRecognitionTestCase.php +++ /dev/null @@ -1,318 +0,0 @@ -parse(); - $this->pass(); - } catch (Exception $e) { - $this->fail($e->getMessage()); - } - } - - public function assertInvalidDql($dql) - { - $parser = new Doctrine_Query_Parser($dql); - - try { - $parser->parse(); - $this->fail(); - } catch (Exception $e) { - $this->pass(); - } - } - - public function testEmptyQueryString() - { - $this->assertInvalidDql(''); - } - - public function testPlainFromClauseWithoutAlias() - { - $this->assertValidDql('FROM User'); - } - - public function testPlainFromClauseWithAlias() - { - $this->assertValidDql('FROM User u'); - } - - public function testSelectSingleComponentWithAsterisk() - { - $this->assertValidDql('SELECT u.* FROM User u'); - } - - public function testSelectSingleComponentWithMultipleColumns() - { - $this->assertValidDql('SELECT u.name, u.type FROM User u'); - } - - public function testSelectMultipleComponentsWithAsterisk() - { - $this->assertValidDql('SELECT u.*, p.* FROM User u, u.Phonenumber p'); - } - - public function testSelectDistinctIsSupported() - { - $this->assertValidDql('SELECT DISTINCT u.name FROM User u'); - } - - public function testAggregateFunctionInSelect() - { - $this->assertValidDql('SELECT COUNT(u.id) FROM User u'); - } - - public function testAggregateFunctionWithDistinctInSelect() - { - $this->assertValidDql('SELECT COUNT(DISTINCT u.name) FROM User u'); - } - - public function testFunctionalExpressionsSupportedInWherePart() - { - $this->assertValidDql("SELECT u.name FROM User u WHERE TRIM(u.name) = 'someone'"); - } - - public function testArithmeticExpressionsSupportedInWherePart() - { - $this->assertValidDql('FROM Account a WHERE ((a.amount + 5000) * a.amount + 3) < 10000000'); - } - - public function testInExpressionSupportedInWherePart() - { - $this->assertValidDql('FROM User WHERE User.id IN (1, 2)'); - } - - public function testNotInExpressionSupportedInWherePart() - { - $this->assertValidDql('FROM User WHERE User.id NOT IN (1)'); - } - - public function testExistsExpressionSupportedInWherePart() - { - $this->assertValidDql('FROM User WHERE EXISTS (SELECT g.id FROM UserGroupuser g WHERE g.user_id = u.id)'); - } - - public function testNotExistsExpressionSupportedInWherePart() - { - $this->assertValidDql('FROM User WHERE NOT EXISTS (SELECT g.id FROM UserGroupuser g WHERE g.user_id = u.id)'); - } - - public function testLiteralValueAsInOperatorOperandIsSupported() - { - $this->assertValidDql('SELECT u.id FROM User u WHERE 1 IN (1, 2)'); - } - - public function testUpdateWorksWithOneColumn() - { - $this->assertValidDql("UPDATE User u SET u.name = 'someone'"); - } - - public function testUpdateWorksWithMultipleColumns() - { - $this->assertValidDql("UPDATE User u SET u.name = 'someone', u.email_id = 5"); - } - - public function testUpdateSupportsConditions() - { - $this->assertValidDql("UPDATE User u SET u.name = 'someone' WHERE u.id = 5"); - } - - public function testDeleteAll() - { - $this->assertValidDql('DELETE FROM Entity'); - } - - public function testDeleteWithCondition() - { - $this->assertValidDql('DELETE FROM Entity WHERE id = 3'); - } - - public function testDeleteWithLimit() - { - $this->assertValidDql('DELETE FROM Entity LIMIT 20'); - } - - public function testDeleteWithLimitAndOffset() - { - $this->assertValidDql('DELETE FROM Entity LIMIT 10 OFFSET 20'); - } - - public function testAdditionExpression() - { - $this->assertValidDql('SELECT u.*, (u.id + u.id) addition FROM User u'); - } - - public function testSubtractionExpression() - { - $this->assertValidDql('SELECT u.*, (u.id - u.id) subtraction FROM User u'); - } - - public function testDivisionExpression() - { - $this->assertValidDql('SELECT u.*, (u.id/u.id) division FROM User u'); - } - - public function testMultiplicationExpression() - { - $this->assertValidDql('SELECT u.*, (u.id * u.id) multiplication FROM User u'); - } - - public function testNegationExpression() - { - $this->assertValidDql('SELECT u.*, -u.id negation FROM User u'); - } - - public function testExpressionWithPrecedingPlusSign() - { - $this->assertValidDql('SELECT u.*, +u.id FROM User u'); - } - - public function testAggregateFunctionInHavingClause() - { - $this->assertValidDql('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p HAVING COUNT(p.id) > 2'); - $this->assertValidDql("SELECT u.name FROM User u LEFT JOIN u.Phonenumber p HAVING MAX(u.name) = 'zYne'"); - } - - public function testMultipleAggregateFunctionsInHavingClause() - { - $this->assertValidDql("SELECT u.name FROM User u LEFT JOIN u.Phonenumber p HAVING MAX(u.name) = 'zYne'"); - } - - public function testLeftJoin() - { - $this->assertValidDql('FROM User u LEFT JOIN u.UserGroup'); - } - - public function testJoin() - { - $this->assertValidDql('FROM User u JOIN u.UserGroup'); - } - - public function testInnerJoin() - { - $this->assertValidDql('FROM User u INNER JOIN u.UserGroup'); - } - - public function testMultipleLeftJoin() - { - $this->assertValidDql('FROM User u LEFT JOIN u.UserGroup LEFT JOIN u.Phonenumber'); - } - - public function testMultipleInnerJoin() - { - $this->assertValidDql('SELECT u.name FROM User u INNER JOIN u.UserGroup INNER JOIN u.Phonenumber'); - } - - public function testMultipleInnerJoin2() - { - $this->assertValidDql('SELECT u.name FROM User u INNER JOIN u.UserGroup, u.Phonenumber'); - } - - public function testMixingOfJoins() - { - $this->assertValidDql('SELECT u.name, g.name, p.phonenumber FROM User u INNER JOIN u.UserGroup g LEFT JOIN u.Phonenumber p'); - } - - public function testMixingOfJoins2() - { - $this->assertValidDql('SELECT u.name, g.name, p.phonenumber FROM User u INNER JOIN u.UserGroup.Phonenumber p'); - } - - public function testOrderBySingleColumn() - { - $this->assertValidDql('SELECT u.name FROM User u ORDER BY u.name'); - } - - public function testOrderBySingleColumnAscending() - { - $this->assertValidDql('SELECT u.name FROM User u ORDER BY u.name ASC'); - } - - public function testOrderBySingleColumnDescending() - { - $this->assertValidDql('SELECT u.name FROM User u ORDER BY u.name DESC'); - } - - public function testOrderByMultipleColumns() - { - $this->assertValidDql('SELECT u.firstname, u.lastname FROM User u ORDER BY u.lastname DESC, u.firstname DESC'); - } - - public function testOrderByWithFunctionExpression() - { - $this->assertValidDql('SELECT u.name FROM User u ORDER BY COALESCE(u.id, u.name) DESC'); - } - - public function testSubselectInInExpression() - { - $this->assertValidDql("FROM User u WHERE u.id NOT IN (SELECT u2.id FROM User u2 WHERE u2.name = 'zYne')"); - } - - public function testSubselectInSelectPart() - { - $this->assertValidDql("SELECT u.name, (SELECT COUNT(p.id) FROM Phonenumber p WHERE p.entity_id = u.id) pcount FROM User u WHERE u.name = 'zYne' LIMIT 1"); - } - - public function testPositionalInputParameter() - { - $this->assertValidDql('FROM User u WHERE u.id = ?'); - } - - public function testNamedInputParameter() - { - $this->assertValidDql('FROM User u WHERE u.id = :id'); - } - - public function testCustomJoinsAndWithKeywordSupported() - { - $this->assertValidDql('SELECT c.*, c2.*, d.* FROM Record_Country c INNER JOIN c.City c2 WITH c2.id = 2 WHERE c.id = 1'); - } - - public function testJoinConditionsSupported() - { - $this->assertValidDql("SELECT u.name, p.id FROM User u LEFT JOIN u.Phonenumber p ON p.phonenumber = '123 123'"); - } - - public function testIndexByClauseWithOneComponent() - { - $this->assertValidDql('FROM Record_City c INDEX BY c.name'); - } - - public function testIndexBySupportsJoins() - { - $this->assertValidDql('FROM Record_Country c LEFT JOIN c.City c2 INDEX BY c2.name'); - } - - public function testIndexBySupportsJoins2() - { - $this->assertValidDql('FROM User u INDEX BY u.name LEFT JOIN u.Phonenumber p INDEX BY p.phonenumber'); - } - - public function testBetweenExpressionSupported() - { - $this->assertValidDql("FROM User u WHERE u.name BETWEEN 'jepso' AND 'zYne'"); - } - - public function testNotBetweenExpressionSupported() - { - $this->assertValidDql("FROM User u WHERE u.name NOT BETWEEN 'jepso' AND 'zYne'"); - } - - public function testAllExpression() - { - $this->assertValidDql('FROM Employee e WHERE e.salary > ALL (SELECT m.salary FROM Manager m WHERE m.department = e.department)'); - } - - public function testAnyExpression() - { - $this->assertValidDql('FROM Employee e WHERE e.salary > ANY (SELECT m.salary FROM Manager m WHERE m.department = e.department)'); - } - - public function testSomeExpression() - { - $this->assertValidDql('FROM Employee e WHERE e.salary > SOME (SELECT m.salary FROM Manager m WHERE m.department = e.department)'); - } -} diff --git a/draft/tests/Query/ScannerTestCase.php b/draft/tests/Query/ScannerTestCase.php deleted file mode 100644 index 6a8450ada..000000000 --- a/draft/tests/Query/ScannerTestCase.php +++ /dev/null @@ -1,194 +0,0 @@ -next(); - $this->assertEqual(Doctrine_Query_Token::T_IDENTIFIER, $token['type']); - $this->assertEqual('u', $token['value']); - } - - public function testScannerRecognizesIdentifierConsistingOfLetters() - { - $scanner = new Doctrine_Query_Scanner('someIdentifier'); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_IDENTIFIER, $token['type']); - $this->assertEqual('someIdentifier', $token['value']); - } - - public function testScannerRecognizesIdentifierIncludingDigits() - { - $scanner = new Doctrine_Query_Scanner('s0m31d3nt1f13r'); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_IDENTIFIER, $token['type']); - $this->assertEqual('s0m31d3nt1f13r', $token['value']); - } - - public function testScannerRecognizesIdentifierIncludingUnderscore() - { - $scanner = new Doctrine_Query_Scanner('some_identifier'); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_IDENTIFIER, $token['type']); - $this->assertEqual('some_identifier', $token['value']); - } - - public function testScannerRecognizesDecimalInteger() - { - $scanner = new Doctrine_Query_Scanner('1234'); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_INTEGER, $token['type']); - $this->assertEqual(1234, $token['value']); - } - - public function testScannerRecognizesFloat() - { - $scanner = new Doctrine_Query_Scanner('1.234'); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_FLOAT, $token['type']); - $this->assertEqual(1.234, $token['value']); - } - - public function testScannerRecognizesFloatWithExponent() - { - $scanner = new Doctrine_Query_Scanner('1.2e3'); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_FLOAT, $token['type']); - $this->assertEqual(1.2e3, $token['value']); - } - - public function testScannerRecognizesFloatWithNegativeExponent() - { - $scanner = new Doctrine_Query_Scanner('7E-10'); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_FLOAT, $token['type']); - $this->assertEqual(7E-10, $token['value']); - } - - public function testScannerRecognizesStringContainingWhitespace() - { - $scanner = new Doctrine_Query_Scanner("'This is a string.'"); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_STRING, $token['type']); - $this->assertEqual("'This is a string.'", $token['value']); - } - - public function testScannerRecognizesStringContainingSingleQuotes() - { - $scanner = new Doctrine_Query_Scanner("'abc''defg'''"); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_STRING, $token['type']); - $this->assertEqual("'abc''defg'''", $token['value']); - } - - public function testScannerRecognizesInputParameter() - { - $scanner = new Doctrine_Query_Scanner('?'); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_INPUT_PARAMETER, $token['type']); - $this->assertEqual('?', $token['value']); - } - - public function testScannerRecognizesNamedInputParameter() - { - $scanner = new Doctrine_Query_Scanner(':name'); - - $token = $scanner->next(); - $this->assertEqual(Doctrine_Query_Token::T_INPUT_PARAMETER, $token['type']); - $this->assertEqual(':name', $token['value']); - } - - public function testScannerTokenizesASimpleQueryCorrectly() - { - $dql = "SELECT u.* FROM User u WHERE u.name = 'Jack O''Neil'"; - $scanner = new Doctrine_Query_Scanner($dql); - - $tokens = array( - array( - 'value' => 'SELECT', - 'type' => Doctrine_Query_Token::T_SELECT, - 'position' => 0 - ), - array( - 'value' => 'u', - 'type' => Doctrine_Query_Token::T_IDENTIFIER, - 'position' => 7 - ), - array( - 'value' => '.', - 'type' => Doctrine_Query_Token::T_NONE, - 'position' => 8 - ), - array( - 'value' => '*', - 'type' => Doctrine_Query_Token::T_NONE, - 'position' => 9 - ), - array( - 'value' => 'FROM', - 'type' => Doctrine_Query_Token::T_FROM, - 'position' => 11 - ), - array( - 'value' => 'User', - 'type' => Doctrine_Query_Token::T_IDENTIFIER, - 'position' => 16 - ), - array( - 'value' => 'u', - 'type' => Doctrine_Query_Token::T_IDENTIFIER, - 'position' => 21 - ), - array( - 'value' => 'WHERE', - 'type' => Doctrine_Query_Token::T_WHERE, - 'position' => 23 - ), - array( - 'value' => 'u', - 'type' => Doctrine_Query_Token::T_IDENTIFIER, - 'position' => 29 - ), - array( - 'value' => '.', - 'type' => Doctrine_Query_Token::T_NONE, - 'position' => 30 - ), - array( - 'value' => 'name', - 'type' => Doctrine_Query_Token::T_IDENTIFIER, - 'position' => 31 - ), - array( - 'value' => '=', - 'type' => Doctrine_Query_Token::T_NONE, - 'position' => 36 - ), - array( - 'value' => "'Jack O''Neil'", - 'type' => Doctrine_Query_Token::T_STRING, - 'position' => 38 - ) - ); - - foreach ($tokens as $expected) { - $actual = $scanner->next(); - $this->assertEqual($expected['value'], $actual['value']); - $this->assertEqual($expected['type'], $actual['type']); - $this->assertEqual($expected['position'], $actual['position']); - } - - $this->assertNull($scanner->next()); - } -} diff --git a/draft/tests/run.php b/draft/tests/run.php deleted file mode 100644 index 4ffc95f49..000000000 --- a/draft/tests/run.php +++ /dev/null @@ -1,47 +0,0 @@ -addTestCase(new Doctrine_Query_Scanner_TestCase()); -$queryTests->addTestCase(new Doctrine_Query_LanguageRecognition_TestCase()); - -$test->addTestCase($queryTests); - - -$test->run(); - -echo memory_get_peak_usage() / 1024 . "\n";