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

QueryBuilder and an empty array in criteria #170

Open
urugator opened this issue Mar 13, 2015 · 5 comments
Open

QueryBuilder and an empty array in criteria #170

urugator opened this issue Mar 13, 2015 · 5 comments
Labels
Milestone

Comments

@urugator
Copy link

Passing an empty array as criteria's parameter, for example:

$qb->whereCriteria(array('e.id !=' => array()))

will result in SQL query containing:

WHERE m0_.id NOT IN (?)

and therefore returning an empty result set, which is quite unexpected.

It might be better to add aditional check for array emptiness and completely skip adding WHERE part to the query in case it's empty.

@fprochazka
Copy link
Member

Are you sure that skipping the condition is the best solution?
Wouldn't something like NOT IN (NULL) be better?

@fprochazka fprochazka added the bug label Apr 5, 2015
@urugator
Copy link
Author

urugator commented Apr 7, 2015

Not sure if there is any special null handling in Doctrine's DQL, but SQL:
SELECT id WHERE id NOT IN (NULL)
is basically translated to
SELECT id WHERE id <> NULL
which always returns an empty set, because any comparison operation returns NULL if any operand is NULL, and NULL is further considered as FALSE. (AFAIK this behavior is DB specific and can be configured in some cases, so I wouldn't rely on null handling in any case)

@tkraut
Copy link

tkraut commented Nov 4, 2015

I think that skipping condition is proper solution.
Condition that says that id should not be one from empty set means that id can be arbitrary, but NOT IN (NULL) is opposite, it filters out all results.

@fprochazka
Copy link
Member

I see now. I agree that with NOT IN it makes sense, but it doesn't with plain IN.

@urugator
Copy link
Author

urugator commented Nov 6, 2015

My apologize, I wasn't clear enough in the description, that negation is indeed crucial.

@fprochazka fprochazka added this to the v4.0 milestone Feb 10, 2016
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

3 participants