home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / MDB2 / Driver / fbsql.php next >
Encoding:
PHP Script  |  2008-07-02  |  24.5 KB  |  741 lines

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