oci8_result.php

Go to the documentation of this file.
00001 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2006, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * oci8 Result Class
00020  *
00021  * This class extends the parent result class: CI_DB_result
00022  *
00023  * @category    Database
00024  * @author              ExpressionEngine Dev Team
00025  * @link                http://codeigniter.com/user_guide/database/
00026  */
00027 class CI_DB_oci8_result extends CI_DB_result {
00028 
00029         var $stmt_id;
00030         var $curs_id;
00031         var $limit_used;
00032 
00033         /**
00034          * Number of rows in the result set.
00035          *
00036          * Oracle doesn't have a graceful way to retun the number of rows
00037          * so we have to use what amounts to a hack.
00038          * 
00039          *
00040          * @access  public
00041          * @return  integer
00042          */
00043         function num_rows()
00044         {
00045         $rowcount = count($this->result_array());
00046         @ociexecute($this->stmt_id);
00047         if ($this->curs_id)
00048                 {
00049                         @ociexecute($this->curs_id);
00050                 }
00051         return $rowcount;
00052         }
00053 
00054         // --------------------------------------------------------------------
00055 
00056         /**
00057          * Number of fields in the result set
00058          *
00059          * @access  public
00060          * @return  integer
00061          */
00062         function num_fields()
00063         {
00064                 $count = @ocinumcols($this->stmt_id);
00065 
00066                 // if we used a limit we subtract it
00067                 if ($this->limit_used)
00068                 {
00069                         $count = $count - 1;
00070                 }
00071 
00072                 return $count;
00073         }
00074 
00075         // --------------------------------------------------------------------
00076 
00077         /**
00078          * Fetch Field Names
00079          *
00080          * Generates an array of column names
00081          *
00082          * @access      public
00083          * @return      array
00084          */
00085         function list_fields()
00086         {
00087                 $field_names = array();
00088                 $fieldCount = $this->num_fields();
00089                 for ($c = 1; $c <= $fieldCount; $c++)
00090                 {
00091                         $field_names[] = ocicolumnname($this->stmt_id, $c);
00092                 }
00093                 return $field_names;
00094         }
00095 
00096         // Deprecated
00097         function field_names()
00098         {
00099                 return $this->list_fields();
00100         }
00101 
00102         // --------------------------------------------------------------------
00103 
00104         /**
00105          * Field data
00106          *
00107          * Generates an array of objects containing field meta-data
00108          *
00109          * @access  public
00110          * @return  array
00111          */
00112         function field_data()
00113         {
00114                 $retval = array();
00115                 $fieldCount = $this->num_fields();
00116                 for ($c = 1; $c <= $fieldCount; $c++)
00117                 {
00118                         $F                        = new stdClass();
00119                         $F->name                = ocicolumnname($this->stmt_id, $c);
00120                         $F->type                = ocicolumntype($this->stmt_id, $c);
00121                         $F->max_length  = ocicolumnsize($this->stmt_id, $c);
00122 
00123                         $retval[] = $F;
00124                 }
00125 
00126                 return $retval;
00127         }
00128 
00129         // --------------------------------------------------------------------
00130 
00131         /**
00132          * Free the result
00133          *
00134          * @return      null
00135          */             
00136         function free_result()
00137         {
00138                 if (is_resource($this->result_id))
00139                 {
00140                         ocifreestatement($this->result_id);                     
00141                         $this->result_id = FALSE;
00142                 }
00143         }
00144 
00145         // --------------------------------------------------------------------
00146 
00147         /**
00148          * Result - associative array
00149          *
00150          * Returns the result set as an array
00151          *
00152          * @access  private
00153          * @return  array
00154          */
00155         function _fetch_assoc(&$row)
00156         {
00157                 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
00158         
00159                 return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);   
00160         }
00161 
00162         // --------------------------------------------------------------------
00163 
00164         /**
00165          * Result - object
00166          *
00167          * Returns the result set as an object
00168          *
00169          * @access  private
00170          * @return  object
00171          */
00172         function _fetch_object()
00173         {       
00174                 $result = array();
00175 
00176                 // If PHP 5 is being used we can fetch an result object
00177                 if (function_exists('oci_fetch_object'))
00178                 {
00179                         $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
00180                         
00181                         return @oci_fetch_object($id);
00182                 }
00183                 
00184                 // If PHP 4 is being used we have to build our own result
00185                 foreach ($this->result_array() as $key => $val)
00186                 {
00187                         $obj = new stdClass();
00188                         if (is_array($val))
00189                         {
00190                                 foreach ($val as $k => $v)
00191                                 {
00192                                         $obj->$k = $v;
00193                                 }
00194                         }
00195                         else
00196                         {
00197                                 $obj->$key = $val;
00198                         }
00199                         
00200                         $result[] = $obj;
00201                 }
00202 
00203                 return $result;
00204         }
00205 
00206         // --------------------------------------------------------------------
00207 
00208         /**
00209          * Query result.  "array" version.
00210          *
00211          * @access  public
00212          * @return  array
00213          */
00214         function result_array()
00215         {
00216                 if (count($this->result_array) > 0)
00217                 {
00218                         return $this->result_array;
00219                 }
00220 
00221                 // oracle's fetch functions do not return arrays.
00222                 // The information is returned in reference parameters
00223                 $row = NULL;
00224                 while ($this->_fetch_assoc($row))
00225                 {
00226                         $this->result_array[] = $row;
00227                 }
00228 
00229                 return $this->result_array;
00230         }
00231 
00232         // --------------------------------------------------------------------
00233 
00234         /**
00235          * Data Seek
00236          *
00237          * Moves the internal pointer to the desired offset.  We call
00238          * this internally before fetching results to make sure the
00239          * result set starts at zero
00240          *
00241          * @access      private
00242          * @return      array
00243          */
00244         function _data_seek($n = 0)
00245         {
00246                 return FALSE; // Not needed
00247         }
00248 
00249 }
00250 
00251 
00252 /* End of file oci8_result.php */
00253 /* Location: ./system/database/drivers/oci8/oci8_result.php */