ID: 39213
Updated by: [EMAIL PROTECTED]
Reported By: frediano dot ziglio at vodafone dot com
-Status: Open
+Status: Feedback
Bug Type: MSSQL related
Operating System: Linux
PHP Version: 5.1.6
Assigned To: fmk
New Comment:
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
Previous Comments:
------------------------------------------------------------------------
[2006-10-20 15:16:45] frediano dot ziglio at vodafone dot com
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 this bug report at http://bugs.php.net/?id=39213&edit=1