ZF-5927: Zend_Db_Statement_Oracle::fetch() doesn't return nulls

Description

The second parameter for oci_fetch_array() is hardcoded, when calling this function inside Zend_Db_Statement_Oracle::fetch(). As a result when the fetchMode property of the database adapter is set to any of Zend_Db::FETCH_NUM, Zend_Db::FETCH_ASSOC, Zend_Db::FETCH_BOTH or Zend_Db::FETCH_BOUND the returned row doesn't contain the columns that have null values.

Maybe this can be made configurable (of course Zend_Db_Statement_Oracle class can be extended and the fetch() method overridden, but I think it would much nicer to allow client code to specify additional flags for the second parameter of the oci_fetch_array() function.

The problem code is written below:


switch ($style) {
            case Zend_Db::FETCH_NUM:
                $row = oci_fetch_array($this->_stmt, OCI_NUM | $lob_as_string);
                break;
            case Zend_Db::FETCH_ASSOC:
                $row = oci_fetch_array($this->_stmt, OCI_ASSOC | $lob_as_string);
                break;
            case Zend_Db::FETCH_BOTH:
                $row = oci_fetch_array($this->_stmt, OCI_BOTH | $lob_as_string);
                break;
            case Zend_Db::FETCH_OBJ:
                $row = oci_fetch_object($this->_stmt);
                break;
            case Zend_Db::FETCH_BOUND:
                $row = oci_fetch_array($this->_stmt, OCI_BOTH | $lob_as_string);
                if ($row !== false) {
                    return $this->_fetchBound($row);
                }
                break;
            default:
                /**
                 * @see Zend_Db_Adapter_Oracle_Exception
                 */
                require_once 'Zend/Db/Statement/Oracle/Exception.php';
                throw new Zend_Db_Statement_Oracle_Exception(
                    array(
                        'code'    => 'HYC00',
                        'message' => "Invalid fetch mode '$style' specified"
                    )
                );
                break;
        }

Comments

Exactly the same for me today. Ralph, I will correct this like I already did for LOB_AS_STRING. But in my idea, default state is activation of OCI_RETURN_NULLS and deactivation if needed. What do you think about it?

I got in to the same problem as listed above, but this does not affect version 1.6.0 or 1.6.2

I agree with Mickael Perraud, that OCI_RETURN_NULLS should be set by default and deactivated if needed.

I will still use 1.6.2 until this is fixed :S

Fixed in SVN 14241 and merge back to 1.7 branch in SVN 14242

With correction of ZF-5146, I exchanged oci_fetch_row and oci_fetch_assoc with oci_fetch_array. The normal behaviour of oci_fetch_row and oci_fecth_assoc is to return null for empty field but not for oci_fetch_array. This behaviour wasn't cover by unit test. This is now ok with SVN 14241.