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

Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got EntityName since upgrade to 2.6.0 #6932

Closed
allan-simon opened this issue Dec 21, 2017 · 8 comments

Comments

@allan-simon
Copy link

allan-simon commented Dec 21, 2017

I have the following builder request

          return $builder
              ->select('e')
              ->from('AppBundle:Event', 'e')
              ->addSelect('MIN(o.startTime) AS HIDDEN')
              ->leftJoin('e.occurences', 'o')
              ->where('o.startTime BETWEEN CURRENT_DATE() AND :date ')
              ->andWhere('e.published = true')
              ->andWhere('e.place = :place')
              ->groupBy('e.id')
              ->setMaxResults(10)
              ->setParameter(':date', $date)
              ->setParameter(':place', $place)
              ->getQuery()
              ->getResult()
          ;   

it used to work fine, but since upgrade to 2.6.0 I got the error

[Syntax Error] line 0, col 42: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got 'AppBundle:Event'

It seems to work if I add FROM like this :

              ->from(' FROM AppBundle:Event', 'e')

is it a known issue ? (or something wrong in my original code ?)

@Ocramius
Copy link
Member

What's the generated DQL string for that query builder?

@allan-simon
Copy link
Author

how do i get it ?

@Ocramius
Copy link
Member

Instead of ->getQuery() do a ->getDQL()

@Majkl578
Copy link
Contributor

On master, QB generates following DQL:

SELECT e, MIN(o.startTime) AS HIDDEN FROM AppBundle:Event e LEFT JOIN e.occurences o WHERE (o.startTime BETWEEN CURRENT_DATE() AND :date ) AND e.published = true AND e.place = :place GROUP BY e.id

So there is obviously missing alias for MIN() function.

@Ocramius
Copy link
Member

Ocramius commented Dec 21, 2017 via email

@Majkl578
Copy link
Contributor

"HIDDEN" is a reserved DQL keyword

Yes, but the query is valid according to 2.5 EBNF:

SelectExpression        ::= (IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression | NewObjectExpression) [["AS"] ["HIDDEN"] AliasResultVariable]

"AS HIDDEN" is fine and the alias should be optional as well (which sounds a bit strange though).

This is not a QueryBuilder bug which generates same DQL as on 2.5, but a parser bug.

LanguageRecognitionTest test case:

    public function testOmittingAliasVariableInSelectExpression() : void
    {
        $this->assertValidDQL('SELECT g, LENGTH(g.from) AS HIDDEN FROM ' . DQLKeywordsModelGroup::class . ' g');
    }

Works with 2.5, fails with 2.6.
Bisected to b7bd426 so it's related to #6928.

@stof
Copy link
Member

stof commented Mar 7, 2018

Not, the EBNF has [["AS"] ["HIDDEN"] AliasResultVariable]. so AS HIDDEN is not valid, as you miss the AliasResultVariable

@beberlei
Copy link
Member

beberlei commented Dec 7, 2020

Fixed by #7077

@beberlei beberlei closed this as completed Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants