ID:               31960
 User updated by:  danielc at analysisandsolutions dot com
 Reported By:      danielc at analysisandsolutions dot com
 Status:           Open
 Bug Type:         mSQL related
 Operating System: NetBSD 2.0
 PHP Version:      5CVS-2005-02-13 (dev)
 New Comment:

I also put together a patch for the PHP_4_3 branch:
http://www.analysisandsolutions.com/php/php_msql.c.bug31960.4_3.diff
It hasn't been tested, but looking at the source of the MySQL extension
makes me think it should work.

Though the script I put in the "Reproduce code" section above doesn't
test what happens with empty strings, I subsequently tested the
behavior and everything works fine.


Previous Comments:
------------------------------------------------------------------------

[2005-02-15 02:36:44] danielc at analysisandsolutions dot com

I looked at the MySQL extension to see how they handled NULL values and
copied that into the mSQL extension.  Here's the patch against head:
http://www.analysisandsolutions.com/php/php_msql.c.bug31960.diff

Works fine on my installation of 5.0.4-dev.

------------------------------------------------------------------------

[2005-02-13 21:02:44] danielc at analysisandsolutions dot com

Description:
------------
msql_fetch_row() and msql_fetch_array() silently drop columns that
contain NULL values.  It's important to retrieve all data from a row,
even if it's NULL.  oci8 does this just fine.

While there's a comment in the msql_fetch_array() documentation to
watch out for items that have NULL/0/'' values, it doesn't exactly say
what the problem is and it only talks about results that have only one
column.

Reproduce code:
---------------
$con = msql_connect();
$db  = msql_select_db('ptdb', $con);
msql_query('CREATE TABLE blah (i INT, c CHAR(5))', $con);
msql_query("INSERT INTO blah VALUES (1, 'a')", $con);
msql_query("INSERT INTO blah VALUES (2, NULL)", $con);
msql_query("INSERT INTO blah VALUES (NULL, 'c')", $con);
$result = msql_query('SELECT * FROM blah', $con);
while ($arr = msql_fetch_array($result, MSQL_ASSOC)) {
    var_dump($arr);
    echo "\n";
}
msql_query('DROP TABLE blah', $con);

Expected result:
----------------
array(2) {
  ["i"]=>
  string(1) "1"
  ["c"]=>
  string(1) "a"
}

array(2) {
  ["i"]=>
  string(1) "2"
  ["c"]=>
  NULL
}

array(2) {
  ["a"]=>
  NULL
  ["c"]=>
  string(1) "c"
}

Actual result:
--------------
array(2) {
  ["i"]=>
  string(1) "1"
  ["c"]=>
  string(1) "a"
}

array(1) {
  ["i"]=>
  string(1) "2"
}

array(1) {
  ["c"]=>
  string(1) "c"
}


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=31960&edit=1

Reply via email to