Issues

ZF-11773: Zend_Db_Statement_Oracle: Unable to set bind data type

Description

Unable to set bind data type. By default, all binding are set as SQLT_CHR, therefore integer variables and other data type are being bind as char instead of the appropriate data type.

Workaround:

check for $params[$name] data type and setting the fourth 5th parameter to the correct type

if (!@oci_bind_by_name($this->_stmt, $name, $params[$name], -1,{color:red}$type{color})) { $error = true; break; }


    SQLT_BFILEE or OCI_B_BFILE - for BFILEs;
    SQLT_CFILEE or OCI_B_CFILEE - for CFILEs;
    SQLT_CLOB or OCI_B_CLOB - for CLOBs;
    SQLT_BLOB or OCI_B_BLOB - for BLOBs;
    SQLT_RDD or OCI_B_ROWID - for ROWIDs;
    SQLT_NTY or OCI_B_NTY - for named datatypes;
    SQLT_INT or OCI_B_INT - for integers;
    SQLT_CHR - for VARCHARs;
    SQLT_BIN or OCI_B_BIN - for RAW columns;
    SQLT_LNG - for LONG columns;
    SQLT_LBI - for LONG RAW columns;
    SQLT_RSET - for cursors created with oci_new_cursor().

Zend/Db/Statement/Oracle.php

 
    public function _execute(array $params = null)
    {
        $connection = $this->_adapter->getConnection();

        if (!$this->_stmt) {
            return false;
        }

        if ($params !== null) {
            if (!is_array($params)) {
                $params = array($params);
            }
            $error = false;

            foreach (array_keys($params) as $name) {
                if (!@oci_bind_by_name($this->_stmt, $name, $params[$name], -1)) {
                    $error = true;
                    break;
                }
            }

            if ($error) {
                /**
                 * @see Zend_Db_Adapter_Oracle_Exception
                 */
                require_once 'Zend/Db/Statement/Oracle/Exception.php';
                throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
            }
        }

        $retval = @oci_execute($this->_stmt, $this->_adapter->_getExecuteMode());
        if ($retval === false) {
            /**
             * @see Zend_Db_Adapter_Oracle_Exception
             */
            require_once 'Zend/Db/Statement/Oracle/Exception.php';
            throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
        }

        $this->_keys = Array();
        if ($field_num = oci_num_fields($this->_stmt)) {
            for ($i = 1; $i <= $field_num; $i++) {
                $name = oci_field_name($this->_stmt, $i);
                $this->_keys[] = $name;
            }
        }

        $this->_values = Array();
        if ($this->_keys) {
            $this->_values = array_fill(0, count($this->_keys), null);
        }

        return $retval;
    }

Comments

No comments to display