blob: 1c4196f2766d2563847dac3cd377983daeb04989 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02005 * An open source application development framework for PHP
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02007 * This content is released under the MIT License (MIT)
Andrey Andreev24abcb92012-01-05 20:40:15 +02008 *
Andrey Andreevcce6bd12018-01-09 11:32:02 +02009 * Copyright (c) 2014 - 2018, British Columbia Institute of Technology
Andrey Andreev24abcb92012-01-05 20:40:15 +020010 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020011 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
Derek Jonesf4a4bd82011-10-20 12:18:42 -050017 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020018 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 *
29 * @package CodeIgniter
30 * @author EllisLab Dev Team
Andrey Andreev1924e872016-01-11 12:55:34 +020031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
Andrey Andreevcce6bd12018-01-09 11:32:02 +020032 * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020033 * @license http://opensource.org/licenses/MIT MIT License
Andrey Andreevbd202c92016-01-11 12:50:18 +020034 * @link https://codeigniter.com
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020035 * @since Version 1.4.1
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @filesource
37 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020038defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000039
Derek Allard2067d1a2008-11-13 22:59:24 +000040/**
41 * oci8 Result Class
42 *
43 * This class extends the parent result class: CI_DB_result
44 *
45 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050046 * @author EllisLab Dev Team
Andrey Andreevbd202c92016-01-11 12:50:18 +020047 * @link https://codeigniter.com/user_guide/database/
Derek Allard2067d1a2008-11-13 22:59:24 +000048 */
49class CI_DB_oci8_result extends CI_DB_result {
50
Andrey Andreev8463b912012-11-02 02:16:28 +020051 /**
52 * Statement ID
53 *
54 * @var resource
55 */
Andrey Andreev24abcb92012-01-05 20:40:15 +020056 public $stmt_id;
Andrey Andreev24abcb92012-01-05 20:40:15 +020057
Andrey Andreev5ca05132012-07-05 12:06:34 +030058 /**
Andrey Andreev8463b912012-11-02 02:16:28 +020059 * Cursor ID
Andrey Andreev5ca05132012-07-05 12:06:34 +030060 *
Andrey Andreev8463b912012-11-02 02:16:28 +020061 * @var resource
62 */
63 public $curs_id;
64
65 /**
66 * Limit used flag
67 *
68 * @var bool
69 */
70 public $limit_used;
71
72 /**
73 * Commit mode flag
74 *
75 * @var int
76 */
77 public $commit_mode;
78
79 // --------------------------------------------------------------------
80
81 /**
82 * Class constructor
83 *
84 * @param object &$driver_object
Andrey Andreev5ca05132012-07-05 12:06:34 +030085 * @return void
Andrey Andreev24abcb92012-01-05 20:40:15 +020086 */
Andrey Andreev57bdeb62012-03-05 15:59:16 +020087 public function __construct(&$driver_object)
88 {
89 parent::__construct($driver_object);
Andrey Andreev5ca05132012-07-05 12:06:34 +030090
Andrey Andreev57bdeb62012-03-05 15:59:16 +020091 $this->stmt_id = $driver_object->stmt_id;
92 $this->curs_id = $driver_object->curs_id;
93 $this->limit_used = $driver_object->limit_used;
Andrey Andreev99013ed2012-03-05 16:17:32 +020094 $this->commit_mode =& $driver_object->commit_mode;
Andrey Andreev57bdeb62012-03-05 15:59:16 +020095 $driver_object->stmt_id = FALSE;
96 }
Derek Allard2067d1a2008-11-13 22:59:24 +000097
Andrey Andreev5ca05132012-07-05 12:06:34 +030098 // --------------------------------------------------------------------
99
Derek Allard2067d1a2008-11-13 22:59:24 +0000100 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000101 * Number of fields in the result set
102 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200103 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000104 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300105 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 {
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +0300107 $count = oci_num_fields($this->stmt_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000108
109 // if we used a limit we subtract it
Andrey Andreevaa786c92012-01-16 12:14:45 +0200110 return ($this->limit_used) ? $count - 1 : $count;
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 }
112
113 // --------------------------------------------------------------------
114
115 /**
116 * Fetch Field Names
117 *
118 * Generates an array of column names
119 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 * @return array
121 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300122 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 {
124 $field_names = 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 $field_names[] = oci_field_name($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 }
129 return $field_names;
130 }
131
132 // --------------------------------------------------------------------
133
134 /**
135 * Field data
136 *
137 * Generates an array of objects containing field meta-data
138 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200139 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300141 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000142 {
143 $retval = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300144 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 {
Andrey Andreevaa786c92012-01-16 12:14:45 +0200146 $F = new stdClass();
147 $F->name = oci_field_name($this->stmt_id, $c);
148 $F->type = oci_field_type($this->stmt_id, $c);
149 $F->max_length = oci_field_size($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000150
151 $retval[] = $F;
152 }
153
154 return $retval;
155 }
156
157 // --------------------------------------------------------------------
158
159 /**
160 * Free the result
161 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200162 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200163 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300164 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 {
166 if (is_resource($this->result_id))
167 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300168 oci_free_statement($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 $this->result_id = FALSE;
170 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200171
172 if (is_resource($this->stmt_id))
173 {
174 oci_free_statement($this->stmt_id);
175 }
176
177 if (is_resource($this->curs_id))
178 {
179 oci_cancel($this->curs_id);
180 $this->curs_id = NULL;
181 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 }
183
184 // --------------------------------------------------------------------
185
186 /**
187 * Result - associative array
188 *
189 * Returns the result set as an array
190 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200191 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300193 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 {
195 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +0300196 return oci_fetch_assoc($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000197 }
198
199 // --------------------------------------------------------------------
200
201 /**
202 * Result - object
203 *
204 * Returns the result set as an object
205 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200206 * @param string $class_name
Andrey Andreevaa786c92012-01-16 12:14:45 +0200207 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300209 protected function _fetch_object($class_name = 'stdClass')
Barry Mienydd671972010-10-04 16:33:58 +0200210 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300211 $row = ($this->curs_id)
212 ? oci_fetch_object($this->curs_id)
213 : oci_fetch_object($this->stmt_id);
214
215 if ($class_name === 'stdClass' OR ! $row)
216 {
217 return $row;
218 }
219
220 $class_name = new $class_name();
221 foreach ($row as $key => $value)
222 {
223 $class_name->$key = $value;
224 }
225
226 return $class_name;
Andrey Andreev24abcb92012-01-05 20:40:15 +0200227 }
228
Derek Allard2067d1a2008-11-13 22:59:24 +0000229}