blob: 947a76109ee365179881cac4f8ef0e3db35b4ba2 [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 {
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 }
admine334c472006-10-21 19:44:22 +000052 return $rowcount;
53 }
admin7b613c72006-09-24 18:05:17 +000054
admine334c472006-10-21 19:44:22 +000055 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +000056
admine334c472006-10-21 19:44:22 +000057 /**
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);
admin7b613c72006-09-24 18:05:17 +000066
admine334c472006-10-21 19:44:22 +000067 // if we used a limit, we added a field,
68 // subtract it out
69 if ($this->limit_used)
70 {
71 $count = $count - 1;
72 }
admin7b613c72006-09-24 18:05:17 +000073
admine334c472006-10-21 19:44:22 +000074 return $count;
75 }
admin7b613c72006-09-24 18:05:17 +000076
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();
admine334c472006-10-21 19:44:22 +000090 $fieldCount = $this->num_fields();
91 for ($c = 1; $c <= $fieldCount; $c++)
92 {
93 $field_names[] = ocicolumnname($this->stmt_id, $c);
94 }
adminab4f61b2006-09-25 22:12:32 +000095 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
admine334c472006-10-21 19:44:22 +0000104 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000105
admine334c472006-10-21 19:44:22 +0000106 /**
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);
admin7b613c72006-09-24 18:05:17 +0000124
admine334c472006-10-21 19:44:22 +0000125 $retval[] = $F;
126 }
admin7b613c72006-09-24 18:05:17 +0000127
admine334c472006-10-21 19:44:22 +0000128 return $retval;
129 }
admin7b613c72006-09-24 18:05:17 +0000130
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 {
admine334c472006-10-21 19:44:22 +0000142 OCIFreeStatement($this->result_id);
143 $this->result_id = FALSE;
admin7b613c72006-09-24 18:05:17 +0000144 }
145 }
146
admine334c472006-10-21 19:44:22 +0000147 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000148
admine334c472006-10-21 19:44:22 +0000149 /**
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)
admin7b613c72006-09-24 18:05:17 +0000161 {
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 }
admine334c472006-10-21 19:44:22 +0000168 }
admin7b613c72006-09-24 18:05:17 +0000169
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
admine334c472006-10-21 19:44:22 +0000187 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000188
admine334c472006-10-21 19:44:22 +0000189 /**
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
admin7b613c72006-09-24 18:05:17 +0000202
admine334c472006-10-21 19:44:22 +0000203 $row = array();
204 $res = $this->_fetch_assoc($row);
205 if ($res != FALSE)
admin7b613c72006-09-24 18:05:17 +0000206 {
207 $obj = new stdClass();
208 foreach ($row as $key => $value)
209 {
210 $obj->{$key} = $value;
211 }
212
213 $res = $obj;
214 }
admine334c472006-10-21 19:44:22 +0000215 return $res;
216 }
admin7b613c72006-09-24 18:05:17 +0000217
admine334c472006-10-21 19:44:22 +0000218 // --------------------------------------------------------------------
admind2dd0312006-10-05 04:34:38 +0000219
admine334c472006-10-21 19:44:22 +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 }
admin7b613c72006-09-24 18:05:17 +0000232
admine334c472006-10-21 19:44:22 +0000233 // 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 }
admin7b613c72006-09-24 18:05:17 +0000242
admine334c472006-10-21 19:44:22 +0000243 if (count($this->result_array) == 0)
244 {
245 return FALSE;
246 }
admin7b613c72006-09-24 18:05:17 +0000247
admine334c472006-10-21 19:44:22 +0000248 return $this->result_array;
249 }
admin7b613c72006-09-24 18:05:17 +0000250
251}
252
253?>