1
0
mirror of synced 2025-01-18 14:31:40 +03:00

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

This commit is contained in:
Miloslav Kmet 2011-12-29 15:39:32 +01:00
parent 959a68694e
commit ae4321b4e3
3 changed files with 21 additions and 3 deletions

View File

@ -2813,7 +2813,7 @@ class Parser
}
/**
* LikeExpression ::= StringExpression ["NOT"] "LIKE" (string | input_parameter) ["ESCAPE" char]
* LikeExpression ::= StringExpression ["NOT"] "LIKE" StringPrimary ["ESCAPE" char]
*
* @return \Doctrine\ORM\Query\AST\LikeExpression
*/
@ -2833,8 +2833,7 @@ class Parser
$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;

View File

@ -1947,6 +1947,10 @@ class SqlWalker implements TreeWalker
$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);
}

View File

@ -822,6 +822,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
/**
* @group DDC-339
* @group DDC-1572
*/
public function testStringFunctionLikeExpression()
{
@ -837,6 +838,20 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
"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)"
);
}
/**