Permalink
Browse files

Merge pull request #542 from FabioBatSilva/DDC-2205

[DDC-2205] Fix DDC-2205
  • Loading branch information...
2 parents 4bbfe0c + 2104ae9 commit 8b5e4a9a52670992b85e7223d255b98cf77a35a3 @guilhermeblanco guilhermeblanco committed Dec 21, 2012
Showing with 34 additions and 0 deletions.
  1. +3 −0 lib/Doctrine/ORM/Query/Parser.php
  2. +31 −0 tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -1792,6 +1792,9 @@ public function ScalarExpression()
switch (true) {
case ($lookahead === Lexer::T_INTEGER):
case ($lookahead === Lexer::T_FLOAT):
+ // SimpleArithmeticExpression : (- u.value ) or ( + u.value ) or ( - 1 ) or ( + 1 )
+ case ($lookahead === Lexer::T_MINUS):
+ case ($lookahead === Lexer::T_PLUS):
return $this->SimpleArithmeticExpression();
case ($lookahead === Lexer::T_STRING):
@@ -1231,6 +1231,37 @@ public function testSimpleCaseWithStringPrimary()
}
/**
+ * @group DDC-2205
+ */
+ public function testCaseNegativeValuesInThenExpression()
+ {
+ $this->assertSqlGeneration(
+ "SELECT CASE g.name WHEN 'admin' THEN - 1 ELSE - 2 END FROM Doctrine\Tests\Models\CMS\CmsGroup g",
+ "SELECT CASE c0_.name WHEN 'admin' THEN -1 ELSE -2 END AS sclr0 FROM cms_groups c0_"
+ );
+
+ $this->assertSqlGeneration(
+ "SELECT CASE g.name WHEN 'admin' THEN - 2 WHEN 'guest' THEN - 1 ELSE 0 END FROM Doctrine\Tests\Models\CMS\CmsGroup g",
+ "SELECT CASE c0_.name WHEN 'admin' THEN -2 WHEN 'guest' THEN -1 ELSE 0 END AS sclr0 FROM cms_groups c0_"
+ );
+
+ $this->assertSqlGeneration(
+ "SELECT CASE g.name WHEN 'admin' THEN (- 1) ELSE (- 2) END FROM Doctrine\Tests\Models\CMS\CmsGroup g",
+ "SELECT CASE c0_.name WHEN 'admin' THEN -1 ELSE -2 END AS sclr0 FROM cms_groups c0_"
+ );
+
+ $this->assertSqlGeneration(
+ "SELECT CASE g.name WHEN 'admin' THEN ( - :value) ELSE ( + :value) END FROM Doctrine\Tests\Models\CMS\CmsGroup g",
+ "SELECT CASE c0_.name WHEN 'admin' THEN -? ELSE +? END AS sclr0 FROM cms_groups c0_"
+ );
+
+ $this->assertSqlGeneration(
+ "SELECT CASE g.name WHEN 'admin' THEN ( - g.id) ELSE ( + g.id) END FROM Doctrine\Tests\Models\CMS\CmsGroup g",
+ "SELECT CASE c0_.name WHEN 'admin' THEN -c0_.id ELSE +c0_.id END AS sclr0 FROM cms_groups c0_"
+ );
+ }
+
+ /**
* @group DDC-1339
*/
public function testIdentityFunctionInSelectClause()

0 comments on commit 8b5e4a9

Please sign in to comment.