blob: 50612ca671a7b1708992c3afb7e045c9bc886f38 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev24abcb92012-01-05 20:40:15 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev24abcb92012-01-05 20:40:15 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
Andrey Andreev342a4662012-01-24 15:24:00 +020012 * bundled with this package in the files license.txt / license.rst. It is
Derek Jonesf4a4bd82011-10-20 12:18:42 -050013 * 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
darwinel871754a2014-02-11 17:34:57 +010021 * @copyright Copyright (c) 2008 - 2014, 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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * oci8 Result Class
31 *
32 * This class extends the parent result class: CI_DB_result
33 *
34 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @link http://codeigniter.com/user_guide/database/
Andrey Andreev5ca05132012-07-05 12:06:34 +030037 * @since 1.4.1
Derek Allard2067d1a2008-11-13 22:59:24 +000038 */
39class CI_DB_oci8_result extends CI_DB_result {
40
Andrey Andreev8463b912012-11-02 02:16:28 +020041 /**
42 * Statement ID
43 *
44 * @var resource
45 */
Andrey Andreev24abcb92012-01-05 20:40:15 +020046 public $stmt_id;
Andrey Andreev24abcb92012-01-05 20:40:15 +020047
Andrey Andreev5ca05132012-07-05 12:06:34 +030048 /**
Andrey Andreev8463b912012-11-02 02:16:28 +020049 * Cursor ID
Andrey Andreev5ca05132012-07-05 12:06:34 +030050 *
Andrey Andreev8463b912012-11-02 02:16:28 +020051 * @var resource
52 */
53 public $curs_id;
54
55 /**
56 * Limit used flag
57 *
58 * @var bool
59 */
60 public $limit_used;
61
62 /**
63 * Commit mode flag
64 *
65 * @var int
66 */
67 public $commit_mode;
68
69 // --------------------------------------------------------------------
70
71 /**
72 * Class constructor
73 *
74 * @param object &$driver_object
Andrey Andreev5ca05132012-07-05 12:06:34 +030075 * @return void
Andrey Andreev24abcb92012-01-05 20:40:15 +020076 */
Andrey Andreev57bdeb62012-03-05 15:59:16 +020077 public function __construct(&$driver_object)
78 {
79 parent::__construct($driver_object);
Andrey Andreev5ca05132012-07-05 12:06:34 +030080
Andrey Andreev57bdeb62012-03-05 15:59:16 +020081 $this->stmt_id = $driver_object->stmt_id;
82 $this->curs_id = $driver_object->curs_id;
83 $this->limit_used = $driver_object->limit_used;
Andrey Andreev99013ed2012-03-05 16:17:32 +020084 $this->commit_mode =& $driver_object->commit_mode;
Andrey Andreev57bdeb62012-03-05 15:59:16 +020085 $driver_object->stmt_id = FALSE;
86 }
Derek Allard2067d1a2008-11-13 22:59:24 +000087
Andrey Andreev5ca05132012-07-05 12:06:34 +030088 // --------------------------------------------------------------------
89
Derek Allard2067d1a2008-11-13 22:59:24 +000090 /**
Derek Allard2067d1a2008-11-13 22:59:24 +000091 * Number of fields in the result set
92 *
Andrey Andreevaa786c92012-01-16 12:14:45 +020093 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000094 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030095 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000096 {
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +030097 $count = oci_num_fields($this->stmt_id);
Derek Allard2067d1a2008-11-13 22:59:24 +000098
99 // if we used a limit we subtract it
Andrey Andreevaa786c92012-01-16 12:14:45 +0200100 return ($this->limit_used) ? $count - 1 : $count;
Derek Allard2067d1a2008-11-13 22:59:24 +0000101 }
102
103 // --------------------------------------------------------------------
104
105 /**
106 * Fetch Field Names
107 *
108 * Generates an array of column names
109 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000110 * @return array
111 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300112 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +0000113 {
114 $field_names = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300115 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300117 $field_names[] = oci_field_name($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 }
119 return $field_names;
120 }
121
122 // --------------------------------------------------------------------
123
124 /**
125 * Field data
126 *
127 * Generates an array of objects containing field meta-data
128 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200129 * @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 Andreevaa786c92012-01-16 12:14:45 +0200136 $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 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200152 * @return void
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 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200161
162 if (is_resource($this->stmt_id))
163 {
164 oci_free_statement($this->stmt_id);
165 }
166
167 if (is_resource($this->curs_id))
168 {
169 oci_cancel($this->curs_id);
170 $this->curs_id = NULL;
171 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 }
173
174 // --------------------------------------------------------------------
175
176 /**
177 * Result - associative array
178 *
179 * Returns the result set as an array
180 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200181 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300183 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 {
185 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +0300186 return oci_fetch_assoc($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000187 }
188
189 // --------------------------------------------------------------------
190
191 /**
192 * Result - object
193 *
194 * Returns the result set as an object
195 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200196 * @param string $class_name
Andrey Andreevaa786c92012-01-16 12:14:45 +0200197 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000198 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300199 protected function _fetch_object($class_name = 'stdClass')
Barry Mienydd671972010-10-04 16:33:58 +0200200 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300201 $row = ($this->curs_id)
202 ? oci_fetch_object($this->curs_id)
203 : oci_fetch_object($this->stmt_id);
204
205 if ($class_name === 'stdClass' OR ! $row)
206 {
207 return $row;
208 }
209
210 $class_name = new $class_name();
211 foreach ($row as $key => $value)
212 {
213 $class_name->$key = $value;
214 }
215
216 return $class_name;
Andrey Andreev24abcb92012-01-05 20:40:15 +0200217 }
218
Derek Allard2067d1a2008-11-13 22:59:24 +0000219}
220
Derek Allard2067d1a2008-11-13 22:59:24 +0000221/* End of file oci8_result.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400222/* Location: ./system/database/drivers/oci8/oci8_result.php */