From: frediano dot ziglio at vodafone dot com
Operating system: Linux
PHP version: 5.1.6
PHP Bug Type: MSSQL related
Bug description: NULL == '' in mssql extention
Description:
------------
when you get data you assume NULL if dbdatlen == 0 however is possible
that data is just an empty string (''), in this case you should check that
dbdatlen == 0 and dbdata == NULL.
Reproduce code:
---------------
I use this test script (pwd.inc define just variable to connect)
<?php
// $Id: null.php,v 1.2 2006/10/20 14:38:22 freddy77 Exp $
require_once("pwd.inc");
$conn = mssql_connect($server,$user,$pass) or die("opps");
mssql_query("CREATE TABLE #MyTable (
myfield VARCHAR(10) NULL,
n INT
)", $conn) or die("error querying");
mssql_query("INSERT INTO #MyTable VALUES('',1)
INSERT INTO #MyTable VALUES(NULL,2)
INSERT INTO #MyTable VALUES(' ',3)
INSERT INTO #MyTable VALUES('a',4)", $conn) or die("error querying");
$result = 0;
function test($sql, $expected)
{
global $conn, $result;
$res = mssql_query($sql, $conn) or die("query");
$row = mssql_fetch_assoc($res);
$s = $row['myfield'];
if (is_null($s))
$s = '(NULL)';
else if ($s == '')
$s = '(Empty String)';
else
$s = "'".str_replace("'", "''", $s)."'";
echo "$sql -> $s\n";
if ($s != $expected)
{
echo "error!\n";
$result = 1;
}
}
test("SELECT top 1 * FROM #MyTable WHERE n = 1 -- ''", "(Empty String)");
test("SELECT top 1 * FROM #MyTable WHERE n = 2 -- NULL", "(NULL)");
test("SELECT top 1 * FROM #MyTable WHERE n = 3 -- ' '", "' '");
test("SELECT top 1 * FROM #MyTable WHERE n = 4 -- 'a'", "'a'");
exit($result);
?>
Expected result:
----------------
SELECT top 1 * FROM #MyTable WHERE n = 1 -- '' -> (Empty String)
SELECT top 1 * FROM #MyTable WHERE n = 2 -- NULL -> (NULL)
SELECT top 1 * FROM #MyTable WHERE n = 3 -- ' ' -> ' '
SELECT top 1 * FROM #MyTable WHERE n = 4 -- 'a' -> 'a'
Actual result:
--------------
SELECT top 1 * FROM #MyTable WHERE n = 1 -- '' -> (NULL)
error!
SELECT top 1 * FROM #MyTable WHERE n = 2 -- NULL -> (NULL)
SELECT top 1 * FROM #MyTable WHERE n = 3 -- ' ' -> ' '
SELECT top 1 * FROM #MyTable WHERE n = 4 -- 'a' -> 'a'
--
Edit bug report at http://bugs.php.net/?id=39213&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=39213&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=39213&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=39213&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39213&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=39213&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39213&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39213&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39213&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39213&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39213&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=39213&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=39213&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39213&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39213&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39213&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39213&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39213&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39213&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39213&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39213&r=mysqlcfg