admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
2 | /** | ||||
3 | * Code Igniter | ||||
4 | * | ||||
5 | * An open source application development framework for PHP 4.3.2 or newer | ||||
6 | * | ||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 7 | * @package CodeIgniter |
8 | * @author Rick Ellis | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 10 | * @license http://www.codeignitor.com/user_guide/license.html |
11 | * @link http://www.codeigniter.com | ||||
12 | * @since Version 1.0 | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 13 | * @filesource |
14 | */ | ||||
15 | |||||
16 | // ------------------------------------------------------------------------ | ||||
17 | |||||
18 | /** | ||||
19 | * oci8 Result Class | ||||
20 | * | ||||
21 | * This class extends the parent result class: CI_DB_result | ||||
22 | * | ||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 23 | * @category Database |
24 | * @author Rick Ellis | ||||
25 | * @link http://www.codeigniter.com/user_guide/database/ | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 26 | */ |
27 | class CI_DB_oci8_result extends CI_DB_result { | ||||
28 | |||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 29 | var $stmt_id; |
30 | var $curs_id; | ||||
31 | var $limit_used; | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 32 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 33 | /** |
34 | * Number of rows in the result set | ||||
35 | * | ||||
36 | * @access public | ||||
37 | * @return integer | ||||
38 | */ | ||||
39 | function num_rows() | ||||
40 | { | ||||
admin | 3f643e6 | 2006-10-27 06:25:31 +0000 | [diff] [blame] | 41 | if (function_exists('oci_num_rows')) |
admin | 3cad41e | 2006-10-02 03:21:46 +0000 | [diff] [blame] | 42 | { |
admin | 3f643e6 | 2006-10-27 06:25:31 +0000 | [diff] [blame] | 43 | return @oci_num_rows($this->stmt_id); |
admin | 3cad41e | 2006-10-02 03:21:46 +0000 | [diff] [blame] | 44 | } |
admin | 3f643e6 | 2006-10-27 06:25:31 +0000 | [diff] [blame] | 45 | else |
46 | { | ||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 47 | return @ocirowcount($this->stmt_id); |
admin | 3f643e6 | 2006-10-27 06:25:31 +0000 | [diff] [blame] | 48 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 49 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 50 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 51 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 52 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 53 | /** |
54 | * Number of fields in the result set | ||||
55 | * | ||||
56 | * @access public | ||||
57 | * @return integer | ||||
58 | */ | ||||
59 | function num_fields() | ||||
60 | { | ||||
61 | $count = @ocinumcols($this->stmt_id); | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 62 | |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 63 | // if we used a limit we subtract it |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 64 | if ($this->limit_used) |
65 | { | ||||
66 | $count = $count - 1; | ||||
67 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 68 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 69 | return $count; |
70 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 71 | |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 72 | // -------------------------------------------------------------------- |
73 | |||||
74 | /** | ||||
75 | * Fetch Field Names | ||||
76 | * | ||||
77 | * Generates an array of column names | ||||
78 | * | ||||
79 | * @access public | ||||
80 | * @return array | ||||
81 | */ | ||||
admin | 606f99c | 2006-10-11 23:48:41 +0000 | [diff] [blame] | 82 | function list_fields() |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 83 | { |
84 | $field_names = array(); | ||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 85 | $fieldCount = $this->num_fields(); |
86 | for ($c = 1; $c <= $fieldCount; $c++) | ||||
87 | { | ||||
88 | $field_names[] = ocicolumnname($this->stmt_id, $c); | ||||
89 | } | ||||
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 90 | return $field_names; |
91 | } | ||||
92 | |||||
admin | 606f99c | 2006-10-11 23:48:41 +0000 | [diff] [blame] | 93 | // Deprecated |
94 | function field_names() | ||||
95 | { | ||||
96 | return $this->list_fields(); | ||||
97 | } | ||||
98 | |||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 99 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 100 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 101 | /** |
102 | * Field data | ||||
103 | * | ||||
104 | * Generates an array of objects containing field meta-data | ||||
105 | * | ||||
106 | * @access public | ||||
107 | * @return array | ||||
108 | */ | ||||
109 | function field_data() | ||||
110 | { | ||||
111 | $retval = array(); | ||||
112 | $fieldCount = $this->num_fields(); | ||||
113 | for ($c = 1; $c <= $fieldCount; $c++) | ||||
114 | { | ||||
115 | $F = new stdClass(); | ||||
116 | $F->name = ocicolumnname($this->stmt_id, $c); | ||||
117 | $F->type = ocicolumntype($this->stmt_id, $c); | ||||
118 | $F->max_length = ocicolumnsize($this->stmt_id, $c); | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 119 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 120 | $retval[] = $F; |
121 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 122 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 123 | return $retval; |
124 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 125 | |
126 | // -------------------------------------------------------------------- | ||||
127 | |||||
128 | /** | ||||
129 | * Free the result | ||||
130 | * | ||||
131 | * @return null | ||||
132 | */ | ||||
133 | function free_result() | ||||
134 | { | ||||
135 | if (is_resource($this->result_id)) | ||||
136 | { | ||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 137 | ocifreestatement($this->result_id); |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 138 | $this->result_id = FALSE; |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 139 | } |
140 | } | ||||
141 | |||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 142 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 143 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 144 | /** |
145 | * Result - associative array | ||||
146 | * | ||||
147 | * Returns the result set as an array | ||||
148 | * | ||||
149 | * @access private | ||||
150 | * @return array | ||||
151 | */ | ||||
152 | function _fetch_assoc(&$row) | ||||
153 | { | ||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 154 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
155 | |||||
156 | return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); | ||||
admin | d2dd031 | 2006-10-05 04:34:38 +0000 | [diff] [blame] | 157 | } |
158 | |||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 159 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 160 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 161 | /** |
162 | * Result - object | ||||
163 | * | ||||
164 | * Returns the result set as an object | ||||
165 | * | ||||
166 | * @access private | ||||
167 | * @return object | ||||
168 | */ | ||||
169 | function _fetch_object() | ||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 170 | { |
171 | $result = array(); | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 172 | |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 173 | // If PHP 5 is being used we can fetch an result object |
174 | if (function_exists('oci_fetch_object')) | ||||
175 | { | ||||
176 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; | ||||
177 | |||||
178 | while ($row = oci_fetch_object($id)) | ||||
179 | { | ||||
180 | $result[] = $row; | ||||
181 | } | ||||
182 | |||||
183 | return $result; | ||||
184 | } | ||||
185 | |||||
186 | // If PHP 4 is being used we have to build our own result | ||||
187 | foreach ($this->result_array() as $key => $val) | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 188 | { |
189 | $obj = new stdClass(); | ||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 190 | if (is_array($val)) |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 191 | { |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 192 | foreach ($val as $k => $v) |
193 | { | ||||
194 | $obj->$k = $v; | ||||
195 | } | ||||
196 | } | ||||
197 | else | ||||
198 | { | ||||
199 | $obj->$key = $val; | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 200 | } |
201 | |||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 202 | $result[] = $obj; |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 203 | } |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 204 | |
205 | return $result; | ||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 206 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 207 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 208 | // -------------------------------------------------------------------- |
admin | d2dd031 | 2006-10-05 04:34:38 +0000 | [diff] [blame] | 209 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 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 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 222 | |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 223 | // oracle's fetch functions do not return arrays. |
224 | // The information is returned in reference parameters | ||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 225 | $row = NULL; |
226 | while ($this->_fetch_assoc($row)) | ||||
227 | { | ||||
228 | $this->result_array[] = $row; | ||||
229 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 230 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 231 | return $this->result_array; |
232 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 233 | |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 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 | |||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 251 | } |
252 | |||||
253 | ?> |