Setting tag www-register-wizard-4.3-5
[www-register-wizard.git] / database / drivers / oci8 / oci8_result.php
1 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2 /**
3  * CodeIgniter
4  *
5  * An open source application development framework for PHP 4.3.2 or newer
6  *
7  * @package             CodeIgniter
8  * @author              ExpressionEngine Dev Team
9  * @copyright   Copyright (c) 2008 - 2009, EllisLab, Inc.
10  * @license             http://codeigniter.com/user_guide/license.html
11  * @link                http://codeigniter.com
12  * @since               Version 1.0
13  * @filesource
14  */
15
16 // ------------------------------------------------------------------------
17
18 /**
19  * oci8 Result Class
20  *
21  * This class extends the parent result class: CI_DB_result
22  *
23  * @category    Database
24  * @author              ExpressionEngine Dev Team
25  * @link                http://codeigniter.com/user_guide/database/
26  */
27 class CI_DB_oci8_result extends CI_DB_result {
28
29         var $stmt_id;
30         var $curs_id;
31         var $limit_used;
32
33         /**
34          * Number of rows in the result set.
35          *
36          * Oracle doesn't have a graceful way to retun the number of rows
37          * so we have to use what amounts to a hack.
38          * 
39          *
40          * @access  public
41          * @return  integer
42          */
43         function num_rows()
44         {
45                 $rowcount = count($this->result_array());
46                 @ociexecute($this->stmt_id);
47
48                 if ($this->curs_id)
49                 {
50                         @ociexecute($this->curs_id);
51                 }
52
53                 return $rowcount;
54         }
55
56         // --------------------------------------------------------------------
57
58         /**
59          * Number of fields in the result set
60          *
61          * @access  public
62          * @return  integer
63          */
64         function num_fields()
65         {
66                 $count = @ocinumcols($this->stmt_id);
67
68                 // if we used a limit we subtract it
69                 if ($this->limit_used)
70                 {
71                         $count = $count - 1;
72                 }
73
74                 return $count;
75         }
76
77         // --------------------------------------------------------------------
78
79         /**
80          * Fetch Field Names
81          *
82          * Generates an array of column names
83          *
84          * @access      public
85          * @return      array
86          */
87         function list_fields()
88         {
89                 $field_names = array();
90                 $fieldCount = $this->num_fields();
91                 for ($c = 1; $c <= $fieldCount; $c++)
92                 {
93                         $field_names[] = ocicolumnname($this->stmt_id, $c);
94                 }
95                 return $field_names;
96         }
97
98         // --------------------------------------------------------------------
99
100         /**
101          * Field data
102          *
103          * Generates an array of objects containing field meta-data
104          *
105          * @access  public
106          * @return  array
107          */
108         function field_data()
109         {
110                 $retval = array();
111                 $fieldCount = $this->num_fields();
112                 for ($c = 1; $c <= $fieldCount; $c++)
113                 {
114                         $F                        = new stdClass();
115                         $F->name                = ocicolumnname($this->stmt_id, $c);
116                         $F->type                = ocicolumntype($this->stmt_id, $c);
117                         $F->max_length  = ocicolumnsize($this->stmt_id, $c);
118
119                         $retval[] = $F;
120                 }
121
122                 return $retval;
123         }
124
125         // --------------------------------------------------------------------
126
127         /**
128          * Free the result
129          *
130          * @return      null
131          */             
132         function free_result()
133         {
134                 if (is_resource($this->result_id))
135                 {
136                         ocifreestatement($this->result_id);                     
137                         $this->result_id = FALSE;
138                 }
139         }
140
141         // --------------------------------------------------------------------
142
143         /**
144          * Result - associative array
145          *
146          * Returns the result set as an array
147          *
148          * @access  private
149          * @return  array
150          */
151         function _fetch_assoc(&$row)
152         {
153                 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
154         
155                 return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);   
156         }
157
158         // --------------------------------------------------------------------
159
160         /**
161          * Result - object
162          *
163          * Returns the result set as an object
164          *
165          * @access  private
166          * @return  object
167          */
168         function _fetch_object()
169         {       
170                 $result = array();
171
172                 // If PHP 5 is being used we can fetch an result object
173                 if (function_exists('oci_fetch_object'))
174                 {
175                         $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
176                         
177                         return @oci_fetch_object($id);
178                 }
179                 
180                 // If PHP 4 is being used we have to build our own result
181                 foreach ($this->result_array() as $key => $val)
182                 {
183                         $obj = new stdClass();
184                         if (is_array($val))
185                         {
186                                 foreach ($val as $k => $v)
187                                 {
188                                         $obj->$k = $v;
189                                 }
190                         }
191                         else
192                         {
193                                 $obj->$key = $val;
194                         }
195                         
196                         $result[] = $obj;
197                 }
198
199                 return $result;
200         }
201
202         // --------------------------------------------------------------------
203
204         /**
205          * Query result.  "array" version.
206          *
207          * @access  public
208          * @return  array
209          */
210         function result_array()
211         {
212                 if (count($this->result_array) > 0)
213                 {
214                         return $this->result_array;
215                 }
216
217                 // oracle's fetch functions do not return arrays.
218                 // The information is returned in reference parameters
219                 $row = NULL;
220                 while ($this->_fetch_assoc($row))
221                 {
222                         $this->result_array[] = $row;
223                 }
224
225                 return $this->result_array;
226         }
227
228         // --------------------------------------------------------------------
229
230         /**
231          * Data Seek
232          *
233          * Moves the internal pointer to the desired offset.  We call
234          * this internally before fetching results to make sure the
235          * result set starts at zero
236          *
237          * @access      private
238          * @return      array
239          */
240         function _data_seek($n = 0)
241         {
242                 return FALSE; // Not needed
243         }
244
245 }
246
247
248 /* End of file oci8_result.php */
249 /* Location: ./system/database/drivers/oci8/oci8_result.php */