blob: 2713f6f12cb53a9b8d05e79cd8f0b11b7044588e [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 *
Barry Mienydd671972010-10-04 16:33:58 +02007 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Derek Jones4b9c6292011-07-01 17:40:48 -05009 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
Barry Mienydd671972010-10-04 16:33:58 +020010 * @license http://codeigniter.com/user_guide/license.html
Derek Allard2067d1a2008-11-13 22:59:24 +000011 * @link http://codeigniter.com
Barry Mienydd671972010-10-04 16:33:58 +020012 * @since Version 1.0
Derek Allard2067d1a2008-11-13 22:59:24 +000013 * @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
Barry Mienydd671972010-10-04 16:33:58 +020024 * @author ExpressionEngine Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000025 * @link http://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 * Oracle doesn't have a graceful way to retun the number of rows
37 * so we have to use what amounts to a hack.
Barry Mienydd671972010-10-04 16:33:58 +020038 *
Derek Allard2067d1a2008-11-13 22:59:24 +000039 *
Derek Jones4b9c6292011-07-01 17:40:48 -050040 * @access public
41 * @return integer
Derek Allard2067d1a2008-11-13 22:59:24 +000042 */
43 function num_rows()
44 {
Andrey Andreevef3e2402011-09-21 14:39:29 +030045 if ($this->num_rows === 0 && count($this->result_array()) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +000046 {
Andrey Andreevef3e2402011-09-21 14:39:29 +030047 $this->num_rows = count($this->result_array());
48 @ociexecute($this->stmt_id);
49
50 if ($this->curs_id)
51 {
52 @ociexecute($this->curs_id);
53 }
Derek Allard2067d1a2008-11-13 22:59:24 +000054 }
55
Andrey Andreevef3e2402011-09-21 14:39:29 +030056 return $this->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000057 }
58
59 // --------------------------------------------------------------------
60
61 /**
62 * Number of fields in the result set
63 *
Derek Jones4b9c6292011-07-01 17:40:48 -050064 * @access public
65 * @return integer
Derek Allard2067d1a2008-11-13 22:59:24 +000066 */
67 function num_fields()
68 {
69 $count = @ocinumcols($this->stmt_id);
70
71 // if we used a limit we subtract it
72 if ($this->limit_used)
73 {
74 $count = $count - 1;
75 }
76
77 return $count;
78 }
79
80 // --------------------------------------------------------------------
81
82 /**
83 * Fetch Field Names
84 *
85 * Generates an array of column names
86 *
87 * @access public
88 * @return array
89 */
90 function list_fields()
91 {
92 $field_names = array();
93 $fieldCount = $this->num_fields();
94 for ($c = 1; $c <= $fieldCount; $c++)
95 {
96 $field_names[] = ocicolumnname($this->stmt_id, $c);
97 }
98 return $field_names;
99 }
100
101 // --------------------------------------------------------------------
102
103 /**
104 * Field data
105 *
106 * Generates an array of objects containing field meta-data
107 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500108 * @access public
109 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000110 */
111 function field_data()
112 {
113 $retval = array();
114 $fieldCount = $this->num_fields();
115 for ($c = 1; $c <= $fieldCount; $c++)
116 {
Barry Mienydd671972010-10-04 16:33:58 +0200117 $F = new stdClass();
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 $F->name = ocicolumnname($this->stmt_id, $c);
119 $F->type = ocicolumntype($this->stmt_id, $c);
Derek Jones4b9c6292011-07-01 17:40:48 -0500120 $F->max_length = ocicolumnsize($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000121
122 $retval[] = $F;
123 }
124
125 return $retval;
126 }
127
128 // --------------------------------------------------------------------
129
130 /**
131 * Free the result
132 *
133 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200134 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 function free_result()
136 {
137 if (is_resource($this->result_id))
138 {
Barry Mienydd671972010-10-04 16:33:58 +0200139 ocifreestatement($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 $this->result_id = FALSE;
141 }
142 }
143
144 // --------------------------------------------------------------------
145
146 /**
147 * Result - associative array
148 *
149 * Returns the result set as an array
150 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500151 * @access private
152 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 */
154 function _fetch_assoc(&$row)
155 {
156 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Barry Mienydd671972010-10-04 16:33:58 +0200157
158 return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
Derek Allard2067d1a2008-11-13 22:59:24 +0000159 }
160
161 // --------------------------------------------------------------------
162
163 /**
164 * Result - object
165 *
166 * Returns the result set as an object
167 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500168 * @access private
169 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 */
171 function _fetch_object()
Barry Mienydd671972010-10-04 16:33:58 +0200172 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 $result = array();
174
175 // If PHP 5 is being used we can fetch an result object
176 if (function_exists('oci_fetch_object'))
177 {
178 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Barry Mienydd671972010-10-04 16:33:58 +0200179
Derek Allard2067d1a2008-11-13 22:59:24 +0000180 return @oci_fetch_object($id);
181 }
Barry Mienydd671972010-10-04 16:33:58 +0200182
Derek Allard2067d1a2008-11-13 22:59:24 +0000183 // If PHP 4 is being used we have to build our own result
184 foreach ($this->result_array() as $key => $val)
185 {
186 $obj = new stdClass();
187 if (is_array($val))
188 {
189 foreach ($val as $k => $v)
190 {
191 $obj->$k = $v;
192 }
193 }
194 else
195 {
196 $obj->$key = $val;
197 }
Barry Mienydd671972010-10-04 16:33:58 +0200198
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 $result[] = $obj;
200 }
201
202 return $result;
203 }
204
205 // --------------------------------------------------------------------
206
207 /**
Derek Jones4b9c6292011-07-01 17:40:48 -0500208 * Query result. "array" version.
Derek Allard2067d1a2008-11-13 22:59:24 +0000209 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500210 * @access public
211 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 */
213 function result_array()
214 {
215 if (count($this->result_array) > 0)
216 {
217 return $this->result_array;
218 }
219
220 // oracle's fetch functions do not return arrays.
221 // The information is returned in reference parameters
222 $row = NULL;
223 while ($this->_fetch_assoc($row))
224 {
225 $this->result_array[] = $row;
226 }
227
228 return $this->result_array;
229 }
230
231 // --------------------------------------------------------------------
232
233 /**
234 * Data Seek
235 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500236 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 * this internally before fetching results to make sure the
238 * result set starts at zero
239 *
240 * @access private
241 * @return array
242 */
243 function _data_seek($n = 0)
244 {
245 return FALSE; // Not needed
246 }
247
248}
249
250
251/* End of file oci8_result.php */
Andrey Andreevef3e2402011-09-21 14:39:29 +0300252/* Location: ./system/database/drivers/oci8/oci8_result.php */