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

Source for file fbsql.php

Documentation is available at fbsql.php

  1. <?php
  2. // vim: set et ts=4 sw=4 fdm=marker:
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox,                 |
  7. // | Stig. S. Bakken, Lukas Smith, Frank M. Kromann                       |
  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@backendmedia.com>                         |
  44. // +----------------------------------------------------------------------+
  45. //
  46. // $Id: fbsql.php,v 1.11 2004/04/25 10:04:59 lsmith Exp $
  47. //
  48.  
  49. /**
  50.  * MDB2 FrontBase driver
  51.  *
  52.  * @package MDB2
  53.  * @category Database
  54.  * @author  Lukas Smith <smith@backendmedia.com>
  55.  * @author  Frank M. Kromann <frank@kromann.info>
  56.  */
  57. {
  58.     // {{{ properties
  59.     var $escape_quotes = "'";
  60.  
  61.     var $max_text_length = 32768;
  62.  
  63.     // }}}
  64.     // {{{ constructor
  65.  
  66.     /**
  67.     * Constructor
  68.     */
  69.     function MDB2_fbsql()
  70.     {
  71.         $this->MDB2_Driver_Common();
  72.         $this->phptype 'fbsql';
  73.         $this->dbsyntax 'fbsql';
  74.  
  75.         $this->supported['sequences'= true;
  76.         $this->supported['indexes'= true;
  77.         $this->supported['affected_rows'= true;
  78.         $this->supported['summary_functions'= true;
  79.         $this->supported['order_by_text'= true;
  80.         $this->supported['current_id'= false;
  81.         $this->supported['limit_queries'= true;
  82.         $this->supported['LOBs'= true;
  83.         $this->supported['replace'= true;
  84.         $this->supported['sub_selects'= true;
  85.     }
  86.  
  87.     // }}}
  88.     // {{{ errorInfo()
  89.  
  90.     /**
  91.      * This method is used to collect information about an error
  92.      *
  93.      * @param integer $error 
  94.      * @return array 
  95.      * @access public
  96.      */
  97.     function errorInfo($error = null)
  98.     {
  99.         $native_code @fbsql_errno($this->connection);
  100.         $native_msg  @fbsql_error($this->connection);
  101.         if (is_null($error)) {
  102.             static $ecode_map;
  103.             if (empty($ecode_map)) {
  104.                 $ecode_map = array(
  105.                     1004 => MDB2_ERROR_CANNOT_CREATE,
  106.                     1005 => MDB2_ERROR_CANNOT_CREATE,
  107.                     1006 => MDB2_ERROR_CANNOT_CREATE,
  108.                     1007 => MDB2_ERROR_ALREADY_EXISTS,
  109.                     1008 => MDB2_ERROR_CANNOT_DROP,
  110.                     1046 => MDB2_ERROR_NODBSELECTED,
  111.                     1050 => MDB2_ERROR_ALREADY_EXISTS,
  112.                     1051 => MDB2_ERROR_NOSUCHTABLE,
  113.                     1054 => MDB2_ERROR_NOSUCHFIELD,
  114.                     1062 => MDB2_ERROR_ALREADY_EXISTS,
  115.                     1064 => MDB2_ERROR_SYNTAX,
  116.                     1100 => MDB2_ERROR_NOT_LOCKED,
  117.                     1136 => MDB2_ERROR_VALUE_COUNT_ON_ROW,
  118.                     1146 => MDB2_ERROR_NOSUCHTABLE,
  119.                 );
  120.             }
  121.             if (isset($ecode_map[$native_code])) {
  122.                 $error $ecode_map[$native_code];
  123.             }
  124.         }
  125.         return array($error$native_code$native_msg);
  126.     }
  127.  
  128.     // }}}
  129.     // {{{ autoCommit()
  130.  
  131.     /**
  132.      * Define whether database changes done on the database be automatically
  133.      * committed. This function may also implicitly start or end a transaction.
  134.      *
  135.      * @param boolean $auto_commit    flag that indicates whether the database
  136.      *                                 changes should be committed right after
  137.      *                                 executing every query statement. If this
  138.      *                                 argument is 0 a transaction implicitly
  139.      *                                 started. Otherwise, if a transaction is
  140.      *                                 in progress it is ended by committing any
  141.      *                                 database changes that were pending.
  142.      *
  143.      * @access public
  144.      *
  145.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  146.      */
  147.     function autoCommit($auto_commit)
  148.     {
  149.         $this->debug(($auto_commit 'On' 'Off')'autoCommit');
  150.         if (!isset($this->supported['transactions'])) {
  151.             return $this->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  152.                 'autoCommit: transactions are not in use');
  153.         }
  154.         if ($this->auto_commit == $auto_commit{
  155.             return MDB2_OK;
  156.         }
  157.         if ($this->connection{
  158.             if ($auto_commit{
  159.                 $result $this->query('COMMIT');
  160.                 if (MDB2::isError($result)) {
  161.                     return $result;
  162.                 }
  163.                 $result $this->query('SET COMMIT TRUE');
  164.             else {
  165.                 $result $this->query('SET COMMIT FALSE');
  166.             }
  167.             if (MDB2::isError($result)) {
  168.                 return $result;
  169.             }
  170.         }
  171.         $this->auto_commit = $auto_commit;
  172.         $this->in_transaction !$auto_commit;
  173.         return MDB2_OK;
  174.     }
  175.  
  176.     // }}}
  177.     // {{{ commit()
  178.  
  179.     /**
  180.      * Commit the database changes done during a transaction that is in
  181.      * progress. This function may only be called when auto-committing is
  182.      * disabled, otherwise it will fail. Therefore, a new transaction is
  183.      * implicitly started after committing the pending changes.
  184.      *
  185.      * @access public
  186.      *
  187.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  188.      */
  189.     function commit()
  190.     {
  191.         $this->debug('commit transaction''commit');
  192.         if (!isset($this->supported['transactions'])) {
  193.             return $this->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  194.                 'commit: transactions are not in use');
  195.         }
  196.         if ($this->auto_commit{
  197.             return $this->raiseError(MDB2_ERRORnullnull,
  198.             'commit: transaction changes are being auto commited');
  199.         }
  200.         return $this->query('COMMIT');
  201.     }
  202.  
  203.     // }}}
  204.     // {{{ rollback()
  205.  
  206.     /**
  207.      * Cancel any database changes done during a transaction that is in
  208.      * progress. This function may only be called when auto-committing is
  209.      * disabled, otherwise it will fail. Therefore, a new transaction is
  210.      * implicitly started after canceling the pending changes.
  211.      *
  212.      * @access public
  213.      *
  214.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  215.      */
  216.     function rollback()
  217.     {
  218.         $this->debug('rolling back transaction''rollback');
  219.         if (!isset($this->supported['transactions'])) {
  220.             return $this->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  221.                 'rollback: transactions are not in use');
  222.         }
  223.         if ($this->auto_commit{
  224.             return $this->raiseError(MDB2_ERRORnullnull,
  225.                 'rollback: transactions can not be rolled back when changes are auto commited');
  226.         }
  227.         return $this->query('ROLLBACK');
  228.     }
  229.  
  230.     // }}}
  231.     // {{{ connect()
  232.  
  233.     /**
  234.      * Connect to the database
  235.      *
  236.      * @return true on success, MDB2 Error Object on failure
  237.      ***/
  238.     function connect()
  239.     {
  240.         if ($this->connection != 0{
  241.             if (count(array_diff($this->connected_dsn$this->dsn)) == 0
  242.                 && $this->opened_persistent == $this->options['persistent']
  243.             {
  244.                 return MDB2_OK;
  245.             }
  246.             @fbsql_close($this->connection);
  247.             $this->connection = 0;
  248.         }
  249.  
  250.         if (!PEAR::loadExtension($this->phptype)) {
  251.             return $this->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  252.                 'connect: extension '.$this->phptype.' is not compiled into PHP');
  253.         }
  254.  
  255.         $function ($this->options['persistent''fbsql_pconnect' 'fbsql_connect');
  256.  
  257.         $dsninfo $this->dsn;
  258.         $dbhost $dsninfo['hostspec'$dsninfo['hostspec''localhost';
  259.         $user $dsninfo['username'];
  260.         $pw $dsninfo['password'];
  261.  
  262.         @ini_set('track_errors'true);
  263.         if ($dbhost && $user && $pw{
  264.             $connection @$function($dbhost$user$pw);
  265.         elseif ($dbhost && $user{
  266.             $connection @$function($dbhost$user);
  267.         elseif ($dbhost{
  268.             $connection @$function($dbhost);
  269.         else {
  270.             $connection = 0;
  271.         }
  272.         @ini_restore('track_errors');
  273.         if ($connection <= 0{
  274.             return $this->raiseError(MDB2_ERROR_CONNECT_FAILEDnullnull,
  275.                 $php_errormsg);
  276.         }
  277.         $this->connection $connection;
  278.         $this->connected_dsn $this->dsn;
  279.         $this->connected_database_name '';
  280.         $this->opened_persistent $this->options['persistent'];
  281.  
  282.         if (isset($this->supported['transactions']&& !$this->auto_commit{
  283.             if (!@fbsql_query('SET AUTOCOMMIT FALSE;'$this->connection)) {
  284.                 @fbsql_close($this->connection);
  285.                 $this->connection = 0;
  286.                 return $this->raiseError();
  287.             }
  288.             $this->in_transaction = true;
  289.         }
  290.         return MDB2_OK;
  291.     }
  292.  
  293.     // }}}
  294.     // {{{ _close()
  295.     /**
  296.      * all the RDBMS specific things needed close a DB connection
  297.      *
  298.      * @return boolean 
  299.      * @access private
  300.      ***/
  301.     function _close()
  302.     {
  303.         if ($this->connection != 0{
  304.             if (isset($this->supported['transactions']&& !$this->auto_commit{
  305.                 $result $this->autoCommit(true);
  306.             }
  307.             @fbsql_close($this->connection);
  308.             $this->connection = 0;
  309.             unset($GLOBALS['_MDB2_databases'][$this->db_index]);
  310.  
  311.             if (isset($result&& MDB2::isError($result)) {
  312.                 return $result;
  313.             }
  314.         }
  315.         return MDB2_OK;
  316.     }
  317.  
  318.     // }}}
  319.     // {{{ _modifyQuery()
  320.  
  321.     /**
  322.      * This method is used by backends to alter queries for various
  323.      * reasons.
  324.      *
  325.      * @param string $query  query to modify
  326.      * @return the new (modified) query
  327.      * @access private
  328.      */
  329.     function _modifyQuery($query)
  330.     {
  331.         // "DELETE FROM table" gives 0 affected rows in fbsql.
  332.         // This little hack lets you know how many rows were deleted.
  333.         if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i'$query)) {
  334.             $query preg_replace(
  335.                 '/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
  336.                 'DELETE FROM \1 WHERE 1=1'$query
  337.             );
  338.         }
  339.         return $query;
  340.     }
  341.  
  342.     // }}}
  343.     // {{{ query()
  344.  
  345.     /**
  346.      * Send a query to the database and return any results
  347.      *
  348.      * @param string  $query  the SQL query
  349.      * @param mixed   $types  string or array that contains the types of the
  350.      *                         columns in the result set
  351.      * @param mixed $result_class string which specifies which result class to use
  352.      * @param mixed $result_wrap_class string which specifies which class to wrap results in
  353.      * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
  354.      *
  355.      * @access public
  356.      */
  357.     function &query($query$types = null$result_class = false$result_wrap_class = false)
  358.     {
  359.         $ismanip MDB2::isManip($query);
  360.         $offset $this->row_offset;
  361.         $limit $this->row_limit;
  362.         $this->row_offset $this->row_limit = 0;
  363.         if ($limit > 0{
  364.             if (!$ismanip{
  365.                 $query str_replace('SELECT'"SELECT TOP($offset,$limit)"$query);
  366.             }
  367.         }
  368.         if ($this->options['portability'MDB2_PORTABILITY_DELETE_COUNT{
  369.             $query $this->_modifyQuery($query);
  370.         }
  371.         $this->last_query = $query;
  372.         $this->debug($query'query');
  373.  
  374.         $connected $this->connect();
  375.         if (MDB2::isError($connected)) {
  376.             return $connected;
  377.         }
  378.  
  379.         if ($this->database_name{
  380.             if (!@fbsql_select_db($this->database_name$this->connection)) {
  381.                 $error =$this->raiseError();
  382.                 return $error;
  383.             }
  384.             $this->connected_database_name $this->database_name;
  385.         }
  386.  
  387.         // Add ; to the end of the query. This is required by FrontBase
  388.         $query .= ';';
  389.         if ($result @fbsql_query($query$this->connection)) {
  390.             if ($ismanip{
  391.                 return MDB2_OK;
  392.             else {
  393.                 if (!$result_class{
  394.                     $result_class $this->options['result_buffering']
  395.                         ? $this->options['buffered_result_class'$this->options['result_class'];
  396.                 }
  397.                 $class_name sprintf($result_class$this->phptype);
  398.                 $result =new $class_name($this$result);
  399.                 if ($types{
  400.                     $err $result->setResultTypes($types);
  401.                     if (MDB2::isError($err)) {
  402.                         $result->free();
  403.                         return $err;
  404.                     }
  405.                 }
  406.                 if (!$result_wrap_class{
  407.                     $result_wrap_class $this->options['result_wrap_class'];
  408.                 }
  409.                 if ($result_wrap_class{
  410.                     $result =new $result_wrap_class($result);
  411.                 }
  412.                 return $result;
  413.             }
  414.         }
  415.         $error =$this->raiseError();
  416.         return $error;
  417.     }
  418.  
  419.     // }}}
  420.     // {{{ affectedRows()
  421.  
  422.     /**
  423.      * returns the affected rows of a query
  424.      *
  425.      * @return mixed MDB2 Error Object or number of rows
  426.      * @access public
  427.      */
  428.     function affectedRows()
  429.     {
  430.         $affected_rows @fbsql_affected_rows($this->connection);
  431.         if ($affected_rows === false{
  432.             return $this->raiseError(MDB2_ERROR_NEED_MORE_DATA);
  433.         }
  434.         return $affected_rows;
  435.     }
  436.  
  437.     // }}}
  438.     // {{{ nextID()
  439.  
  440.     /**
  441.      * returns the next free id of a sequence
  442.      *
  443.      * @param string  $seq_name name of the sequence
  444.      * @param boolean $ondemand when true the seqence is
  445.      *                           automatic created, if it
  446.      *                           not exists
  447.      *
  448.      * @return mixed MDB2 Error Object or id
  449.      * @access public
  450.      */
  451.     function nextID($seq_name$ondemand = true)
  452.     {
  453.         $sequence_name $this->getSequenceName($seq_name);
  454.         $this->expectError(MDB2_ERROR_NOSUCHTABLE);
  455.         $result $this->query("INSERT INTO $sequence_name VALUES (NULL)");
  456.         $this->popExpect();
  457.         if (MDB2::isError($result)) {
  458.             if ($ondemand && $result->getCode(== MDB2_ERROR_NOSUCHTABLE{
  459.                 $this->loadModule('manager');
  460.                 // Since we are creating the sequence on demand
  461.                 // we know the first id = 1 so initialize the
  462.                 // sequence at 2
  463.                 $result $this->manager->createSequence($seq_name2);
  464.                 if (MDB2::isError($result)) {
  465.                     return $this->raiseError(MDB2_ERRORnullnull,
  466.                         'nextID: on demand sequence could not be created');
  467.                 else {
  468.                     // First ID of a newly created sequence is 1
  469.                     return 1;
  470.                 }
  471.             }
  472.             return $result;
  473.         }
  474.         $value $this->queryOne("SELECT UNIQUE FROM $sequence_name"'integer');
  475.         $result = ;
  476.         if (is_numeric($value)
  477.             && MDB2::isError($this->query("DELETE FROM $sequence_name WHERE ".$this->options['seqname_col_name']." < $value"))
  478.         {
  479.             $this->warnings['nextID: could not delete previous sequence table values from '.$seq_name;
  480.         }
  481.         return $value;
  482.     }
  483.  
  484.     // }}}
  485.     // {{{ currID()
  486.  
  487.     /**
  488.      * returns the current id of a sequence
  489.      *
  490.      * @param string  $seq_name name of the sequence
  491.      * @return mixed MDB2 Error Object or id
  492.      * @access public
  493.      */
  494.     function currID($seq_name)
  495.     {
  496.         $sequence_name $this->getSequenceName($seq_name);
  497.         return $this->queryOne("SELECT MAX(".$this->options['seqname_col_name'].") FROM $sequence_name"'integer');
  498.     }
  499.  
  500. }
  501.  
  502. class MDB2_Result_mysql extends MDB2_Result_Common
  503. {
  504.     // }}}
  505.     // {{{ constructor
  506.  
  507.     /**
  508.      * Constructor
  509.      */
  510.     function MDB2_Result_mysql(&$mdb&$result)
  511.     {
  512.         parent::MDB2_Result_Common($mdb$result);
  513.     }
  514.  
  515.     // }}}
  516.     // {{{ fetch()
  517.  
  518.     /**
  519.     * fetch value from a result set
  520.     *
  521.     * @param int    $rownum    number of the row where the data can be found
  522.     * @param int    $colnum    field number where the data can be found
  523.     * @return mixed string on success, a MDB2 error on failure
  524.     * @access public
  525.     */
  526.     function fetch($rownum = 0$colnum = 0)
  527.     {
  528.         $value @fbsql_result($this->result$rownum$colnum);
  529.         if (!$value{
  530.             if (is_null($this->result)) {
  531.                 return $this->mdb->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  532.                     'fetch: resultset has already been freed');
  533.             }
  534.         }
  535.         if (isset($this->types[$colnum])) {
  536.             $value $this->mdb->datatype->convertResult($value$this->types[$colnum]);
  537.         }
  538.         if ($this->mdb->options['portability'MDB2_PORTABILITY_RTRIM{
  539.             $value rtrim($value);
  540.         }
  541.         if ($value === ''
  542.             && $this->mdb->options['portability'MDB2_PORTABILITY_EMPTY_TO_NULL
  543.         {
  544.             $value = null;
  545.         }
  546.         return $value;
  547.     }
  548.  
  549.     // }}}
  550.     // {{{ fetchRow()
  551.  
  552.     /**
  553.      * Fetch a row and insert the data into an existing array.
  554.      *
  555.      * @param int       $fetchmode  how the array data should be indexed
  556.      * @return int data array on success, a MDB2 error on failure
  557.      * @access public
  558.      */
  559.     function fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT)
  560.     {
  561.         if ($fetchmode == MDB2_FETCHMODE_DEFAULT{
  562.             $fetchmode $this->mdb->fetchmode;
  563.         }
  564.         if ($fetchmode MDB2_FETCHMODE_ASSOC{
  565.             $row @fbsql_fetch_assoc($this->result);
  566.             if ($this->mdb->options['portability'MDB2_PORTABILITY_LOWERCASE
  567.                 && is_array($row)
  568.             {
  569.                 $row array_change_key_case($rowCASE_LOWER);
  570.             }
  571.         else {
  572.            $row @fbsql_fetch_row($this->result);
  573.         }
  574.         if (!$row{
  575.             if (is_null($this->result)) {
  576.                 return $this->mdb->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  577.                     'fetchRow: resultset has already been freed');
  578.             }
  579.             return null;
  580.         }
  581.         if (isset($this->types)) {
  582.             $row $this->mdb->datatype->convertResultRow($this->types$row);
  583.         }
  584.         if ($this->mdb->options['portability'MDB2_PORTABILITY_EMPTY_TO_NULL{
  585.             $this->mdb->_convertEmptyArrayValuesToNull($row);
  586.         }
  587.         ++$this->rownum;
  588.         return $row;
  589.     }
  590.  
  591.     // }}}
  592.     // {{{ getColumnNames()
  593.  
  594.     /**
  595.      * Retrieve the names of columns returned by the DBMS in a query result.
  596.      *
  597.      * @return mixed                an associative array variable
  598.      *                               that will hold the names of columns. The
  599.      *                               indexes of the array are the column names
  600.      *                               mapped to lower case and the values are the
  601.      *                               respective numbers of the columns starting
  602.      *                               from 0. Some DBMS may not return any
  603.      *                               columns when the result set does not
  604.      *                               contain any rows.
  605.      *
  606.      *                               a MDB2 error on failure
  607.      * @access public
  608.      */
  609.     function getColumnNames()
  610.     {
  611.         $columns = array();
  612.         $numcols $this->numCols();
  613.         if (MDB2::isError($numcols)) {
  614.             return $numcols;
  615.         }
  616.         for ($column = 0; $column $numcols$column++{
  617.             $column_name @fbsql_field_name($this->result$column);
  618.             $columns[$column_name$column;
  619.         }
  620.         if ($this->mdb->options['portability'MDB2_PORTABILITY_LOWERCASE{
  621.             $columns array_change_key_case($columnsCASE_LOWER);
  622.         }
  623.         return $columns;
  624.     }
  625.  
  626.     // }}}
  627.     // {{{ numCols()
  628.  
  629.     /**
  630.      * Count the number of columns returned by the DBMS in a query result.
  631.      *
  632.      * @access public
  633.      * @return mixed integer value with the number of columns, a MDB2 error
  634.      *                        on failure
  635.      */
  636.     function numCols()
  637.     {
  638.         $cols @fbsql_num_fields($this->result);
  639.         if (is_null($cols)) {
  640.             if (is_null($this->result)) {
  641.                 return $this->mdb->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  642.                     'numCols: resultset has already been freed');
  643.             }
  644.             return $this->mdb->raiseError();
  645.         }
  646.         return $cols;
  647.     }
  648.  
  649.     // }}}
  650.     // {{{ nextResult()
  651.  
  652.     /**
  653.      * Move the internal result pointer to the next available result
  654.      * Currently not supported
  655.      *
  656.      * @return true if a result is available otherwise return false
  657.      * @access public
  658.      */
  659.     function nextResult()
  660.     {
  661.         if (is_null($this->result)) {
  662.             return $this->mdb->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  663.                 'nextResult: resultset has already been freed');
  664.         }
  665.         return @fbsql_next_result($this->result);
  666.     }
  667.  
  668.     // }}}
  669.     // {{{ free()
  670.  
  671.     /**
  672.      * Free the internal resources associated with result.
  673.      *
  674.      * @return boolean true on success, false if result is invalid
  675.      * @access public
  676.      */
  677.     function free()
  678.     {
  679.         $free @fbsql_free_result($this->result);
  680.         if (!$free{
  681.             if (is_null($this->result)) {
  682.                 return MDB2_OK;
  683.             }
  684.             return $this->mdb->raiseError();
  685.         }
  686.         $this->result = null;
  687.         return MDB2_OK;
  688.     }
  689. }
  690.  
  691. class MDB2_BufferedResult_mysql extends MDB2_Result_mysql
  692. {
  693.     // }}}
  694.     // {{{ constructor
  695.  
  696.     /**
  697.      * Constructor
  698.      */
  699.     function MDB2_BufferedResult_mysql(&$mdb&$result)
  700.     {
  701.         parent::MDB2_Result_mysql($mdb$result);
  702.     }
  703.  
  704.     // }}}
  705.     // {{{ seek()
  706.  
  707.     /**
  708.     * seek to a specific row in a result set
  709.     *
  710.     * @param int    $rownum    number of the row where the data can be found
  711.     * @return mixed MDB2_OK on success, a MDB2 error on failure
  712.     * @access public
  713.     */
  714.     function seek($rownum = 0)
  715.     {
  716.         if (!@fbsql_data_seek($this->result$rownum)) {
  717.             if (is_null($this->result)) {
  718.                 return $this->mdb->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  719.                     'seek: resultset has already been freed');
  720.             }
  721.             return $this->mdb->raiseError(MDB2_ERROR_INVALIDnullnull,
  722.                 'seek: tried to seek to an invalid row number ('.$rownum.')');
  723.         }
  724.         $this->rownum $rownum - 1;
  725.         return MDB2_OK;
  726.     }
  727.  
  728.     // }}}
  729.     // {{{ valid()
  730.  
  731.     /**
  732.     * check if the end of the result set has been reached
  733.     *
  734.     * @return mixed true or false on sucess, a MDB2 error on failure
  735.     * @access public
  736.     */
  737.     function valid()
  738.     {
  739.         $numrows $this->numRows();
  740.         if (MDB2::isError($numrows)) {
  741.             return $numrows;
  742.         }
  743.         return $this->rownum ($numrows - 1);
  744.     }
  745.  
  746.     // }}}
  747.     // {{{ numRows()
  748.  
  749.     /**
  750.     * returns the number of rows in a result object
  751.     *
  752.     * @return mixed MDB2 Error Object or the number of rows
  753.     * @access public
  754.     */
  755.     function numRows()
  756.     {
  757.         $rows @fbsql_num_rows($this->result);
  758.         if (is_null($rows)) {
  759.             if (is_null($this->result)) {
  760.                 return $this->mdb->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  761.                     'numRows: resultset has already been freed');
  762.             }
  763.             return $this->raiseError();
  764.         }
  765.         return $rows;
  766.     }
  767. }
  768.  
  769. ?>

Documentation generated on Mon, 11 Mar 2019 10:15:46 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.