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 ...@@ -43,6 +43,7 @@ class SingleScalarHydrator extends AbstractHydrator
} else if ($num > 1 || count($result[key($result)]) > 1) { } else if ($num > 1 || count($result[key($result)]) > 1) {
throw new \Doctrine\ORM\NonUniqueResultException; throw new \Doctrine\ORM\NonUniqueResultException;
} }
$result = $this->_gatherScalarRowData($result[key($result)], $cache); $result = $this->_gatherScalarRowData($result[key($result)], $cache);
return array_shift($result); return array_shift($result);
......
...@@ -41,6 +41,7 @@ namespace Doctrine\ORM\Query\AST; ...@@ -41,6 +41,7 @@ namespace Doctrine\ORM\Query\AST;
*/ */
class PathExpression extends Node class PathExpression extends Node
{ {
const TYPE_IDENTIFICATION_VARIABLE = 1;
const TYPE_COLLECTION_VALUED_ASSOCIATION = 2; const TYPE_COLLECTION_VALUED_ASSOCIATION = 2;
const TYPE_SINGLE_VALUED_ASSOCIATION = 4; const TYPE_SINGLE_VALUED_ASSOCIATION = 4;
const TYPE_STATE_FIELD = 8; const TYPE_STATE_FIELD = 8;
......
...@@ -565,7 +565,8 @@ class Parser ...@@ -565,7 +565,8 @@ class Parser
$aliasIdentificationVariable = $pathExpression->identificationVariable; $aliasIdentificationVariable = $pathExpression->identificationVariable;
$parentField = $pathExpression->identificationVariable; $parentField = $pathExpression->identificationVariable;
$class = $qComp['metadata']; $class = $qComp['metadata'];
$fieldType = null; $fieldType = ($pathExpression->expectedType == AST\PathExpression::TYPE_IDENTIFICATION_VARIABLE)
? AST\PathExpression::TYPE_IDENTIFICATION_VARIABLE : null;
$curIndex = 0; $curIndex = 0;
foreach ($parts as $field) { foreach ($parts as $field) {
...@@ -602,8 +603,8 @@ class Parser ...@@ -602,8 +603,8 @@ class Parser
$class = $this->_em->getClassMetadata($assoc->targetEntityName); $class = $this->_em->getClassMetadata($assoc->targetEntityName);
if ( if (
($curIndex != $numParts - 1) && ($curIndex != $numParts - 1) &&
! isset($this->_queryComponents[$aliasIdentificationVariable . '.' . $field]) ! isset($this->_queryComponents[$aliasIdentificationVariable . '.' . $field])
) { ) {
// Building queryComponent // Building queryComponent
$joinQueryComponent = array( $joinQueryComponent = array(
...@@ -617,13 +618,13 @@ class Parser ...@@ -617,13 +618,13 @@ class Parser
// Create AST node // Create AST node
$joinVariableDeclaration = new AST\JoinVariableDeclaration( $joinVariableDeclaration = new AST\JoinVariableDeclaration(
new AST\Join( new AST\Join(
AST\Join::JOIN_TYPE_INNER, AST\Join::JOIN_TYPE_INNER,
new AST\JoinAssociationPathExpression($aliasIdentificationVariable, $field), new AST\JoinAssociationPathExpression($aliasIdentificationVariable, $field),
$aliasIdentificationVariable . '.' . $field, $aliasIdentificationVariable . '.' . $field,
false false
), ),
null null
); );
$AST->fromClause->identificationVariableDeclarations[0]->joinVariableDeclarations[] = $joinVariableDeclaration; $AST->fromClause->identificationVariableDeclarations[0]->joinVariableDeclarations[] = $joinVariableDeclaration;
...@@ -649,6 +650,11 @@ class Parser ...@@ -649,6 +650,11 @@ class Parser
// We need to recognize which was expected type(s) // We need to recognize which was expected type(s)
$expectedStringTypes = array(); $expectedStringTypes = array();
// Validate state field type
if ($expectedType & AST\PathExpression::TYPE_IDENTIFICATION_VARIABLE) {
$expectedStringTypes[] = 'IdentificationVariable';
}
// Validate state field type // Validate state field type
if ($expectedType & AST\PathExpression::TYPE_STATE_FIELD) { if ($expectedType & AST\PathExpression::TYPE_STATE_FIELD) {
$expectedStringTypes[] = 'StateFieldPathExpression'; $expectedStringTypes[] = 'StateFieldPathExpression';
...@@ -915,12 +921,12 @@ class Parser ...@@ -915,12 +921,12 @@ class Parser
$identVariable = $this->IdentificationVariable(); $identVariable = $this->IdentificationVariable();
$parts = array(); $parts = array();
do { while ($this->_lexer->isNextToken(Lexer::T_DOT)) {
$this->match(Lexer::T_DOT); $this->match(Lexer::T_DOT);
$this->match(Lexer::T_IDENTIFIER); $this->match(Lexer::T_IDENTIFIER);
$parts[] = $this->_lexer->token['value']; $parts[] = $this->_lexer->token['value'];
} while ($this->_lexer->isNextToken(Lexer::T_DOT)); }
// Creating AST node // Creating AST node
$pathExpr = new AST\PathExpression($expectedTypes, $identVariable, $parts); $pathExpr = new AST\PathExpression($expectedTypes, $identVariable, $parts);
...@@ -2168,7 +2174,7 @@ class Parser ...@@ -2168,7 +2174,7 @@ class Parser
return $this->SingleValuedPathExpression(); return $this->SingleValuedPathExpression();
} }
return $this->IdentificationVariable(); return $this->PathExpression(AST\PathExpression::TYPE_IDENTIFICATION_VARIABLE);
case Lexer::T_INPUT_PARAMETER: case Lexer::T_INPUT_PARAMETER:
return $this->InputParameter(); return $this->InputParameter();
......
...@@ -446,6 +446,17 @@ class SqlWalker implements TreeWalker ...@@ -446,6 +446,17 @@ class SqlWalker implements TreeWalker
$sql = ''; $sql = '';
switch ($pathExpr->type) { 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: case AST\PathExpression::TYPE_STATE_FIELD:
$parts = $pathExpr->parts; $parts = $pathExpr->parts;
$fieldName = array_pop($parts); $fieldName = array_pop($parts);
...@@ -458,6 +469,7 @@ class SqlWalker implements TreeWalker ...@@ -458,6 +469,7 @@ class SqlWalker implements TreeWalker
$sql .= $class->getQuotedColumnName($fieldName, $this->_platform); $sql .= $class->getQuotedColumnName($fieldName, $this->_platform);
break; break;
case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION: case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION:
// 1- the owning side: // 1- the owning side:
// Just use the foreign key, i.e. u.group_id // Just use the foreign key, i.e. u.group_id
...@@ -484,6 +496,7 @@ class SqlWalker implements TreeWalker ...@@ -484,6 +496,7 @@ class SqlWalker implements TreeWalker
throw QueryException::associationPathInverseSideNotSupported(); throw QueryException::associationPathInverseSideNotSupported();
} }
break; break;
default: default:
throw QueryException::invalidPathExpression($pathExpr); throw QueryException::invalidPathExpression($pathExpr);
} }
......
...@@ -21,6 +21,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -21,6 +21,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
$query = $this->_em->createQuery($dqlToBeTested); $query = $this->_em->createQuery($dqlToBeTested);
$query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true) $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
->useQueryCache(false); ->useQueryCache(false);
parent::assertEquals($sqlToBeConfirmed, $query->getSql()); parent::assertEquals($sqlToBeConfirmed, $query->getSql());
$query->free(); $query->free();
} catch (\Exception $e) { } catch (\Exception $e) {
...@@ -385,7 +386,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -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()); $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( $this->assertSqlGeneration(
// DQL // DQL
...@@ -402,7 +403,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ...@@ -402,7 +403,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
. ')' . ')'
); );
}*/ }
public function testLimitFromQueryClass() 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