blob: 3ec71a9d64b9572a5092149d24d840f7ab7e17ad [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 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030055 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000056 {
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());
Andrey Andreev5c3a2022011-10-07 21:04:58 +030060 @oci_execute($this->stmt_id);
Andrey Andreevef3e2402011-09-21 14:39:29 +030061
62 if ($this->curs_id)
63 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +030064 @oci_execute($this->curs_id);
Andrey Andreevef3e2402011-09-21 14:39:29 +030065 }
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 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030079 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000080 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +030081 $count = @oci_num_fields($this->stmt_id);
Derek Allard2067d1a2008-11-13 22:59:24 +000082
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 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300102 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +0000103 {
104 $field_names = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300105 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300107 $field_names[] = oci_field_name($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 }
109 return $field_names;
110 }
111
112 // --------------------------------------------------------------------
113
114 /**
115 * Field data
116 *
117 * Generates an array of objects containing field meta-data
118 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500119 * @access public
120 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300122 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 {
124 $retval = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300125 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000126 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300127 $F = new stdClass();
128 $F->name = oci_field_name($this->stmt_id, $c);
129 $F->type = oci_field_type($this->stmt_id, $c);
130 $F->max_length = oci_field_size($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000131
132 $retval[] = $F;
133 }
134
135 return $retval;
136 }
137
138 // --------------------------------------------------------------------
139
140 /**
141 * Free the result
142 *
143 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200144 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300145 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 {
147 if (is_resource($this->result_id))
148 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300149 oci_free_statement($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000150 $this->result_id = FALSE;
151 }
152 }
153
154 // --------------------------------------------------------------------
155
156 /**
157 * Result - associative array
158 *
159 * Returns the result set as an array
160 *
Andrey Andreevbc95e472011-10-20 09:44:48 +0300161 * @access protected
Derek Jones4b9c6292011-07-01 17:40:48 -0500162 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300164 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 {
166 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300167 return oci_fetch_assoc($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 }
169
170 // --------------------------------------------------------------------
171
172 /**
173 * Result - object
174 *
175 * Returns the result set as an object
176 *
Andrey Andreevbc95e472011-10-20 09:44:48 +0300177 * @access protected
Derek Jones4b9c6292011-07-01 17:40:48 -0500178 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000179 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300180 protected function _fetch_object()
Barry Mienydd671972010-10-04 16:33:58 +0200181 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300182 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
183 return @oci_fetch_object($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 }
185
186 // --------------------------------------------------------------------
187
188 /**
Derek Jones4b9c6292011-07-01 17:40:48 -0500189 * Query result. "array" version.
Derek Allard2067d1a2008-11-13 22:59:24 +0000190 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500191 * @access public
192 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300194 public function result_array()
Derek Allard2067d1a2008-11-13 22:59:24 +0000195 {
196 if (count($this->result_array) > 0)
197 {
198 return $this->result_array;
199 }
200
Derek Allard2067d1a2008-11-13 22:59:24 +0000201 $row = NULL;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300202 while ($row = $this->_fetch_assoc())
Derek Allard2067d1a2008-11-13 22:59:24 +0000203 {
204 $this->result_array[] = $row;
205 }
206
207 return $this->result_array;
208 }
209
210 // --------------------------------------------------------------------
211
212 /**
213 * Data Seek
214 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500215 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000216 * this internally before fetching results to make sure the
217 * result set starts at zero
218 *
Andrey Andreevbc95e472011-10-20 09:44:48 +0300219 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 * @return array
221 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300222 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000223 {
224 return FALSE; // Not needed
225 }
226
227}
228
229
230/* End of file oci8_result.php */
Andrey Andreevef3e2402011-09-21 14:39:29 +0300231/* Location: ./system/database/drivers/oci8/oci8_result.php */