Permalink
Browse files

DDC-1858 Added missing support to ResultVariable in LikeExpression.

  • Loading branch information...
Guilherme Blanco
Guilherme Blanco committed Aug 19, 2013
1 parent 605c32d commit 43fc8bafa766b4e924b05c74825dd30393a17f06
@@ -1583,7 +1583,7 @@ Scalar and Type Expressions
.. code-block:: php
ScalarExpression ::= SimpleArithmeticExpression | StringPrimary | DateTimePrimary | StateFieldPathExpression | BooleanPrimary | CaseExpression | InstanceOfExpression
- StringExpression ::= StringPrimary | "(" Subselect ")"
+ StringExpression ::= StringPrimary | ResultVariable | "(" Subselect ")"
StringPrimary ::= StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression | CaseExpression
BooleanExpression ::= BooleanPrimary | "(" Subselect ")"
BooleanPrimary ::= StateFieldPathExpression | boolean | InputParameter
@@ -2776,23 +2776,29 @@ public function ArithmeticPrimary()
}
/**
- * StringExpression ::= StringPrimary | "(" Subselect ")"
+ * StringExpression ::= StringPrimary | ResultVariable | "(" Subselect ")"
*
* @return \Doctrine\ORM\Query\AST\StringPrimary |
- * \Doctrine\ORM\Query\AST\Subselect
+ * \Doctrine\ORM\Query\AST\Subselect |
+ * string
*/
public function StringExpression()
{
- if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) {
- $peek = $this->lexer->glimpse();
+ $peek = $this->lexer->glimpse();
- if ($peek['type'] === Lexer::T_SELECT) {
- $this->match(Lexer::T_OPEN_PARENTHESIS);
- $expr = $this->Subselect();
- $this->match(Lexer::T_CLOSE_PARENTHESIS);
+ // Subselect
+ if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS) && $peek['type'] === Lexer::T_SELECT) {
+ $this->match(Lexer::T_OPEN_PARENTHESIS);
+ $expr = $this->Subselect();
+ $this->match(Lexer::T_CLOSE_PARENTHESIS);
- return $expr;
- }
+ return $expr;
+ }
+
+ // ResultVariable (string)
+ if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER) &&
+ isset($this->queryComponents[$this->lexer->lookahead['value']]['resultVariable'])) {
+ return $this->ResultVariable();
}
return $this->StringPrimary();
@@ -1944,8 +1944,8 @@ public function walkEmptyCollectionComparisonExpression($emptyCollCompExpr)
*/
public function walkNullComparisonExpression($nullCompExpr)
{
- $expression = $nullCompExpr->expression;
- $comparison = ' IS' . ($nullCompExpr->not ? ' NOT' : '') . ' NULL';
+ $expression = $nullCompExpr->expression;
+ $comparison = ' IS' . ($nullCompExpr->not ? ' NOT' : '') . ' NULL';
// Handle ResultVariable
if (is_string($expression) && isset($this->queryComponents[$expression]['resultVariable'])) {
@@ -2001,9 +2001,7 @@ public function walkInstanceOfExpression($instanceOfExpr)
$sqlParameterList = array();
foreach ($instanceOfExpr->value as $parameter) {
-
if ($parameter instanceof AST\InputParameter) {
-
$this->rsm->addMetadataParameterMapping($parameter->name, 'discriminatorValue');
$sqlParameterList[] = $this->walkInputParameter($parameter);
@@ -2073,7 +2071,9 @@ public function walkBetweenExpression($betweenExpr)
{
$sql = $this->walkArithmeticExpression($betweenExpr->expression);
- if ($betweenExpr->not) $sql .= ' NOT';
+ if ($betweenExpr->not) {
+ $sql .= ' NOT';
+ }
$sql .= ' BETWEEN ' . $this->walkArithmeticExpression($betweenExpr->leftBetweenExpression)
. ' AND ' . $this->walkArithmeticExpression($betweenExpr->rightBetweenExpression);
@@ -2087,14 +2087,18 @@ public function walkBetweenExpression($betweenExpr)
public function walkLikeExpression($likeExpr)
{
$stringExpr = $likeExpr->stringExpression;
- $sql = $stringExpr->dispatch($this) . ($likeExpr->not ? ' NOT' : '') . ' LIKE ';
+ $leftExpr = (is_string($stringExpr) && isset($this->queryComponents[$stringExpr]['resultVariable']))
+ ? $this->walkResultVariable($stringExpr)
+ : $stringExpr->dispatch($this);
+
+ $sql = $leftExpr . ($likeExpr->not ? ' NOT' : '') . ' LIKE ';
if ($likeExpr->stringPattern instanceof AST\InputParameter) {
$inputParam = $likeExpr->stringPattern;
$dqlParamKey = $inputParam->name;
$this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++);
$sql .= '?';
- } elseif ($likeExpr->stringPattern instanceof AST\Functions\FunctionNode ) {
+ } elseif ($likeExpr->stringPattern instanceof AST\Functions\FunctionNode) {
$sql .= $this->walkFunction($likeExpr->stringPattern);
} elseif ($likeExpr->stringPattern instanceof AST\PathExpression) {
$sql .= $this->walkPathExpression($likeExpr->stringPattern);
@@ -598,6 +598,14 @@ public function testHavingSupportIsNullExpression()
{
$this->assertValidDQL("SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING u.username IS NULL");
}
+
+ /**
+ * @gorup DDC-1858
+ */
+ public function testHavingSupportLikeExpression()
+ {
+ $this->assertValidDQL("SELECT _u.id, count(_articles) as uuuu FROM Doctrine\Tests\Models\CMS\CmsUser _u LEFT JOIN _u.articles _articles GROUP BY _u HAVING uuuu LIKE '3'");
+ }
}
/** @Entity */
@@ -2142,6 +2142,17 @@ public function testHavingSupportResultVariableInExpression()
);
}
+ /**
+ * @group DDC-1858
+ */
+ public function testHavingSupportResultVariableLikeExpression()
+ {
+ $this->assertSqlGeneration(
+ "SELECT u.name AS foo FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING foo LIKE '3'",
+ "SELECT c0_.name AS name0 FROM cms_users c0_ HAVING name0 LIKE '3'"
+ );
+ }
+
/**
* @group DDC-1858
*/

0 comments on commit 43fc8ba

Please sign in to comment.