ID:               31960
 User updated by:  danielc at analysisandsolutions dot com
-Summary:          msql_fetch_row() and msql_fetch_array() dropping
                   columns with NULL values
 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 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.


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

[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