InExpression will give Syntax error if using non-named empty array #5142

Open
opened 2026-01-22 14:59:24 +01:00 by admin · 1 comment
Owner

Originally created by @mickadoo on GitHub (Jun 6, 2016).

I would expect the following to produce the same result whether $hits is empty or not:

$queryBuilder->where($queryBuilder->expr()->in($entityName . '.id', ':hits'))->setParameter('hits', $hits);
$queryBuilder->where($queryBuilder->expr()->in($entityName . '.id', $hits));

However the second version produces [Syntax Error] line 0, col 70: Error: Expected Literal, got ')' while the first version correctly returns an empty result set.

I believe the problem is in ORM/Query/Parser.php in the InExpression function. I thought I could create a pull request suggesting to change it to something like:

...
} else {
  $literals = array();
  if (!$this->lexer->isNextToken(Lexer::T_CLOSE_PARENTHESIS)) {
    $literals[] = $this->InParameter();
  }
  while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
...

But when I did that I got another error because an extra closing parentheses is added to the query resulting in WHERE s0_.id IN ())

Originally created by @mickadoo on GitHub (Jun 6, 2016). I would expect the following to produce the same result whether `$hits` is empty or not: ``` $queryBuilder->where($queryBuilder->expr()->in($entityName . '.id', ':hits'))->setParameter('hits', $hits); $queryBuilder->where($queryBuilder->expr()->in($entityName . '.id', $hits)); ``` However the second version produces `[Syntax Error] line 0, col 70: Error: Expected Literal, got ')'` while the first version correctly returns an empty result set. I believe the problem is in `ORM/Query/Parser.php` in the `InExpression` function. I thought I could create a pull request suggesting to change it to something like: ``` ... } else { $literals = array(); if (!$this->lexer->isNextToken(Lexer::T_CLOSE_PARENTHESIS)) { $literals[] = $this->InParameter(); } while ($this->lexer->isNextToken(Lexer::T_COMMA)) { ... ``` But when I did that I got another error because an extra closing parentheses is added to the query resulting in `WHERE s0_.id IN ())`
Author
Owner

@eigan commented on GitHub (Dec 2, 2020):

@Ocramius Open for PR on this change as proposed by @mickadoo? It should result in a query like IN(NULL).

@eigan commented on GitHub (Dec 2, 2020): @Ocramius Open for PR on this change as proposed by @mickadoo? It should result in a query like `IN(NULL)`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5142