From 34cbb8af24697c04dfdea32de948d3a514d206c6 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Tue, 16 Mar 2010 19:21:59 +0000 Subject: [PATCH] [2.0] Fixed issue with DQL that was not considering input parameter 10. Also added support to retrieve the generated AST. --- lib/Doctrine/ORM/Query.php | 13 +++++++++ lib/Doctrine/ORM/Query/Lexer.php | 2 +- lib/Doctrine/ORM/Query/Parser.php | 44 ++++++++++++++++++++----------- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 981869fbb..b12ab1fb6 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -165,6 +165,19 @@ final class Query extends AbstractQuery return $this->_parse()->getSqlExecutor()->getSqlStatements(); } + /** + * Returns the correspondent AST for this Query. + * + * @return \Doctrine\ORM\Query\AST\SelectStatement | + * \Doctrine\ORM\Query\AST\UpdateStatement | + * \Doctrine\ORM\Query\AST\DeleteStatement + */ + public function getAST() + { + $parser = new Parser($this); + return $parser->getAST(); + } + /** * Parses the DQL query, if necessary, and stores the parser result. * diff --git a/lib/Doctrine/ORM/Query/Lexer.php b/lib/Doctrine/ORM/Query/Lexer.php index 79a8dfd39..ca65213a9 100644 --- a/lib/Doctrine/ORM/Query/Lexer.php +++ b/lib/Doctrine/ORM/Query/Lexer.php @@ -126,7 +126,7 @@ class Lexer extends \Doctrine\Common\Lexer '[a-z_][a-z0-9_\:\\\]*[a-z0-9_]{1}', '(?:[0-9]+(?:[,\.][0-9]+)*)(?:e[+-]?[0-9]+)?', "'(?:[^']|'')*'", - '\?[1-9]+|:[a-z][a-z0-9_]+' + '\?[1-9][0-9]*|:[a-z][a-z0-9_]+' ); } diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 2d626e0d4..8f372a45f 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -193,6 +193,34 @@ class Parser return $this->_em; } + /** + * Parse and build AST for the given Query. + * + * @return \Doctrine\ORM\Query\AST\SelectStatement | + * \Doctrine\ORM\Query\AST\UpdateStatement | + * \Doctrine\ORM\Query\AST\DeleteStatement + */ + public function getAST() + { + // Parse & build AST + $AST = $this->QueryLanguage(); + + // Process any deferred validations of some nodes in the AST. + // This also allows post-processing of the AST for modification purposes. + $this->_processDeferredIdentificationVariables(); + if ($this->_deferredPartialObjectExpressions) { + $this->_processDeferredPartialObjectExpressions(); + } + if ($this->_deferredPathExpressions) { + $this->_processDeferredPathExpressions($AST); + } + if ($this->_deferredResultVariables) { + $this->_processDeferredResultVariables(); + } + + return $AST; + } + /** * Attempts to match the given token with the current lookahead token. * @@ -239,21 +267,7 @@ class Parser */ public function parse() { - // Parse & build AST - $AST = $this->QueryLanguage(); - - // Process any deferred validations of some nodes in the AST. - // This also allows post-processing of the AST for modification purposes. - $this->_processDeferredIdentificationVariables(); - if ($this->_deferredPartialObjectExpressions) { - $this->_processDeferredPartialObjectExpressions(); - } - if ($this->_deferredPathExpressions) { - $this->_processDeferredPathExpressions($AST); - } - if ($this->_deferredResultVariables) { - $this->_processDeferredResultVariables(); - } + $AST = $this->getAST(); if ($customWalkers = $this->_query->getHint(Query::HINT_CUSTOM_TREE_WALKERS)) { $this->_customTreeWalkers = $customWalkers;