From e46275e80df1253112593b6a82a0c955e100dd43 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 12 Mar 2012 20:25:31 -0300 Subject: [PATCH] remove case expressions and functions support --- lib/Doctrine/ORM/Query/Parser.php | 31 ++---------- .../ORM/Query/SelectSqlGenerationTest.php | 49 ------------------- 2 files changed, 5 insertions(+), 75 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index a9f411146..b7b105d82 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1334,8 +1334,8 @@ class Parser /** * OrderByItem ::= ( - * SimpleArithmeticExpression | SingleValuedPathExpression | CaseExpression | - * ScalarExpression | AggregateExpression | FunctionDeclaration | ResultVariable + * SimpleArithmeticExpression | SingleValuedPathExpression | + * ScalarExpression | ResultVariable * ) ["ASC" | "DESC"] * * @return \Doctrine\ORM\Query\AST\OrderByItem @@ -1359,34 +1359,13 @@ class Parser $expr = $this->SingleValuedPathExpression(); break; + case ($this->_lexer->peek() && $this->_isMathOperator($this->_peekBeyondClosingParenthesis())): + $expr = $this->ScalarExpression(); - case ($this->_lexer->lookahead['type'] === Lexer::T_CASE): - case ($this->_lexer->lookahead['type'] === Lexer::T_COALESCE): - case ($this->_lexer->lookahead['type'] === Lexer::T_NULLIF): - // Since NULLIF and COALESCE can be identified as a function, - // we need to check if before check for FunctionDeclaration - $expr = $this->CaseExpression(); break; - - case ($this->_isFunction()): - $this->_lexer->peek(); // "(" - - // SUM(u.id) + COUNT(u.id) - if ($this->_isMathOperator($this->_peekBeyondClosingParenthesis())) { - $expr = $this->ScalarExpression(); - break; - } - // COUNT(u.id) - if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) { - $expr = $this->AggregateExpression(); - break; - } - // IDENTITY(u) - $expr = $this->FunctionDeclaration(); - break; - default: $expr = $this->ResultVariable(); + break; } diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index b816584dc..40bbbaab7 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1572,33 +1572,6 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } - /** - * @group DDC-775 - */ - public function testOrderByClauseSupportsFunctions() - { - $this->assertSqlGeneration( - 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY TRIM(u.name)', - 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ ORDER BY TRIM(c0_.name) ASC' - ); - $this->assertSqlGeneration( - 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY IDENTITY(u.email)', - 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ ORDER BY c0_.email_id ASC' - ); - $this->assertSqlGeneration( - 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY TRIM(IDENTITY(u.email))', - 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ ORDER BY TRIM(c0_.email_id) ASC' - ); - $this->assertSqlGeneration( - 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY SUM(u.id)', - 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ ORDER BY SUM(c0_.id) ASC' - ); - $this->assertSqlGeneration( - 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY SUM(u.id) + COUNT(u.email)', - 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ ORDER BY SUM(c0_.id) + COUNT(c0_.email_id) ASC' - ); - } - /** * @group DDC-775 */ @@ -1616,30 +1589,8 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY ((u.id + 5000) * u.id + 3) ', 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ ORDER BY (c0_.id + 5000) * c0_.id + 3 ASC' ); - $this->assertSqlGeneration( - 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY ((u.id + 5000) * SUM(u.id) + 3) ', - 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ ORDER BY (c0_.id + 5000) * SUM(c0_.id) + 3 ASC' - ); } - /** - * @group DDC-775 - */ - public function testOrderByClauseSupportsNullIfAndCoalesce() - { - $this->assertSqlGeneration( - 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY NULLIF(u.name, u.username)', - 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ ORDER BY NULLIF(c0_.name, c0_.username) ASC' - ); - $this->assertSqlGeneration( - 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY COALESCE(NULLIF(u.name, u.username), u.id)', - 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ ORDER BY COALESCE(NULLIF(c0_.name, c0_.username), c0_.id) ASC' - ); - $this->assertSqlGeneration( - 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY CASE u.id WHEN 1 THEN 1 ELSE 0 END', - 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ ORDER BY CASE c0_.id WHEN 1 THEN 1 ELSE 0 END ASC' - ); - } }