blob: 383b9f1a06c86ec632d58a2163e9feb734580c1f [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
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @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
Andrey Andreev57bdeb62012-03-05 15:59:16 +020041 public $stmt_id;
42 public $curs_id;
43 public $limit_used;
44
45 public function __construct(&$driver_object)
46 {
47 parent::__construct($driver_object);
48 $this->stmt_id = $driver_object->stmt_id;
49 $this->curs_id = $driver_object->curs_id;
50 $this->limit_used = $driver_object->limit_used;
51 $driver_object->stmt_id = FALSE;
52 }
Derek Allard2067d1a2008-11-13 22:59:24 +000053
54 /**
55 * Number of rows in the result set.
56 *
57 * Oracle doesn't have a graceful way to retun the number of rows
58 * so we have to use what amounts to a hack.
Barry Mienydd671972010-10-04 16:33:58 +020059 *
Derek Allard2067d1a2008-11-13 22:59:24 +000060 *
Derek Jones4b9c6292011-07-01 17:40:48 -050061 * @access public
62 * @return integer
Derek Allard2067d1a2008-11-13 22:59:24 +000063 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030064 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000065 {
Andrey Andreevef3e2402011-09-21 14:39:29 +030066 if ($this->num_rows === 0 && count($this->result_array()) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +000067 {
Andrey Andreevef3e2402011-09-21 14:39:29 +030068 $this->num_rows = count($this->result_array());
a-krebs0372f1a2011-11-23 00:04:34 -070069 @oci_execute($this->stmt_id, OCI_DEFAULT);
Andrey Andreevef3e2402011-09-21 14:39:29 +030070
71 if ($this->curs_id)
72 {
a-krebs0372f1a2011-11-23 00:04:34 -070073 @oci_execute($this->curs_id, OCI_DEFAULT);
Andrey Andreevef3e2402011-09-21 14:39:29 +030074 }
Derek Allard2067d1a2008-11-13 22:59:24 +000075 }
76
Andrey Andreevef3e2402011-09-21 14:39:29 +030077 return $this->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000078 }
79
80 // --------------------------------------------------------------------
81
82 /**
83 * Number of fields in the result set
84 *
Derek Jones4b9c6292011-07-01 17:40:48 -050085 * @access public
86 * @return integer
Derek Allard2067d1a2008-11-13 22:59:24 +000087 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030088 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000089 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +030090 $count = @oci_num_fields($this->stmt_id);
Derek Allard2067d1a2008-11-13 22:59:24 +000091
92 // if we used a limit we subtract it
93 if ($this->limit_used)
94 {
95 $count = $count - 1;
96 }
97
98 return $count;
99 }
100
101 // --------------------------------------------------------------------
102
103 /**
104 * Fetch Field Names
105 *
106 * Generates an array of column names
107 *
108 * @access public
109 * @return array
110 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300111 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 {
113 $field_names = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300114 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000115 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300116 $field_names[] = oci_field_name($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000117 }
118 return $field_names;
119 }
120
121 // --------------------------------------------------------------------
122
123 /**
124 * Field data
125 *
126 * Generates an array of objects containing field meta-data
127 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500128 * @access public
129 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000130 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300131 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 {
133 $retval = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300134 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300136 $F = new stdClass();
137 $F->name = oci_field_name($this->stmt_id, $c);
138 $F->type = oci_field_type($this->stmt_id, $c);
139 $F->max_length = oci_field_size($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000140
141 $retval[] = $F;
142 }
143
144 return $retval;
145 }
146
147 // --------------------------------------------------------------------
148
149 /**
150 * Free the result
151 *
152 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200153 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300154 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 {
156 if (is_resource($this->result_id))
157 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300158 oci_free_statement($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000159 $this->result_id = FALSE;
160 }
161 }
162
163 // --------------------------------------------------------------------
164
165 /**
166 * Result - associative array
167 *
168 * Returns the result set as an array
169 *
Andrey Andreevbc95e472011-10-20 09:44:48 +0300170 * @access protected
Derek Jones4b9c6292011-07-01 17:40:48 -0500171 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300173 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000174 {
175 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300176 return oci_fetch_assoc($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 }
178
179 // --------------------------------------------------------------------
180
181 /**
182 * Result - object
183 *
184 * Returns the result set as an object
185 *
Andrey Andreevbc95e472011-10-20 09:44:48 +0300186 * @access protected
Derek Jones4b9c6292011-07-01 17:40:48 -0500187 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300189 protected function _fetch_object()
Barry Mienydd671972010-10-04 16:33:58 +0200190 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300191 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
192 return @oci_fetch_object($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 }
194
195 // --------------------------------------------------------------------
196
197 /**
Derek Jones4b9c6292011-07-01 17:40:48 -0500198 * Query result. "array" version.
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500200 * @access public
201 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300203 public function result_array()
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 {
205 if (count($this->result_array) > 0)
206 {
207 return $this->result_array;
208 }
209
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 $row = NULL;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300211 while ($row = $this->_fetch_assoc())
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 {
213 $this->result_array[] = $row;
214 }
215
216 return $this->result_array;
217 }
218
219 // --------------------------------------------------------------------
220
221 /**
222 * Data Seek
223 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500224 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 * this internally before fetching results to make sure the
226 * result set starts at zero
227 *
Andrey Andreevbc95e472011-10-20 09:44:48 +0300228 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 * @return array
230 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300231 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 {
233 return FALSE; // Not needed
234 }
235
236}
237
238
239/* End of file oci8_result.php */
Andrey Andreevef3e2402011-09-21 14:39:29 +0300240/* Location: ./system/database/drivers/oci8/oci8_result.php */