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) 2008, 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 
00048                 if ($this->curs_id)
00049                 {
00050                         @ociexecute($this->curs_id);
00051                 }
00052 
00053                 return $rowcount;
00054         }
00055 
00056         // --------------------------------------------------------------------
00057 
00058         /**
00059          * Number of fields in the result set
00060          *
00061          * @access  public
00062          * @return  integer
00063          */
00064         function num_fields()
00065         {
00066                 $count = @ocinumcols($this->stmt_id);
00067 
00068                 // if we used a limit we subtract it
00069                 if ($this->limit_used)
00070                 {
00071                         $count = $count - 1;
00072                 }
00073 
00074                 return $count;
00075         }
00076 
00077         // --------------------------------------------------------------------
00078 
00079         /**
00080          * Fetch Field Names
00081          *
00082          * Generates an array of column names
00083          *
00084          * @access      public
00085          * @return      array
00086          */
00087         function list_fields()
00088         {
00089                 $field_names = array();
00090                 $fieldCount = $this->num_fields();
00091                 for ($c = 1; $c <= $fieldCount; $c++)
00092                 {
00093                         $field_names[] = ocicolumnname($this->stmt_id, $c);
00094                 }
00095                 return $field_names;
00096         }
00097 
00098         // --------------------------------------------------------------------
00099 
00100         /**
00101          * Field data
00102          *
00103          * Generates an array of objects containing field meta-data
00104          *
00105          * @access  public
00106          * @return  array
00107          */
00108         function field_data()
00109         {
00110                 $retval = array();
00111                 $fieldCount = $this->num_fields();
00112                 for ($c = 1; $c <= $fieldCount; $c++)
00113                 {
00114                         $F                        = new stdClass();
00115                         $F->name                = ocicolumnname($this->stmt_id, $c);
00116                         $F->type                = ocicolumntype($this->stmt_id, $c);
00117                         $F->max_length  = ocicolumnsize($this->stmt_id, $c);
00118 
00119                         $retval[] = $F;
00120                 }
00121 
00122                 return $retval;
00123         }
00124 
00125         // --------------------------------------------------------------------
00126 
00127         /**
00128          * Free the result
00129          *
00130          * @return      null
00131          */             
00132         function free_result()
00133         {
00134                 if (is_resource($this->result_id))
00135                 {
00136                         ocifreestatement($this->result_id);                     
00137                         $this->result_id = FALSE;
00138                 }
00139         }
00140 
00141         // --------------------------------------------------------------------
00142 
00143         /**
00144          * Result - associative array
00145          *
00146          * Returns the result set as an array
00147          *
00148          * @access  private
00149          * @return  array
00150          */
00151         function _fetch_assoc(&$row)
00152         {
00153                 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
00154         
00155                 return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);   
00156         }
00157 
00158         // --------------------------------------------------------------------
00159 
00160         /**
00161          * Result - object
00162          *
00163          * Returns the result set as an object
00164          *
00165          * @access  private
00166          * @return  object
00167          */
00168         function _fetch_object()
00169         {       
00170                 $result = array();
00171 
00172                 // If PHP 5 is being used we can fetch an result object
00173                 if (function_exists('oci_fetch_object'))
00174                 {
00175                         $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
00176                         
00177                         return @oci_fetch_object($id);
00178                 }
00179                 
00180                 // If PHP 4 is being used we have to build our own result
00181                 foreach ($this->result_array() as $key => $val)
00182                 {
00183                         $obj = new stdClass();
00184                         if (is_array($val))
00185                         {
00186                                 foreach ($val as $k => $v)
00187                                 {
00188                                         $obj->$k = $v;
00189                                 }
00190                         }
00191                         else
00192                         {
00193                                 $obj->$key = $val;
00194                         }
00195                         
00196                         $result[] = $obj;
00197                 }
00198 
00199                 return $result;
00200         }
00201 
00202         // --------------------------------------------------------------------
00203 
00204         /**
00205          * Query result.  "array" version.
00206          *
00207          * @access  public
00208          * @return  array
00209          */
00210         function result_array()
00211         {
00212                 if (count($this->result_array) > 0)
00213                 {
00214                         return $this->result_array;
00215                 }
00216 
00217                 // oracle's fetch functions do not return arrays.
00218                 // The information is returned in reference parameters
00219                 $row = NULL;
00220                 while ($this->_fetch_assoc($row))
00221                 {
00222                         $this->result_array[] = $row;
00223                 }
00224 
00225                 return $this->result_array;
00226         }
00227 
00228         // --------------------------------------------------------------------
00229 
00230         /**
00231          * Data Seek
00232          *
00233          * Moves the internal pointer to the desired offset.  We call
00234          * this internally before fetching results to make sure the
00235          * result set starts at zero
00236          *
00237          * @access      private
00238          * @return      array
00239          */
00240         function _data_seek($n = 0)
00241         {
00242                 return FALSE; // Not needed
00243         }
00244 
00245 }
00246 
00247 
00248 /* End of file oci8_result.php */
00249 /* Location: ./system/database/drivers/oci8/oci8_result.php */