MDB2
[ class tree: MDB2 ] [ index: MDB2 ] [ all elements ]

Source for file oci8.php

Documentation is available at oci8.php

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

Documentation generated on Mon, 11 Mar 2019 14:40:50 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.