Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDC-864: DQL: EBNF for Subselects is incorrect. Path expressions in general do not work as described. Related to Bugs 857, 863 #5386

Closed
doctrinebot opened this issue Nov 6, 2010 · 6 comments
Labels

Comments

@doctrinebot
Copy link

Jira issue originally created by user dalvarez:

DQL queries of the following form will not work:

SELECT a FROM \SomeNamespace\SomeClass a
WHERE a.someField IN (SELECT b.someRelationship.someField FROM \SomeNamespace\SomeOtherClass b
WHERE b.someOtherField = :whatever)

failing with an error like

exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 137: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '.'' in /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/QueryException.php:42 Stack trace: #0 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(345): Doctrine\ORM\Query\QueryException::syntaxError('line 0, col 137...') #1 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(240): Doctrine\ORM\Query\Parser->syntaxError('Doctrine\ORM\Qu...') #2 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(1142): Doctrine\ORM\Query\Parser->match(120) #3 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(1229): Doctrine\ORM\Query\Parser->SubselectFromClause() #4 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(2077): Doctrine\ORM\Query\Parser->Subselect() #5 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(2407): Doctrine\ORM\Query\Parser->ArithmeticExpression() #6 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(1947): Doctrine\ORM\Query\Parser->ComparisonExpression() #7 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(1863): Doctrine\ORM\Query\Parser->SimpleConditionalExpression() #8 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(1829): Doctrine\ORM\Query\Parser->ConditionalPrimary() #9 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(1799): Doctrine\ORM\Query\Parser->ConditionalFactor() #10 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(1775): Doctrine\ORM\Query\Parser->ConditionalTerm() #11 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(1163): Doctrine\ORM\Query\Parser->ConditionalExpression() #12 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(718): Doctrine\ORM\Query\Parser->WhereClause() #13 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(687): Doctrine\ORM\Query\Parser->SelectStatement() #14 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(202): Doctrine\ORM\Query\Parser->QueryLanguage() #15 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query/Parser.php(273): Doctrine\ORM\Query\Parser->getAST() #16 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query.php(203): Doctrine\ORM\Query\Parser->parse() #17 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/Query.php(223): Doctrine\ORM\Query->_parse() #18 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/AbstractQuery.php(528): Doctrine\ORM\Query->_doExecute() #19 /var/www/invoiceCreator/src/thirdPartyComponents/doctrine/Doctrine/ORM/AbstractQuery.php(366): Doctrine\ORM\AbstractQuery->execute(Array, 1)

Whereas queries of the form:

SELECT a FROM \SomeNamespace\SomeClass a
WHERE a.someField IN (SELECT b.someField FROM \SomeNamespace\SomeOtherClass b
WHERE b.someOtherField = :whatever)

will work.

The following EBNF definitions told me to do it:

Subselect ::= SimpleSelectClause SubselectFromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
SimpleSelectClause ::= "SELECT" ["DISTINCT"] SimpleSelectExpression
SimpleSelectExpression ::= ScalarExpression | IdentificationVariable |
(AggregateExpression [["AS"] AliasResultVariable])
ScalarExpression ::= SimpleArithmeticExpression | StringPrimary | DateTimePrimary | StateFieldPathExpression
BooleanPrimary | CaseExpression | EntityTypeExpression
StateFieldPathExpression ::= IdentificationVariable "." StateField | SingleValuedAssociationPathExpression "." StateField
SingleValuedAssociationPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}* SingleValuedAssociationField

Of course, the query shown above is impractical, because ideally it could all be written as a single path expression, but I was trying to work around Bug http://www.doctrine-project.org/jira/browse/[DDC-857](http://www.doctrine-project.org/jira/browse/DDC-857).

I think all the EBNF relating to path expressions needs some serious reworking. It seems that the SingleValuedAssociationPathExpression never works as described. Currently it is not elegantly possible to work with DQL queries that involve various related entities without performing manual joins.

See Bugs http://www.doctrine-project.org/jira/browse/[DDC-857](http://www.doctrine-project.org/jira/browse/DDC-857) and http://www.doctrine-project.org/jira/browse/[DDC-863](http://www.doctrine-project.org/jira/browse/DDC-863)

The ideal fix would probably be to implement support for the SingleValuedAssociationPathExpression the way it is documented. It really makes sense and should not be too difficult to implement, but would be a real win in terms of usability.

@doctrinebot
Copy link
Author

Comment created by romanb:

It is a documentation issue. The BNF has not yet been updated. Support for "deep" path expressions, which was only a (small) convenience for more explicit joins, are no longer supported due to too many complications in the implementation.

@doctrinebot
Copy link
Author

Comment created by romanb:

Please do not open any more tickets that are about the same issue. A single ticket that says that the EBNF in the documentation needs to be updated would be ideal. Thank you.

@doctrinebot
Copy link
Author

Comment created by dalvarez:

Sorry, I was trying to be specific.

@doctrinebot
Copy link
Author

Comment created by romanb:

You were. I didn't mean to critize the tickets :) The way you wrote them is exemplary. Please keep this style for any new tickets, it really helps to quickly grasp the issue.

@doctrinebot
Copy link
Author

Comment created by dalvarez:

I close this bug, which is still unresolved, combining Bugs 857, 863 and 864 into Bug 866.

@doctrinebot
Copy link
Author

Issue was closed with resolution "Duplicate"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant