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

Source for file ibase.php

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

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