Commit 88909470 authored by Guilherme Blanco's avatar Guilherme Blanco

[2.0] Added support to IdentificationVariable that was missing in...

[2.0] Added support to IdentificationVariable that was missing in ArithmeticPrimary (it was not correctly handling it). Uncommented a unit test that added coverage to it.
parent f3d91b9e
......@@ -43,6 +43,7 @@ class SingleScalarHydrator extends AbstractHydrator
} else if ($num > 1 || count($result[key($result)]) > 1) {
throw new \Doctrine\ORM\NonUniqueResultException;
}
$result = $this->_gatherScalarRowData($result[key($result)], $cache);
return array_shift($result);
......
......@@ -41,6 +41,7 @@ namespace Doctrine\ORM\Query\AST;
*/
class PathExpression extends Node
{
const TYPE_IDENTIFICATION_VARIABLE = 1;
const TYPE_COLLECTION_VALUED_ASSOCIATION = 2;
const TYPE_SINGLE_VALUED_ASSOCIATION = 4;
const TYPE_STATE_FIELD = 8;
......
......@@ -565,7 +565,8 @@ class Parser
$aliasIdentificationVariable = $pathExpression->identificationVariable;
$parentField = $pathExpression->identificationVariable;
$class = $qComp['metadata'];
$fieldType = null;
$fieldType = ($pathExpression->expectedType == AST\PathExpression::TYPE_IDENTIFICATION_VARIABLE)
? AST\PathExpression::TYPE_IDENTIFICATION_VARIABLE : null;
$curIndex = 0;
foreach ($parts as $field) {
......@@ -602,8 +603,8 @@ class Parser
$class = $this->_em->getClassMetadata($assoc->targetEntityName);
if (
($curIndex != $numParts - 1) &&
! isset($this->_queryComponents[$aliasIdentificationVariable . '.' . $field])
($curIndex != $numParts - 1) &&
! isset($this->_queryComponents[$aliasIdentificationVariable . '.' . $field])
) {
// Building queryComponent
$joinQueryComponent = array(
......@@ -617,13 +618,13 @@ class Parser
// Create AST node
$joinVariableDeclaration = new AST\JoinVariableDeclaration(
new AST\Join(
AST\Join::JOIN_TYPE_INNER,
new AST\JoinAssociationPathExpression($aliasIdentificationVariable, $field),
$aliasIdentificationVariable . '.' . $field,
false
),
null
new AST\Join(
AST\Join::JOIN_TYPE_INNER,
new AST\JoinAssociationPathExpression($aliasIdentificationVariable, $field),
$aliasIdentificationVariable . '.' . $field,
false
),
null
);
$AST->fromClause->identificationVariableDeclarations[0]->joinVariableDeclarations[] = $joinVariableDeclaration;
......@@ -649,6 +650,11 @@ class Parser
// We need to recognize which was expected type(s)
$expectedStringTypes = array();
// Validate state field type
if ($expectedType & AST\PathExpression::TYPE_IDENTIFICATION_VARIABLE) {
$expectedStringTypes[] = 'IdentificationVariable';
}
// Validate state field type
if ($expectedType & AST\PathExpression::TYPE_STATE_FIELD) {
$expectedStringTypes[] = 'StateFieldPathExpression';
......@@ -915,12 +921,12 @@ class Parser
$identVariable = $this->IdentificationVariable();
$parts = array();
do {
while ($this->_lexer->isNextToken(Lexer::T_DOT)) {
$this->match(Lexer::T_DOT);
$this->match(Lexer::T_IDENTIFIER);
$parts[] = $this->_lexer->token['value'];
} while ($this->_lexer->isNextToken(Lexer::T_DOT));
}
// Creating AST node
$pathExpr = new AST\PathExpression($expectedTypes, $identVariable, $parts);
......@@ -2168,7 +2174,7 @@ class Parser
return $this->SingleValuedPathExpression();
}
return $this->IdentificationVariable();
return $this->PathExpression(AST\PathExpression::TYPE_IDENTIFICATION_VARIABLE);
case Lexer::T_INPUT_PARAMETER:
return $this->InputParameter();
......
......@@ -446,6 +446,17 @@ class SqlWalker implements TreeWalker
$sql = '';
switch ($pathExpr->type) {
case AST\PathExpression::TYPE_IDENTIFICATION_VARIABLE:
$dqlAlias = $pathExpr->identificationVariable;
$class = $this->_queryComponents[$dqlAlias]['metadata'];
if ($this->_useSqlTableAliases) {
$sql .= $this->walkIdentificationVariable($dqlAlias) . '.';
}
$sql .= $class->getQuotedColumnName($class->identifier[0], $this->_platform);
break;
case AST\PathExpression::TYPE_STATE_FIELD:
$parts = $pathExpr->parts;
$fieldName = array_pop($parts);
......@@ -458,6 +469,7 @@ class SqlWalker implements TreeWalker
$sql .= $class->getQuotedColumnName($fieldName, $this->_platform);
break;
case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION:
// 1- the owning side:
// Just use the foreign key, i.e. u.group_id
......@@ -484,6 +496,7 @@ class SqlWalker implements TreeWalker
throw QueryException::associationPathInverseSideNotSupported();
}
break;
default:
throw QueryException::invalidPathExpression($pathExpr);
}
......
......@@ -21,6 +21,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
$query = $this->_em->createQuery($dqlToBeTested);
$query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
->useQueryCache(false);
parent::assertEquals($sqlToBeConfirmed, $query->getSql());
$query->free();
} catch (\Exception $e) {
......@@ -385,7 +386,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.col_datetime > CURRENT_TIMESTAMP', $q->getSql());
}
/*public function testExistsExpressionInWhereCorrelatedSubqueryAssocCondition()
public function testExistsExpressionInWhereCorrelatedSubqueryAssocCondition()
{
$this->assertSqlGeneration(
// DQL
......@@ -402,7 +403,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
. ')'
);
}*/
}
public function testLimitFromQueryClass()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment