blob: 416c57de0e0b87b70074032f9643aebf12876b7f [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?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 *
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 {
45 $rowcount = count($this->result_array());
46 @ociexecute($this->stmt_id);
47 if ($this->curs_id)
48 {
49 @ociexecute($this->curs_id);
50 }
51 return $rowcount;
52 }
53
54 // --------------------------------------------------------------------
55
56 /**
57 * Number of fields in the result set
58 *
59 * @access public
60 * @return integer
61 */
62 function num_fields()
63 {
64 $count = @ocinumcols($this->stmt_id);
65
66 // if we used a limit we subtract it
67 if ($this->limit_used)
68 {
69 $count = $count - 1;
70 }
71
72 return $count;
73 }
74
75 // --------------------------------------------------------------------
76
77 /**
78 * Fetch Field Names
79 *
80 * Generates an array of column names
81 *
82 * @access public
83 * @return array
84 */
85 function list_fields()
86 {
87 $field_names = array();
88 $fieldCount = $this->num_fields();
89 for ($c = 1; $c <= $fieldCount; $c++)
90 {
91 $field_names[] = ocicolumnname($this->stmt_id, $c);
92 }
93 return $field_names;
94 }
95
96 // Deprecated
97 function field_names()
98 {
99 return $this->list_fields();
100 }
101
102 // --------------------------------------------------------------------
103
104 /**
105 * Field data
106 *
107 * Generates an array of objects containing field meta-data
108 *
109 * @access public
110 * @return array
111 */
112 function field_data()
113 {
114 $retval = array();
115 $fieldCount = $this->num_fields();
116 for ($c = 1; $c <= $fieldCount; $c++)
117 {
118 $F = new stdClass();
119 $F->name = ocicolumnname($this->stmt_id, $c);
120 $F->type = ocicolumntype($this->stmt_id, $c);
121 $F->max_length = ocicolumnsize($this->stmt_id, $c);
122
123 $retval[] = $F;
124 }
125
126 return $retval;
127 }
128
129 // --------------------------------------------------------------------
130
131 /**
132 * Free the result
133 *
134 * @return null
135 */
136 function free_result()
137 {
138 if (is_resource($this->result_id))
139 {
140 ocifreestatement($this->result_id);
141 $this->result_id = FALSE;
142 }
143 }
144
145 // --------------------------------------------------------------------
146
147 /**
148 * Result - associative array
149 *
150 * Returns the result set as an array
151 *
152 * @access private
153 * @return array
154 */
155 function _fetch_assoc(&$row)
156 {
157 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
158
159 return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
160 }
161
162 // --------------------------------------------------------------------
163
164 /**
165 * Result - object
166 *
167 * Returns the result set as an object
168 *
169 * @access private
170 * @return object
171 */
172 function _fetch_object()
173 {
174 $result = array();
175
176 // If PHP 5 is being used we can fetch an result object
177 if (function_exists('oci_fetch_object'))
178 {
179 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
180
181 return @oci_fetch_object($id);
182 }
183
184 // If PHP 4 is being used we have to build our own result
185 foreach ($this->result_array() as $key => $val)
186 {
187 $obj = new stdClass();
188 if (is_array($val))
189 {
190 foreach ($val as $k => $v)
191 {
192 $obj->$k = $v;
193 }
194 }
195 else
196 {
197 $obj->$key = $val;
198 }
199
200 $result[] = $obj;
201 }
202
203 return $result;
204 }
205
206 // --------------------------------------------------------------------
207
208 /**
209 * Query result. "array" version.
210 *
211 * @access public
212 * @return array
213 */
214 function result_array()
215 {
216 if (count($this->result_array) > 0)
217 {
218 return $this->result_array;
219 }
220
221 // oracle's fetch functions do not return arrays.
222 // The information is returned in reference parameters
223 $row = NULL;
224 while ($this->_fetch_assoc($row))
225 {
226 $this->result_array[] = $row;
227 }
228
229 return $this->result_array;
230 }
231
232 // --------------------------------------------------------------------
233
234 /**
235 * Data Seek
236 *
237 * Moves the internal pointer to the desired offset. We call
238 * this internally before fetching results to make sure the
239 * result set starts at zero
240 *
241 * @access private
242 * @return array
243 */
244 function _data_seek($n = 0)
245 {
246 return FALSE; // Not needed
247 }
248
249}
250
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000251
252/* End of file oci8_result.php */
253/* Location: ./system/database/drivers/oci8/oci8_result.php */