mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Query builder WHERE does not convert != to NOT NULL in case if parameter value is null #6008
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Arkemlar on GitHub (Jul 2, 2018).
Originally assigned to: @Ocramius on GitHub.
Bug Report
Summary
Using MYSQL. Imagine simple query:
If
$someValueis int - then OK, but if NULL - then query executes and returns 0 rows. Thats because doctrine builds query likeWHERE entity.id <> NULL. I expected that!=will be converted toIS NOT.Current behavior
!=converts to<>if NULL passed as parameter value.How to reproduce
Expected behavior
!=converts toIS NOTif NULL passed as parameter value.@Ocramius commented on GitHub (Jul 3, 2018):
This is correct: in SQL and DQL,
nullcomparison needs to be explicitly defined withIS NULLorIS NOT NULL.Closing as
invalid@parijke commented on GitHub (Feb 14, 2021):
How to handle this situation? I ran into the same issue, where a parameter can be null. but != null obviousely returns the worng result?
@Adamko23 commented on GitHub (Aug 10, 2022):
omg, really is it that hard make the conversion in doctrine? Cause programmer must do this disgusting thing
@Ocramius commented on GitHub (Aug 10, 2022):
Yes, it is part of the SQL standard:
IS NULLis the correct way to do this.Setting parameter values also doesn't modify the SQL/DQL structure pre-defined before: it's too late to modify a prepared statement while parameters are being bound to it.
Yes, really.