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

Profiler give a non-executable query when using empty array. #1143

Closed
VincentLanglet opened this issue Feb 22, 2020 · 1 comment · Fixed by #1144
Closed

Profiler give a non-executable query when using empty array. #1143

VincentLanglet opened this issue Feb 22, 2020 · 1 comment · Fixed by #1144
Labels

Comments

@VincentLanglet
Copy link
Contributor

When writing the following where clause

$query->andWhere('o.id not in (:q)');
$query->setParameter('q', []);

The query is executed without errors. (And return no result)

I was looking for the real executed query, looked at the profiler and saw this.
image

But

SELECT count(DISTINCT a0_.id) AS sclr_0 FROM asv_client a0_ WHERE a0_.id NOT IN ();

Is not an executable query.

So, something else is executed in database ; and should be displayed in the profiler.

The actual code to display the query in the profiler is the following

# Ressources/views/Collector/db.html.twig
 {{ (query.sql ~ ';')|doctrine_replace_query_parameters(query.params)|doctrine_pretty_query(highlight_only = true) }}
@VincentLanglet
Copy link
Contributor Author

After some investigation, I found that when you write

$query->andWhere("$alias.foo IN (:bar)");
$query->setParameter('bar', []);

Or

$query->andWhere("$alias.foo NOT IN (:bar)");
$query->setParameter('bar', []);

The params are processed by the method expandListParameters of the class Doctrine\DBAL\SQLParserUtils by the following line.
$expandStr = $count > 0 ? implode(', ', array_fill(0, $count, '?')) : 'NULL';

So the real executed query is

SELECT count(DISTINCT a0_.id) AS sclr_0 FROM asv_client a0_ WHERE a0_.id NOT IN (NULL);

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

Successfully merging a pull request may close this issue.

3 participants