Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014 - 2018, British Columbia Institute of Technology |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * 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 Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * 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 Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 1.4.1 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | /** |
| 41 | * oci8 Result Class |
| 42 | * |
| 43 | * This class extends the parent result class: CI_DB_result |
| 44 | * |
| 45 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 46 | * @author EllisLab Dev Team |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 47 | * @link https://codeigniter.com/user_guide/database/ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 48 | */ |
| 49 | class CI_DB_oci8_result extends CI_DB_result { |
| 50 | |
Andrey Andreev | 8463b91 | 2012-11-02 02:16:28 +0200 | [diff] [blame] | 51 | /** |
| 52 | * Statement ID |
| 53 | * |
| 54 | * @var resource |
| 55 | */ |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 56 | public $stmt_id; |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 57 | |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 58 | /** |
Andrey Andreev | 8463b91 | 2012-11-02 02:16:28 +0200 | [diff] [blame] | 59 | * Cursor ID |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 60 | * |
Andrey Andreev | 8463b91 | 2012-11-02 02:16:28 +0200 | [diff] [blame] | 61 | * @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 Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 85 | * @return void |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 86 | */ |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 87 | public function __construct(&$driver_object) |
| 88 | { |
| 89 | parent::__construct($driver_object); |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 90 | |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 91 | $this->stmt_id = $driver_object->stmt_id; |
| 92 | $this->curs_id = $driver_object->curs_id; |
| 93 | $this->limit_used = $driver_object->limit_used; |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 94 | $this->commit_mode =& $driver_object->commit_mode; |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 95 | $driver_object->stmt_id = FALSE; |
| 96 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 97 | |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 98 | // -------------------------------------------------------------------- |
| 99 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 101 | * Number of fields in the result set |
| 102 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 103 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 104 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 105 | public function num_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 106 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame] | 107 | $count = oci_num_fields($this->stmt_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 108 | |
| 109 | // if we used a limit we subtract it |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 110 | return ($this->limit_used) ? $count - 1 : $count; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | // -------------------------------------------------------------------- |
| 114 | |
| 115 | /** |
| 116 | * Fetch Field Names |
| 117 | * |
| 118 | * Generates an array of column names |
| 119 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 120 | * @return array |
| 121 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 122 | public function list_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 123 | { |
| 124 | $field_names = array(); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 125 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 126 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 127 | $field_names[] = oci_field_name($this->stmt_id, $c); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 128 | } |
| 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 Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 139 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 140 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 141 | public function field_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 142 | { |
| 143 | $retval = array(); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 144 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 145 | { |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 146 | $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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 150 | |
| 151 | $retval[] = $F; |
| 152 | } |
| 153 | |
| 154 | return $retval; |
| 155 | } |
| 156 | |
| 157 | // -------------------------------------------------------------------- |
| 158 | |
| 159 | /** |
| 160 | * Free the result |
| 161 | * |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 162 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 163 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 164 | public function free_result() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 165 | { |
| 166 | if (is_resource($this->result_id)) |
| 167 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 168 | oci_free_statement($this->result_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | $this->result_id = FALSE; |
| 170 | } |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 171 | |
| 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // -------------------------------------------------------------------- |
| 185 | |
| 186 | /** |
| 187 | * Result - associative array |
| 188 | * |
| 189 | * Returns the result set as an array |
| 190 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 191 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 192 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 193 | protected function _fetch_assoc() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 194 | { |
| 195 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame] | 196 | return oci_fetch_assoc($id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | // -------------------------------------------------------------------- |
| 200 | |
| 201 | /** |
| 202 | * Result - object |
| 203 | * |
| 204 | * Returns the result set as an object |
| 205 | * |
Andrey Andreev | 8463b91 | 2012-11-02 02:16:28 +0200 | [diff] [blame] | 206 | * @param string $class_name |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 207 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 208 | */ |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 209 | protected function _fetch_object($class_name = 'stdClass') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 210 | { |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 211 | $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 Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 229 | } |