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

📄 oci8.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 3 页
字号:
        return $result;    }    // }}}    // {{{ modifyQuery()    /**     * Changes a query string for various DBMS specific reasons     *     * "SELECT 2+2" must be "SELECT 2+2 FROM dual" in Oracle.     *     * @param string $query  the query string to modify     *     * @return string  the modified query string     *     * @access protected     */    function modifyQuery($query)    {        if (preg_match('/^\s*SELECT/i', $query) &&            !preg_match('/\sFROM\s/i', $query)) {            $query .= ' FROM dual';        }        return $query;    }    // }}}    // {{{ modifyLimitQuery()    /**     * Adds LIMIT clauses to a query string according to current DBMS standards     *     * @param string $query   the query to modify     * @param int    $from    the row to start to fetching (0 = the first row)     * @param int    $count   the numbers of rows to fetch     * @param mixed  $params  array, string or numeric data to be used in     *                         execution of the statement.  Quantity of items     *                         passed must match quantity of placeholders in     *                         query:  meaning 1 placeholder for non-array     *                         parameters or 1 placeholder per array element.     *     * @return string  the query string with LIMIT clauses added     *     * @access protected     */    function modifyLimitQuery($query, $from, $count, $params = array())    {        // Let Oracle return the name of the columns instead of        // coding a "home" SQL parser        if (count($params)) {            $result = $this->prepare("SELECT * FROM ($query) "                                     . 'WHERE NULL = NULL');            $tmp =& $this->execute($result, $params);        } else {            $q_fields = "SELECT * FROM ($query) WHERE NULL = NULL";            if (!$result = @OCIParse($this->connection, $q_fields)) {                $this->last_query = $q_fields;                return $this->oci8RaiseError();            }            if (!@OCIExecute($result, OCI_DEFAULT)) {                $this->last_query = $q_fields;                return $this->oci8RaiseError($result);            }        }        $ncols = OCINumCols($result);        $cols  = array();        for ( $i = 1; $i <= $ncols; $i++ ) {            $cols[] = '"' . OCIColumnName($result, $i) . '"';        }        $fields = implode(', ', $cols);        // XXX Test that (tip by John Lim)        //if (preg_match('/^\s*SELECT\s+/is', $query, $match)) {        //    // Introduce the FIRST_ROWS Oracle query optimizer        //    $query = substr($query, strlen($match[0]), strlen($query));        //    $query = "SELECT /* +FIRST_ROWS */ " . $query;        //}        // Construct the query        // more at: http://marc.theaimsgroup.com/?l=php-db&m=99831958101212&w=2        // Perhaps this could be optimized with the use of Unions        $query = "SELECT $fields FROM".                 "  (SELECT rownum as linenum, $fields FROM".                 "      ($query)".                 '  WHERE rownum <= '. ($from + $count) .                 ') WHERE linenum >= ' . ++$from;        return $query;    }    // }}}    // {{{ nextId()    /**     * Returns the next free id in a sequence     *     * @param string  $seq_name  name of the sequence     * @param boolean $ondemand  when true, the seqence is automatically     *                            created if it does not exist     *     * @return int  the next id number in the sequence.     *               A DB_Error object on failure.     *     * @see DB_common::nextID(), DB_common::getSequenceName(),     *      DB_oci8::createSequence(), DB_oci8::dropSequence()     */    function nextId($seq_name, $ondemand = true)    {        $seqname = $this->getSequenceName($seq_name);        $repeat = 0;        do {            $this->expectError(DB_ERROR_NOSUCHTABLE);            $result =& $this->query("SELECT ${seqname}.nextval FROM dual");            $this->popExpect();            if ($ondemand && DB::isError($result) &&                $result->getCode() == DB_ERROR_NOSUCHTABLE) {                $repeat = 1;                $result = $this->createSequence($seq_name);                if (DB::isError($result)) {                    return $this->raiseError($result);                }            } else {                $repeat = 0;            }        } while ($repeat);        if (DB::isError($result)) {            return $this->raiseError($result);        }        $arr = $result->fetchRow(DB_FETCHMODE_ORDERED);        return $arr[0];    }    /**     * Creates a new sequence     *     * @param string $seq_name  name of the new sequence     *     * @return int  DB_OK on success.  A DB_Error object on failure.     *     * @see DB_common::createSequence(), DB_common::getSequenceName(),     *      DB_oci8::nextID(), DB_oci8::dropSequence()     */    function createSequence($seq_name)    {        return $this->query('CREATE SEQUENCE '                            . $this->getSequenceName($seq_name));    }    // }}}    // {{{ dropSequence()    /**     * Deletes a sequence     *     * @param string $seq_name  name of the sequence to be deleted     *     * @return int  DB_OK on success.  A DB_Error object on failure.     *     * @see DB_common::dropSequence(), DB_common::getSequenceName(),     *      DB_oci8::nextID(), DB_oci8::createSequence()     */    function dropSequence($seq_name)    {        return $this->query('DROP SEQUENCE '                            . $this->getSequenceName($seq_name));    }    // }}}    // {{{ oci8RaiseError()    /**     * Produces a DB_Error object regarding the current problem     *     * @param int $errno  if the error is being manually raised pass a     *                     DB_ERROR* constant here.  If this isn't passed     *                     the error information gathered from the DBMS.     *     * @return object  the DB_Error object     *     * @see DB_common::raiseError(),     *      DB_oci8::errorNative(), DB_oci8::errorCode()     */    function oci8RaiseError($errno = null)    {        if ($errno === null) {            $error = @OCIError($this->connection);            return $this->raiseError($this->errorCode($error['code']),                                     null, null, null, $error['message']);        } elseif (is_resource($errno)) {            $error = @OCIError($errno);            return $this->raiseError($this->errorCode($error['code']),                                     null, null, null, $error['message']);        }        return $this->raiseError($this->errorCode($errno));    }    // }}}    // {{{ errorNative()    /**     * Gets the DBMS' native error code produced by the last query     *     * @return int  the DBMS' error code.  FALSE if the code could not be     *               determined     */    function errorNative()    {        if (is_resource($this->last_stmt)) {            $error = @OCIError($this->last_stmt);        } else {            $error = @OCIError($this->connection);        }        if (is_array($error)) {            return $error['code'];        }        return false;    }    // }}}    // {{{ tableInfo()    /**     * Returns information about a table or a result set     *     * NOTE: only supports 'table' and 'flags' if <var>$result</var>     * is a table name.     *     * NOTE: flags won't contain index information.     *     * @param object|string  $result  DB_result object from a query or a     *                                 string containing the name of a table.     *                                 While this also accepts a query result     *                                 resource identifier, this behavior is     *                                 deprecated.     * @param int            $mode    a valid tableInfo mode     *     * @return array  an associative array with the information requested.     *                 A DB_Error object on failure.     *     * @see DB_common::tableInfo()     */    function tableInfo($result, $mode = null)    {        if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {            $case_func = 'strtolower';        } else {            $case_func = 'strval';        }        $res = array();        if (is_string($result)) {            /*             * Probably received a table name.             * Create a result resource identifier.             */            $result = strtoupper($result);            $q_fields = 'SELECT column_name, data_type, data_length, '                        . 'nullable '                        . 'FROM user_tab_columns '                        . "WHERE table_name='$result' ORDER BY column_id";            $this->last_query = $q_fields;            if (!$stmt = @OCIParse($this->connection, $q_fields)) {                return $this->oci8RaiseError(DB_ERROR_NEED_MORE_DATA);            }            if (!@OCIExecute($stmt, OCI_DEFAULT)) {                return $this->oci8RaiseError($stmt);            }            $i = 0;            while (@OCIFetch($stmt)) {                $res[$i] = array(                    'table' => $case_func($result),                    'name'  => $case_func(@OCIResult($stmt, 1)),                    'type'  => @OCIResult($stmt, 2),                    'len'   => @OCIResult($stmt, 3),                    'flags' => (@OCIResult($stmt, 4) == 'N') ? 'not_null' : '',                );                if ($mode & DB_TABLEINFO_ORDER) {                    $res['order'][$res[$i]['name']] = $i;                }                if ($mode & DB_TABLEINFO_ORDERTABLE) {                    $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;                }                $i++;            }            if ($mode) {                $res['num_fields'] = $i;            }            @OCIFreeStatement($stmt);        } else {            if (isset($result->result)) {                /*                 * Probably received a result object.                 * Extract the result resource identifier.                 */                $result = $result->result;            }            $res = array();            if ($result === $this->last_stmt) {                $count = @OCINumCols($result);                if ($mode) {                    $res['num_fields'] = $count;                }                for ($i = 0; $i < $count; $i++) {                    $res[$i] = array(                        'table' => '',                        'name'  => $case_func(@OCIColumnName($result, $i+1)),                        'type'  => @OCIColumnType($result, $i+1),                        'len'   => @OCIColumnSize($result, $i+1),                        'flags' => '',                    );                    if ($mode & DB_TABLEINFO_ORDER) {                        $res['order'][$res[$i]['name']] = $i;                    }                    if ($mode & DB_TABLEINFO_ORDERTABLE) {                        $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;                    }                }            } else {                return $this->raiseError(DB_ERROR_NOT_CAPABLE);            }        }        return $res;    }    // }}}    // {{{ getSpecialQuery()    /**     * Obtains the query string needed for listing a given type of objects     *     * @param string $type  the kind of objects you want to retrieve     *     * @return string  the SQL query string or null if the driver doesn't     *                  support the object type requested     *     * @access protected     * @see DB_common::getListOf()     */    function getSpecialQuery($type)    {        switch ($type) {            case 'tables':                return 'SELECT table_name FROM user_tables';            case 'synonyms':                return 'SELECT synonym_name FROM user_synonyms';            default:                return null;        }    }    // }}}}/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */?>

⌨️ 快捷键说明

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