blob: fb4ed1f0d16034490d6edb630a3fa8feb0a33718 [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 /**
Rick Ellis325197e2006-11-20 17:29:05 +000034 * Number of rows in the result set.
35 *
36 * Oracle doesn't have a graceful way to retun the number of rows
37 * so we have to use what amounts to a hack.
38 *
admine334c472006-10-21 19:44:22 +000039 *
40 * @access public
41 * @return integer
42 */
43 function num_rows()
44 {
Rick Ellis325197e2006-11-20 17:29:05 +000045 $rowcount = count($this->result_array());
46 @ociexecute($this->stmt_id);
47 if ($this->curs_id)
admin3cad41e2006-10-02 03:21:46 +000048 {
Rick Ellis325197e2006-11-20 17:29:05 +000049 @ociexecute($this->curs_id);
admin3cad41e2006-10-02 03:21:46 +000050 }
Rick Ellis325197e2006-11-20 17:29:05 +000051 return $rowcount;
admine334c472006-10-21 19:44:22 +000052 }
admin7b613c72006-09-24 18:05:17 +000053
admine334c472006-10-21 19:44:22 +000054 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +000055
admine334c472006-10-21 19:44:22 +000056 /**
57 * Number of fields in the result set
58 *
59 * @access public
60 * @return integer
61 */
62 function num_fields()
63 {
64 $count = @ocinumcols($this->stmt_id);
admin7b613c72006-09-24 18:05:17 +000065
admin259ea842006-10-27 17:56:58 +000066 // if we used a limit we subtract it
admine334c472006-10-21 19:44:22 +000067 if ($this->limit_used)
68 {
69 $count = $count - 1;
70 }
admin7b613c72006-09-24 18:05:17 +000071
admine334c472006-10-21 19:44:22 +000072 return $count;
73 }
admin7b613c72006-09-24 18:05:17 +000074
adminab4f61b2006-09-25 22:12:32 +000075 // --------------------------------------------------------------------
76
77 /**
78 * Fetch Field Names
79 *
80 * Generates an array of column names
81 *
82 * @access public
83 * @return array
84 */
admin606f99c2006-10-11 23:48:41 +000085 function list_fields()
adminab4f61b2006-09-25 22:12:32 +000086 {
87 $field_names = array();
admine334c472006-10-21 19:44:22 +000088 $fieldCount = $this->num_fields();
89 for ($c = 1; $c <= $fieldCount; $c++)
90 {
91 $field_names[] = ocicolumnname($this->stmt_id, $c);
92 }
adminab4f61b2006-09-25 22:12:32 +000093 return $field_names;
94 }
95
admin606f99c2006-10-11 23:48:41 +000096 // Deprecated
97 function field_names()
98 {
99 return $this->list_fields();
100 }
101
admine334c472006-10-21 19:44:22 +0000102 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000103
admine334c472006-10-21 19:44:22 +0000104 /**
105 * Field data
106 *
107 * Generates an array of objects containing field meta-data
108 *
109 * @access public
110 * @return array
111 */
112 function field_data()
113 {
114 $retval = array();
115 $fieldCount = $this->num_fields();
116 for ($c = 1; $c <= $fieldCount; $c++)
117 {
118 $F = new stdClass();
119 $F->name = ocicolumnname($this->stmt_id, $c);
120 $F->type = ocicolumntype($this->stmt_id, $c);
121 $F->max_length = ocicolumnsize($this->stmt_id, $c);
admin7b613c72006-09-24 18:05:17 +0000122
admine334c472006-10-21 19:44:22 +0000123 $retval[] = $F;
124 }
admin7b613c72006-09-24 18:05:17 +0000125
admine334c472006-10-21 19:44:22 +0000126 return $retval;
127 }
admin7b613c72006-09-24 18:05:17 +0000128
129 // --------------------------------------------------------------------
130
131 /**
132 * Free the result
133 *
134 * @return null
135 */
136 function free_result()
137 {
138 if (is_resource($this->result_id))
139 {
admin259ea842006-10-27 17:56:58 +0000140 ocifreestatement($this->result_id);
admine334c472006-10-21 19:44:22 +0000141 $this->result_id = FALSE;
admin7b613c72006-09-24 18:05:17 +0000142 }
143 }
144
admine334c472006-10-21 19:44:22 +0000145 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000146
admine334c472006-10-21 19:44:22 +0000147 /**
148 * Result - associative array
149 *
150 * Returns the result set as an array
151 *
152 * @access private
153 * @return array
154 */
155 function _fetch_assoc(&$row)
156 {
admin259ea842006-10-27 17:56:58 +0000157 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
158
159 return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
admind2dd0312006-10-05 04:34:38 +0000160 }
161
admine334c472006-10-21 19:44:22 +0000162 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +0000163
admine334c472006-10-21 19:44:22 +0000164 /**
165 * Result - object
166 *
167 * Returns the result set as an object
168 *
169 * @access private
170 * @return object
171 */
172 function _fetch_object()
admin259ea842006-10-27 17:56:58 +0000173 {
174 $result = array();
admin7b613c72006-09-24 18:05:17 +0000175
admin259ea842006-10-27 17:56:58 +0000176 // If PHP 5 is being used we can fetch an result object
177 if (function_exists('oci_fetch_object'))
178 {
179 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
180
Rick Ellis325197e2006-11-20 17:29:05 +0000181 return @oci_fetch_object($id);
admin259ea842006-10-27 17:56:58 +0000182 }
183
184 // If PHP 4 is being used we have to build our own result
185 foreach ($this->result_array() as $key => $val)
admin7b613c72006-09-24 18:05:17 +0000186 {
187 $obj = new stdClass();
admin259ea842006-10-27 17:56:58 +0000188 if (is_array($val))
admin7b613c72006-09-24 18:05:17 +0000189 {
admin259ea842006-10-27 17:56:58 +0000190 foreach ($val as $k => $v)
191 {
192 $obj->$k = $v;
193 }
194 }
195 else
196 {
197 $obj->$key = $val;
admin7b613c72006-09-24 18:05:17 +0000198 }
199
admin259ea842006-10-27 17:56:58 +0000200 $result[] = $obj;
admin7b613c72006-09-24 18:05:17 +0000201 }
admin259ea842006-10-27 17:56:58 +0000202
203 return $result;
admine334c472006-10-21 19:44:22 +0000204 }
admin7b613c72006-09-24 18:05:17 +0000205
admine334c472006-10-21 19:44:22 +0000206 // --------------------------------------------------------------------
admind2dd0312006-10-05 04:34:38 +0000207
admine334c472006-10-21 19:44:22 +0000208 /**
209 * Query result. "array" version.
210 *
211 * @access public
212 * @return array
213 */
214 function result_array()
215 {
216 if (count($this->result_array) > 0)
217 {
218 return $this->result_array;
219 }
admin7b613c72006-09-24 18:05:17 +0000220
admin259ea842006-10-27 17:56:58 +0000221 // oracle's fetch functions do not return arrays.
222 // The information is returned in reference parameters
admine334c472006-10-21 19:44:22 +0000223 $row = NULL;
224 while ($this->_fetch_assoc($row))
225 {
226 $this->result_array[] = $row;
227 }
admin7b613c72006-09-24 18:05:17 +0000228
admine334c472006-10-21 19:44:22 +0000229 return $this->result_array;
230 }
admin7b613c72006-09-24 18:05:17 +0000231
admin259ea842006-10-27 17:56:58 +0000232 // --------------------------------------------------------------------
233
234 /**
235 * Data Seek
236 *
237 * Moves the internal pointer to the desired offset. We call
238 * this internally before fetching results to make sure the
239 * result set starts at zero
240 *
241 * @access private
242 * @return array
243 */
244 function _data_seek($n = 0)
245 {
246 return FALSE; // Not needed
247 }
248
admin7b613c72006-09-24 18:05:17 +0000249}
250
251?>