Properly fixed DDC-1858. Added support for ResultVariable in NullComparisons while using HavingClause.
This commit is contained in:
parent
a19106b03d
commit
d9c1782a4f
@ -3108,7 +3108,7 @@ class Parser
|
||||
}
|
||||
|
||||
/**
|
||||
* NullComparisonExpression ::= (InputParameter | NullIfExpression | CoalesceExpression | SingleValuedPathExpression) "IS" ["NOT"] "NULL"
|
||||
* NullComparisonExpression ::= (InputParameter | NullIfExpression | CoalesceExpression | SingleValuedPathExpression | ResultVariable) "IS" ["NOT"] "NULL"
|
||||
*
|
||||
* @return \Doctrine\ORM\Query\AST\NullComparisonExpression
|
||||
*/
|
||||
@ -3134,7 +3134,29 @@ class Parser
|
||||
break;
|
||||
|
||||
default:
|
||||
$expr = $this->SingleValuedPathExpression();
|
||||
// We need to check if we are in a IdentificationVariable or SingleValuedPathExpression
|
||||
$glimpse = $this->lexer->glimpse();
|
||||
|
||||
if ($glimpse['type'] === Lexer::T_DOT) {
|
||||
$expr = $this->SingleValuedPathExpression();
|
||||
|
||||
// Leave switch statement
|
||||
break;
|
||||
}
|
||||
|
||||
$lookaheadValue = $this->lexer->lookahead['value'];
|
||||
|
||||
// Validate existing component
|
||||
if ( ! isset($this->queryComponents[$lookaheadValue])) {
|
||||
$this->semanticalError('Cannot add having condition on undefined result variable.');
|
||||
}
|
||||
|
||||
// Validating ResultVariable
|
||||
if ( ! isset($this->queryComponents[$lookaheadValue]['resultVariable'])) {
|
||||
$this->semanticalError('Cannot add having condition on a non result variable.');
|
||||
}
|
||||
|
||||
$expr = $this->ResultVariable();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1921,9 +1921,15 @@ class SqlWalker implements TreeWalker
|
||||
*/
|
||||
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'])) {
|
||||
return $this->walkResultVariable($expression) . $comparison;
|
||||
}
|
||||
|
||||
// Handle InputParameter mapping inclusion to ParserResult
|
||||
if ($expression instanceof AST\InputParameter) {
|
||||
$this->parserResult->addParameterMapping($expression->name, $this->sqlParamIndex++);
|
||||
|
||||
|
@ -2050,6 +2050,17 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
'SELECT c0_.name AS name0 FROM cms_users c0_ HAVING name0 IN (?)'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1858
|
||||
*/
|
||||
public function testHavingSupportResultVariableInAggregateFunction()
|
||||
{
|
||||
$this->assertSqlGeneration(
|
||||
'SELECT COUNT(u.name) AS countName FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING countName IS NULL',
|
||||
'SELECT COUNT(c0_.name) AS sclr0 FROM cms_users c0_ HAVING sclr0 IS NULL'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyAbsFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode
|
||||
|
Loading…
x
Reference in New Issue
Block a user