Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDC-1572] Allow LIKE pattern to be a function or path expression #245

Merged
merged 1 commit into from Dec 31, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/Doctrine/ORM/Query/Parser.php
Expand Up @@ -2813,7 +2813,7 @@ public function InstanceOfParameter()
}

/**
* LikeExpression ::= StringExpression ["NOT"] "LIKE" (string | input_parameter) ["ESCAPE" char]
* LikeExpression ::= StringExpression ["NOT"] "LIKE" StringPrimary ["ESCAPE" char]
*
* @return \Doctrine\ORM\Query\AST\LikeExpression
*/
Expand All @@ -2833,8 +2833,7 @@ public function LikeExpression()
$this->match(Lexer::T_INPUT_PARAMETER);
$stringPattern = new AST\InputParameter($this->_lexer->token['value']);
} else {
$this->match(Lexer::T_STRING);
$stringPattern = $this->_lexer->token['value'];
$stringPattern = $this->StringPrimary();
}

$escapeChar = null;
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Query/SqlWalker.php
Expand Up @@ -1947,6 +1947,10 @@ public function walkLikeExpression($likeExpr)
$dqlParamKey = $inputParam->name;
$this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++);
$sql .= '?';
} elseif ($likeExpr->stringPattern instanceof AST\Functions\FunctionNode ) {
$sql .= $this->walkFunction($likeExpr->stringPattern);
} elseif ($likeExpr->stringPattern instanceof AST\PathExpression) {
$sql .= $this->walkPathExpression($likeExpr->stringPattern);
} else {
$sql .= $this->_conn->quote($likeExpr->stringPattern);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
Expand Up @@ -822,6 +822,7 @@ public function testSingleValuedAssociationNullCheckOnInverseSide()

/**
* @group DDC-339
* @group DDC-1572
*/
public function testStringFunctionLikeExpression()
{
Expand All @@ -837,6 +838,20 @@ public function testStringFunctionLikeExpression()
"SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(UPPER(u.name), '_moo') LIKE :str",
"SELECT c0_.name AS name0 FROM cms_users c0_ WHERE UPPER(c0_.name) || '_moo' LIKE ?"
);

// DDC-1572
$this->assertSqlGeneration(
"SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE UPPER(u.name) LIKE UPPER(:str)",
"SELECT c0_.name AS name0 FROM cms_users c0_ WHERE UPPER(c0_.name) LIKE UPPER(?)"
);
$this->assertSqlGeneration(
"SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE UPPER(LOWER(u.name)) LIKE UPPER(LOWER(:str))",
"SELECT c0_.name AS name0 FROM cms_users c0_ WHERE UPPER(LOWER(c0_.name)) LIKE UPPER(LOWER(?))"
);
$this->assertSqlGeneration(
"SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a WITH a.topic LIKE u.name",
"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 LIKE c0_.name)"
);
}

/**
Expand Down