blob: a3da800263d0a63422619564ac0f7b4515d6df3c [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 */
87 function field_names()
88 {
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
admin7b613c72006-09-24 18:05:17 +000098 // --------------------------------------------------------------------
99
100 /**
101 * Field data
102 *
103 * Generates an array of objects containing field meta-data
104 *
105 * @access public
106 * @return array
107 */
108 function field_data()
109 {
110 $retval = array();
111 $fieldCount = $this->num_fields();
112 for ($c = 1; $c <= $fieldCount; $c++)
113 {
114 $F = new stdClass();
115 $F->name = ocicolumnname($this->stmt_id, $c);
116 $F->type = ocicolumntype($this->stmt_id, $c);
117 $F->max_length = ocicolumnsize($this->stmt_id, $c);
118
119 $retval[] = $F;
120 }
121
122 return $retval;
123 }
124
125 // --------------------------------------------------------------------
126
127 /**
128 * Free the result
129 *
130 * @return null
131 */
132 function free_result()
133 {
134 if (is_resource($this->result_id))
135 {
136 OCIFreeStatement($this->result_id);
137 $this->result_id = FALSE;
138 }
139 }
140
141 // --------------------------------------------------------------------
142
143 /**
144 * Result - associative array
145 *
146 * Returns the result set as an array
147 *
148 * @access private
149 * @return array
150 */
151 function _fetch_assoc(&$row)
152 {
153 // if pulling from a cursor, use curs_id
154 if ($this->curs_id)
155 {
156 return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
157 }
158 else
159 {
160 return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
161 }
162 }
163
admind2dd0312006-10-05 04:34:38 +0000164 // --------------------------------------------------------------------
165
166 /**
167 * Data Seek
168 *
169 * Moves the internal pointer to the desired offset. We call
170 * this internally before fetching results to make sure the
171 * result set starts at zero
172 *
173 * @access private
174 * @return array
175 */
176 function _data_seek($n = 0)
177 {
178 return FALSE;
179 }
180
admin7b613c72006-09-24 18:05:17 +0000181 // --------------------------------------------------------------------
182
183 /**
184 * Result - object
185 *
186 * Returns the result set as an object
187 *
188 * @access private
189 * @return object
190 */
191 function _fetch_object()
192 {
193 // the PHP 4 version of the oracle functions do not
194 // have a fetch method so we call the array version
195 // and build an object from that
196
197 $row = array();
198 $res = $this->_fetch_assoc($row);
199 if ($res != FALSE)
200 {
201 $obj = new stdClass();
202 foreach ($row as $key => $value)
203 {
204 $obj->{$key} = $value;
205 }
206
207 $res = $obj;
208 }
209 return $res;
210 }
211
admind2dd0312006-10-05 04:34:38 +0000212 // --------------------------------------------------------------------
213
admin7b613c72006-09-24 18:05:17 +0000214 /**
215 * Query result. "array" version.
216 *
217 * @access public
218 * @return array
219 */
220 function result_array()
221 {
222 if (count($this->result_array) > 0)
223 {
224 return $this->result_array;
225 }
226
227 // oracle's fetch functions do not
228 // return arrays, the information
229 // is returned in reference parameters
230 //
231 $row = NULL;
232 while ($this->_fetch_assoc($row))
233 {
234 $this->result_array[] = $row;
235 }
236
237 if (count($this->result_array) == 0)
238 {
239 return FALSE;
240 }
241
242 return $this->result_array;
243 }
244
245}
246
247?>