Fixed issue with SimpleSelectExpression containing Literals. This issue is related to a previously fixed ticket DDC-1079.
This commit is contained in:
parent
7841ccb7c0
commit
1f06e9fca5
@ -1292,83 +1292,80 @@ class SqlWalker implements TreeWalker
|
||||
*/
|
||||
public function walkSimpleSelectExpression($simpleSelectExpression)
|
||||
{
|
||||
$sql = '';
|
||||
$expr = $simpleSelectExpression->expression;
|
||||
$sql = ' ';
|
||||
|
||||
if ($expr instanceof AST\PathExpression) {
|
||||
switch (true) {
|
||||
case ($expr instanceof AST\PathExpression):
|
||||
$sql .= $this->walkPathExpression($expr);
|
||||
} else if ($expr instanceof AST\AggregateExpression) {
|
||||
if ( ! $simpleSelectExpression->fieldIdentificationVariable) {
|
||||
$alias = $this->_scalarResultCounter++;
|
||||
} else {
|
||||
$alias = $simpleSelectExpression->fieldIdentificationVariable;
|
||||
}
|
||||
break;
|
||||
|
||||
case ($expr instanceof AST\AggregateExpression):
|
||||
$alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->_scalarResultCounter++;
|
||||
|
||||
$sql .= $this->walkAggregateExpression($expr) . ' AS dctrn__' . $alias;
|
||||
} else if ($expr instanceof AST\Subselect) {
|
||||
if ( ! $simpleSelectExpression->fieldIdentificationVariable) {
|
||||
$alias = $this->_scalarResultCounter++;
|
||||
} else {
|
||||
$alias = $simpleSelectExpression->fieldIdentificationVariable;
|
||||
}
|
||||
break;
|
||||
|
||||
case ($expr instanceof AST\Subselect):
|
||||
$alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->_scalarResultCounter++;
|
||||
|
||||
$columnAlias = 'sclr' . $this->_aliasCounter++;
|
||||
$this->_scalarResultAliasMap[$alias] = $columnAlias;
|
||||
|
||||
$sql .= '(' . $this->walkSubselect($expr) . ') AS ' . $columnAlias;
|
||||
$this->_scalarResultAliasMap[$alias] = $columnAlias;
|
||||
} else if ($expr instanceof AST\Functions\FunctionNode) {
|
||||
if ( ! $simpleSelectExpression->fieldIdentificationVariable) {
|
||||
$alias = $this->_scalarResultCounter++;
|
||||
} else {
|
||||
$alias = $simpleSelectExpression->fieldIdentificationVariable;
|
||||
}
|
||||
break;
|
||||
|
||||
case ($expr instanceof AST\Functions\FunctionNode):
|
||||
$alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->_scalarResultCounter++;
|
||||
|
||||
$columnAlias = 'sclr' . $this->_aliasCounter++;
|
||||
$this->_scalarResultAliasMap[$alias] = $columnAlias;
|
||||
|
||||
$sql .= $this->walkFunction($expr) . ' AS ' . $columnAlias;
|
||||
$this->_scalarResultAliasMap[$alias] = $columnAlias;
|
||||
} else if (
|
||||
$expr instanceof AST\SimpleArithmeticExpression ||
|
||||
$expr instanceof AST\ArithmeticTerm ||
|
||||
$expr instanceof AST\ArithmeticFactor ||
|
||||
$expr instanceof AST\ArithmeticPrimary
|
||||
) {
|
||||
if ( ! $simpleSelectExpression->fieldIdentificationVariable) {
|
||||
$alias = $this->_scalarResultCounter++;
|
||||
} else {
|
||||
$alias = $simpleSelectExpression->fieldIdentificationVariable;
|
||||
}
|
||||
break;
|
||||
|
||||
case ($expr instanceof AST\Literal):
|
||||
$sql .= $this->walkLiteral($expr);
|
||||
break;
|
||||
|
||||
case ($expr instanceof AST\SimpleArithmeticExpression):
|
||||
case ($expr instanceof AST\ArithmeticTerm):
|
||||
case ($expr instanceof AST\ArithmeticFactor):
|
||||
case ($expr instanceof AST\ArithmeticPrimary):
|
||||
$alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->_scalarResultCounter++;
|
||||
|
||||
$columnAlias = 'sclr' . $this->_aliasCounter++;
|
||||
$this->_scalarResultAliasMap[$alias] = $columnAlias;
|
||||
|
||||
$sql .= $this->walkSimpleArithmeticExpression($expr) . ' AS ' . $columnAlias;
|
||||
$this->_scalarResultAliasMap[$alias] = $columnAlias;
|
||||
} else if (
|
||||
$expr instanceof AST\NullIfExpression ||
|
||||
$expr instanceof AST\CoalesceExpression ||
|
||||
$expr instanceof AST\GeneralCaseExpression ||
|
||||
$expr instanceof AST\SimpleCaseExpression
|
||||
) {
|
||||
if ( ! $simpleSelectExpression->fieldIdentificationVariable) {
|
||||
$alias = $this->_scalarResultCounter++;
|
||||
} else {
|
||||
$alias = $simpleSelectExpression->fieldIdentificationVariable;
|
||||
}
|
||||
break;
|
||||
|
||||
case ($expr instanceof AST\NullIfExpression):
|
||||
case ($expr instanceof AST\CoalesceExpression):
|
||||
case ($expr instanceof AST\GeneralCaseExpression):
|
||||
case ($expr instanceof AST\SimpleCaseExpression):
|
||||
$alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->_scalarResultCounter++;
|
||||
|
||||
$columnAlias = 'sclr' . $this->_aliasCounter++;
|
||||
$sql .= $this->walkCaseExpression($expr) . ' AS ' . $columnAlias;
|
||||
|
||||
$this->_scalarResultAliasMap[$alias] = $columnAlias;
|
||||
} else {
|
||||
// IdentificationVariable
|
||||
|
||||
$sql .= $this->walkCaseExpression($expr) . ' AS ' . $columnAlias;
|
||||
break;
|
||||
|
||||
default: // IdentificationVariable
|
||||
$class = $this->_queryComponents[$expr]['metadata'];
|
||||
$tableAlias = $this->getSQLTableAlias($class->getTableName(), $expr);
|
||||
$first = true;
|
||||
$sqlParts = array();
|
||||
|
||||
foreach ($class->identifier as $identifier) {
|
||||
if ($first) $first = false; else $sql .= ', ';
|
||||
$sql .= $tableAlias . '.' . $class->getQuotedColumnName($identifier, $this->_platform);
|
||||
}
|
||||
$sqlParts[] = $tableAlias . '.' . $class->getQuotedColumnName($identifier, $this->_platform);
|
||||
}
|
||||
|
||||
return ' ' . $sql;
|
||||
$sql .= implode(', ', $sqlParts);
|
||||
break;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -604,7 +604,24 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
. ' WHERE EXISTS ('
|
||||
. 'SELECT c1_.id FROM cms_employees c1_ WHERE c1_.id = c0_.spouse_id'
|
||||
. ')'
|
||||
);
|
||||
}
|
||||
|
||||
public function testExistsExpressionWithSimpleSelectReturningScalar()
|
||||
{
|
||||
$this->assertSqlGeneration(
|
||||
// DQL
|
||||
// The result of this query consists of all employees whose spouses are also employees.
|
||||
'SELECT DISTINCT emp FROM Doctrine\Tests\Models\CMS\CmsEmployee emp
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM Doctrine\Tests\Models\CMS\CmsEmployee spouseEmp
|
||||
WHERE spouseEmp = emp.spouse)',
|
||||
// SQL
|
||||
'SELECT DISTINCT c0_.id AS id0, c0_.name AS name1 FROM cms_employees c0_'
|
||||
. ' WHERE EXISTS ('
|
||||
. 'SELECT 1 FROM cms_employees c1_ WHERE c1_.id = c0_.spouse_id'
|
||||
. ')'
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user