blob: 7d49c620e04a0c5e06a29bd1e6b8d4be068cf223 [file] [log] [blame]
Derek Jones4b9c6292011-07-01 17:40:48 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Barry Mienydd671972010-10-04 16:33:58 +020019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
Barry Mienydd671972010-10-04 16:33:58 +020024 * @since Version 1.0
Derek Allard2067d1a2008-11-13 22:59:24 +000025 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * oci8 Result Class
32 *
33 * This class extends the parent result class: CI_DB_result
34 *
35 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/database/
38 */
39class CI_DB_oci8_result extends CI_DB_result {
40
41 var $stmt_id;
42 var $curs_id;
43 var $limit_used;
44
45 /**
46 * Number of rows in the result set.
47 *
48 * Oracle doesn't have a graceful way to retun the number of rows
49 * so we have to use what amounts to a hack.
Barry Mienydd671972010-10-04 16:33:58 +020050 *
Derek Allard2067d1a2008-11-13 22:59:24 +000051 *
Derek Jones4b9c6292011-07-01 17:40:48 -050052 * @access public
53 * @return integer
Derek Allard2067d1a2008-11-13 22:59:24 +000054 */
55 function num_rows()
56 {
Andrey Andreevef3e2402011-09-21 14:39:29 +030057 if ($this->num_rows === 0 && count($this->result_array()) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +000058 {
Andrey Andreevef3e2402011-09-21 14:39:29 +030059 $this->num_rows = count($this->result_array());
60 @ociexecute($this->stmt_id);
61
62 if ($this->curs_id)
63 {
64 @ociexecute($this->curs_id);
65 }
Derek Allard2067d1a2008-11-13 22:59:24 +000066 }
67
Andrey Andreevef3e2402011-09-21 14:39:29 +030068 return $this->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000069 }
70
71 // --------------------------------------------------------------------
72
73 /**
74 * Number of fields in the result set
75 *
Derek Jones4b9c6292011-07-01 17:40:48 -050076 * @access public
77 * @return integer
Derek Allard2067d1a2008-11-13 22:59:24 +000078 */
79 function num_fields()
80 {
81 $count = @ocinumcols($this->stmt_id);
82
83 // if we used a limit we subtract it
84 if ($this->limit_used)
85 {
86 $count = $count - 1;
87 }
88
89 return $count;
90 }
91
92 // --------------------------------------------------------------------
93
94 /**
95 * Fetch Field Names
96 *
97 * Generates an array of column names
98 *
99 * @access public
100 * @return array
101 */
102 function list_fields()
103 {
104 $field_names = array();
105 $fieldCount = $this->num_fields();
106 for ($c = 1; $c <= $fieldCount; $c++)
107 {
108 $field_names[] = ocicolumnname($this->stmt_id, $c);
109 }
110 return $field_names;
111 }
112
113 // --------------------------------------------------------------------
114
115 /**
116 * Field data
117 *
118 * Generates an array of objects containing field meta-data
119 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500120 * @access public
121 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000122 */
123 function field_data()
124 {
125 $retval = array();
126 $fieldCount = $this->num_fields();
127 for ($c = 1; $c <= $fieldCount; $c++)
128 {
Barry Mienydd671972010-10-04 16:33:58 +0200129 $F = new stdClass();
Derek Allard2067d1a2008-11-13 22:59:24 +0000130 $F->name = ocicolumnname($this->stmt_id, $c);
131 $F->type = ocicolumntype($this->stmt_id, $c);
Derek Jones4b9c6292011-07-01 17:40:48 -0500132 $F->max_length = ocicolumnsize($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000133
134 $retval[] = $F;
135 }
136
137 return $retval;
138 }
139
140 // --------------------------------------------------------------------
141
142 /**
143 * Free the result
144 *
145 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200146 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 function free_result()
148 {
149 if (is_resource($this->result_id))
150 {
Barry Mienydd671972010-10-04 16:33:58 +0200151 ocifreestatement($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 $this->result_id = FALSE;
153 }
154 }
155
156 // --------------------------------------------------------------------
157
158 /**
159 * Result - associative array
160 *
161 * Returns the result set as an array
162 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500163 * @access private
164 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 */
166 function _fetch_assoc(&$row)
167 {
168 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Barry Mienydd671972010-10-04 16:33:58 +0200169
170 return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 }
172
173 // --------------------------------------------------------------------
174
175 /**
176 * Result - object
177 *
178 * Returns the result set as an object
179 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500180 * @access private
181 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 */
183 function _fetch_object()
Barry Mienydd671972010-10-04 16:33:58 +0200184 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000185 $result = array();
186
187 // If PHP 5 is being used we can fetch an result object
188 if (function_exists('oci_fetch_object'))
189 {
190 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Barry Mienydd671972010-10-04 16:33:58 +0200191
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 return @oci_fetch_object($id);
193 }
Barry Mienydd671972010-10-04 16:33:58 +0200194
Derek Allard2067d1a2008-11-13 22:59:24 +0000195 // If PHP 4 is being used we have to build our own result
196 foreach ($this->result_array() as $key => $val)
197 {
198 $obj = new stdClass();
199 if (is_array($val))
200 {
201 foreach ($val as $k => $v)
202 {
203 $obj->$k = $v;
204 }
205 }
206 else
207 {
208 $obj->$key = $val;
209 }
Barry Mienydd671972010-10-04 16:33:58 +0200210
Derek Allard2067d1a2008-11-13 22:59:24 +0000211 $result[] = $obj;
212 }
213
214 return $result;
215 }
216
217 // --------------------------------------------------------------------
218
219 /**
Derek Jones4b9c6292011-07-01 17:40:48 -0500220 * Query result. "array" version.
Derek Allard2067d1a2008-11-13 22:59:24 +0000221 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500222 * @access public
223 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000224 */
225 function result_array()
226 {
227 if (count($this->result_array) > 0)
228 {
229 return $this->result_array;
230 }
231
232 // oracle's fetch functions do not return arrays.
233 // The information is returned in reference parameters
234 $row = NULL;
235 while ($this->_fetch_assoc($row))
236 {
237 $this->result_array[] = $row;
238 }
239
240 return $this->result_array;
241 }
242
243 // --------------------------------------------------------------------
244
245 /**
246 * Data Seek
247 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500248 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000249 * this internally before fetching results to make sure the
250 * result set starts at zero
251 *
252 * @access private
253 * @return array
254 */
255 function _data_seek($n = 0)
256 {
257 return FALSE; // Not needed
258 }
259
260}
261
262
263/* End of file oci8_result.php */
Andrey Andreevef3e2402011-09-21 14:39:29 +0300264/* Location: ./system/database/drivers/oci8/oci8_result.php */