|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-10-20 15:16 UTC] 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'
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
Here you are a simplified version. It require a db but it create the only table it needs and delete it. Expected result: got -- <?php $conn = mssql_connect(<server>,<user>,<pass>) or die("opps"); mssql_query("CREATE TABLE #tmp(c VARCHAR(10) NULL)", $conn) or die("error querying"); mssql_query("INSERT INTO #tmp VALUES('')", $conn) or die("error querying"); $res = mssql_query("SELECT * FROM #tmp", $conn) or die("query"); $row = mssql_fetch_assoc($res); $s = is_null($row['c']) ? 'NULL' : $row['c']; echo "got -$s-\n"; ?> In http://cvs.php.net/viewvc.cgi/php-src/ext/mssql/php_mssql.c?view=markup you have if (dbdatlen(mssql_ptr->link,offset) == 0) { however in order to fix the problem should be if (dbdatlen(mssql_ptr->link,offset) == 0 && dbdata(mssql_ptr->link,offset) == NULL) { note that under Windows Microsoft dblib use only older wire protocol version which do not support empty string so it returns them as a single space.Mmm... perhaps a less invasive change is to add if (data == 0) { ZVAL_NULL(result); return; } after char *data = charcol(offset); line on the same function.