Expected Doctrine\ORM\Query\Lexer::T_END, got 'AS' since 2.6.0 #5841

Closed
opened 2026-01-22 15:19:21 +01:00 by admin · 5 comments
Owner

Originally created by @soullivaneuh on GitHub (Jan 9, 2018).

With the following query builder:

$qb = $this->createQueryBuilder('t');
$qb
    ->select('t, a, m, s')
    ->leftJoin('t.author', 'a')
    ->leftJoin('t.messages', 'm')
    ->leftJoin('t.server', 's')
;

// STATE_* are integers.
$qb->where('t.state != :state')->setParameter('state', Ticket::STATE_CLOSE);

$qb->addSelect('CASE WHEN (t.assigned IS NULL) THEN -10 + t.state ELSE t.state AS state_order');
$qb->addOrderBy('state_order', 'ASC');
$qb->addOrderBy('t.priority', 'DESC');
$qb->addOrderBy('t.addedAt', 'ASC');
// $assignee is a User entity instance.
$qb->andWhere('t.assigned = :assigned')->setParameter('assigned', $assignee);
$qb->andWhere($qb->expr()->in('t.state', [
    Ticket::STATE_OPEN,
    Ticket::STATE_PENDING,
    Ticket::STATE_PENDING,
]));

I have this error on execute():

[Syntax Error] line 0, col 82: Error: Expected Doctrine\ORM\Query\Lexer::T_END, got 'AS'

Here is the produced DQL:

SELECT t, a, m, s, CASE WHEN (t.assigned IS NULL) THEN -10 + t.state ELSE t.state AS state_order FROM AppBundle\Entity\Ticket t LEFT JOIN t.author a LEFT JOIN t.messages m LEFT JOIN t.server s WHERE t.state != :state AND t.assigned = :assigned AND t.state IN(0, 1, 1) ORDER BY state_order ASC, t.priority DESC, t.addedAt ASC

Rolling back to 2.5 solve the issue, so it looks like a BC break.

Originally created by @soullivaneuh on GitHub (Jan 9, 2018). With the following query builder: ```php $qb = $this->createQueryBuilder('t'); $qb ->select('t, a, m, s') ->leftJoin('t.author', 'a') ->leftJoin('t.messages', 'm') ->leftJoin('t.server', 's') ; // STATE_* are integers. $qb->where('t.state != :state')->setParameter('state', Ticket::STATE_CLOSE); $qb->addSelect('CASE WHEN (t.assigned IS NULL) THEN -10 + t.state ELSE t.state AS state_order'); $qb->addOrderBy('state_order', 'ASC'); $qb->addOrderBy('t.priority', 'DESC'); $qb->addOrderBy('t.addedAt', 'ASC'); // $assignee is a User entity instance. $qb->andWhere('t.assigned = :assigned')->setParameter('assigned', $assignee); $qb->andWhere($qb->expr()->in('t.state', [ Ticket::STATE_OPEN, Ticket::STATE_PENDING, Ticket::STATE_PENDING, ])); ``` I have this error on `execute()`: ``` [Syntax Error] line 0, col 82: Error: Expected Doctrine\ORM\Query\Lexer::T_END, got 'AS' ``` Here is the produced DQL: ``` SELECT t, a, m, s, CASE WHEN (t.assigned IS NULL) THEN -10 + t.state ELSE t.state AS state_order FROM AppBundle\Entity\Ticket t LEFT JOIN t.author a LEFT JOIN t.messages m LEFT JOIN t.server s WHERE t.state != :state AND t.assigned = :assigned AND t.state IN(0, 1, 1) ORDER BY state_order ASC, t.priority DESC, t.addedAt ASC ``` Rolling back to 2.5 solve the issue, so it looks like a BC break.
admin added the BugDQL labels 2026-01-22 15:19:21 +01:00
admin closed this issue 2026-01-22 15:19:21 +01:00
Author
Owner

@Majkl578 commented on GitHub (Jan 9, 2018):

This is actually bug in your code: CASE WHEN ... THEN ... ELSE ... requires to be ended with END. For reference see DQL EBNF for GeneralCaseExpression in 2.5: https://github.com/doctrine/doctrine2/blob/v2.5.14/docs/en/reference/dql-doctrine-query-language.rst#case-expressions
The code for this hasn't been touched for years though so any breakage in this regard is suspicious.

@Majkl578 commented on GitHub (Jan 9, 2018): This is actually bug in your code: `CASE WHEN ... THEN ... ELSE ...` requires to be ended with `END`. For reference see DQL EBNF for GeneralCaseExpression in 2.5: https://github.com/doctrine/doctrine2/blob/v2.5.14/docs/en/reference/dql-doctrine-query-language.rst#case-expressions The code for this [hasn't been touched](https://github.com/doctrine/doctrine2/blame/v2.6.0/lib/Doctrine/ORM/Query/Parser.php#L2106) for years though so any breakage in this regard is suspicious.
Author
Owner

@soullivaneuh commented on GitHub (Jan 10, 2018):

@Majkl578 I'll take a look, but this change nothing.

This was perfectly working with the same code for v2.5, not after upgrading to 2.6.

Rolling back to v2.5 was the only thing I did to make it working again.

@soullivaneuh commented on GitHub (Jan 10, 2018): @Majkl578 I'll take a look, but this change nothing. This was perfectly working with the same code for v2.5, not after upgrading to 2.6. Rolling back to v2.5 was the only thing I did to make it working again.
Author
Owner

@soullivaneuh commented on GitHub (Jan 10, 2018):

I confirm that changing to since:

$qb->addSelect('CASE WHEN (t.assigned IS NULL) THEN -10 + t.state ELSE t.state END AS state_order');

solved the issue, thanks.

But I maintain this is working on 2.5. Event if it should not work, a deprecation message should be thrown instead IMHO.

@soullivaneuh commented on GitHub (Jan 10, 2018): I confirm that changing to since: ```php $qb->addSelect('CASE WHEN (t.assigned IS NULL) THEN -10 + t.state ELSE t.state END AS state_order'); ``` solved the issue, thanks. But I maintain this is working on 2.5. Event if it should not work, a deprecation message should be thrown instead IMHO.
Author
Owner

@Seb33300 commented on GitHub (Jan 25, 2018):

This looks like to be a bug in 2.5 syntax parser, 2.6 fixed it.

@Seb33300 commented on GitHub (Jan 25, 2018): This looks like to be a bug in 2.5 syntax parser, 2.6 fixed it.
Author
Owner

@wuestkamp commented on GitHub (Oct 26, 2018):

ran into the same issue when upgrading 2.5 -> 2.6. Solution described above (using the end keyword) worked.

@wuestkamp commented on GitHub (Oct 26, 2018): ran into the same issue when upgrading 2.5 -> 2.6. Solution described above (using the `end` keyword) worked.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5841