Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ab6ad2

Browse files
committed
DDC-1802 fixed parsing: FunctionDeclaration "NOT" ("LIKE" | "IN" | "BETWEEN")
1 parent 0a09a28 commit 3ab6ad2

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

lib/Doctrine/ORM/Query/Parser.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,10 @@ public function semanticalError($message = '', $token = null)
416416
/**
417417
* Peek beyond the matched closing parenthesis and return the first token after that one.
418418
*
419+
* @param boolean $resetPeek Reset peek after finding the closing parenthesis
419420
* @return array
420421
*/
421-
private function _peekBeyondClosingParenthesis()
422+
private function _peekBeyondClosingParenthesis($resetPeek = true)
422423
{
423424
$token = $this->_lexer->peek();
424425
$numUnmatched = 1;
@@ -440,7 +441,9 @@ private function _peekBeyondClosingParenthesis()
440441
$token = $this->_lexer->peek();
441442
}
442443

443-
$this->_lexer->resetPeek();
444+
if ($resetPeek) {
445+
$this->_lexer->resetPeek();
446+
}
444447

445448
return $token;
446449
}
@@ -541,7 +544,7 @@ private function _processDeferredPartialObjectExpressions()
541544

542545
foreach ($expr->partialFieldSet as $field) {
543546
if (isset($class->fieldMappings[$field])) {
544-
continue;
547+
continue;
545548
}
546549

547550
$this->semanticalError(
@@ -1335,7 +1338,7 @@ public function OrderByItem()
13351338
break;
13361339
case ($glimpse['type'] === Lexer::T_DOT):
13371340
$expr = $this->SingleValuedPathExpression();
1338-
1341+
13391342
break;
13401343
case ($this->_lexer->peek() && $this->_isMathOperator($this->_peekBeyondClosingParenthesis())):
13411344
$expr = $this->ScalarExpression();
@@ -2206,7 +2209,13 @@ public function SimpleConditionalExpression()
22062209
if ($peek['value'] == '(') {
22072210
// Peek beyond the matching closing paranthesis ')'
22082211
$this->_lexer->peek();
2209-
$token = $this->_peekBeyondClosingParenthesis();
2212+
$token = $this->_peekBeyondClosingParenthesis(false);
2213+
2214+
if ($token['type'] === Lexer::T_NOT) {
2215+
$token = $this->_lexer->peek();
2216+
}
2217+
2218+
$this->_lexer->resetPeek();
22102219
} else {
22112220
// Peek beyond the PathExpression (or InputParameter)
22122221
$peek = $this->_lexer->peek();
@@ -2658,7 +2667,7 @@ public function AggregateExpression()
26582667
? $this->SingleValuedPathExpression()
26592668
: $this->SimpleArithmeticExpression();
26602669

2661-
$this->match(Lexer::T_CLOSE_PARENTHESIS);
2670+
$this->match(Lexer::T_CLOSE_PARENTHESIS);
26622671

26632672
return new AST\AggregateExpression($functionName, $pathExp, $isDistinct);
26642673
}

tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,26 @@ public function testStringFunctionLikeExpression()
854854
);
855855
}
856856

857+
/**
858+
* @group DDC-1802
859+
*/
860+
public function testStringFunctionNotLikeExpression()
861+
{
862+
$this->assertSqlGeneration(
863+
"SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE LOWER(u.name) NOT LIKE '%foo OR bar%'",
864+
"SELECT c0_.name AS name0 FROM cms_users c0_ WHERE LOWER(c0_.name) NOT LIKE '%foo OR bar%'"
865+
);
866+
867+
$this->assertSqlGeneration(
868+
"SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE UPPER(LOWER(u.name)) NOT LIKE UPPER(LOWER(:str))",
869+
"SELECT c0_.name AS name0 FROM cms_users c0_ WHERE UPPER(LOWER(c0_.name)) NOT LIKE UPPER(LOWER(?))"
870+
);
871+
$this->assertSqlGeneration(
872+
"SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a WITH a.topic NOT LIKE u.name",
873+
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ LEFT JOIN cms_articles c1_ ON c0_.id = c1_.user_id AND (c1_.topic NOT LIKE c0_.name)"
874+
);
875+
}
876+
857877
/**
858878
* @group DDC-338
859879
*/

0 commit comments

Comments
 (0)