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 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
Andrey Andreev | 342a466 | 2012-01-24 15:24:00 +0200 | [diff] [blame] | 12 | * bundled with this package in the files license.txt / license.rst. It is |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 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 Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 24 | * @since Version 1.0 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame^] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 29 | /** |
| 30 | * oci8 Result Class |
| 31 | * |
| 32 | * This class extends the parent result class: CI_DB_result |
| 33 | * |
| 34 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 35 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @link http://codeigniter.com/user_guide/database/ |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 37 | * @since 1.4.1 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 38 | */ |
| 39 | class CI_DB_oci8_result extends CI_DB_result { |
| 40 | |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 41 | public $stmt_id; |
| 42 | public $curs_id; |
| 43 | public $limit_used; |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 44 | public $commit_mode; |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 45 | |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 46 | /** |
| 47 | * Constructor |
| 48 | * |
| 49 | * @param object |
| 50 | * @return void |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 51 | */ |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 52 | public function __construct(&$driver_object) |
| 53 | { |
| 54 | parent::__construct($driver_object); |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 55 | |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 56 | $this->stmt_id = $driver_object->stmt_id; |
| 57 | $this->curs_id = $driver_object->curs_id; |
| 58 | $this->limit_used = $driver_object->limit_used; |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 59 | $this->commit_mode =& $driver_object->commit_mode; |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 60 | $driver_object->stmt_id = FALSE; |
| 61 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 62 | |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 63 | // -------------------------------------------------------------------- |
| 64 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 65 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 66 | * Number of fields in the result set |
| 67 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 68 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 69 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 70 | public function num_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 72 | $count = @oci_num_fields($this->stmt_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | |
| 74 | // if we used a limit we subtract it |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 75 | return ($this->limit_used) ? $count - 1 : $count; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | // -------------------------------------------------------------------- |
| 79 | |
| 80 | /** |
| 81 | * Fetch Field Names |
| 82 | * |
| 83 | * Generates an array of column names |
| 84 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 85 | * @return array |
| 86 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 87 | public function list_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 88 | { |
| 89 | $field_names = array(); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 90 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 91 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 92 | $field_names[] = oci_field_name($this->stmt_id, $c); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 93 | } |
| 94 | return $field_names; |
| 95 | } |
| 96 | |
| 97 | // -------------------------------------------------------------------- |
| 98 | |
| 99 | /** |
| 100 | * Field data |
| 101 | * |
| 102 | * Generates an array of objects containing field meta-data |
| 103 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 104 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 105 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 106 | public function field_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 107 | { |
| 108 | $retval = array(); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 109 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 110 | { |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 111 | $F = new stdClass(); |
| 112 | $F->name = oci_field_name($this->stmt_id, $c); |
| 113 | $F->type = oci_field_type($this->stmt_id, $c); |
| 114 | $F->max_length = oci_field_size($this->stmt_id, $c); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 115 | |
| 116 | $retval[] = $F; |
| 117 | } |
| 118 | |
| 119 | return $retval; |
| 120 | } |
| 121 | |
| 122 | // -------------------------------------------------------------------- |
| 123 | |
| 124 | /** |
| 125 | * Free the result |
| 126 | * |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 127 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 128 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 129 | public function free_result() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 130 | { |
| 131 | if (is_resource($this->result_id)) |
| 132 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 133 | oci_free_statement($this->result_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 134 | $this->result_id = FALSE; |
| 135 | } |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 136 | |
| 137 | if (is_resource($this->stmt_id)) |
| 138 | { |
| 139 | oci_free_statement($this->stmt_id); |
| 140 | } |
| 141 | |
| 142 | if (is_resource($this->curs_id)) |
| 143 | { |
| 144 | oci_cancel($this->curs_id); |
| 145 | $this->curs_id = NULL; |
| 146 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | // -------------------------------------------------------------------- |
| 150 | |
| 151 | /** |
| 152 | * Result - associative array |
| 153 | * |
| 154 | * Returns the result set as an array |
| 155 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 156 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 157 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 158 | protected function _fetch_assoc() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 159 | { |
| 160 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
Yannick Lyn Fatt | 642e313 | 2012-08-13 14:41:17 -0500 | [diff] [blame] | 161 | return @oci_fetch_assoc($id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | // -------------------------------------------------------------------- |
| 165 | |
| 166 | /** |
| 167 | * Result - object |
| 168 | * |
| 169 | * Returns the result set as an object |
| 170 | * |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 171 | * @param string |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 172 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 173 | */ |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 174 | protected function _fetch_object($class_name = 'stdClass') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 175 | { |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 176 | $row = ($this->curs_id) |
| 177 | ? oci_fetch_object($this->curs_id) |
| 178 | : oci_fetch_object($this->stmt_id); |
| 179 | |
| 180 | if ($class_name === 'stdClass' OR ! $row) |
| 181 | { |
| 182 | return $row; |
| 183 | } |
| 184 | |
| 185 | $class_name = new $class_name(); |
| 186 | foreach ($row as $key => $value) |
| 187 | { |
| 188 | $class_name->$key = $value; |
| 189 | } |
| 190 | |
| 191 | return $class_name; |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | // -------------------------------------------------------------------- |
| 195 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 196 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 197 | * Data Seek |
| 198 | * |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 199 | * Moves the internal pointer to the desired offset. We call |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 200 | * this internally before fetching results to make sure the |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 201 | * result set starts at zero. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 202 | * |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 203 | * Oracle's PHP extension doesn't have an easy way of doing this |
| 204 | * and the only workaround is to (re)execute the statement or cursor |
| 205 | * in order to go to the first (zero) index of the result set. |
| 206 | * Then, we would need to "dummy" fetch ($n - 1) rows to get to the |
| 207 | * right one. |
| 208 | * |
| 209 | * This is as ridiculous as it sounds and it's the reason why every |
| 210 | * other method that is fetching data tries to use an already "cached" |
| 211 | * result set. Keeping this just in case it becomes needed at |
| 212 | * some point in the future, but it will only work for resetting the |
| 213 | * pointer to zero. |
| 214 | * |
| 215 | * @return bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 216 | */ |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 217 | protected function _data_seek() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 218 | { |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 219 | /* The PHP manual says that if OCI_NO_AUTO_COMMIT mode |
| 220 | * is used, and oci_rollback() and/or oci_commit() are |
| 221 | * not subsequently called - this will cause an unnecessary |
| 222 | * rollback to be triggered at the end of the script execution. |
| 223 | * |
| 224 | * Therefore we'll try to avoid using that mode flag |
| 225 | * if we're not currently in the middle of a transaction. |
| 226 | */ |
| 227 | if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS) |
| 228 | { |
| 229 | $result = @oci_execute($this->stmt_id, $this->commit_mode); |
| 230 | } |
| 231 | else |
| 232 | { |
| 233 | $result = @oci_execute($this->stmt_id); |
| 234 | } |
| 235 | |
| 236 | if ($result && $this->curs_id) |
| 237 | { |
| 238 | if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS) |
| 239 | { |
| 240 | return @oci_execute($this->curs_id, $this->commit_mode); |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | return @oci_execute($this->curs_id); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return $result; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | } |
| 252 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 253 | /* End of file oci8_result.php */ |
Timothy Warren | 215890b | 2012-03-20 09:38:16 -0400 | [diff] [blame] | 254 | /* Location: ./system/database/drivers/oci8/oci8_result.php */ |