⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oracle.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
         * Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection         */        $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);        $table_name      = 0;        $owner           = 1;        $column_name     = 2;        $data_type       = 3;        $data_default    = 4;        $nullable        = 5;        $column_id       = 6;        $data_length     = 7;        $data_scale      = 8;        $data_precision  = 9;        $constraint_type = 10;        $position        = 11;        $desc = array();        foreach ($result as $key => $row) {            list ($primary, $primaryPosition, $identity) = array(false, null, false);            if ($row[$constraint_type] == 'P') {                $primary = true;                $primaryPosition = $row[$position];                /**                 * Oracle does not support auto-increment keys.                 */                $identity = false;            }            $desc[$this->foldCase($row[$column_name])] = array(                'SCHEMA_NAME'      => $this->foldCase($row[$owner]),                'TABLE_NAME'       => $this->foldCase($row[$table_name]),                'COLUMN_NAME'      => $this->foldCase($row[$column_name]),                'COLUMN_POSITION'  => $row[$column_id],                'DATA_TYPE'        => $row[$data_type],                'DEFAULT'          => $row[$data_default],                'NULLABLE'         => (bool) ($row[$nullable] == 'Y'),                'LENGTH'           => $row[$data_length],                'SCALE'            => $row[$data_scale],                'PRECISION'        => $row[$data_precision],                'UNSIGNED'         => null, // @todo                'PRIMARY'          => $primary,                'PRIMARY_POSITION' => $primaryPosition,                'IDENTITY'         => $identity            );        }        return $desc;    }    /**     * Leave autocommit mode and begin a transaction.     *     * @return void     */    protected function _beginTransaction()    {        $this->_setExecuteMode(OCI_DEFAULT);    }    /**     * Commit a transaction and return to autocommit mode.     *     * @return void     * @throws Zend_Db_Adapter_Oracle_Exception     */    protected function _commit()    {        if (!oci_commit($this->_connection)) {            /**             * @see Zend_Db_Adapter_Oracle_Exception             */            require_once 'Zend/Db/Adapter/Oracle/Exception.php';            throw new Zend_Db_Adapter_Oracle_Exception(oci_error($this->_connection));        }        $this->_setExecuteMode(OCI_COMMIT_ON_SUCCESS);    }    /**     * Roll back a transaction and return to autocommit mode.     *     * @return void     * @throws Zend_Db_Adapter_Oracle_Exception     */    protected function _rollBack()    {        if (!oci_rollback($this->_connection)) {            /**             * @see Zend_Db_Adapter_Oracle_Exception             */            require_once 'Zend/Db/Adapter/Oracle/Exception.php';            throw new Zend_Db_Adapter_Oracle_Exception(oci_error($this->_connection));        }        $this->_setExecuteMode(OCI_COMMIT_ON_SUCCESS);    }    /**     * Set the fetch mode.     *     * @todo Support FETCH_CLASS and FETCH_INTO.     *     * @param integer $mode A fetch mode.     * @return void     * @throws Zend_Db_Adapter_Oracle_Exception     */    public function setFetchMode($mode)    {        switch ($mode) {            case Zend_Db::FETCH_NUM:   // seq array            case Zend_Db::FETCH_ASSOC: // assoc array            case Zend_Db::FETCH_BOTH:  // seq+assoc array            case Zend_Db::FETCH_OBJ:   // object                $this->_fetchMode = $mode;                break;            case Zend_Db::FETCH_BOUND: // bound to PHP variable                /**                 * @see Zend_Db_Adapter_Oracle_Exception                 */                require_once 'Zend/Db/Adapter/Oracle/Exception.php';                throw new Zend_Db_Adapter_Oracle_Exception('FETCH_BOUND is not supported yet');                break;            default:                /**                 * @see Zend_Db_Adapter_Oracle_Exception                 */                require_once 'Zend/Db/Adapter/Oracle/Exception.php';                throw new Zend_Db_Adapter_Oracle_Exception("Invalid fetch mode '$mode' specified");                break;        }    }    /**     * Adds an adapter-specific LIMIT clause to the SELECT statement.     *     * @param string $sql     * @param integer $count     * @param integer $offset OPTIONAL     * @return string     * @throws Zend_Db_Adapter_Oracle_Exception     */    public function limit($sql, $count, $offset = 0)    {        $count = intval($count);        if ($count <= 0) {            /**             * @see Zend_Db_Adapter_Oracle_Exception             */            require_once 'Zend/Db/Adapter/Oracle/Exception.php';            throw new Zend_Db_Adapter_Oracle_Exception("LIMIT argument count=$count is not valid");        }        $offset = intval($offset);        if ($offset < 0) {            /**             * @see Zend_Db_Adapter_Oracle_Exception             */            require_once 'Zend/Db/Adapter/Oracle/Exception.php';            throw new Zend_Db_Adapter_Oracle_Exception("LIMIT argument offset=$offset is not valid");        }        /**         * Oracle does not implement the LIMIT clause as some RDBMS do.         * We have to simulate it with subqueries and ROWNUM.         * Unfortunately because we use the column wildcard "*",         * this puts an extra column into the query result set.         */        $limit_sql = "SELECT z2.*            FROM (                SELECT ROWNUM AS zend_db_rownum, z1.*                FROM (                    " . $sql . "                ) z1            ) z2            WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) . " AND " . ($offset+$count);        return $limit_sql;    }    /**     * @param integer $mode     * @throws Zend_Db_Adapter_Oracle_Exception     */    private function _setExecuteMode($mode)    {        switch($mode) {            case OCI_COMMIT_ON_SUCCESS:            case OCI_DEFAULT:            case OCI_DESCRIBE_ONLY:                $this->_execute_mode = $mode;                break;            default:                /**                 * @see Zend_Db_Adapter_Oracle_Exception                 */                require_once 'Zend/Db/Adapter/Oracle/Exception.php';                throw new Zend_Db_Adapter_Oracle_Exception("Invalid execution mode '$mode' specified");                break;        }    }    /**     * @return int     */    public function _getExecuteMode()    {        return $this->_execute_mode;    }    /**     * Inserts a table row with specified data.     *     * Oracle does not support anonymous ('?') binds.     *     * @param mixed $table The table to insert data into.     * @param array $bind Column-value pairs.     * @return int The number of affected rows.     */    public function insert($table, array $bind)    {        $i = 0;        // extract and quote col names from the array keys        $cols = array();        $vals = array();        foreach ($bind as $col => $val) {            $cols[] = $this->quoteIdentifier($col, true);            if ($val instanceof Zend_Db_Expr) {                $vals[] = $val->__toString();                unset($bind[$col]);            } else {                $vals[] = ':'.$col.$i;                unset($bind[$col]);                $bind[':'.$col.$i] = $val;            }            $i++;        }        // build the statement        $sql = "INSERT INTO "             . $this->quoteIdentifier($table, true)             . ' (' . implode(', ', $cols) . ') '             . 'VALUES (' . implode(', ', $vals) . ')';        // execute the statement and return the number of affected rows        $stmt = $this->query($sql, $bind);        $result = $stmt->rowCount();        return $result;    }    /**     * Updates table rows with specified data based on a WHERE clause.     *     * @param  mixed        $table The table to update.     * @param  array        $bind  Column-value pairs.     * @param  array|string $where UPDATE WHERE clause(s).     * @return int          The number of affected rows.     */    public function update($table, array $bind, $where = '')    {        $i = 0;        // build "col = ?" pairs for the statement        $set = array();        foreach ($bind as $col => $val) {            if ($val instanceof Zend_Db_Expr) {                $val = $val->__toString();                unset($bind[$col]);            } else {                unset($bind[$col]);                $bind[':'.$col.$i] = $val;                $val = ':'.$col.$i;            }            $set[] = $this->quoteIdentifier($col, true) . ' = ' . $val;            $i++;        }        if (is_array($where)) {            $where = implode(' AND ', $where);        }        // build the statement        $sql = "UPDATE "             . $this->quoteIdentifier($table, true)             . ' SET ' . implode(', ', $set)             . (($where) ? " WHERE $where" : '');        // execute the statement and return the number of affected rows        $stmt = $this->query($sql, $bind);        $result = $stmt->rowCount();        return $result;    }    /**     * Check if the adapter supports real SQL parameters.     *     * @param string $type 'positional' or 'named'     * @return bool     */    public function supportsParameters($type)    {        switch ($type) {            case 'named':                return true;            case 'positional':            default:                return false;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -