blob: ab13a3935df3eb10746a4e84691f3e1726063216 [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 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @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
24 * @author Rick Ellis
25 * @link http://www.codeigniter.com/user_guide/database/
26 */
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 * @access public
37 * @return integer
38 */
39 function num_rows()
40 {
41 // get the results, count them,
42 // rerun query - otherwise we
43 // won't have data after calling
44 // num_rows()
45 $this->result_array();
46 $rowcount = count($this->result_array);
47 @ociexecute($this->stmt_id);
48 if ($this->curs_id)
admin3cad41e2006-10-02 03:21:46 +000049 {
50 @ociexecute($this->curs_id);
51 }
admin7b613c72006-09-24 18:05:17 +000052 return $rowcount;
53 }
54
55 // --------------------------------------------------------------------
56
57 /**
58 * Number of fields in the result set
59 *
60 * @access public
61 * @return integer
62 */
63 function num_fields()
64 {
65 $count = @ocinumcols($this->stmt_id);
66
67 // if we used a limit, we added a field,
68 // subtract it out
69 if ($this->limit_used)
70 {
71 $count = $count - 1;
72 }
73
74 return $count;
75 }
76
adminab4f61b2006-09-25 22:12:32 +000077 // --------------------------------------------------------------------
78
79 /**
80 * Fetch Field Names
81 *
82 * Generates an array of column names
83 *
84 * @access public
85 * @return array
86 */
admin606f99c2006-10-11 23:48:41 +000087 function list_fields()
adminab4f61b2006-09-25 22:12:32 +000088 {
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
admin606f99c2006-10-11 23:48:41 +000098 // Deprecated
99 function field_names()
100 {
101 return $this->list_fields();
102 }
103
admin7b613c72006-09-24 18:05:17 +0000104 // --------------------------------------------------------------------
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 // if pulling from a cursor, use curs_id
160 if ($this->curs_id)
161 {
162 return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
163 }
164 else
165 {
166 return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
167 }
168 }
169
admind2dd0312006-10-05 04:34:38 +0000170 // --------------------------------------------------------------------
171
172 /**
173 * Data Seek
174 *
175 * Moves the internal pointer to the desired offset. We call
176 * this internally before fetching results to make sure the
177 * result set starts at zero
178 *
179 * @access private
180 * @return array
181 */
182 function _data_seek($n = 0)
183 {
184 return FALSE;
185 }
186
admin7b613c72006-09-24 18:05:17 +0000187 // --------------------------------------------------------------------
188
189 /**
190 * Result - object
191 *
192 * Returns the result set as an object
193 *
194 * @access private
195 * @return object
196 */
197 function _fetch_object()
198 {
199 // the PHP 4 version of the oracle functions do not
200 // have a fetch method so we call the array version
201 // and build an object from that
202
203 $row = array();
204 $res = $this->_fetch_assoc($row);
205 if ($res != FALSE)
206 {
207 $obj = new stdClass();
208 foreach ($row as $key => $value)
209 {
210 $obj->{$key} = $value;
211 }
212
213 $res = $obj;
214 }
215 return $res;
216 }
217
admind2dd0312006-10-05 04:34:38 +0000218 // --------------------------------------------------------------------
219
admin7b613c72006-09-24 18:05:17 +0000220 /**
221 * Query result. "array" version.
222 *
223 * @access public
224 * @return array
225 */
226 function result_array()
227 {
228 if (count($this->result_array) > 0)
229 {
230 return $this->result_array;
231 }
232
233 // oracle's fetch functions do not
234 // return arrays, the information
235 // is returned in reference parameters
236 //
237 $row = NULL;
238 while ($this->_fetch_assoc($row))
239 {
240 $this->result_array[] = $row;
241 }
242
243 if (count($this->result_array) == 0)
244 {
245 return FALSE;
246 }
247
248 return $this->result_array;
249 }
250
251}
252
253?>