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

Source for file querysim.php

Documentation is available at querysim.php

  1. <?php
  2. // vim: set et ts=4 sw=4 fdm=marker:
  3. // +----------------------------------------------------------------------+
  4. // | PHP versions 4 and 5                                                 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox,                 |
  7. // | Stig. S. Bakken, Lukas Smith                                         |
  8. // | All rights reserved.                                                 |
  9. // +----------------------------------------------------------------------+
  10. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
  11. // | API as well as database abstraction for PHP applications.            |
  12. // | This LICENSE is in the BSD license style.                            |
  13. // |                                                                      |
  14. // | Redistribution and use in source and binary forms, with or without   |
  15. // | modification, are permitted provided that the following conditions   |
  16. // | are met:                                                             |
  17. // |                                                                      |
  18. // | Redistributions of source code must retain the above copyright       |
  19. // | notice, this list of conditions and the following disclaimer.        |
  20. // |                                                                      |
  21. // | Redistributions in binary form must reproduce the above copyright    |
  22. // | notice, this list of conditions and the following disclaimer in the  |
  23. // | documentation and/or other materials provided with the distribution. |
  24. // |                                                                      |
  25. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  26. // | Lukas Smith nor the names of his contributors may be used to endorse |
  27. // | or promote products derived from this software without specific prior|
  28. // | written permission.                                                  |
  29. // |                                                                      |
  30. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  31. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  32. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  33. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  34. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  35. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  36. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  37. // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  38. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  39. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  40. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  41. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  42. // +----------------------------------------------------------------------+
  43. // | Original QuerySim Concept & ColdFusion Author: Hal Helms             |
  44. // | <hal.helms@teamallaire.com>                                          |
  45. // | Bert Dawson <bdawson@redbanner.com>                                  |
  46. // +----------------------------------------------------------------------+
  47. // | Original PHP Author: Alan Richmond <arichmond@bigfoot.com>           |
  48. // | David Huyck <b@bombusbee.com>                                        |
  49. // +----------------------------------------------------------------------+
  50. // | Special note concerning code documentation:                          |
  51. // | QuerySim was originally created for use during development of        |
  52. // | applications built using the Fusebox framework. (www.fusebox.org)    |
  53. // | Fusebox uses an XML style of documentation called Fusedoc. (Which    |
  54. // | is admittedly not well suited to documenting classes and functions.  |
  55. // | This short-coming is being addressed by the Fusebox community.) PEAR |
  56. // | uses a Javadoc style of documentation called PHPDoc. (www.phpdoc.de) |
  57. // | Since this class extension spans two groups of users, it is asked    |
  58. // | that the members of each respect the documentation standard of the   |
  59. // | other.  So it is a further requirement that both documentation       |
  60. // | standards be included and maintained. If assistance is required      |
  61. // | please contact Alan Richmond.                                        |
  62. // +----------------------------------------------------------------------+
  63. //
  64. // $Id: querysim.php,v 1.67 2006/06/08 20:35:40 lsmith Exp $
  65. //
  66.  
  67. /*
  68. <fusedoc fuse="querysim.php" language="PHP">
  69.     <responsibilities>
  70.         I take information and turn it into a recordset that can be accessed
  71.         through the PEAR MDB2 API.  Based on Hal Helms' QuerySim.cfm ColdFusion
  72.         custom tag available at halhelms.com.
  73.     </responsibilities>
  74.     <properties>
  75.         <property name="API" value="PEAR MDB2" />
  76.         <property name="version" value="0.2.1" />
  77.         <property name="status" value="beta" />
  78.         <history author="Hal Helms" email="hal.helms@teamallaire.com" type="Create" />
  79.         <history author="Bert Dawson" email="bdawson@redbanner.com" type="Update">
  80.             Extensive revision that is backwardly compatible but eliminates the
  81.             need for a separate .sim file.
  82.         </history>
  83.         <history author="Alan Richmond" email="arichmond@bigfoot.com" type="Create" date="10-July-2002">
  84.             Rewrote in PHP as an extention to the PEAR DB API.
  85.             Functions supported:
  86.                 connect, disconnect, query, fetchRow, freeResult,
  87.                 numCols, numRows, getSpecialQuery
  88.             David Huyck (bombusbee.com) added ability to escape special
  89.                 characters (i.e., delimiters) using a '\'.
  90.             Extended PEAR DB options[] for adding incoming parameters.  Added
  91.                 options:  columnDelim, dataDelim, eolDelim
  92.         </history>
  93.         <history author="David Huyck" email="b@bombusbee.com" type="Update" date="19-July-2002">
  94.             Added the ability to set the QuerySim options at runtime.
  95.             Default options are:
  96.                 'columnDelim' => ',',            // Commas split the column names
  97.                 'dataDelim'   => '|',            // Pipes split the data fields
  98.                 'eolDelim'    => chr(13).chr(10) // Carriage returns split the
  99.                                                  // lines of data
  100.             Affected functions are:
  101.                 DB_querysim():          set the default options when the
  102.                                         constructor method is called
  103.                 _parseQuerySim($query): altered the parsing of lines, column
  104.                                         names, and data fields
  105.                 _empty2null:            altered the way this function is called
  106.                                         to simplify calling it
  107.         </history>
  108.         <history author="Alan Richmond" email="arichmond@bigfoot.com" type="Update" date="24-July-2002">
  109.             Added error catching for malformed QuerySim text.
  110.             Bug fix _empty2null():  altered version was returning unmodified
  111.                                     lineData.
  112.             Cleanup:
  113.                 PEAR compliant formatting, finished PHPDocs and added 'out' to
  114.                 Fusedoc 'io'.
  115.                 Broke up _parseQuerySim() into _buildResult() and _parseOnDelim()
  116.                 to containerize duplicate parse code.
  117.         </history>
  118.         <history author="David Huyck" email="b@bombusbee.com" type="Update" date="25-July-2002">
  119.             Edited the _buildResult() and _parseOnDelim() functions to improve
  120.             reliability of special character escaping.
  121.             Re-introduced a custom setOption() method to throw an error when a
  122.             person tries to set one of the delimiters to '\'.
  123.         </history>
  124.         <history author="Alan Richmond" email="arichmond@bigfoot.com" type="Update" date="27-July-2002">
  125.             Added '/' delimiter param to preg_quote() in _empty2null() and
  126.             _parseOnDelim() so '/' can be used as a delimiter.
  127.             Added error check for columnDelim == eolDelim or dataDelim == eolDelim.
  128.             Renamed some variables for consistancy.
  129.         </history>
  130.         <history author="Alan Richmond" email="arichmond@bigfoot.com" type="Update" date="30-July-2002">
  131.             Removed protected function _empty2null().  Turns out preg_split()
  132.             deals with empty elemants by making them zero length strings, just
  133.             what they ended up being anyway.  This should speed things up a little.
  134.             Affected functions:
  135.                 _parseOnDelim()     perform trim on line here, instead of in
  136.                                     _empty2null().
  137.                 _buildResult()      remove call to _empty2null().
  138.                 _empty2null()       removed function.
  139.         </history>
  140.         <history author="Alan Richmond" email="arichmond@bigfoot.com" type="Update" date="1-Jan-2003">
  141.             Ported to PEAR MDB2.
  142.             Methods supported:
  143.                 connect, query, getColumnNames, numCols, valid, fetch,
  144.                 numRows, free, fetchRow, nextResult, setLimit
  145.                 (inherited).
  146.         </history>
  147.         <history
  148.             Removed array_change_key_case() work around for <4.2.0 in
  149.             getColumnNames(), found it already done in MDB2/Common.php.
  150.         </history>
  151.         <history author="Alan Richmond" email="arichmond@bigfoot.com" type="Update" date="3-Feb-2003">
  152.             Changed default eolDelim to a *nix file eol, since we're trimming
  153.             the result anyway, it makes no difference for Windows.  Now only
  154.             Mac file eols should need to be set (and other kinds of chars).
  155.         </history>
  156.         <note author="Alan Richmond">
  157.             Got WAY too long.  See querysim_readme.txt for instructions and some
  158.             examples.
  159.             io section only documents elements of DB_result that DB_querysim uses,
  160.             adds or changes; see MDB2 and MDB2_Driver_Common for more info.
  161.             io section uses some elements that are not Fusedoc 2.0 compliant:
  162.             object and resource.
  163.         </note>
  164.     </properties>
  165.     <io>
  166.         <in>
  167.             <file path="MDB2/Common.php" action="require_once" />
  168.         </in>
  169.         <out>
  170.             <object name="MDB2_querysim" extends="MDB2_Driver_Common" instantiatedby="MDB2::connect()">
  171.                 <resource type="file" name="connection" oncondition="source is external file" scope="class" />
  172.                 <string name="phptype" default="querysim" />
  173.                 <string name="dbsyntax" default="querysim" />
  174.                 <array name="supported" comments="most of these don't actually do anything, they are enabled to simulate the option being available if checked">
  175.                     <boolean name="sequences" default="true" />
  176.                     <boolean name="indexes" default="true" />
  177.                     <boolean name="affected_rows" default="true" />
  178.                     <boolean name="summary_functions" default="true" />
  179.                     <boolean name="order_by_text" default="true" />
  180.                     <boolean name="current_id" default="true" />
  181.                     <boolean name="limit_querys" default="true" comments="this one is functional" />
  182.                     <boolean name="LOBs" default="true" />
  183.                     <boolean name="replace" default="true" />
  184.                     <boolean name="sub_selects" default="true" />
  185.                     <boolean name="transactions" default="true" />
  186.                 </array>
  187.                 <string name="last_query" comments="last value passed in with query()" />
  188.                 <array name="options" comments="these can be changed at run time">
  189.                     <string name="columnDelim" default="," />
  190.                     <string name="dataDelim" default="|" />
  191.                     <string name="eolDelim" default="chr(13).chr(10)" />
  192.                 </array>
  193.             </object>
  194.             <array name="result" comments="the simulated record set returned by ::query()">
  195.                 <array comments="columns">
  196.                     <string comments="column name" />
  197.                 </array>
  198.                 <array comments="data">
  199.                     <array comments="row">
  200.                         <string comments="data element" />
  201.                     </array>
  202.                 </array>
  203.             </array>
  204.         </out>
  205.     </io>
  206. </fusedoc>
  207. */
  208.  
  209. /**
  210.  * MDB2 QuerySim driver
  211.  *
  212.  * @package MDB2
  213.  * @category Database
  214.  * @author  Alan Richmond <arichmond@bigfoot.com>
  215.  */
  216. class MDB2_Driver_querysim extends MDB2_Driver_Common
  217. {
  218.     var $escape_quotes = "\\";
  219.  
  220.     var $escape_identifier = '';
  221.  
  222.     // }}}
  223.     // {{{ constructor
  224.  
  225.     /**
  226.      * Constructor
  227.      */
  228.     function __construct()
  229.     {
  230.         parent::__construct();
  231.  
  232.         $this->phptype  'querysim';
  233.         $this->dbsyntax 'querysim';
  234.  
  235.         // Most of these are dummies to simulate availability if checked
  236.         $this->supported['sequences''emulated';
  237.         $this->supported['indexes'= true;
  238.         $this->supported['affected_rows'= false;
  239.         $this->supported['summary_functions'= false;
  240.         $this->supported['order_by_text'= false;
  241.         $this->supported['current_id''emulated';
  242.         $this->supported['limit_queries'= true;// this one is real
  243.         $this->supported['LOBs'= true;
  244.         $this->supported['replace''emulated';
  245.         $this->supported['sub_selects''emulated';
  246.         $this->supported['transactions'= false;
  247.         $this->supported['auto_increment'= false;
  248.         $this->supported['primary_key'= false;
  249.         $this->supported['result_introspection'= false; // not implemented
  250.         $this->supported['prepared_statements''emulated';
  251.  
  252.         $this->options['columnDelim'',';
  253.         $this->options['dataDelim''|';
  254.         $this->options['eolDelim'"\n";
  255.     }
  256.  
  257.     // }}}
  258.     // {{{ connect()
  259.  
  260.     /**
  261.      * Open a file or simulate a successful database connect
  262.      *
  263.      * @access public
  264.      *
  265.      * @return mixed MDB2_OK string on success, a MDB2 error object on failure
  266.      */
  267.     function connect()
  268.     {
  269.         if (is_resource($this->connection)) {
  270.             if ($this->connected_database_name == $this->database_name
  271.                 && ($this->opened_persistent == $this->options['persistent'])
  272.             {
  273.                 return MDB2_OK;
  274.             }
  275.             if ($this->connected_database_name{
  276.                 $this->_close($this->connection);
  277.             }
  278.             $this->disconnect();
  279.         }
  280.  
  281.         $connection = 1;// sim connect
  282.         // if external, check file...
  283.         if ($this->database_name{
  284.             $file $this->database_name;
  285.             if (!file_exists($file)) {
  286.                 return $this->raiseError(MDB2_ERROR_NOT_FOUNDnullnull'file not found');
  287.             }
  288.             if (!is_file($file)) {
  289.                 return $this->raiseError(MDB2_ERROR_INVALIDnullnull'not a file');
  290.             }
  291.             if (!is_readable($file)) {
  292.                 return $this->raiseError(MDB2_ERROR_ACCESS_VIOLATIONnullnull,
  293.                     'could not open file - check permissions');
  294.             }
  295.             // ...and open if persistent
  296.             if ($this->options['persistent']{
  297.                 $connection @fopen($file'r');
  298.             }
  299.         }
  300.  
  301.         if (!empty($this->dsn['charset'])) {
  302.             $result $this->setCharset($this->dsn['charset']$connection);
  303.             if (PEAR::isError($result)) {
  304.                 return $result;
  305.             }
  306.         }
  307.  
  308.         $this->connection $connection;
  309.         $this->connected_database_name $this->database_name;
  310.         $this->opened_persistent $this->options['persistent'];
  311.         $this->dbsyntax $this->dsn['dbsyntax'$this->dsn['dbsyntax'$this->phptype;
  312.  
  313.         return MDB2_OK;
  314.     }
  315.  
  316.     // }}}
  317.     // {{{ disconnect()
  318.  
  319.     /**
  320.      * Log out and disconnect from the database.
  321.      *
  322.      * @param  boolean $force if the disconnect should be forced even if the
  323.      *                         connection is opened persistently
  324.      * @return mixed true on success, false if not connected and error
  325.      *                 object on error
  326.      * @access public
  327.      */
  328.     function disconnect($force = true)
  329.     {
  330.         if (is_resource($this->connection)) {
  331.             if ($this->opened_persistent{
  332.                 @fclose($this->connection);
  333.             }
  334.         }
  335.         return parent::disconnect($force);
  336.     }
  337.  
  338.     // }}}
  339.     // {{{ _doQuery()
  340.  
  341.     /**
  342.      * Execute a query
  343.      * @param string $query  query
  344.      * @param boolean $is_manip  if the query is a manipulation query
  345.      * @param resource $connection 
  346.      * @param string $database_name 
  347.      * @return result or error object
  348.      * @access protected
  349.      */
  350.     function &_doQuery($query$is_manip = false$connection = null$database_name = null)
  351.     {
  352.         if ($this->database_name{
  353.             $query $this->_readFile();
  354.         }
  355.         $this->last_query $query;
  356.         $result $this->debug($query'query'$is_manip);
  357.         if ($result{
  358.             if (PEAR::isError($result)) {
  359.                 return $result;
  360.             }
  361.             $query $result;
  362.         }
  363.         if ($is_manip{
  364.             $err =$this->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  365.                 '_doQuery: Manipulation statements are not supported');
  366.             return $err;
  367.         }
  368.         if ($this->options['disable_query']{
  369.             return null;
  370.         }
  371.  
  372.         $result $this->_buildResult($query);
  373.         if (PEAR::isError($result)) {
  374.             return $result;
  375.         }
  376.  
  377.         if ($this->next_limit > 0{
  378.             $result[1array_slice($result[1]$this->next_offset$this->next_limit);
  379.         }
  380.         return $result;
  381.     }
  382.  
  383.     // }}}
  384.     // {{{ _modifyQuery()
  385.  
  386.     /**
  387.      * Changes a query string for various DBMS specific reasons
  388.      *
  389.      * @param string $query  query to modify
  390.      * @param boolean $is_manip  if it is a DML query
  391.      * @param integer $limit  limit the number of rows
  392.      * @param integer $offset  start reading from given offset
  393.      * @return string modified query
  394.      * @access protected
  395.      */
  396.     function _modifyQuery($query$is_manip$limit$offset)
  397.     {
  398.         $this->next_limit $limit;
  399.         $this->next_offset $offset;
  400.         return $query;
  401.     }
  402.  
  403.     // }}}
  404.     // {{{ _readFile()
  405.  
  406.     /**
  407.      * Read an external file
  408.      *
  409.      * @param string filepath/filename
  410.      *
  411.      * @access protected
  412.      *
  413.      * @return string the contents of a file
  414.      */
  415.     function _readFile()
  416.     {
  417.         $buffer '';
  418.         if ($this->opened_persistent{
  419.             $connection $this->getConnection();
  420.             if (PEAR::isError($connection)) {
  421.                 return $connection;
  422.             }
  423.             while (!feof($connection)) {
  424.                 $buffer.= fgets($connection1024);
  425.             }
  426.             rewind($connection);
  427.         else {
  428.             $connection @fopen($this->connected_database_name'r');
  429.             while (!feof($connection)) {
  430.                 $buffer.= fgets($connection1024);
  431.             }
  432.             @fclose($connection);
  433.         }
  434.         return $buffer;
  435.     }
  436.  
  437.     // }}}
  438.     // {{{ _buildResult()
  439.  
  440.     /**
  441.      * Convert QuerySim text into an array
  442.      *
  443.      * @param string Text of simulated query
  444.      *
  445.      * @access protected
  446.      *
  447.      * @return multi-dimensional array containing the column names and data
  448.      *                                  from the QuerySim
  449.      */
  450.     function _buildResult($query)
  451.     {
  452.         $eolDelim    $this->options['eolDelim'];
  453.         $columnDelim $this->options['columnDelim'];
  454.         $dataDelim   $this->options['dataDelim'];
  455.  
  456.         $columnNames = array();
  457.         $data        = array();
  458.  
  459.         if ($columnDelim == $eolDelim{
  460.             return $this->raiseError(MDB2_ERROR_INVALIDnullnull,
  461.                 'columnDelim and eolDelim must be different');
  462.         elseif ($dataDelim == $eolDelim){
  463.             return $this->raiseError(MDB2_ERROR_INVALIDnullnull,
  464.                 'dataDelim and eolDelim must be different');
  465.         }
  466.  
  467.         $query trim($query);
  468.         //tokenize escaped slashes
  469.         $query str_replace('\\\\''[$double-slash$]'$query);
  470.  
  471.         if (!strlen($query)) {
  472.             return $this->raiseError(MDB2_ERROR_SYNTAXnullnull,
  473.                 'empty querysim text');
  474.         }
  475.         $lineData $this->_parseOnDelim($query$eolDelim);
  476.         //kill the empty last row created by final eol char if it exists
  477.         if (!strlen(trim($lineData[count($lineData- 1]))) {
  478.             unset($lineData[count($lineData- 1]);
  479.         }
  480.         //populate columnNames array
  481.         $thisLine each($lineData);
  482.         $columnNames $this->_parseOnDelim($thisLine[1]$columnDelim);
  483.         if ((in_array(''$columnNames)) || (in_array('NULL'$columnNames))) {
  484.             return $this->raiseError(MDB2_ERROR_SYNTAXnullnull,
  485.                 'all column names must be defined');
  486.         }
  487.         //replace double-slash tokens with single-slash
  488.         $columnNames str_replace('[$double-slash$]''\\'$columnNames);
  489.         $columnCount count($columnNames);
  490.         $rowNum = 0;
  491.         //loop through data lines
  492.         if (count($lineData> 1{
  493.             while ($thisLine each($lineData)) {
  494.                 $thisData $this->_parseOnDelim($thisLine[1]$dataDelim);
  495.                 $thisDataCount count($thisData);
  496.                 if ($thisDataCount != $columnCount{
  497.                     $fileLineNo $rowNum + 2;
  498.                     return $this->raiseError(MDB2_ERROR_SYNTAXnullnull,
  499.                         "number of data elements ($thisDataCount) in line $fileLineNo not equal to number of defined columns ($columnCount)");
  500.                 }
  501.                 //loop through data elements in data line
  502.                 foreach ($thisData as $thisElement{
  503.                     if (strtoupper($thisElement== 'NULL'){
  504.                         $thisElement '';
  505.                     }
  506.                     //replace double-slash tokens with single-slash
  507.                     $data[$rowNum][str_replace('[$double-slash$]''\\'$thisElement);
  508.                 }//end foreach
  509.                 ++$rowNum;
  510.             }//end while
  511.         }//end if
  512.         return array($columnNames$data);
  513.     }
  514.  
  515.     // }}}
  516.     // {{{ _parseOnDelim()
  517.  
  518.     /**
  519.      * Split QuerySim string into an array on a delimiter
  520.      *
  521.      * @param string $thisLine Text of simulated query
  522.      * @param string $delim    The delimiter to split on
  523.      *
  524.      * @access protected
  525.      *
  526.      * @return array containing parsed string
  527.      */
  528.     function _parseOnDelim($thisLine$delim)
  529.     {
  530.         $delimQuoted preg_quote($delim'/');
  531.         $thisLine trim($thisLine);
  532.  
  533.         $parsed preg_split('/(?<!\\\\)' .$delimQuoted'/'$thisLine);
  534.         //replaces escaped delimiters
  535.         $parsed preg_replace('/\\\\' .$delimQuoted'/'$delim$parsed);
  536.         if ($delim != $this->options['eolDelim']{
  537.             //replaces escape chars
  538.             $parsed preg_replace('/\\\\/'''$parsed);
  539.         }
  540.         return $parsed;
  541.     }
  542.  
  543.     // }}}
  544.     // {{{ exec()
  545.  
  546.     /**
  547.      * Execute a manipulation query to the database and return any the affected rows
  548.      *
  549.      * @param string $query the SQL query
  550.      * @return mixed affected rows on success, a MDB2 error on failure
  551.      * @access public
  552.      */
  553.     function exec($query)
  554.     {
  555.         return $this->raiseError(MDB2_ERROR_UNSUPPORTED);
  556.     }
  557.  
  558.     // }}}
  559.     // {{{ getServerVersion()
  560.  
  561.     /**
  562.      * return version information about the server
  563.      *
  564.      * @param string     $native  determines if the raw version string should be returned
  565.      * @return mixed array/string with version information or MDB2 error object
  566.      * @access public
  567.      */
  568.     function getServerVersion($native = false)
  569.     {
  570.         $server_info '@package_version@';
  571.         // cache server_info
  572.         $this->connected_server_info $server_info;
  573.         if (!$native{
  574.             $tmp explode('.'$server_info3);
  575.             if (!isset($tmp[2]|| !preg_match('/(\d+)(.*)/'$tmp[2]$tmp2)) {
  576.                 $tmp2[0= isset($tmp[2]$tmp[2: null;
  577.                 $tmp2[1= null;
  578.             }
  579.             $server_info = array(
  580.                 'major' => isset($tmp[0]$tmp[0: null,
  581.                 'minor' => isset($tmp[1]$tmp[1: null,
  582.                 'patch' => isset($tmp2[0]$tmp2[0: null,
  583.                 'extra' => isset($tmp2[1]$tmp2[1: null,
  584.                 'native' => $server_info,
  585.             );
  586.         }
  587.         return $server_info;
  588.     }
  589. }
  590.  
  591. /**
  592.  * MDB2 QuerySim result driver
  593.  *
  594.  * @package MDB2
  595.  * @category Database
  596.  * @author  Alan Richmond <arichmond@bigfoot.com>
  597.  */
  598. class MDB2_Result_querysim extends MDB2_Result_Common
  599. {
  600.     // }}}
  601.     // {{{ fetchRow()
  602.  
  603.     /**
  604.      * Fetch a row and insert the data into an existing array.
  605.      *
  606.      * @param int       $fetchmode  how the array data should be indexed
  607.      * @param int    $rownum    number of the row where the data can be found
  608.      * @return int data array on success, a MDB2 error on failure
  609.      * @access public
  610.      */
  611.     function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT$rownum = null)
  612.     {
  613.         if ($this->result === false{
  614.             $err =$this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  615.                 'fetchRow: resultset has already been freed');
  616.             return $err;
  617.         elseif (is_null($this->result)) {
  618.             return null;
  619.         }
  620.         if (!is_null($rownum)) {
  621.             $seek $this->seek($rownum);
  622.             if (PEAR::isError($seek)) {
  623.                 return $seek;
  624.             }
  625.         }
  626.         $target_rownum $this->rownum + 1;
  627.         if ($fetchmode == MDB2_FETCHMODE_DEFAULT{
  628.             $fetchmode $this->db->fetchmode;
  629.         }
  630.         if (!isset($this->result[1][$target_rownum])) {
  631.             $null = null;
  632.             return $null;
  633.         }
  634.         $row $this->result[1][$target_rownum];
  635.         // make row associative
  636.         if ($fetchmode MDB2_FETCHMODE_ASSOC{
  637.             $column_names $this->getColumnNames();
  638.             foreach ($column_names as $name => $i{
  639.                 $column_names[$name$row[$i];
  640.             }
  641.             $row $column_names;
  642.         }
  643.         if (($mode ($this->db->options['portability'MDB2_PORTABILITY_RTRIM)
  644.             + ($this->db->options['portability'MDB2_PORTABILITY_EMPTY_TO_NULL))
  645.         {
  646.             $this->db->_fixResultArrayValues($row$mode);
  647.         }
  648.         if (!empty($this->values)) {
  649.             $this->_assignBindColumns($row);
  650.         }
  651.         if (!empty($this->types)) {
  652.             $row $this->db->datatype->convertResultRow($this->types$row);
  653.         }
  654.         if ($fetchmode === MDB2_FETCHMODE_OBJECT{
  655.             $object_class $this->db->options['fetch_class'];
  656.             if ($object_class == 'stdClass'{
  657.                 $row = (object) $row;
  658.             else {
  659.                 $row &new $object_class($row);
  660.             }
  661.         }
  662.         ++$this->rownum;
  663.         return $row;
  664.     }
  665.  
  666.     // }}}
  667.     // {{{ _getColumnNames()
  668.  
  669.     /**
  670.      * Retrieve the names of columns returned by the DBMS in a query result.
  671.      *
  672.      * @return  mixed   Array variable that holds the names of columns as keys
  673.      *                   or an MDB2 error on failure.
  674.      *                   Some DBMS may not return any columns when the result set
  675.      *                   does not contain any rows.
  676.      * @access private
  677.      */
  678.     function _getColumnNames()
  679.     {
  680.         if ($this->result === false{
  681.             return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  682.                 'getColumnNames: resultset has already been freed');
  683.         elseif (is_null($this->result)) {
  684.             return array();
  685.         }
  686.         $columns array_flip($this->result[0]);
  687.         if ($this->db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  688.             $columns array_change_key_case($columns$this->db->options['field_case']);
  689.         }
  690.         return $columns;
  691.     }
  692.  
  693.     // }}}
  694.     // {{{ numCols()
  695.  
  696.     /**
  697.      * Count the number of columns returned by the DBMS in a query result.
  698.      *
  699.      * @access public
  700.      * @return mixed integer value with the number of columns, a MDB2 error
  701.      *                        on failure
  702.      */
  703.     function numCols()
  704.     {
  705.         if ($this->result === false{
  706.             return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  707.                 'numCols: resultset has already been freed');
  708.         elseif (is_null($this->result)) {
  709.             return count($this->types);
  710.         }
  711.         $cols count($this->result[0]);
  712.         return $cols;
  713.     }
  714. }
  715.  
  716. /**
  717.  * MDB2 QuerySim buffered result driver
  718.  *
  719.  * @package MDB2
  720.  * @category Database
  721.  * @author  Alan Richmond <arichmond@bigfoot.com>
  722.  */
  723. {
  724.     // }}}
  725.     // {{{ seek()
  726.  
  727.     /**
  728.      * Seek to a specific row in a result set
  729.      *
  730.      * @param int    $rownum    number of the row where the data can be found
  731.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  732.      * @access public
  733.      */
  734.     function seek($rownum = 0)
  735.     {
  736.         if ($this->result === false{
  737.             return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  738.                 'seek: resultset has already been freed');
  739.         }
  740.         $this->rownum $rownum - 1;
  741.         return MDB2_OK;
  742.     }
  743.  
  744.     // }}}
  745.     // {{{ valid()
  746.  
  747.     /**
  748.      * Check if the end of the result set has been reached
  749.      *
  750.      * @return mixed true or false on sucess, a MDB2 error on failure
  751.      * @access public
  752.      */
  753.     function valid()
  754.     {
  755.         $numrows $this->numRows();
  756.         if (PEAR::isError($numrows)) {
  757.             return $numrows;
  758.         }
  759.         return $this->rownum ($numrows - 1);
  760.     }
  761.  
  762.     // }}}
  763.     // {{{ numRows()
  764.  
  765.     /**
  766.      * Returns the number of rows in a result object
  767.      *
  768.      * @return mixed MDB2 Error Object or the number of rows
  769.      * @access public
  770.      */
  771.     function numRows()
  772.     {
  773.         if ($this->result === false{
  774.             return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  775.                 'numRows: resultset has already been freed');
  776.         elseif (is_null($this->result)) {
  777.             return 0;
  778.         }
  779.         $rows count($this->result[1]);
  780.         return $rows;
  781.     }
  782. }
  783.  
  784. /**
  785.  * MDB2 QuerySim statement driver
  786.  *
  787.  * @package MDB2
  788.  * @category Database
  789.  * @author  Alan Richmond <arichmond@bigfoot.com>
  790.  */
  791. class MDB2_Statement_querysim extends MDB2_Statement_Common
  792. {
  793.  
  794. }
  795.  
  796. ?>

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