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 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_ERRORnullnull,
  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_ERRORnullnull,
  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_FOUNDnullnull,
  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.                 nullnull'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($querytrue);
  425.         $this->popExpect();
  426.         if (PEAR::isError($result)) {
  427.             if ($ondemand && $result->getCode(== MDB2_ERROR_NOSUCHTABLE{
  428.                 $this->loadModule('Manager'nulltrue);
  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_name2);
  433.                 if (PEAR::isError($result)) {
  434.                     return $this->raiseError(MDB2_ERRORnullnull,
  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($querytrue);
  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_DATAnullnull,
  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($rowMDB2_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_DATAnullnull,
  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_DATAnullnull,
  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. {
  666.     // }}}
  667.     // {{{ seek()
  668.  
  669.     /**
  670.      * seek to a specific row in a result set
  671.      *
  672.      * @param int    $rownum    number of the row where the data can be found
  673.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  674.      * @access public
  675.      */
  676.     function seek($rownum = 0)
  677.     {
  678.         if ($this->rownum != ($rownum - 1&& !@fbsql_data_seek($this->result$rownum)) {
  679.             if ($this->result === false{
  680.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  681.                     'seek: resultset has already been freed');
  682.             elseif (is_null($this->result)) {
  683.                 return MDB2_OK;
  684.             }
  685.             return $this->db->raiseError(MDB2_ERROR_INVALIDnullnull,
  686.                 'seek: tried to seek to an invalid row number ('.$rownum.')');
  687.         }
  688.         $this->rownum $rownum - 1;
  689.         return MDB2_OK;
  690.     }
  691.  
  692.     // }}}
  693.     // {{{ valid()
  694.  
  695.     /**
  696.      * check if the end of the result set has been reached
  697.      *
  698.      * @return mixed true or false on sucess, a MDB2 error on failure
  699.      * @access public
  700.      */
  701.     function valid()
  702.     {
  703.         $numrows $this->numRows();
  704.         if (PEAR::isError($numrows)) {
  705.             return $numrows;
  706.         }
  707.         return $this->rownum ($numrows - 1);
  708.     }
  709.  
  710.     // }}}
  711.     // {{{ numRows()
  712.  
  713.     /**
  714.      * returns the number of rows in a result object
  715.      *
  716.      * @return mixed MDB2 Error Object or the number of rows
  717.      * @access public
  718.      */
  719.     function numRows()
  720.     {
  721.         $rows @fbsql_num_rows($this->result);
  722.         if (is_null($rows)) {
  723.             if ($this->result === false{
  724.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  725.                     'numRows: resultset has already been freed');
  726.             elseif (is_null($this->result)) {
  727.                 return 0;
  728.             }
  729.             return $this->db->raiseError();
  730.         }
  731.         return $rows;
  732.     }
  733. }
  734.  
  735. class MDB2_Statement_fbsql extends MDB2_Statement_Common
  736. {
  737.  
  738. }
  739.  
  740. ?>

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