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 | /** |
Rick Ellis | 325197e | 2006-11-20 17:29:05 +0000 | [diff] [blame] | 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 | * | ||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 39 | * |
40 | * @access public | ||||
41 | * @return integer | ||||
42 | */ | ||||
43 | function num_rows() | ||||
44 | { | ||||
Rick Ellis | 325197e | 2006-11-20 17:29:05 +0000 | [diff] [blame] | 45 | $rowcount = count($this->result_array()); |
46 | @ociexecute($this->stmt_id); | ||||
47 | if ($this->curs_id) | ||||
admin | 3cad41e | 2006-10-02 03:21:46 +0000 | [diff] [blame] | 48 | { |
Rick Ellis | 325197e | 2006-11-20 17:29:05 +0000 | [diff] [blame] | 49 | @ociexecute($this->curs_id); |
admin | 3cad41e | 2006-10-02 03:21:46 +0000 | [diff] [blame] | 50 | } |
Rick Ellis | 325197e | 2006-11-20 17:29:05 +0000 | [diff] [blame] | 51 | return $rowcount; |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 52 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 53 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 54 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 55 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 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); | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 65 | |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 66 | // if we used a limit we subtract it |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 67 | if ($this->limit_used) |
68 | { | ||||
69 | $count = $count - 1; | ||||
70 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 71 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 72 | return $count; |
73 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 74 | |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 75 | // -------------------------------------------------------------------- |
76 | |||||
77 | /** | ||||
78 | * Fetch Field Names | ||||
79 | * | ||||
80 | * Generates an array of column names | ||||
81 | * | ||||
82 | * @access public | ||||
83 | * @return array | ||||
84 | */ | ||||
admin | 606f99c | 2006-10-11 23:48:41 +0000 | [diff] [blame] | 85 | function list_fields() |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 86 | { |
87 | $field_names = array(); | ||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 88 | $fieldCount = $this->num_fields(); |
89 | for ($c = 1; $c <= $fieldCount; $c++) | ||||
90 | { | ||||
91 | $field_names[] = ocicolumnname($this->stmt_id, $c); | ||||
92 | } | ||||
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 93 | return $field_names; |
94 | } | ||||
95 | |||||
admin | 606f99c | 2006-10-11 23:48:41 +0000 | [diff] [blame] | 96 | // Deprecated |
97 | function field_names() | ||||
98 | { | ||||
99 | return $this->list_fields(); | ||||
100 | } | ||||
101 | |||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 102 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 103 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 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); | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 122 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 123 | $retval[] = $F; |
124 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 125 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 126 | return $retval; |
127 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 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 | { | ||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 140 | ocifreestatement($this->result_id); |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 141 | $this->result_id = FALSE; |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 142 | } |
143 | } | ||||
144 | |||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 145 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 146 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 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 | { | ||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 157 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
158 | |||||
159 | return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); | ||||
admin | d2dd031 | 2006-10-05 04:34:38 +0000 | [diff] [blame] | 160 | } |
161 | |||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 162 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 163 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 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() | ||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 173 | { |
174 | $result = array(); | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 175 | |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 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 | |||||
Rick Ellis | 325197e | 2006-11-20 17:29:05 +0000 | [diff] [blame] | 181 | return @oci_fetch_object($id); |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 182 | } |
183 | |||||
184 | // If PHP 4 is being used we have to build our own result | ||||
185 | foreach ($this->result_array() as $key => $val) | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 186 | { |
187 | $obj = new stdClass(); | ||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 188 | if (is_array($val)) |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 189 | { |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 190 | foreach ($val as $k => $v) |
191 | { | ||||
192 | $obj->$k = $v; | ||||
193 | } | ||||
194 | } | ||||
195 | else | ||||
196 | { | ||||
197 | $obj->$key = $val; | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 198 | } |
199 | |||||
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 200 | $result[] = $obj; |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 201 | } |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 202 | |
203 | return $result; | ||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 204 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 205 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 206 | // -------------------------------------------------------------------- |
admin | d2dd031 | 2006-10-05 04:34:38 +0000 | [diff] [blame] | 207 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 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 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 220 | |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 221 | // oracle's fetch functions do not return arrays. |
222 | // The information is returned in reference parameters | ||||
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 223 | $row = NULL; |
224 | while ($this->_fetch_assoc($row)) | ||||
225 | { | ||||
226 | $this->result_array[] = $row; | ||||
227 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 228 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 229 | return $this->result_array; |
230 | } | ||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 231 | |
admin | 259ea84 | 2006-10-27 17:56:58 +0000 | [diff] [blame] | 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 | |||||
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 249 | } |
250 | |||||
251 | ?> |