#46575 [Opn]: NULL comparison when using "not in" not consistent with Windows SQL
| From: | kalle@php.net | Date: | Wed, 07 Jan 2009 18:17:08 +0000 |
| Subject: | #46575 [Opn]: NULL comparison when using "not in" not consistent with Windows SQL | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-132640@lists.php.net to get a copy of this message | ||
ID: 46575
Updated by: kalle@php.net
Reported By: ben at thelocust dot org
Status: Open
-Bug Type: MSSQL related
+Bug Type: Feature/Change Request
Operating System: *
PHP Version: 5.2.6
New Comment:
I don't see the error here, your asking SQL server to return 'test_id'
from the table 'test' where 'test_number' doesn't even to 1 or 2, and
since NULL is different from 1 and 2 then why shouldn't it be returned?
I see that more of a bug in the ASP/VBScript drivers, and I don't think
we should put such an inconsistency into because others do it.
I changed the category of this to a Feature/Change request, letting the
extension maintainer decided whenever to do it or not :)
Previous Comments:
------------------------------------------------------------------------
[2008-11-14 16:35:50] ben at thelocust dot org
Description:
------------
When querying a MSSQL database table, and using the "not in" syntax,
PHP's mssql_query will also return rows with NULL in the field
specified.
Reproduce code:
---------------
SQL Server 2000 or 2005
Table "test"
test_id (int) test_name (vchar) test_number (int)
1 Foo 1
2 Bar 2
3 <null> 3
4 Baz <null>
$sql = "select test_id from test where test_number not in (1,2)";
$res = mssql_query($sql);
while ($row = mssql_fetch_array($res)) {
?>
<?=$row['test_id'];?><br/>
<?
}
Expected result:
----------------
In PHP, either using FreeTDS on Linux or the MSSQL extension on
Windows, the above returns:
3
4
In ASP/VBScript or using Query Analyzer on Windows the following is
returned:
3
Windows' MSSQL driver apparently will not compare the "not in" values
to a NULL field. PHP, apparently, will.
This creates and inconsistency between the two platforms.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46575&edit=1