blob: efb2f7bed0c78130095fb3bd2b671a00caa1f7f6 [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 {
47 return @ocirowcount($this->stmt_id)
48 }
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
admine334c472006-10-21 19:44:22 +000063 // if we used a limit, we added a field,
64 // subtract it out
65 if ($this->limit_used)
66 {
67 $count = $count - 1;
68 }
admin7b613c72006-09-24 18:05:17 +000069
admine334c472006-10-21 19:44:22 +000070 return $count;
71 }
admin7b613c72006-09-24 18:05:17 +000072
adminab4f61b2006-09-25 22:12:32 +000073 // --------------------------------------------------------------------
74
75 /**
76 * Fetch Field Names
77 *
78 * Generates an array of column names
79 *
80 * @access public
81 * @return array
82 */
admin606f99c2006-10-11 23:48:41 +000083 function list_fields()
adminab4f61b2006-09-25 22:12:32 +000084 {
85 $field_names = array();
admine334c472006-10-21 19:44:22 +000086 $fieldCount = $this->num_fields();
87 for ($c = 1; $c <= $fieldCount; $c++)
88 {
89 $field_names[] = ocicolumnname($this->stmt_id, $c);
90 }
adminab4f61b2006-09-25 22:12:32 +000091 return $field_names;
92 }
93
admin606f99c2006-10-11 23:48:41 +000094 // Deprecated
95 function field_names()
96 {
97 return $this->list_fields();
98 }
99
admine334c472006-10-21 19:44:22 +0000100 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000101
admine334c472006-10-21 19:44:22 +0000102 /**
103 * Field data
104 *
105 * Generates an array of objects containing field meta-data
106 *
107 * @access public
108 * @return array
109 */
110 function field_data()
111 {
112 $retval = array();
113 $fieldCount = $this->num_fields();
114 for ($c = 1; $c <= $fieldCount; $c++)
115 {
116 $F = new stdClass();
117 $F->name = ocicolumnname($this->stmt_id, $c);
118 $F->type = ocicolumntype($this->stmt_id, $c);
119 $F->max_length = ocicolumnsize($this->stmt_id, $c);
admin7b613c72006-09-24 18:05:17 +0000120
admine334c472006-10-21 19:44:22 +0000121 $retval[] = $F;
122 }
admin7b613c72006-09-24 18:05:17 +0000123
admine334c472006-10-21 19:44:22 +0000124 return $retval;
125 }
admin7b613c72006-09-24 18:05:17 +0000126
127 // --------------------------------------------------------------------
128
129 /**
130 * Free the result
131 *
132 * @return null
133 */
134 function free_result()
135 {
136 if (is_resource($this->result_id))
137 {
admine334c472006-10-21 19:44:22 +0000138 OCIFreeStatement($this->result_id);
139 $this->result_id = FALSE;
admin7b613c72006-09-24 18:05:17 +0000140 }
141 }
142
admine334c472006-10-21 19:44:22 +0000143 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000144
admine334c472006-10-21 19:44:22 +0000145 /**
146 * Result - associative array
147 *
148 * Returns the result set as an array
149 *
150 * @access private
151 * @return array
152 */
153 function _fetch_assoc(&$row)
154 {
155 // if pulling from a cursor, use curs_id
156 if ($this->curs_id)
admin7b613c72006-09-24 18:05:17 +0000157 {
158 return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
159 }
160 else
161 {
162 return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
163 }
admine334c472006-10-21 19:44:22 +0000164 }
admin7b613c72006-09-24 18:05:17 +0000165
admind2dd0312006-10-05 04:34:38 +0000166 // --------------------------------------------------------------------
167
168 /**
169 * Data Seek
170 *
171 * Moves the internal pointer to the desired offset. We call
172 * this internally before fetching results to make sure the
173 * result set starts at zero
174 *
175 * @access private
176 * @return array
177 */
178 function _data_seek($n = 0)
179 {
180 return FALSE;
181 }
182
admine334c472006-10-21 19:44:22 +0000183 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000184
admine334c472006-10-21 19:44:22 +0000185 /**
186 * Result - object
187 *
188 * Returns the result set as an object
189 *
190 * @access private
191 * @return object
192 */
193 function _fetch_object()
194 {
195 // the PHP 4 version of the oracle functions do not
196 // have a fetch method so we call the array version
197 // and build an object from that
admin7b613c72006-09-24 18:05:17 +0000198
admine334c472006-10-21 19:44:22 +0000199 $row = array();
200 $res = $this->_fetch_assoc($row);
201 if ($res != FALSE)
admin7b613c72006-09-24 18:05:17 +0000202 {
203 $obj = new stdClass();
204 foreach ($row as $key => $value)
205 {
206 $obj->{$key} = $value;
207 }
208
209 $res = $obj;
210 }
admine334c472006-10-21 19:44:22 +0000211 return $res;
212 }
admin7b613c72006-09-24 18:05:17 +0000213
admine334c472006-10-21 19:44:22 +0000214 // --------------------------------------------------------------------
admind2dd0312006-10-05 04:34:38 +0000215
admine334c472006-10-21 19:44:22 +0000216 /**
217 * Query result. "array" version.
218 *
219 * @access public
220 * @return array
221 */
222 function result_array()
223 {
224 if (count($this->result_array) > 0)
225 {
226 return $this->result_array;
227 }
admin7b613c72006-09-24 18:05:17 +0000228
admine334c472006-10-21 19:44:22 +0000229 // oracle's fetch functions do not
230 // return arrays, the information
231 // is returned in reference parameters
232 //
233 $row = NULL;
234 while ($this->_fetch_assoc($row))
235 {
236 $this->result_array[] = $row;
237 }
admin7b613c72006-09-24 18:05:17 +0000238
admine334c472006-10-21 19:44:22 +0000239 if (count($this->result_array) == 0)
240 {
241 return FALSE;
242 }
admin7b613c72006-09-24 18:05:17 +0000243
admine334c472006-10-21 19:44:22 +0000244 return $this->result_array;
245 }
admin7b613c72006-09-24 18:05:17 +0000246
247}
248
249?>