From 5506d7adce0cc75c38b42280b2bf524046d5e56e Mon Sep 17 00:00:00 2001 From: Vincent BOURDEIX Date: Mon, 14 Oct 2013 15:04:52 +0200 Subject: [PATCH] Fixes a Fatal Error when using a subexpression in parenthesis When some dql contains a subselect with expression in parenthesis, the expression of the $simpleSelectExpression parameter given to walkSimpleSelectExpression is an instance of AST\ParenthesisExpression. Before this commit, this case defaulted to $this->walkEntityIdentificationVariable($expr) where $expr is supposed to be a string. A fatal error was then yielded. --- lib/Doctrine/ORM/Query/SqlWalker.php | 4 ++++ tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index fb6177919..37f970843 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1581,6 +1581,10 @@ class SqlWalker implements TreeWalker $sql .= $expr->dispatch($this) . ' AS ' . $columnAlias; break; + case ($expr instanceof AST\ParenthesisExpression): + $sql .= $this->walkParenthesisExpression($expr); + break; + default: // IdentificationVariable $sql .= $this->walkEntityIdentificationVariable($expr); break; diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 19624e1b8..f0afcc798 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1641,6 +1641,13 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } + public function testSupportsParenthesisExpressionInSubSelect() { + $this->assertSqlGeneration( + 'SELECT u.id, (SELECT (1000*SUM(subU.id)/SUM(subU.id)) FROM Doctrine\Tests\Models\CMS\CmsUser subU where subU.id = u.id) AS subSelect FROM Doctrine\Tests\Models\CMS\CmsUser u', + 'SELECT c0_.id AS id0, (SELECT (1000 * SUM(c1_.id) / SUM(c1_.id)) FROM cms_users c1_ WHERE c1_.id = c0_.id) AS sclr1 FROM cms_users c0_' + ); + } + /** * @group DDC-1557 */