We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I realised that PHP AR wasn't handling WHERE correctly while looking for NULL fields doing = instead of IS.
WHERE
NULL
=
IS
And MySQL doesn't like that, Problems with NULL Values: “To look for NULL values, you must use the IS NULL test.”
IS NULL
Find here a little patch, because I'm too lazy to branch and send a pull request that (you'll cherry pick anyway).
Cheers,
diff --git a/lib/Expressions.php b/lib/Expressions.php index ee7509c..0c1d076 100644 --- a/lib/Expressions.php +++ b/lib/Expressions.php @@ -132,6 +132,8 @@ class Expressions if (is_array($value)) $sql .= "$g$name IN(?)"; + else if (is_null($value)) + $sql .= "$g$name IS ?"; else $sql .= "$g$name=?"; diff --git a/test/SQLBuilderTest.php b/test/SQLBuilderTest.php index 29ea734..4ce5e7a 100644 --- a/test/SQLBuilderTest.php +++ b/test/SQLBuilderTest.php @@ -67,6 +67,13 @@ class SQLBuilderTest extends DatabaseTest $this->assert_equals(array(1,'Tito','Mexican'),$this->sql->get_where_values()); } + public function test_where_with_hash_and_null() + { + $this->sql->where(array('id' => 1, 'name' => null)); + $this->assert_sql_has("SELECT * FROM authors WHERE id=? AND name IS ?",(string)$this->sql); + $this->assert_equals(array(1, null),$this->sql->get_where_values()); + } + public function test_where_with_null() { $this->sql->where(null);
The text was updated successfully, but these errors were encountered:
the commit: greut@7ef3060
Sorry, something went wrong.
Thanks:
490f119
No branches or pull requests
I realised that PHP AR wasn't handling
WHERE
correctly while looking forNULL
fields doing=
instead ofIS
.And MySQL doesn't like that, Problems with
NULL
Values:“To look for
NULL
values, you must use theIS NULL
test.”Find here a little patch, because I'm too lazy to branch and send a pull request that (you'll cherry pick anyway).
Cheers,
The text was updated successfully, but these errors were encountered: