blob: af30457b34367efff1d64a48dd88c44430333306 [file] [log] [blame]
admin7b613c72006-09-24 18:05:17 +00001<?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 *
admine334c472006-10-21 19:44:22 +00007 * @package CodeIgniter
8 * @author Rick Ellis
admin7b613c72006-09-24 18:05:17 +00009 * @copyright Copyright (c) 2006, pMachine, Inc.
admine334c472006-10-21 19:44:22 +000010 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
admin7b613c72006-09-24 18:05: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 *
admine334c472006-10-21 19:44:22 +000023 * @category Database
24 * @author Rick Ellis
25 * @link http://www.codeigniter.com/user_guide/database/
admin7b613c72006-09-24 18:05:17 +000026 */
27class CI_DB_oci8_result extends CI_DB_result {
28
admine334c472006-10-21 19:44:22 +000029 var $stmt_id;
30 var $curs_id;
31 var $limit_used;
admin7b613c72006-09-24 18:05:17 +000032
admine334c472006-10-21 19:44:22 +000033 /**
34 * Number of rows in the result set
35 *
36 * @access public
37 * @return integer
38 */
39 function num_rows()
40 {
admin3f643e62006-10-27 06:25:31 +000041 if (function_exists('oci_num_rows'))
admin3cad41e2006-10-02 03:21:46 +000042 {
admin3f643e62006-10-27 06:25:31 +000043 return @oci_num_rows($this->stmt_id);
admin3cad41e2006-10-02 03:21:46 +000044 }
admin3f643e62006-10-27 06:25:31 +000045 else
46 {
admin259ea842006-10-27 17:56:58 +000047 return @ocirowcount($this->stmt_id);
admin3f643e62006-10-27 06:25:31 +000048 }
admine334c472006-10-21 19:44:22 +000049 }
admin7b613c72006-09-24 18:05:17 +000050
admine334c472006-10-21 19:44:22 +000051 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +000052
admine334c472006-10-21 19:44:22 +000053 /**
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);
admin7b613c72006-09-24 18:05:17 +000062
admin259ea842006-10-27 17:56:58 +000063 // if we used a limit we subtract it
admine334c472006-10-21 19:44:22 +000064 if ($this->limit_used)
65 {
66 $count = $count - 1;
67 }
admin7b613c72006-09-24 18:05:17 +000068
admine334c472006-10-21 19:44:22 +000069 return $count;
70 }
admin7b613c72006-09-24 18:05:17 +000071
adminab4f61b2006-09-25 22:12:32 +000072 // --------------------------------------------------------------------
73
74 /**
75 * Fetch Field Names
76 *
77 * Generates an array of column names
78 *
79 * @access public
80 * @return array
81 */
admin606f99c2006-10-11 23:48:41 +000082 function list_fields()
adminab4f61b2006-09-25 22:12:32 +000083 {
84 $field_names = array();
admine334c472006-10-21 19:44:22 +000085 $fieldCount = $this->num_fields();
86 for ($c = 1; $c <= $fieldCount; $c++)
87 {
88 $field_names[] = ocicolumnname($this->stmt_id, $c);
89 }
adminab4f61b2006-09-25 22:12:32 +000090 return $field_names;
91 }
92
admin606f99c2006-10-11 23:48:41 +000093 // Deprecated
94 function field_names()
95 {
96 return $this->list_fields();
97 }
98
admine334c472006-10-21 19:44:22 +000099 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000100
admine334c472006-10-21 19:44:22 +0000101 /**
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);
admin7b613c72006-09-24 18:05:17 +0000119
admine334c472006-10-21 19:44:22 +0000120 $retval[] = $F;
121 }
admin7b613c72006-09-24 18:05:17 +0000122
admine334c472006-10-21 19:44:22 +0000123 return $retval;
124 }
admin7b613c72006-09-24 18:05:17 +0000125
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 {
admin259ea842006-10-27 17:56:58 +0000137 ocifreestatement($this->result_id);
admine334c472006-10-21 19:44:22 +0000138 $this->result_id = FALSE;
admin7b613c72006-09-24 18:05:17 +0000139 }
140 }
141
admine334c472006-10-21 19:44:22 +0000142 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000143
admine334c472006-10-21 19:44:22 +0000144 /**
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 {
admin259ea842006-10-27 17:56:58 +0000154 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
155
156 return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
admind2dd0312006-10-05 04:34:38 +0000157 }
158
admine334c472006-10-21 19:44:22 +0000159 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000160
admine334c472006-10-21 19:44:22 +0000161 /**
162 * Result - object
163 *
164 * Returns the result set as an object
165 *
166 * @access private
167 * @return object
168 */
169 function _fetch_object()
admin259ea842006-10-27 17:56:58 +0000170 {
171 $result = array();
admin7b613c72006-09-24 18:05:17 +0000172
admin259ea842006-10-27 17:56:58 +0000173 // 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)
admin7b613c72006-09-24 18:05:17 +0000188 {
189 $obj = new stdClass();
admin259ea842006-10-27 17:56:58 +0000190 if (is_array($val))
admin7b613c72006-09-24 18:05:17 +0000191 {
admin259ea842006-10-27 17:56:58 +0000192 foreach ($val as $k => $v)
193 {
194 $obj->$k = $v;
195 }
196 }
197 else
198 {
199 $obj->$key = $val;
admin7b613c72006-09-24 18:05:17 +0000200 }
201
admin259ea842006-10-27 17:56:58 +0000202 $result[] = $obj;
admin7b613c72006-09-24 18:05:17 +0000203 }
admin259ea842006-10-27 17:56:58 +0000204
205 return $result;
admine334c472006-10-21 19:44:22 +0000206 }
admin7b613c72006-09-24 18:05:17 +0000207
admine334c472006-10-21 19:44:22 +0000208 // --------------------------------------------------------------------
admind2dd0312006-10-05 04:34:38 +0000209
admine334c472006-10-21 19:44:22 +0000210 /**
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 }
admin7b613c72006-09-24 18:05:17 +0000222
admin259ea842006-10-27 17:56:58 +0000223 // oracle's fetch functions do not return arrays.
224 // The information is returned in reference parameters
admine334c472006-10-21 19:44:22 +0000225 $row = NULL;
226 while ($this->_fetch_assoc($row))
227 {
228 $this->result_array[] = $row;
229 }
admin7b613c72006-09-24 18:05:17 +0000230
admine334c472006-10-21 19:44:22 +0000231 return $this->result_array;
232 }
admin7b613c72006-09-24 18:05:17 +0000233
admin259ea842006-10-27 17:56:58 +0000234 // --------------------------------------------------------------------
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
admin7b613c72006-09-24 18:05:17 +0000251}
252
253?>