Commit 3bc4042a authored by guilhermeblanco's avatar guilhermeblanco

[2.0] Fixed wrong DQL error message. More improvements in DQL parser

parent 55651ec9
...@@ -656,11 +656,12 @@ class Parser ...@@ -656,11 +656,12 @@ class Parser
$fieldIdentificationVariable = $this->_lexer->token['value']; $fieldIdentificationVariable = $this->_lexer->token['value'];
} }
} else { } else {
// Deny hydration of partial objects if doctrine.forcePartialLoad query hint not defined
if ( if (
$this->_query->getHydrationMode() == Query::HYDRATE_OBJECT && $this->_query->getHydrationMode() == Query::HYDRATE_OBJECT &&
! $this->_em->getConfiguration()->getAllowPartialObjects() ! $this->_em->getConfiguration()->getAllowPartialObjects()
) { ) {
$this->semanticalError('Cannot select partial object when using object hydration'); throw DoctrineException::partialObjectsAreDangerous();
} }
$expression = $this->StateFieldPathExpression(); $expression = $this->StateFieldPathExpression();
...@@ -912,6 +913,7 @@ class Parser ...@@ -912,6 +913,7 @@ class Parser
public function SingleValuedAssociationPathExpression() public function SingleValuedAssociationPathExpression()
{ {
$pathExpr = $this->PathExpression(AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION); $pathExpr = $this->PathExpression(AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION);
if ( ! empty($this->_deferredPathExpressionStacks)) { if ( ! empty($this->_deferredPathExpressionStacks)) {
$exprStack = array_pop($this->_deferredPathExpressionStacks); $exprStack = array_pop($this->_deferredPathExpressionStacks);
$exprStack[] = $pathExpr; $exprStack[] = $pathExpr;
...@@ -1035,38 +1037,52 @@ class Parser ...@@ -1035,38 +1037,52 @@ class Parser
* *
* PathExpression ::= IdentificationVariable "." {identifier "."}* identifier * PathExpression ::= IdentificationVariable "." {identifier "."}* identifier
* *
* @todo Refactor. We should never use break in a loop! This should use a do { ... } while (...) instead
* @return PathExpression * @return PathExpression
*/ */
public function PathExpression($type) public function PathExpression($type)
{ {
$this->match(Lexer::T_IDENTIFIER); $this->match(Lexer::T_IDENTIFIER);
$identificationVariable = $this->_lexer->token['value']; $identificationVariable = $this->_lexer->token['value'];
$this->match('.');
$parts = array(); $parts = array();
while ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) { do {
$this->match('.');
$this->match(Lexer::T_IDENTIFIER); $this->match(Lexer::T_IDENTIFIER);
$parts[] = $this->_lexer->token['value']; $parts[] = $this->_lexer->token['value'];
} while ($this->_lexer->isNextToken('.'));
if ($this->_lexer->isNextToken('.')) {
$this->match('.');
} else {
break;
}
}
return new AST\PathExpression($type, $identificationVariable, $parts); return new AST\PathExpression($type, $identificationVariable, $parts);
} }
/** /**
* EntityExpression ::= SingleValuedAssociationPathExpression | SimpleEntityExpression * EntityExpression ::= SingleValuedAssociationPathExpression | SimpleEntityExpression
* SimpleEntityExpression ::= IdentificationVariable | InputParameter
*/ */
public function EntityExpression() public function EntityExpression()
{ {
$glimpse = $this->_lexer->glimpse();
if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER) && $glimpse['value'] === '.') {
return $this->SingleValuedAssociationPathExpression();
}
return $this->SimpleEntityExpression();
}
/**
* SimpleEntityExpression ::= IdentificationVariable | InputParameter
*/
public function SimpleEntityExpression()
{
if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) {
$this->match(Lexer::T_INPUT_PARAMETER);
return new AST\InputParameter($this->_lexer->token['value']);
}
$this->match(Lexer::T_IDENTIFIER);
return $this->_lexer->token['value'];
} }
/** /**
...@@ -1390,33 +1406,27 @@ class Parser ...@@ -1390,33 +1406,27 @@ class Parser
* SimpleEntityExpression ::= IdentificationVariable | InputParameter * SimpleEntityExpression ::= IdentificationVariable | InputParameter
* *
* @return AST\CollectionMemberExpression * @return AST\CollectionMemberExpression
* @todo Support SingleValuedAssociationPathExpression and IdentificationVariable
*/ */
public function CollectionMemberExpression() public function CollectionMemberExpression()
{ {
$isNot = false; $isNot = false;
if ($this->_lexer->lookahead['type'] == Lexer::T_INPUT_PARAMETER) { $entityExpr = $this->EntityExpression();
$this->match($this->_lexer->lookahead['value']);
$entityExpr = new AST\InputParameter($this->_lexer->token['value']);
if ($this->_lexer->isNextToken(Lexer::T_NOT)) { if ($this->_lexer->isNextToken(Lexer::T_NOT)) {
$isNot = true; $isNot = true;
$this->match(Lexer::T_NOT); $this->match(Lexer::T_NOT);
} }
$this->match(Lexer::T_MEMBER);
if ($this->_lexer->isNextToken(Lexer::T_OF)) { $this->match(Lexer::T_MEMBER);
$this->match(Lexer::T_OF);
}
$collValuedPathExpr = $this->CollectionValuedPathExpression(); if ($this->_lexer->isNextToken(Lexer::T_OF)) {
} else { $this->match(Lexer::T_OF);
throw QueryException::notImplemented();
} }
return new AST\CollectionMemberExpression($entityExpr, $collValuedPathExpr, $isNot); return new AST\CollectionMemberExpression(
$entityExpr, $this->CollectionValuedPathExpression(), $isNot
);
} }
/** /**
......
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