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 |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2014, 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 | 8463b91 | 2012-11-02 02:16:28 +0200 | [diff] [blame] | 41 | /** |
| 42 | * Statement ID |
| 43 | * |
| 44 | * @var resource |
| 45 | */ |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 46 | public $stmt_id; |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 47 | |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 48 | /** |
Andrey Andreev | 8463b91 | 2012-11-02 02:16:28 +0200 | [diff] [blame] | 49 | * Cursor ID |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 50 | * |
Andrey Andreev | 8463b91 | 2012-11-02 02:16:28 +0200 | [diff] [blame] | 51 | * @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 Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 75 | * @return void |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 76 | */ |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 77 | public function __construct(&$driver_object) |
| 78 | { |
| 79 | parent::__construct($driver_object); |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 80 | |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 81 | $this->stmt_id = $driver_object->stmt_id; |
| 82 | $this->curs_id = $driver_object->curs_id; |
| 83 | $this->limit_used = $driver_object->limit_used; |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 84 | $this->commit_mode =& $driver_object->commit_mode; |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 85 | $driver_object->stmt_id = FALSE; |
| 86 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 88 | // -------------------------------------------------------------------- |
| 89 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 90 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 91 | * Number of fields in the result set |
| 92 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 93 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 94 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 95 | public function num_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 96 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame^] | 97 | $count = oci_num_fields($this->stmt_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 98 | |
| 99 | // if we used a limit we subtract it |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 100 | return ($this->limit_used) ? $count - 1 : $count; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // -------------------------------------------------------------------- |
| 104 | |
| 105 | /** |
| 106 | * Fetch Field Names |
| 107 | * |
| 108 | * Generates an array of column names |
| 109 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 110 | * @return array |
| 111 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 112 | public function list_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 113 | { |
| 114 | $field_names = array(); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 115 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 116 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 117 | $field_names[] = oci_field_name($this->stmt_id, $c); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | } |
| 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 Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 129 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 130 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 131 | public function field_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 132 | { |
| 133 | $retval = array(); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 134 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 135 | { |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 136 | $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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 140 | |
| 141 | $retval[] = $F; |
| 142 | } |
| 143 | |
| 144 | return $retval; |
| 145 | } |
| 146 | |
| 147 | // -------------------------------------------------------------------- |
| 148 | |
| 149 | /** |
| 150 | * Free the result |
| 151 | * |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 152 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 153 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 154 | public function free_result() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 155 | { |
| 156 | if (is_resource($this->result_id)) |
| 157 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 158 | oci_free_statement($this->result_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 159 | $this->result_id = FALSE; |
| 160 | } |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 161 | |
| 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | // -------------------------------------------------------------------- |
| 175 | |
| 176 | /** |
| 177 | * Result - associative array |
| 178 | * |
| 179 | * Returns the result set as an array |
| 180 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 181 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 183 | protected function _fetch_assoc() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 184 | { |
| 185 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame^] | 186 | return oci_fetch_assoc($id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | // -------------------------------------------------------------------- |
| 190 | |
| 191 | /** |
| 192 | * Result - object |
| 193 | * |
| 194 | * Returns the result set as an object |
| 195 | * |
Andrey Andreev | 8463b91 | 2012-11-02 02:16:28 +0200 | [diff] [blame] | 196 | * @param string $class_name |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 197 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 198 | */ |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 199 | protected function _fetch_object($class_name = 'stdClass') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 200 | { |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 201 | $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 Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 221 | /* End of file oci8_result.php */ |
Timothy Warren | 215890b | 2012-03-20 09:38:16 -0400 | [diff] [blame] | 222 | /* Location: ./system/database/drivers/oci8/oci8_result.php */ |