ibase.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,757 行 · 第 1/5 页

PHP
1,757
字号
<?php// +----------------------------------------------------------------------+// | PHP Version 4                                                        |// +----------------------------------------------------------------------+// | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox,                 |// | Stig. S. Bakken, Lukas Smith                                         |// | All rights reserved.                                                 |// +----------------------------------------------------------------------+// | MDB is a merge of PEAR DB and Metabases that provides a unified DB   |// | API as well as database abstraction for PHP applications.            |// | This LICENSE is in the BSD license style.                            |// |                                                                      |// | Redistribution and use in source and binary forms, with or without   |// | modification, are permitted provided that the following conditions   |// | are met:                                                             |// |                                                                      |// | Redistributions of source code must retain the above copyright       |// | notice, this list of conditions and the following disclaimer.        |// |                                                                      |// | Redistributions in binary form must reproduce the above copyright    |// | notice, this list of conditions and the following disclaimer in the  |// | documentation and/or other materials provided with the distribution. |// |                                                                      |// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |// | Lukas Smith nor the names of his contributors may be used to endorse |// | or promote products derived from this software without specific prior|// | written permission.                                                  |// |                                                                      |// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|// |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |// | POSSIBILITY OF SUCH DAMAGE.                                          |// +----------------------------------------------------------------------+// | Author: Lorenzo Alberton <l.alberton@quipo.it>                       |// +----------------------------------------------------------------------+//// $Id: ibase.php,v 1.9.4.29 2004/03/31 20:00:55 quipo Exp $require_once 'MDB/Common.php';/** * MDB FireBird/InterBase driver * * Notes: * - when fetching in associative mode all keys are lowercased. * * - Currently, the driver relies on the Interbase server to use SQL dialect 3 *   that was introduced with Interbase 6. Some versions of Interbase server, *   like the Super Server, do not seem to work by default with dialect 3. *   This may lead to errors when trying to create tables using Interbase SQL *   data types that are only available when using this dialect version. * * - Interbase does not support per field index sorting support. Indexes are *   either ascending, descending or both even when they are defined from more *   than one field. Currently Metabase Interbase driver uses the index sorting *   type given by the first field of the index for which it is specified the *   sorting type. * * - The numRows method is emulated by fetching all the rows into memory. *   Avoid using it if for queries with large result sets. * * - Interbase does not provide direct support for returning result sets     restrictedto a given range. Such support is emulated in the MDB ibase driver. * * - Current Interbase versions do not support altering table field DEFAULT *   values and NOT NULL constraint. Text fields' length may only be raised in *   increments defined by Interbase, so the Metabase Interbase does not support *   altering text field length yet. * * - createDatabase and dropDatabase are not supported * * - MDB creates Interbase blobs before executing a prepared queries to insert *   or update large object fields. If such queries fail to execute, MDB *   Interbase driver class is not able to reclaim the database space allocated *   for the large object values because there is currently no PHP function to do so. * * @package MDB * @category Database * @author  Lorenzo Alberton <l.alberton@quipo.it> */class MDB_ibase extends MDB_Common{    var $connection = 0;    var $connected_host;    var $connected_port;    var $selected_database = '';    var $selected_database_file = '';    var $opened_persistent = '';    var $transaction_id = 0;    var $escape_quotes = "'";    var $decimal_factor = 1.0;    var $results = array();    var $current_row = array();    var $columns = array();    var $rows = array();    var $limits = array();    var $row_buffer = array();    var $highest_fetched_row = array();    var $query_parameters = array();    var $query_parameter_values = array();    // }}}    // {{{ constructor    /**     * Constructor     */    function MDB_ibase()    {        $this->MDB_Common();        $this->phptype  = 'ibase';        $this->dbsyntax = 'ibase';        $this->supported['Sequences'] = 1;        $this->supported['Indexes'] = 1;        $this->supported['SummaryFunctions'] = 1;        $this->supported['OrderByText'] = 1;        $this->supported['Transactions'] = 1;        $this->supported['CurrId'] = 0;        $this->supported['AffectedRows'] = 0;        $this->supported['SelectRowRanges'] = 1;        $this->supported['LOBs'] = 1;        $this->supported['Replace'] = 1;        $this->supported['SubSelects'] = 1;        $this->decimal_factor = pow(10.0, $this->decimal_places);        $this->options['DatabasePath'] = '';        $this->options['DatabaseExtension'] = '.gdb';        $this->options['DBAUser'] = FALSE;        $this->options['DBAPassword'] = FALSE;        $this->errorcode_map = array(            -104 => MDB_ERROR_SYNTAX,            -150 => MDB_ERROR_ACCESS_VIOLATION,            -151 => MDB_ERROR_ACCESS_VIOLATION,            -155 => MDB_ERROR_NOSUCHTABLE,              88 => MDB_ERROR_NOSUCHTABLE,            -157 => MDB_ERROR_NOSUCHFIELD,            -158 => MDB_ERROR_VALUE_COUNT_ON_ROW,            -170 => MDB_ERROR_MISMATCH,            -171 => MDB_ERROR_MISMATCH,            -172 => MDB_ERROR_INVALID,            -204 => MDB_ERROR_INVALID,            -205 => MDB_ERROR_NOSUCHFIELD,            -206 => MDB_ERROR_NOSUCHFIELD,            -208 => MDB_ERROR_INVALID,            -219 => MDB_ERROR_NOSUCHTABLE,            -297 => MDB_ERROR_CONSTRAINT,            -530 => MDB_ERROR_CONSTRAINT,            -551 => MDB_ERROR_ACCESS_VIOLATION,            -552 => MDB_ERROR_ACCESS_VIOLATION,            -607 => MDB_ERROR_NOSUCHTABLE,            -803 => MDB_ERROR_CONSTRAINT,            -913 => MDB_ERROR_DEADLOCK,            -922 => MDB_ERROR_NOSUCHDB,            -923 => MDB_ERROR_CONNECT_FAILED,            -924 => MDB_ERROR_CONNECT_FAILED        );    }    // }}}    // {{{ errorCode()    /**     * Map native error codes to DB's portable ones.  Requires that     * the DB implementation's constructor fills in the $errorcode_map     * property.     *     * @param $nativecode the native error code, as returned by the backend     * database extension (string or integer)     * @return int a portable MDB error code, or FALSE if this DB     * implementation has no mapping for the given error code.     */    function errorCode($errormsg)    {        // memo for the interbase php module hackers: we need something similar        // to mysql_errno() to retrieve error codes instead of this ugly hack        if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $errormsg, $match)) {            $errno = (int)$match[2];        } else {            $errno = NULL;        }        switch ($errno) {            case -204:                if (is_int(strpos($match[3], 'Table unknown'))) {                    return MDB_ERROR_NOSUCHTABLE;                }            break;            default:                if (isset($this->errorcode_map[$errno])) {                    return($this->errorcode_map[$errno]);                }                static $error_regexps;                if (empty($error_regexps)) {                    $error_regexps = array(                        '/[tT]able not found/' => MDB_ERROR_NOSUCHTABLE,                        '/[tT]able unknown/' => MDB_ERROR_NOSUCHTABLE,                        '/[tT]able .* already exists/' => MDB_ERROR_ALREADY_EXISTS,                        '/validation error for column .* value "\*\*\* null/' => MDB_ERROR_CONSTRAINT_NOT_NULL,                        '/violation of [\w ]+ constraint/' => MDB_ERROR_CONSTRAINT,                        '/conversion error from string/' => MDB_ERROR_INVALID_NUMBER,                        '/no permission for/' => MDB_ERROR_ACCESS_VIOLATION,                        '/arithmetic exception, numeric overflow, or string truncation/' => MDB_ERROR_DIVZERO,                        '/deadlock/' => MDB_ERROR_DEADLOCK,                        '/attempt to store duplicate value/' => MDB_ERROR_CONSTRAINT                    );                }                foreach ($error_regexps as $regexp => $code) {                    if (preg_match($regexp, $errormsg)) {                        return $code;                    }                }        }        // Fall back to MDB_ERROR if there was no mapping.        return MDB_ERROR;    }    // }}}    // {{{ ibaseRaiseError()    /**     * This method is used to communicate an error and invoke error     * callbacks etc.  Basically a wrapper for MDB::raiseError     * that checks for native error msgs.     *     * @param integer $errno error code     * @param string  $message userinfo message     * @return object a PEAR error object     * @access public     * @see PEAR_Error     */    function ibaseRaiseError($errno = NULL, $message = NULL)    {        $error = $this->errorNative();        return($this->raiseError($this->errorCode($error), NULL, NULL,            $message, $error));    }    // }}}    // {{{ errorNative()    /**     * Get the native error code of the last error (if any) that     * occured on the current connection.     *     * @access public     * @return int native ibase error code     */    function errorNative()    {        return @ibase_errmsg();    }    // }}}    // {{{ autoCommit()    /**     * Define whether database changes done on the database be automatically     * committed. This function may also implicitly start or end a transaction.     *     * @param boolean $auto_commit flag that indicates whether the database     *     changes should be committed right after executing every query     *     statement. If this argument is 0 a transaction implicitly started.     *     Otherwise, if a transaction is in progress it is ended by committing     *     any database changes that were pending.     * @return mixed MDB_OK on success, a MDB error on failure     * @access public     */    function autoCommit($auto_commit)    {        $this->debug('AutoCommit: '.($auto_commit ? 'On' : 'Off'));        if ((!$this->auto_commit) == (!$auto_commit)) {            return MDB_OK;        }        if ($this->connection && $auto_commit && MDB::isError($commit = $this->commit())) {            return($commit);        }        $this->auto_commit = $auto_commit;        $this->in_transaction = !$auto_commit;        return MDB_OK;    }    // }}}    // {{{ commit()    /**     * Commit the database changes done during a transaction that is in     * progress. This function may only be called when auto-committing is     * disabled, otherwise it will fail. Therefore, a new transaction is     * implicitly started after committing the pending changes.     *     * @return mixed MDB_OK on success, a MDB error on failure     * @access public     */    function commit()    {        $this->debug('Commit Transaction');        if ($this->auto_commit) {            return($this->raiseError(MDB_ERROR, NULL, NULL,                'Commit: transaction changes are being auto commited'));        }        return @ibase_commit($this->connection);    }    // }}}    // {{{ rollback()    /**     * Cancel any database changes done during a transaction that is in     * progress. This function may only be called when auto-committing is     * disabled, otherwise it will fail. Therefore, a new transaction is     * implicitly started after canceling the pending changes.     *     * @return mixed MDB_OK on success, a MDB error on failure     * @access public     */    function rollback()    {        $this->debug('Rollback Transaction');        if ($this->auto_commit) {            return($this->raiseError(MDB_ERROR, NULL, NULL,                'Rollback: transactions can not be rolled back when changes are auto commited'));        }        //return ibase_rollback($this->connection);        if ($this->transaction_id && !@ibase_rollback($this->connection)) {            return($this->raiseError(MDB_ERROR, NULL, NULL,                'Rollback: Could not rollback a pending transaction: '.@ibase_errmsg()));        }        if (!$this->transaction_id = @ibase_trans(IBASE_COMMITTED, $this->connection)) {            return($this->raiseError(MDB_ERROR, NULL, NULL,                'Rollback: Could not start a new transaction: '.@ibase_errmsg()));        }        return MDB_OK;    }    // }}}    // {{{ getDatabaseFile()

⌨️ 快捷键说明

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