From ce9643bce1eafc76897f3c6183f9f76b106a825f Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 15 Feb 2012 17:57:42 -0200 Subject: [PATCH 1/5] Order by clause support functions --- lib/Doctrine/ORM/Query/Parser.php | 37 +++++++++++--- lib/Doctrine/ORM/Query/SqlWalker.php | 15 ++++-- .../ORM/Query/SelectSqlGenerationTest.php | 48 +++++++++++++++++++ 3 files changed, 91 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 0233e4c5e..4d097b5ff 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1339,12 +1339,37 @@ class Parser */ public function OrderByItem() { - $type = 'ASC'; - // We need to check if we are in a ResultVariable or StateFieldPathExpression $glimpse = $this->_lexer->glimpse(); - $expr = ($glimpse['type'] != Lexer::T_DOT) ? $this->ResultVariable() : $this->SingleValuedPathExpression(); + switch (true) { + case ($glimpse['type'] === Lexer::T_DOT): + $expr = $this->SingleValuedPathExpression(); + 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; + } + + $type = 'ASC'; $item = new AST\OrderByItem($expr); switch (true) { @@ -2166,10 +2191,10 @@ class Parser if (in_array($peek['value'], array("=", "<", "<=", "<>", ">", ">=", "!=")) || in_array($peek['type'], array(Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS)) || $this->_isMathOperator($peek)) { - $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); + $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); - return $condPrimary; - } + return $condPrimary; + } $this->match(Lexer::T_OPEN_PARENTHESIS); $condPrimary->conditionalExpression = $this->ConditionalExpression(); diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index b04d6e8d3..8426dc124 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -780,9 +780,18 @@ class SqlWalker implements TreeWalker public function walkOrderByItem($orderByItem) { $expr = $orderByItem->expression; - $sql = ($expr instanceof AST\PathExpression) - ? $this->walkPathExpression($expr) - : $this->walkResultVariable($this->_queryComponents[$expr]['token']['value']); + + switch (true) { + case ($expr instanceof AST\PathExpression): + case ($expr instanceof AST\AggregateExpression): + case ($expr instanceof AST\Functions\FunctionNode): + case ($expr instanceof AST\SimpleArithmeticExpression): + $sql = $expr->dispatch($this); + break; + default: + $sql = $this->walkResultVariable($this->_queryComponents[$expr]['token']['value']); + break; + } return $sql . ' ' . strtoupper($orderByItem->type); } diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 5b750462c..e77fa6447 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1571,6 +1571,54 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.fixPrice AS fixPrice2, c1_.id AS id3, c1_.completed AS completed4, c1_.hoursWorked AS hoursWorked5, c1_.pricePerHour AS pricePerHour6, c1_.maxPrice AS maxPrice7, c0_.discr AS discr8, c1_.discr AS discr9 FROM company_contracts c0_, company_contracts c1_ WHERE (c0_.discr IN ('fix') AND c1_.discr IN ('flexible', 'flexultra'))" ); } + + /** + * @group DDC-775 + */ + public function testOrderByClauseSupportFunctions() + { + $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 + */ + public function testOrderByClauseSupportNullIfAndCoalesce() + { + $this->markTestIncomplete(); + $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 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 COALESCE(NULLIF(u.name, \'\'), u.username) ASC' + ); + } } From df0632258a2204bc5f81fb835c7f7ff4af79b3f7 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 15 Feb 2012 19:24:06 -0200 Subject: [PATCH 2/5] Order by clause support case expressions --- lib/Doctrine/ORM/Query/Parser.php | 8 ++++++++ lib/Doctrine/ORM/Query/SqlWalker.php | 4 ++++ .../Tests/ORM/Query/SelectSqlGenerationTest.php | 11 ++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 4d097b5ff..4d1bba2fd 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1347,6 +1347,14 @@ class Parser $expr = $this->SingleValuedPathExpression(); break; + 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(); // "(" diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 8426dc124..1e095ff5a 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -786,6 +786,10 @@ class SqlWalker implements TreeWalker case ($expr instanceof AST\AggregateExpression): case ($expr instanceof AST\Functions\FunctionNode): case ($expr instanceof AST\SimpleArithmeticExpression): + case ($expr instanceof AST\NullIfExpression): + case ($expr instanceof AST\CoalesceExpression): + case ($expr instanceof AST\SimpleCaseExpression): + case ($expr instanceof AST\GeneralCaseExpression): $sql = $expr->dispatch($this); break; default: diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index e77fa6447..314f998b4 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1608,15 +1608,20 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase */ public function testOrderByClauseSupportNullIfAndCoalesce() { - $this->markTestIncomplete(); + $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 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 COALESCE(NULLIF(u.name, \'\'), u.username) ASC' + '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' ); } } From 797c9cf70e517a206e88ef1d25059c0f04749762 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 15 Feb 2012 21:16:58 -0200 Subject: [PATCH 3/5] supports simple math operator --- lib/Doctrine/ORM/Query/Parser.php | 17 ++++++++-- lib/Doctrine/ORM/Query/SqlWalker.php | 19 ++--------- .../ORM/Query/SelectSqlGenerationTest.php | 32 ++++++++++++++----- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 4d1bba2fd..a9f411146 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1333,18 +1333,31 @@ class Parser } /** - * OrderByItem ::= (ResultVariable | SingleValuedPathExpression) ["ASC" | "DESC"] + * OrderByItem ::= ( + * SimpleArithmeticExpression | SingleValuedPathExpression | CaseExpression | + * ScalarExpression | AggregateExpression | FunctionDeclaration | ResultVariable + * ) ["ASC" | "DESC"] * * @return \Doctrine\ORM\Query\AST\OrderByItem */ public function OrderByItem() { - // We need to check if we are in a ResultVariable or StateFieldPathExpression + + $this->_lexer->peek(); // lookahead => '.' + $this->_lexer->peek(); // lookahead => token after '.' + $peek = $this->_lexer->peek(); // lookahead => token after the token after the '.' + $this->_lexer->resetPeek(); $glimpse = $this->_lexer->glimpse(); switch (true) { + + case ($this->_isMathOperator($peek)): + $expr = $this->SimpleArithmeticExpression(); + + break; case ($glimpse['type'] === Lexer::T_DOT): $expr = $this->SingleValuedPathExpression(); + break; case ($this->_lexer->lookahead['type'] === Lexer::T_CASE): diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 1e095ff5a..da7867640 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -780,22 +780,9 @@ class SqlWalker implements TreeWalker public function walkOrderByItem($orderByItem) { $expr = $orderByItem->expression; - - switch (true) { - case ($expr instanceof AST\PathExpression): - case ($expr instanceof AST\AggregateExpression): - case ($expr instanceof AST\Functions\FunctionNode): - case ($expr instanceof AST\SimpleArithmeticExpression): - case ($expr instanceof AST\NullIfExpression): - case ($expr instanceof AST\CoalesceExpression): - case ($expr instanceof AST\SimpleCaseExpression): - case ($expr instanceof AST\GeneralCaseExpression): - $sql = $expr->dispatch($this); - break; - default: - $sql = $this->walkResultVariable($this->_queryComponents[$expr]['token']['value']); - break; - } + $sql = ($expr instanceof AST\Node) + ? $expr->dispatch($this) + : $this->walkResultVariable($this->_queryComponents[$expr]['token']['value']); return $sql . ' ' . strtoupper($orderByItem->type); } diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 314f998b4..b816584dc 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1575,28 +1575,24 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase /** * @group DDC-775 */ - public function testOrderByClauseSupportFunctions() + 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' @@ -1606,19 +1602,39 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase /** * @group DDC-775 */ - public function testOrderByClauseSupportNullIfAndCoalesce() + public function testOrderByClauseSupportsSimpleArithmeticExpression() { + $this->assertSqlGeneration( + 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.id + 1 ', + '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 + 1 ASC' + ); + $this->assertSqlGeneration( + 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY ( ( (u.id + 1) * (u.id - 1) ) / 2)', + '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 + 1) * (c0_.id - 1) / 2 ASC' + ); + $this->assertSqlGeneration( + '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' From e46275e80df1253112593b6a82a0c955e100dd43 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 12 Mar 2012 20:25:31 -0300 Subject: [PATCH 4/5] 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' - ); - } } From 84b31714a66f72c6f9857b8c806980007bfec3fb Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 12 Mar 2012 22:07:43 -0300 Subject: [PATCH 5/5] fix indentation --- lib/Doctrine/ORM/Query/Parser.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index b7b105d82..bbb91c040 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -2191,10 +2191,10 @@ class Parser if (in_array($peek['value'], array("=", "<", "<=", "<>", ">", ">=", "!=")) || in_array($peek['type'], array(Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS)) || $this->_isMathOperator($peek)) { - $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); + $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); - return $condPrimary; - } + return $condPrimary; + } $this->match(Lexer::T_OPEN_PARENTHESIS); $condPrimary->conditionalExpression = $this->ConditionalExpression();