[DDC-1572] Allow LIKE pattern to be a function or path expression
This commit is contained in:
parent
959a68694e
commit
ae4321b4e3
@ -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
|
* @return \Doctrine\ORM\Query\AST\LikeExpression
|
||||||
*/
|
*/
|
||||||
@ -2833,8 +2833,7 @@ class Parser
|
|||||||
$this->match(Lexer::T_INPUT_PARAMETER);
|
$this->match(Lexer::T_INPUT_PARAMETER);
|
||||||
$stringPattern = new AST\InputParameter($this->_lexer->token['value']);
|
$stringPattern = new AST\InputParameter($this->_lexer->token['value']);
|
||||||
} else {
|
} else {
|
||||||
$this->match(Lexer::T_STRING);
|
$stringPattern = $this->StringPrimary();
|
||||||
$stringPattern = $this->_lexer->token['value'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$escapeChar = null;
|
$escapeChar = null;
|
||||||
|
@ -1947,6 +1947,10 @@ class SqlWalker implements TreeWalker
|
|||||||
$dqlParamKey = $inputParam->name;
|
$dqlParamKey = $inputParam->name;
|
||||||
$this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++);
|
$this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++);
|
||||||
$sql .= '?';
|
$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 {
|
} else {
|
||||||
$sql .= $this->_conn->quote($likeExpr->stringPattern);
|
$sql .= $this->_conn->quote($likeExpr->stringPattern);
|
||||||
}
|
}
|
||||||
|
@ -822,6 +822,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group DDC-339
|
* @group DDC-339
|
||||||
|
* @group DDC-1572
|
||||||
*/
|
*/
|
||||||
public function testStringFunctionLikeExpression()
|
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 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 ?"
|
"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)"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user