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