From bb94f6ea7cd7281e87d316590d8c06e7dbea2d82 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Tue, 16 Mar 2010 15:02:43 +0000 Subject: [PATCH] [2.0] Fixed support to ResultVariable usage in ArithmeticExpression. --- lib/Doctrine/ORM/Query/Parser.php | 4 ++-- lib/Doctrine/ORM/Query/SqlWalker.php | 4 ++++ .../Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 2d626e0d4..51e16a765 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -2129,7 +2129,7 @@ class Parser /** * ArithmeticPrimary ::= SingleValuedPathExpression | Literal | "(" SimpleArithmeticExpression ")" * | FunctionsReturningNumerics | AggregateExpression | FunctionsReturningStrings - * | FunctionsReturningDatetime | IdentificationVariable + * | FunctionsReturningDatetime | ResultVariable */ public function ArithmeticPrimary() { @@ -2154,7 +2154,7 @@ class Parser return $this->SingleValuedPathExpression(); } - return $this->IdentificationVariable(); + return $this->ResultVariable(); case Lexer::T_INPUT_PARAMETER: return $this->InputParameter(); diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 2cd6895dc..f1a561464 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1639,6 +1639,10 @@ class SqlWalker implements TreeWalker $sql .= '(' . $this->walkSimpleArithmeticExpression($primary) . ')'; } else if ($primary instanceof AST\Node) { $sql .= $primary->dispatch($this); + } else if (is_string($primary)) { + $columnName = $this->_queryComponents[$primary]['token']['value']; + + $sql .= $this->_scalarResultAliasMap[$columnName]; } return $sql; diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 303bd29de..3b6edeaef 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -527,6 +527,14 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } + public function testSupportResultVariableInWherePart() + { + $this->assertSqlGeneration( + "SELECT p.phonenumber, COUNT(p.user) AS total FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE total > 0 GROUP BY p.user", + "SELECT c0_.phonenumber AS phonenumber0, COUNT(c0_.user_id) AS sclr1 FROM cms_phonenumbers c0_ WHERE sclr1 > 0 GROUP BY c0_.user_id" + ); + } + public function testSingleValuedAssociationNullCheckOnOwningSide() { $this->assertSqlGeneration(