PageRenderTime 255ms CodeModel.GetById 178ms app.highlight 67ms RepoModel.GetById 1ms app.codeStats 0ms

/ railoapacheportable/php/PEAR/MDB2/Driver/oci8.php

http://railoapacheportable.googlecode.com/
PHP | 1514 lines | 1097 code | 89 blank | 328 comment | 207 complexity | de0f5761819216fd8580e3aba853eacc MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2// vim: set et ts=4 sw=4 fdm=marker:
   3// +----------------------------------------------------------------------+
   4// | PHP versions 4 and 5                                                 |
   5// +----------------------------------------------------------------------+
   6// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox,                 |
   7// | Stig. S. Bakken, Lukas Smith                                         |
   8// | All rights reserved.                                                 |
   9// +----------------------------------------------------------------------+
  10// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
  11// | API as well as database abstraction for PHP applications.            |
  12// | This LICENSE is in the BSD license style.                            |
  13// |                                                                      |
  14// | Redistribution and use in source and binary forms, with or without   |
  15// | modification, are permitted provided that the following conditions   |
  16// | are met:                                                             |
  17// |                                                                      |
  18// | Redistributions of source code must retain the above copyright       |
  19// | notice, this list of conditions and the following disclaimer.        |
  20// |                                                                      |
  21// | Redistributions in binary form must reproduce the above copyright    |
  22// | notice, this list of conditions and the following disclaimer in the  |
  23// | documentation and/or other materials provided with the distribution. |
  24// |                                                                      |
  25// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  26// | Lukas Smith nor the names of his contributors may be used to endorse |
  27// | or promote products derived from this software without specific prior|
  28// | written permission.                                                  |
  29// |                                                                      |
  30// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  31// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  32// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  33// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  34// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  35// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  36// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  37// |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  38// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  39// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  40// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  41// | POSSIBILITY OF SUCH DAMAGE.                                          |
  42// +----------------------------------------------------------------------+
  43// | Author: Lukas Smith <smith@pooteeweet.org>                           |
  44// +----------------------------------------------------------------------+
  45
  46// $Id: oci8.php,v 1.192 2007/03/04 22:27:11 quipo Exp $
  47
  48/**
  49 * MDB2 OCI8 driver
  50 *
  51 * @package MDB2
  52 * @category Database
  53 * @author Lukas Smith <smith@pooteeweet.org>
  54 */
  55class MDB2_Driver_oci8 extends MDB2_Driver_Common
  56{
  57    // {{{ properties
  58    var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => "'", 'escape_pattern' => '@');
  59
  60    var $identifier_quoting = array('start' => '"', 'end' => '"', 'escape' => '"');
  61
  62    var $uncommitedqueries = 0;
  63    // }}}
  64    // {{{ constructor
  65
  66    /**
  67     * Constructor
  68     */
  69    function __construct()
  70    {
  71        parent::__construct();
  72
  73        $this->phptype = 'oci8';
  74        $this->dbsyntax = 'oci8';
  75
  76        $this->supported['sequences'] = true;
  77        $this->supported['indexes'] = true;
  78        $this->supported['summary_functions'] = true;
  79        $this->supported['order_by_text'] = true;
  80        $this->supported['current_id'] = true;
  81        $this->supported['affected_rows'] = true;
  82        $this->supported['transactions'] = true;
  83        $this->supported['savepoints'] = true;
  84        $this->supported['limit_queries'] = true;
  85        $this->supported['LOBs'] = true;
  86        $this->supported['replace'] = 'emulated';
  87        $this->supported['sub_selects'] = true;
  88        $this->supported['auto_increment'] = false; // implementation is broken
  89        $this->supported['primary_key'] = true;
  90        $this->supported['result_introspection'] = true;
  91        $this->supported['prepared_statements'] = true;
  92        $this->supported['identifier_quoting'] = true;
  93        $this->supported['pattern_escaping'] = true;
  94        $this->supported['new_link'] = true;
  95
  96        $this->options['DBA_username'] = false;
  97        $this->options['DBA_password'] = false;
  98        $this->options['database_name_prefix'] = false;
  99        $this->options['emulate_database'] = true;
 100        $this->options['default_tablespace'] = false;
 101        $this->options['default_text_field_length'] = 2000;
 102        $this->options['result_prefetching'] = false;
 103    }
 104
 105    // }}}
 106    // {{{ errorInfo()
 107
 108    /**
 109     * This method is used to collect information about an error
 110     *
 111     * @param integer $error
 112     * @return array
 113     * @access public
 114     */
 115    function errorInfo($error = null)
 116    {
 117        if (is_resource($error)) {
 118            $error_data = @OCIError($error);
 119            $error = null;
 120        } elseif ($this->connection) {
 121            $error_data = @OCIError($this->connection);
 122        } else {
 123            $error_data = @OCIError();
 124        }
 125        $native_code = $error_data['code'];
 126        $native_msg  = $error_data['message'];
 127        if (is_null($error)) {
 128            static $ecode_map;
 129            if (empty($ecode_map)) {
 130                $ecode_map = array(
 131                    1    => MDB2_ERROR_CONSTRAINT,
 132                    900  => MDB2_ERROR_SYNTAX,
 133                    904  => MDB2_ERROR_NOSUCHFIELD,
 134                    911  => MDB2_ERROR_SYNTAX, //invalid character
 135                    913  => MDB2_ERROR_VALUE_COUNT_ON_ROW,
 136                    921  => MDB2_ERROR_SYNTAX,
 137                    923  => MDB2_ERROR_SYNTAX,
 138                    942  => MDB2_ERROR_NOSUCHTABLE,
 139                    955  => MDB2_ERROR_ALREADY_EXISTS,
 140                    1400 => MDB2_ERROR_CONSTRAINT_NOT_NULL,
 141                    1401 => MDB2_ERROR_INVALID,
 142                    1407 => MDB2_ERROR_CONSTRAINT_NOT_NULL,
 143                    1418 => MDB2_ERROR_NOT_FOUND,
 144                    1476 => MDB2_ERROR_DIVZERO,
 145                    1722 => MDB2_ERROR_INVALID_NUMBER,
 146                    2289 => MDB2_ERROR_NOSUCHTABLE,
 147                    2291 => MDB2_ERROR_CONSTRAINT,
 148                    2292 => MDB2_ERROR_CONSTRAINT,
 149                    2449 => MDB2_ERROR_CONSTRAINT,
 150                    24344 => MDB2_ERROR_SYNTAX, //success with compilation error
 151                );
 152            }
 153            if (isset($ecode_map[$native_code])) {
 154                $error = $ecode_map[$native_code];
 155            }
 156        }
 157        return array($error, $native_code, $native_msg);
 158    }
 159
 160    // }}}
 161    // {{{ beginTransaction()
 162
 163    /**
 164     * Start a transaction or set a savepoint.
 165     *
 166     * @param   string  name of a savepoint to set
 167     * @return  mixed   MDB2_OK on success, a MDB2 error on failure
 168     *
 169     * @access  public
 170     */
 171    function beginTransaction($savepoint = null)
 172    {
 173        $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
 174        if (!is_null($savepoint)) {
 175            if (!$this->in_transaction) {
 176                return $this->raiseError(MDB2_ERROR_INVALID, null, null,
 177                    'savepoint cannot be released when changes are auto committed', __FUNCTION__);
 178            }
 179            $query = 'SAVEPOINT '.$savepoint;
 180            return $this->_doQuery($query, true);
 181        } elseif ($this->in_transaction) {
 182            return MDB2_OK;  //nothing to do
 183        }
 184        if (!$this->destructor_registered && $this->opened_persistent) {
 185            $this->destructor_registered = true;
 186            register_shutdown_function('MDB2_closeOpenTransactions');
 187        }
 188        $this->in_transaction = true;
 189        ++$this->uncommitedqueries;
 190        return MDB2_OK;
 191    }
 192
 193    // }}}
 194    // {{{ commit()
 195
 196    /**
 197     * Commit the database changes done during a transaction that is in
 198     * progress or release a savepoint. This function may only be called when
 199     * auto-committing is disabled, otherwise it will fail. Therefore, a new
 200     * transaction is implicitly started after committing the pending changes.
 201     *
 202     * @param   string  name of a savepoint to release
 203     * @return  mixed   MDB2_OK on success, a MDB2 error on failure
 204     *
 205     * @access  public
 206     */
 207    function commit($savepoint = null)
 208    {
 209        $this->debug('Committing transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
 210        if (!$this->in_transaction) {
 211            return $this->raiseError(MDB2_ERROR_INVALID, null, null,
 212                'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__);
 213        }
 214        if (!is_null($savepoint)) {
 215            return MDB2_OK;
 216        }
 217
 218        if ($this->uncommitedqueries) {
 219            $connection = $this->getConnection();
 220            if (PEAR::isError($connection)) {
 221                return $connection;
 222            }
 223            if (!@OCICommit($connection)) {
 224                return $this->raiseError(null, null, null,
 225                'Unable to commit transaction', __FUNCTION__);
 226            }
 227            $this->uncommitedqueries = 0;
 228        }
 229        $this->in_transaction = false;
 230        return MDB2_OK;
 231    }
 232
 233    // }}}
 234    // {{{ rollback()
 235
 236    /**
 237     * Cancel any database changes done during a transaction or since a specific
 238     * savepoint that is in progress. This function may only be called when
 239     * auto-committing is disabled, otherwise it will fail. Therefore, a new
 240     * transaction is implicitly started after canceling the pending changes.
 241     *
 242     * @param   string  name of a savepoint to rollback to
 243     * @return  mixed   MDB2_OK on success, a MDB2 error on failure
 244     *
 245     * @access  public
 246     */
 247    function rollback($savepoint = null)
 248    {
 249        $this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
 250        if (!$this->in_transaction) {
 251            return $this->raiseError(MDB2_ERROR_INVALID, null, null,
 252                'rollback cannot be done changes are auto committed', __FUNCTION__);
 253        }
 254        if (!is_null($savepoint)) {
 255            $query = 'ROLLBACK TO SAVEPOINT '.$savepoint;
 256            return $this->_doQuery($query, true);
 257        }
 258
 259        if ($this->uncommitedqueries) {
 260            $connection = $this->getConnection();
 261            if (PEAR::isError($connection)) {
 262                return $connection;
 263            }
 264            if (!@OCIRollback($connection)) {
 265                return $this->raiseError(null, null, null,
 266                'Unable to rollback transaction', __FUNCTION__);
 267            }
 268            $this->uncommitedqueries = 0;
 269        }
 270        $this->in_transaction = false;
 271        return MDB2_OK;
 272    }
 273
 274    // }}}
 275    // {{{ function setTransactionIsolation()
 276
 277    /**
 278     * Set the transacton isolation level.
 279     *
 280     * @param   string  standard isolation level
 281     *                  READ UNCOMMITTED (allows dirty reads)
 282     *                  READ COMMITTED (prevents dirty reads)
 283     *                  REPEATABLE READ (prevents nonrepeatable reads)
 284     *                  SERIALIZABLE (prevents phantom reads)
 285     * @return  mixed   MDB2_OK on success, a MDB2 error on failure
 286     *
 287     * @access  public
 288     * @since   2.1.1
 289     */
 290    function setTransactionIsolation($isolation)
 291    {
 292        $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
 293        switch ($isolation) {
 294        case 'READ UNCOMMITTED':
 295            $isolation = 'READ COMMITTED';
 296        case 'READ COMMITTED':
 297        case 'REPEATABLE READ':
 298            $isolation = 'SERIALIZABLE';
 299        case 'SERIALIZABLE':
 300            break;
 301        default:
 302            return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
 303                'isolation level is not supported: '.$isolation, __FUNCTION__);
 304        }
 305
 306        $query = "ALTER SESSION ISOLATION LEVEL $isolation";
 307        return $this->_doQuery($query, true);
 308    }
 309
 310    // }}}
 311    // {{{ _doConnect()
 312
 313    /**
 314     * do the grunt work of the connect
 315     *
 316     * @return connection on success or MDB2 Error Object on failure
 317     * @access protected
 318     */
 319    function _doConnect($username, $password, $persistent = false)
 320    {
 321        if (!PEAR::loadExtension($this->phptype)) {
 322            return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
 323                'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
 324        }
 325
 326        $sid = '';
 327
 328        if (!empty($this->dsn['service']) && $this->dsn['hostspec']) {
 329            //oci8://username:password@foo.example.com[:port]/?service=service
 330            // service name is given, it is assumed that hostspec is really a
 331            // hostname, we try to construct an oracle connection string from this
 332            $port = $this->dsn['port'] ? $this->dsn['port'] : 1521;
 333            $sid = sprintf("(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
 334                            (HOST=%s) (PORT=%s)))
 335                            (CONNECT_DATA=(SERVICE_NAME=%s)))",
 336                $this->dsn['hostspec'],
 337                $port,
 338                $this->dsn['service']
 339            );
 340        } elseif ($this->dsn['hostspec']) {
 341            // we are given something like 'oci8://username:password@foo/'
 342            // we have hostspec but not a service name, now we assume that
 343            // hostspec is a tnsname defined in tnsnames.ora
 344            $sid = $this->dsn['hostspec'];
 345        } else {
 346            // oci://username:password@
 347            // if everything fails, we have to rely on environment variables
 348            // not before a check to 'emulate_database'
 349            if (!$this->options['emulate_database'] && $this->database_name) {
 350                $sid = $this->database_name;
 351            } elseif (getenv('ORACLE_SID')) {
 352                $sid = getenv('ORACLE_SID');
 353            } elseif ($sid = getenv('TWO_TASK')) {
 354                $sid = getenv('TWO_TASK');
 355            } else {
 356                return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
 357                    'not a valid connection string or environment variable [ORACLE_SID|TWO_TASK] not set',
 358                    __FUNCTION__);
 359            }
 360        }
 361
 362        if (function_exists('oci_connect')) {
 363            if (isset($this->dsn['new_link'])
 364                && ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true)
 365            ) {
 366                $connect_function = 'oci_new_connect';
 367            } else {
 368                $connect_function = $persistent ? 'oci_pconnect' : 'oci_connect';
 369            }
 370
 371            $charset = empty($this->dsn['charset']) ? null : $this->dsn['charset'];
 372            $connection = @$connect_function($username, $password, $sid, $charset);
 373            $error = @OCIError();
 374            if (isset($error['code']) && $error['code'] == 12541) {
 375                // Couldn't find TNS listener.  Try direct connection.
 376                $connection = @$connect_function($username, $password, null, $charset);
 377            }
 378        } else {
 379            $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon';
 380            $connection = @$connect_function($username, $password, $sid);
 381
 382            if (!empty($this->dsn['charset'])) {
 383                $result = $this->setCharset($this->dsn['charset'], $connection);
 384                if (PEAR::isError($result)) {
 385                    return $result;
 386                }
 387            }
 388        }
 389
 390        if (!$connection) {
 391            return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
 392                'unable to establish a connection', __FUNCTION__);
 393        }
 394
 395       if (empty($this->dsn['disable_iso_date'])) {
 396            $query = "ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'";
 397            $err =& $this->_doQuery($query, true, $connection);
 398            if (PEAR::isError($err)) {
 399                $this->disconnect(false);
 400                return $err;
 401            }
 402       }
 403
 404        $query = "ALTER SESSION SET NLS_NUMERIC_CHARACTERS='. '";
 405        $err =& $this->_doQuery($query, true, $connection);
 406        if (PEAR::isError($err)) {
 407            $this->disconnect(false);
 408            return $err;
 409        }
 410
 411        return $connection;
 412    }
 413
 414    // }}}
 415    // {{{ connect()
 416
 417    /**
 418     * Connect to the database
 419     *
 420     * @return MDB2_OK on success, MDB2 Error Object on failure
 421     * @access public
 422     */
 423    function connect()
 424    {
 425        if ($this->database_name && $this->options['emulate_database']) {
 426             $this->dsn['username'] = $this->options['database_name_prefix'].$this->database_name;
 427        }
 428        if (is_resource($this->connection)) {
 429            if (count(array_diff($this->connected_dsn, $this->dsn)) == 0
 430                && $this->connected_database_name == $this->database_name
 431                && $this->opened_persistent == $this->options['persistent']
 432            ) {
 433                return MDB2_OK;
 434            }
 435            $this->disconnect(false);
 436        }
 437
 438        $connection = $this->_doConnect(
 439            $this->dsn['username'],
 440            $this->dsn['password'],
 441            $this->options['persistent']
 442        );
 443        if (PEAR::isError($connection)) {
 444            return $connection;
 445        }
 446        $this->connection = $connection;
 447        $this->connected_dsn = $this->dsn;
 448        $this->connected_database_name = $this->database_name;
 449        $this->opened_persistent = $this->options['persistent'];
 450        $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype;
 451
 452        $this->as_keyword = ' ';
 453        $server_info = $this->getServerVersion();
 454        if (is_array($server_info)) {
 455            if ($server_info['major'] >= '10') {
 456                $this->as_keyword = ' AS ';
 457            }
 458        }
 459        return MDB2_OK;
 460    }
 461
 462    // }}}
 463    // {{{ disconnect()
 464
 465    /**
 466     * Log out and disconnect from the database.
 467     *
 468     * @param  boolean $force if the disconnect should be forced even if the
 469     *                        connection is opened persistently
 470     * @return mixed true on success, false if not connected and error
 471     *                object on error
 472     * @access public
 473     */
 474    function disconnect($force = true)
 475    {
 476        if (is_resource($this->connection)) {
 477            if ($this->in_transaction) {
 478                $dsn = $this->dsn;
 479                $database_name = $this->database_name;
 480                $persistent = $this->options['persistent'];
 481                $this->dsn = $this->connected_dsn;
 482                $this->database_name = $this->connected_database_name;
 483                $this->options['persistent'] = $this->opened_persistent;
 484                $this->rollback();
 485                $this->dsn = $dsn;
 486                $this->database_name = $database_name;
 487                $this->options['persistent'] = $persistent;
 488            }
 489
 490            if (!$this->opened_persistent || $force) {
 491                if (function_exists('oci_close')) {
 492                    @oci_close($this->connection);
 493                } else {
 494                    @OCILogOff($this->connection);
 495                }
 496            }
 497            $this->uncommitedqueries = 0;
 498        }
 499        return parent::disconnect($force);
 500    }
 501
 502    // }}}
 503    // {{{ standaloneExec()
 504
 505   /**
 506     * execute a query as database administrator
 507     *
 508     * @param string $query the SQL query
 509     * @return mixed MDB2_OK on success, a MDB2 error on failure
 510     * @access public
 511     */
 512    function &standaloneExec($query)
 513    {
 514        $connection = $this->_doConnect(
 515            $this->options['DBA_username'],
 516            $this->options['DBA_password'],
 517            $this->options['persistent']
 518        );
 519        if (PEAR::isError($connection)) {
 520            return $connection;
 521        }
 522
 523        $offset = $this->offset;
 524        $limit = $this->limit;
 525        $this->offset = $this->limit = 0;
 526        $query = $this->_modifyQuery($query, false, $limit, $offset);
 527
 528        $result =& $this->_doQuery($query, false, $connection, false);
 529        if (PEAR::isError($result)) {
 530            @OCILogOff($connection);
 531            return $result;
 532        }
 533
 534        $ret = $this->_affectedRows($connection, $result);
 535        @OCILogOff($connection);
 536        return $ret;
 537    }
 538
 539    // }}}
 540    // {{{ standaloneQuery()
 541
 542   /**
 543     * execute a query as DBA
 544     *
 545     * @param string $query the SQL query
 546     * @param mixed   $types  array that contains the types of the columns in
 547     *                        the result set
 548     * @param boolean $is_manip  if the query is a manipulation query
 549     * @return mixed MDB2_OK on success, a MDB2 error on failure
 550     * @access public
 551     */
 552    function &standaloneQuery($query, $types = null, $is_manip = false)
 553    {
 554        $connection = $this->_doConnect(
 555            $this->options['DBA_username'],
 556            $this->options['DBA_password'],
 557            $this->options['persistent']
 558        );
 559        if (PEAR::isError($connection)) {
 560            return $connection;
 561        }
 562
 563        $offset = $this->offset;
 564        $limit = $this->limit;
 565        $this->offset = $this->limit = 0;
 566        $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
 567
 568        $result =& $this->_doQuery($query, $is_manip, $connection, false);
 569        @OCILogOff($connection);
 570        if (PEAR::isError($result)) {
 571            return $result;
 572        }
 573
 574        if ($is_manip) {
 575            $affected_rows =  $this->_affectedRows($connection, $result);
 576            return $affected_rows;
 577        }
 578        $return =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
 579        return $return;
 580    }
 581
 582    // }}}
 583    // {{{ _modifyQuery()
 584
 585    /**
 586     * Changes a query string for various DBMS specific reasons
 587     *
 588     * @param string $query  query to modify
 589     * @param boolean $is_manip  if it is a DML query
 590     * @param integer $limit  limit the number of rows
 591     * @param integer $offset  start reading from given offset
 592     * @return string modified query
 593     * @access protected
 594     */
 595    function _modifyQuery($query, $is_manip, $limit, $offset)
 596    {
 597        if (preg_match('/^\s*SELECT/i', $query)) {
 598            if (!preg_match('/\sFROM\s/i', $query)) {
 599                $query.= " FROM dual";
 600            }
 601            if ($limit > 0) {
 602                // taken from http://svn.ez.no/svn/ezcomponents/packages/Database
 603                $max = $offset + $limit;
 604                if ($offset > 0) {
 605                    $min = $offset + 1;
 606                    $query = "SELECT * FROM (SELECT a.*, ROWNUM mdb2rn FROM ($query) a WHERE ROWNUM <= $max) WHERE mdb2rn >= $min";
 607                } else {
 608                    $query = "SELECT a.* FROM ($query) a WHERE ROWNUM <= $max";
 609                }
 610            }
 611        }
 612        return $query;
 613    }
 614
 615    // }}}
 616    // {{{ _doQuery()
 617
 618    /**
 619     * Execute a query
 620     * @param string $query  query
 621     * @param boolean $is_manip  if the query is a manipulation query
 622     * @param resource $connection
 623     * @param string $database_name
 624     * @return result or error object
 625     * @access protected
 626     */
 627    function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
 628    {
 629        $this->last_query = $query;
 630        $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
 631        if ($result) {
 632            if (PEAR::isError($result)) {
 633                return $result;
 634            }
 635            $query = $result;
 636        }
 637        if ($this->getOption('disable_query')) {
 638            if ($is_manip) {
 639                return 0;
 640            }
 641            return null;
 642        }
 643
 644        if (is_null($connection)) {
 645            $connection = $this->getConnection();
 646            if (PEAR::isError($connection)) {
 647                return $connection;
 648            }
 649        }
 650
 651        $result = @OCIParse($connection, $query);
 652        if (!$result) {
 653            $err = $this->raiseError(null, null, null,
 654                'Could not create statement', __FUNCTION__);
 655            return $err;
 656        }
 657
 658        $mode = $this->in_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS;
 659        if (!@OCIExecute($result, $mode)) {
 660            $err =& $this->raiseError($result, null, null,
 661                'Could not execute statement', __FUNCTION__);
 662            return $err;
 663        }
 664
 665        if (is_numeric($this->options['result_prefetching'])) {
 666            @ocisetprefetch($result, $this->options['result_prefetching']);
 667        }
 668
 669        $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'post', 'result' => $result));
 670        return $result;
 671    }
 672
 673    // }}}
 674    // {{{ _affectedRows()
 675
 676    /**
 677     * Returns the number of rows affected
 678     *
 679     * @param resource $result
 680     * @param resource $connection
 681     * @return mixed MDB2 Error Object or the number of rows affected
 682     * @access private
 683     */
 684    function _affectedRows($connection, $result = null)
 685    {
 686        if (is_null($connection)) {
 687            $connection = $this->getConnection();
 688            if (PEAR::isError($connection)) {
 689                return $connection;
 690            }
 691        }
 692        return @OCIRowCount($result);
 693    }
 694
 695    // }}}
 696    // {{{ getServerVersion()
 697
 698    /**
 699     * return version information about the server
 700     *
 701     * @param bool   $native  determines if the raw version string should be returned
 702     * @return mixed array/string with version information or MDB2 error object
 703     * @access public
 704     */
 705    function getServerVersion($native = false)
 706    {
 707        $connection = $this->getConnection();
 708        if (PEAR::isError($connection)) {
 709            return $connection;
 710        }
 711        if ($this->connected_server_info) {
 712            $server_info = $this->connected_server_info;
 713        } else {
 714            $server_info = @ociserverversion($connection);
 715        }
 716        if (!$server_info) {
 717            return $this->raiseError(null, null, null,
 718                'Could not get server information', __FUNCTION__);
 719        }
 720        // cache server_info
 721        $this->connected_server_info = $server_info;
 722        if (!$native) {
 723            if (!preg_match('/ (\d+)\.(\d+)\.(\d+)\.([\d\.]+) /', $server_info, $tmp)) {
 724                return $this->raiseError(MDB2_ERROR_INVALID, null, null,
 725                    'Could not parse version information:'.$server_info, __FUNCTION__);
 726            }
 727            $server_info = array(
 728                'major' => $tmp[1],
 729                'minor' => $tmp[2],
 730                'patch' => $tmp[3],
 731                'extra' => $tmp[4],
 732                'native' => $server_info,
 733            );
 734        }
 735        return $server_info;
 736    }
 737
 738    // }}}
 739    // {{{ prepare()
 740
 741    /**
 742     * Prepares a query for multiple execution with execute().
 743     * With some database backends, this is emulated.
 744     * prepare() requires a generic query as string like
 745     * 'INSERT INTO numbers VALUES(?,?)' or
 746     * 'INSERT INTO numbers VALUES(:foo,:bar)'.
 747     * The ? and :[a-zA-Z] and  are placeholders which can be set using
 748     * bindParam() and the query can be send off using the execute() method.
 749     *
 750     * @param string $query the query to prepare
 751     * @param mixed   $types  array that contains the types of the placeholders
 752     * @param mixed   $result_types  array that contains the types of the columns in
 753     *                        the result set or MDB2_PREPARE_RESULT, if set to
 754     *                        MDB2_PREPARE_MANIP the query is handled as a manipulation query
 755     * @param mixed   $lobs   key (field) value (parameter) pair for all lob placeholders
 756     * @return mixed resource handle for the prepared query on success, a MDB2
 757     *        error on failure
 758     * @access public
 759     * @see bindParam, execute
 760     */
 761    function &prepare($query, $types = null, $result_types = null, $lobs = array())
 762    {
 763        if ($this->options['emulate_prepared']) {
 764            $obj =& parent::prepare($query, $types, $result_types, $lobs);
 765            return $obj;
 766        }
 767        $is_manip = ($result_types === MDB2_PREPARE_MANIP);
 768        $offset = $this->offset;
 769        $limit = $this->limit;
 770        $this->offset = $this->limit = 0;
 771        $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
 772        if ($result) {
 773            if (PEAR::isError($result)) {
 774                return $result;
 775            }
 776            $query = $result;
 777        }
 778        $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
 779        $placeholder_type_guess = $placeholder_type = null;
 780        $question = '?';
 781        $colon = ':';
 782        $positions = array();
 783        $position = 0;
 784        $parameter = -1;
 785        while ($position < strlen($query)) {
 786            $q_position = strpos($query, $question, $position);
 787            $c_position = strpos($query, $colon, $position);
 788            if ($q_position && $c_position) {
 789                $p_position = min($q_position, $c_position);
 790            } elseif ($q_position) {
 791                $p_position = $q_position;
 792            } elseif ($c_position) {
 793                $p_position = $c_position;
 794            } else {
 795                break;
 796            }
 797            if (is_null($placeholder_type)) {
 798                $placeholder_type_guess = $query[$p_position];
 799            }
 800            
 801            $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
 802            if (PEAR::isError($new_pos)) {
 803                return $new_pos;
 804            }
 805            if ($new_pos != $position) {
 806                $position = $new_pos;
 807                continue; //evaluate again starting from the new position
 808            }
 809
 810            if ($query[$position] == $placeholder_type_guess) {
 811                if (is_null($placeholder_type)) {
 812                    $placeholder_type = $query[$p_position];
 813                    $question = $colon = $placeholder_type;
 814                    if (!empty($types) && is_array($types)) {
 815                        if ($placeholder_type == ':') {
 816                            if (is_int(key($types))) {
 817                                $types_tmp = $types;
 818                                $types = array();
 819                                $count = -1;
 820                            }
 821                        } else {
 822                            $types = array_values($types);
 823                        }
 824                    }
 825                }
 826                if ($placeholder_type == ':') {
 827                    $parameter = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
 828                    if ($parameter === '') {
 829                        $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
 830                            'named parameter with an empty name', __FUNCTION__);
 831                        return $err;
 832                    }
 833                    // use parameter name in type array
 834                    if (isset($count) && isset($types_tmp[++$count])) {
 835                        $types[$parameter] = $types_tmp[$count];
 836                    }
 837                    $length = strlen($parameter) + 1;
 838                } else {
 839                    ++$parameter;
 840                    $length = strlen($parameter);
 841                }
 842                if (!in_array($parameter, $positions)) {
 843                    $positions[] = $parameter;
 844                }
 845                if (isset($types[$parameter])
 846                    && ($types[$parameter] == 'clob' || $types[$parameter] == 'blob')
 847                ) {
 848                    if (!isset($lobs[$parameter])) {
 849                        $lobs[$parameter] = $parameter;
 850                    }
 851                    $value = $this->quote(true, $types[$parameter]);
 852                    $query = substr_replace($query, $value, $p_position, $length);
 853                    $position = $p_position + strlen($value) - 1;
 854                } elseif ($placeholder_type == '?') {
 855                    $query = substr_replace($query, ':'.$parameter, $p_position, 1);
 856                    $position = $p_position + $length;
 857                } else {
 858                    $position = $p_position + 1;
 859                }
 860            } else {
 861                $position = $p_position;
 862            }
 863        }
 864        if (is_array($lobs)) {
 865            $columns = $variables = '';
 866            foreach ($lobs as $parameter => $field) {
 867                $columns.= ($columns ? ', ' : ' RETURNING ').$field;
 868                $variables.= ($variables ? ', ' : ' INTO ').':'.$parameter;
 869            }
 870            $query.= $columns.$variables;
 871        }
 872        $connection = $this->getConnection();
 873        if (PEAR::isError($connection)) {
 874            return $connection;
 875        }
 876        $statement = @OCIParse($connection, $query);
 877        if (!$statement) {
 878            $err =& $this->raiseError(null, null, null,
 879                'Could not create statement', __FUNCTION__);
 880            return $err;
 881        }
 882
 883        $class_name = 'MDB2_Statement_'.$this->phptype;
 884        $obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
 885        $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
 886        return $obj;
 887    }
 888
 889    // }}}
 890    // {{{ nextID()
 891
 892    /**
 893     * Returns the next free id of a sequence
 894     *
 895     * @param string $seq_name name of the sequence
 896     * @param boolean $ondemand when true the sequence is
 897     *                           automatic created, if it
 898     *                           not exists
 899     * @return mixed MDB2 Error Object or id
 900     * @access public
 901     */
 902    function nextID($seq_name, $ondemand = true)
 903    {
 904        $sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
 905        $query = "SELECT $sequence_name.nextval FROM DUAL";
 906        $this->expectError(MDB2_ERROR_NOSUCHTABLE);
 907        $result = $this->queryOne($query, 'integer');
 908        $this->popExpect();
 909        if (PEAR::isError($result)) {
 910            if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) {
 911                $this->loadModule('Manager', null, true);
 912                $result = $this->manager->createSequence($seq_name);
 913                if (PEAR::isError($result)) {
 914                    return $result;
 915                }
 916                return $this->nextId($seq_name, false);
 917            }
 918        }
 919        return $result;
 920    }
 921
 922    // }}}
 923    // {{{ lastInsertID()
 924
 925    /**
 926     * Returns the autoincrement ID if supported or $id or fetches the current
 927     * ID in a sequence called: $table.(empty($field) ? '' : '_'.$field)
 928     *
 929     * @param string $table name of the table into which a new row was inserted
 930     * @param string $field name of the field into which a new row was inserted
 931     * @return mixed MDB2 Error Object or id
 932     * @access public
 933     */
 934    function lastInsertID($table = null, $field = null)
 935    {
 936        $seq = $table.(empty($field) ? '' : '_'.$field);
 937        $sequence_name = $this->quoteIdentifier($this->getSequenceName($seq), true);
 938        return $this->queryOne("SELECT $sequence_name.currval", 'integer');
 939    }
 940
 941    // }}}
 942    // {{{ currId()
 943
 944    /**
 945     * Returns the current id of a sequence
 946     *
 947     * @param string $seq_name name of the sequence
 948     * @return mixed MDB2_Error or id
 949     * @access public
 950     */
 951    function currId($seq_name)
 952    {
 953        $sequence_name = $this->getSequenceName($seq_name);
 954        $query = 'SELECT (last_number-1) FROM user_sequences';
 955        $query.= ' WHERE sequence_name='.$this->quote($sequence_name, 'text');
 956        $query.= ' OR sequence_name='.$this->quote(strtoupper($sequence_name), 'text');
 957        return $this->queryOne($query, 'integer');
 958    }
 959}
 960
 961/**
 962 * MDB2 OCI8 result driver
 963 *
 964 * @package MDB2
 965 * @category Database
 966 * @author Lukas Smith <smith@pooteeweet.org>
 967 */
 968class MDB2_Result_oci8 extends MDB2_Result_Common
 969{
 970    // }}}
 971    // {{{ fetchRow()
 972
 973    /**
 974     * Fetch a row and insert the data into an existing array.
 975     *
 976     * @param int       $fetchmode  how the array data should be indexed
 977     * @param int    $rownum    number of the row where the data can be found
 978     * @return int data array on success, a MDB2 error on failure
 979     * @access public
 980     */
 981    function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
 982    {
 983        if (!is_null($rownum)) {
 984            $seek = $this->seek($rownum);
 985            if (PEAR::isError($seek)) {
 986                return $seek;
 987            }
 988        }
 989        if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
 990            $fetchmode = $this->db->fetchmode;
 991        }
 992        if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
 993            @OCIFetchInto($this->result, $row, OCI_ASSOC+OCI_RETURN_NULLS);
 994            if (is_array($row)
 995                && $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
 996            ) {
 997                $row = array_change_key_case($row, $this->db->options['field_case']);
 998            }
 999        } else {
1000            @OCIFetchInto($this->result, $row, OCI_RETURN_NULLS);
1001        }
1002        if (!$row) {
1003            if ($this->result === false) {
1004                $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
1005                    'resultset has already been freed', __FUNCTION__);
1006                return $err;
1007            }
1008            $null = null;
1009            return $null;
1010        }
1011        // remove additional column at the end
1012        if ($this->offset > 0) {
1013            array_pop($row);
1014        }
1015        $mode = 0;
1016        $rtrim = false;
1017        if ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) {
1018            if (empty($this->types)) {
1019                $mode += MDB2_PORTABILITY_RTRIM;
1020            } else {
1021                $rtrim = true;
1022            }
1023        }
1024        if ($mode) {
1025            $this->db->_fixResultArrayValues($row, $mode);
1026        }
1027        if (!empty($this->types)) {
1028            $row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
1029        }
1030        if (!empty($this->values)) {
1031            $this->_assignBindColumns($row);
1032        }
1033        if ($fetchmode === MDB2_FETCHMODE_OBJECT) {
1034            $object_class = $this->db->options['fetch_class'];
1035            if ($object_class == 'stdClass') {
1036                $row = (object) $row;
1037            } else {
1038                $row = &new $object_class($row);
1039            }
1040        }
1041        ++$this->rownum;
1042        return $row;
1043    }
1044
1045    // }}}
1046    // {{{ _getColumnNames()
1047
1048    /**
1049     * Retrieve the names of columns returned by the DBMS in a query result.
1050     *
1051     * @return  mixed   Array variable that holds the names of columns as keys
1052     *                  or an MDB2 error on failure.
1053     *                  Some DBMS may not return any columns when the result set
1054     *                  does not contain any rows.
1055     * @access private
1056     */
1057    function _getColumnNames()
1058    {
1059        $columns = array();
1060        $numcols = $this->numCols();
1061        if (PEAR::isError($numcols)) {
1062            return $numcols;
1063        }
1064        for ($column = 0; $column < $numcols; $column++) {
1065            $column_name = @OCIColumnName($this->result, $column + 1);
1066            $columns[$column_name] = $column;
1067        }
1068        if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
1069            $columns = array_change_key_case($columns, $this->db->options['field_case']);
1070        }
1071        return $columns;
1072    }
1073
1074    // }}}
1075    // {{{ numCols()
1076
1077    /**
1078     * Count the number of columns returned by the DBMS in a query result.
1079     *
1080     * @return mixed integer value with the number of columns, a MDB2 error
1081     *      on failure
1082     * @access public
1083     */
1084    function numCols()
1085    {
1086        $cols = @OCINumCols($this->result);
1087        if (is_null($cols)) {
1088            if ($this->result === false) {
1089                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
1090                    'resultset has already been freed', __FUNCTION__);
1091            } elseif (is_null($this->result)) {
1092                return count($this->types);
1093            }
1094            return $this->db->raiseError(null, null, null,
1095                'Could not get column count', __FUNCTION__);
1096        }
1097        if ($this->offset > 0) {
1098            --$cols;
1099        }
1100        return $cols;
1101    }
1102
1103    // }}}
1104    // {{{ free()
1105
1106    /**
1107     * Free the internal resources associated with $result.
1108     *
1109     * @return boolean true on success, false if $result is invalid
1110     * @access public
1111     */
1112    function free()
1113    {
1114        if (is_resource($this->result) && $this->db->connection) {
1115            $free = @OCIFreeCursor($this->result);
1116            if ($free === false) {
1117                return $this->db->raiseError(null, null, null,
1118                    'Could not free result', __FUNCTION__);
1119            }
1120        }
1121        $this->result = false;
1122        return MDB2_OK;
1123
1124    }
1125}
1126
1127/**
1128 * MDB2 OCI8 buffered result driver
1129 *
1130 * @package MDB2
1131 * @category Database
1132 * @author Lukas Smith <smith@pooteeweet.org>
1133 */
1134class MDB2_BufferedResult_oci8 extends MDB2_Result_oci8
1135{
1136    var $buffer;
1137    var $buffer_rownum = - 1;
1138
1139    // {{{ _fillBuffer()
1140
1141    /**
1142     * Fill the row buffer
1143     *
1144     * @param int $rownum   row number upto which the buffer should be filled
1145                            if the row number is null all rows are ready into the buffer
1146     * @return boolean true on success, false on failure
1147     * @access protected
1148     */
1149    function _fillBuffer($rownum = null)
1150    {
1151        if (isset($this->buffer) && is_array($this->buffer)) {
1152            if (is_null($rownum)) {
1153                if (!end($this->buffer)) {
1154                    return false;
1155                }
1156            } elseif (isset($this->buffer[$rownum])) {
1157                return (bool)$this->buffer[$rownum];
1158            }
1159        }
1160
1161        $row = true;
1162        while ((is_null($rownum) || $this->buffer_rownum < $rownum)
1163            && ($row = @OCIFetchInto($this->result, $buffer, OCI_RETURN_NULLS))
1164        ) {
1165            ++$this->buffer_rownum;
1166            // remove additional column at the end
1167            if ($this->offset > 0) {
1168                array_pop($buffer);
1169            }
1170            if (empty($this->types)) {
1171                foreach (array_keys($buffer) as $key) {
1172                    if (is_a($buffer[$key], 'oci-lob')) {
1173                        $buffer[$key] = $buffer[$key]->load();
1174                    }
1175                }
1176            }
1177            $this->buffer[$this->buffer_rownum] = $buffer;
1178        }
1179
1180        if (!$row) {
1181            ++$this->buffer_rownum;
1182            $this->buffer[$this->buffer_rownum] = false;
1183            return false;
1184        }
1185        return true;
1186    }
1187
1188    // }}}
1189    // {{{ fetchRow()
1190
1191    /**
1192     * Fetch a row and insert the data into an existing array.
1193     *
1194     * @param int       $fetchmode  how the array data should be indexed
1195     * @param int    $rownum    number of the row where the data can be found
1196     * @return int data array on success, a MDB2 error on failure
1197     * @access public
1198     */
1199    function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
1200    {
1201        if ($this->result === false) {
1202            $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
1203                'resultset has already been freed', __FUNCTION__);
1204            return $err;
1205        } elseif (is_null($this->result)) {
1206            return null;
1207        }
1208        if (!is_null($rownum)) {
1209            $seek = $this->seek($rownum);
1210            if (PEAR::isError($seek)) {
1211                return $seek;
1212            }
1213        }
1214        $target_rownum = $this->rownum + 1;
1215        if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
1216            $fetchmode = $this->db->fetchmode;
1217        }
1218        if (!$this->_fillBuffer($target_rownum)) {
1219            $null = null;
1220            return $null;
1221        }
1222        $row = $this->buffer[$target_rownum];
1223        if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
1224            $column_names = $this->getColumnNames();
1225            foreach ($column_names as $name => $i) {
1226                $column_names[$name] = $row[$i];
1227            }
1228            $row = $column_names;
1229        }
1230        $mode = 0;
1231        $rtrim = false;
1232        if ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) {
1233            if (empty($this->types)) {
1234                $mode += MDB2_PORTABILITY_RTRIM;
1235            } else {
1236                $rtrim = true;
1237            }
1238        }
1239        if ($mode) {
1240            $this->db->_fixResultArrayValues($row, $mode);
1241        }
1242        if (!empty($this->types)) {
1243            $row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
1244        }
1245        if (!empty($this->values)) {
1246            $this->_assignBindColumns($row);
1247        }
1248        if ($fetchmode === MDB2_FETCHMODE_OBJECT) {
1249            $object_class = $this->db->options['fetch_class'];
1250            if ($object_class == 'stdClass') {
1251                $row = (object) $row;
1252            } else {
1253                $row = &new $object_class($row);
1254            }
1255        }
1256        ++$this->rownum;
1257        return $row;
1258    }
1259
1260    // }}}
1261    // {{{ seek()
1262
1263    /**
1264     * Seek to a specific row in a result set
1265     *
1266     * @param int    $rownum    number of the row where the data can be found
1267     * @return mixed MDB2_OK on success, a MDB2 error on failure
1268     * @access public
1269     */
1270    function seek($rownum = 0)
1271    {
1272        if ($this->result === false) {
1273            return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
1274                'resultset has already been freed', __FUNCTION__);
1275        }
1276        $this->rownum = $rownum - 1;
1277        return MDB2_OK;
1278    }
1279
1280    // }}}
1281    // {{{ valid()
1282
1283    /**
1284     * Check if the end of the result set has been reached
1285     *
1286     * @return mixed true or false on sucess, a MDB2 error on failure
1287     * @access public
1288     */
1289    function valid()
1290    {
1291        if ($this->result === false) {
1292            return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
1293                'resultset has already been freed', __FUNCTION__);
1294        } elseif (is_null($this->result)) {
1295            return true;
1296        }
1297        if ($this->_fillBuffer($this->rownum + 1)) {
1298            return true;
1299        }
1300        return false;
1301    }
1302
1303    // }}}
1304    // {{{ numRows()
1305
1306    /**
1307     * Returns the number of rows in a result object
1308     *
1309     * @return mixed MDB2 Error Object or the number of rows
1310     * @access public
1311     */
1312    function numRows()
1313    {
1314        if ($this->result === false) {
1315            return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
1316                'resultset has already been freed', __FUNCTION__);
1317        } elseif (is_null($this->result)) {
1318            return 0;
1319        }
1320        $this->_fillBuffer();
1321        return $this->buffer_rownum;
1322    }
1323
1324    // }}}
1325    // {{{ free()
1326
1327    /**
1328     * Free the internal resources associated with $result.
1329     *
1330     * @return boolean true on success, false if $result is invalid
1331     * @access public
1332     */
1333    function free()
1334    {
1335        $this->buffer = null;
1336        $this->buffer_rownum = null;
1337        return parent::free();
1338    }
1339}
1340
1341/**
1342 * MDB2 OCI8 statement driver
1343 *
1344 * @package MDB2
1345 * @category Database
1346 * @author Lukas Smith <smith@pooteeweet.org>
1347 */
1348class MDB2_Statement_oci8 extends MDB2_Statement_Common
1349{
1350    // }}}
1351    // {{{ _execute()
1352
1353    /**
1354     * Execute a prepared query statement helper method.
1355     *
1356     * @param mixed $result_class string which specifies which result class to use
1357     * @param mixed $result_wrap_class string which specifies which class to wrap results in
1358     * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
1359     * @access private
1360     */
1361    function &_execute($result_class = true, $result_wrap_class = false)
1362    {
1363        if (is_null($this->statement)) {
1364            $result =& parent::_execute($result_class, $result_wrap_class);
1365            return $result;
1366        }
1367        $this->db->last_query = $this->query;
1368        $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'pre', 'parameters' => $this->values));
1369        if ($this->db->getOption('disable_query')) {
1370            $result = $this->is_manip ? 0 : null;
1371            return $result;
1372        }
1373
1374        $connection = $this->db->getConnection();
1375        if (PEAR::isError($connection)) {
1376            return $connection;
1377        }
1378
1379        $result = MDB2_OK;
1380        $lobs = $quoted_values = array();
1381        $i = 0;
1382        foreach ($this->positions as $parameter) {
1383            if (!array_key_exists($parameter, $this->values)) {
1384                return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
1385                    'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
1386            }
1387            $value = $this->values[$parameter];
1388            $type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null;
1389            if ($type == 'clob' || $type == 'blob') {
1390                $l…

Large files files are truncated, but you can click here to view the full file