blob: 20ab925fd3c9b8f61cf77014fc87bbf58f446560 [file] [log] [blame]
Derek Jones0b59f272008-05-13 04:22:33 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allardd2df9bc2007-04-15 17:41:17 +00002/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
Derek Allard3d879d52008-01-18 19:41:32 +00007 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allard3d879d52008-01-18 19:41:32 +000012 * @since Version 1.0
Derek Allardd2df9bc2007-04-15 17:41:17 +000013 * @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
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/database/
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
27class 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 {
Derek Allard993925b2008-08-21 12:43:31 +000045 $rowcount = count($this->result_array());
46 @ociexecute($this->stmt_id);
47
48 if ($this->curs_id)
Derek Allardd2df9bc2007-04-15 17:41:17 +000049 {
50 @ociexecute($this->curs_id);
51 }
Derek Allard993925b2008-08-21 12:43:31 +000052
53 return $rowcount;
Derek Allardd2df9bc2007-04-15 17:41:17 +000054 }
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 // Deprecated
99 function field_names()
100 {
101 return $this->list_fields();
102 }
103
104 // --------------------------------------------------------------------
105
106 /**
107 * Field data
108 *
109 * Generates an array of objects containing field meta-data
110 *
111 * @access public
112 * @return array
113 */
114 function field_data()
115 {
116 $retval = array();
117 $fieldCount = $this->num_fields();
118 for ($c = 1; $c <= $fieldCount; $c++)
119 {
120 $F = new stdClass();
121 $F->name = ocicolumnname($this->stmt_id, $c);
122 $F->type = ocicolumntype($this->stmt_id, $c);
123 $F->max_length = ocicolumnsize($this->stmt_id, $c);
124
125 $retval[] = $F;
126 }
127
128 return $retval;
129 }
130
131 // --------------------------------------------------------------------
132
133 /**
134 * Free the result
135 *
136 * @return null
137 */
138 function free_result()
139 {
140 if (is_resource($this->result_id))
141 {
142 ocifreestatement($this->result_id);
143 $this->result_id = FALSE;
144 }
145 }
146
147 // --------------------------------------------------------------------
148
149 /**
150 * Result - associative array
151 *
152 * Returns the result set as an array
153 *
154 * @access private
155 * @return array
156 */
157 function _fetch_assoc(&$row)
158 {
159 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
160
161 return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
162 }
163
164 // --------------------------------------------------------------------
165
166 /**
167 * Result - object
168 *
169 * Returns the result set as an object
170 *
171 * @access private
172 * @return object
173 */
174 function _fetch_object()
175 {
176 $result = array();
177
178 // If PHP 5 is being used we can fetch an result object
179 if (function_exists('oci_fetch_object'))
180 {
181 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
182
183 return @oci_fetch_object($id);
184 }
185
186 // If PHP 4 is being used we have to build our own result
187 foreach ($this->result_array() as $key => $val)
188 {
189 $obj = new stdClass();
190 if (is_array($val))
191 {
192 foreach ($val as $k => $v)
193 {
194 $obj->$k = $v;
195 }
196 }
197 else
198 {
199 $obj->$key = $val;
200 }
201
202 $result[] = $obj;
203 }
204
205 return $result;
206 }
207
208 // --------------------------------------------------------------------
209
210 /**
211 * Query result. "array" version.
212 *
213 * @access public
214 * @return array
215 */
216 function result_array()
217 {
218 if (count($this->result_array) > 0)
219 {
220 return $this->result_array;
221 }
222
223 // oracle's fetch functions do not return arrays.
224 // The information is returned in reference parameters
225 $row = NULL;
226 while ($this->_fetch_assoc($row))
227 {
228 $this->result_array[] = $row;
229 }
230
231 return $this->result_array;
232 }
233
234 // --------------------------------------------------------------------
235
236 /**
237 * Data Seek
238 *
239 * Moves the internal pointer to the desired offset. We call
240 * this internally before fetching results to make sure the
241 * result set starts at zero
242 *
243 * @access private
244 * @return array
245 */
246 function _data_seek($n = 0)
247 {
248 return FALSE; // Not needed
249 }
250
251}
252
Derek Jones0b59f272008-05-13 04:22:33 +0000253
254/* End of file oci8_result.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000255/* Location: ./system/database/drivers/oci8/oci8_result.php */