From 3d852397db224f2e5a39625a270a4cb576ff65bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Wed, 2 May 2012 19:10:21 +0200 Subject: [PATCH] DDC-1802 removed unnecessary tokens T_SIZE and T_MOD --- .../ORM/Query/AST/Functions/ModFunction.php | 2 +- .../ORM/Query/AST/Functions/SizeFunction.php | 2 +- lib/Doctrine/ORM/Query/Lexer.php | 24 +++++++++---------- .../ORM/Query/SelectSqlGenerationTest.php | 22 +++++++++++++++++ 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php index 53f064a90..66c27efab 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php @@ -53,7 +53,7 @@ class ModFunction extends FunctionNode */ public function parse(\Doctrine\ORM\Query\Parser $parser) { - $parser->match(Lexer::T_MOD); + $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->firstSimpleArithmeticExpression = $parser->SimpleArithmeticExpression(); diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php index 52173c406..1a7c1a150 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php @@ -109,7 +109,7 @@ class SizeFunction extends FunctionNode */ public function parse(\Doctrine\ORM\Query\Parser $parser) { - $parser->match(Lexer::T_SIZE); + $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->collectionPathExpression = $parser->CollectionValuedPathExpression(); diff --git a/lib/Doctrine/ORM/Query/Lexer.php b/lib/Doctrine/ORM/Query/Lexer.php index 1eef6afeb..0000b3fe2 100644 --- a/lib/Doctrine/ORM/Query/Lexer.php +++ b/lib/Doctrine/ORM/Query/Lexer.php @@ -98,18 +98,16 @@ class Lexer extends \Doctrine\Common\Lexer const T_OUTER = 144; const T_SELECT = 145; const T_SET = 146; - const T_SIZE = 147; - const T_SOME = 148; - const T_SUM = 149; - const T_THEN = 150; - const T_TRAILING = 151; - const T_TRUE = 152; - const T_UPDATE = 153; - const T_WHEN = 154; - const T_WHERE = 155; - const T_WITH = 156; - const T_PARTIAL = 157; - const T_MOD = 158; + const T_SOME = 147; + const T_SUM = 148; + const T_THEN = 149; + const T_TRAILING = 150; + const T_TRUE = 151; + const T_UPDATE = 152; + const T_WHEN = 153; + const T_WHERE = 154; + const T_WITH = 155; + const T_PARTIAL = 156; /** * Creates a new query scanner object. @@ -205,4 +203,4 @@ class Lexer extends \Doctrine\Common\Lexer return $type; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index a89190eb9..9a998580b 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -374,6 +374,17 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } + /** + * @group DDC-1802 + */ + public function testSupportsNotBetweenForSizeFunction() + { + $this->assertSqlGeneration( + "SELECT m.name FROM Doctrine\Tests\Models\StockExchange\Market m WHERE SIZE(m.stocks) NOT BETWEEN ?1 AND ?2", + "SELECT e0_.name AS name0 FROM exchange_markets e0_ WHERE (SELECT COUNT(*) FROM exchange_stocks e1_ WHERE e1_.market_id = e0_.id) NOT BETWEEN ? AND ?" + ); + } + public function testSupportsFunctionalExpressionsInWherePart() { $this->assertSqlGeneration( @@ -472,6 +483,17 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } + /** + * @group DDC-1802 + */ + public function testSupportsNotInExpressionForModFunction() + { + $this->assertSqlGeneration( + "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE MOD(u.id, 5) NOT IN(1,3,4)", + "SELECT c0_.name AS name0 FROM cms_users c0_ WHERE MOD(c0_.id, 5) NOT IN (1, 3, 4)" + ); + } + public function testInExpressionWithSingleValuedAssociationPathExpressionInWherePart() { $this->assertSqlGeneration(