Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 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 |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 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 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * oci8 Result Class |
| 32 | * |
| 33 | * This class extends the parent result class: CI_DB_result |
| 34 | * |
| 35 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/database/ |
| 38 | */ |
| 39 | class CI_DB_oci8_result extends CI_DB_result { |
| 40 | |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame^] | 41 | public $stmt_id; |
| 42 | public $curs_id; |
| 43 | public $limit_used; |
| 44 | |
| 45 | public function __construct(&$driver_object) |
| 46 | { |
| 47 | parent::__construct($driver_object); |
| 48 | $this->stmt_id = $driver_object->stmt_id; |
| 49 | $this->curs_id = $driver_object->curs_id; |
| 50 | $this->limit_used = $driver_object->limit_used; |
| 51 | $driver_object->stmt_id = FALSE; |
| 52 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Number of rows in the result set. |
| 56 | * |
| 57 | * Oracle doesn't have a graceful way to retun the number of rows |
| 58 | * so we have to use what amounts to a hack. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 59 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 60 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 61 | * @access public |
| 62 | * @return integer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 63 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 64 | public function num_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 65 | { |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 66 | if ($this->num_rows === 0 && count($this->result_array()) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 67 | { |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 68 | $this->num_rows = count($this->result_array()); |
a-krebs | 0372f1a | 2011-11-23 00:04:34 -0700 | [diff] [blame] | 69 | @oci_execute($this->stmt_id, OCI_DEFAULT); |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 70 | |
| 71 | if ($this->curs_id) |
| 72 | { |
a-krebs | 0372f1a | 2011-11-23 00:04:34 -0700 | [diff] [blame] | 73 | @oci_execute($this->curs_id, OCI_DEFAULT); |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 74 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 77 | return $this->num_rows; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // -------------------------------------------------------------------- |
| 81 | |
| 82 | /** |
| 83 | * Number of fields in the result set |
| 84 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 85 | * @access public |
| 86 | * @return integer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 88 | public function num_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 89 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 90 | $count = @oci_num_fields($this->stmt_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 91 | |
| 92 | // if we used a limit we subtract it |
| 93 | if ($this->limit_used) |
| 94 | { |
| 95 | $count = $count - 1; |
| 96 | } |
| 97 | |
| 98 | return $count; |
| 99 | } |
| 100 | |
| 101 | // -------------------------------------------------------------------- |
| 102 | |
| 103 | /** |
| 104 | * Fetch Field Names |
| 105 | * |
| 106 | * Generates an array of column names |
| 107 | * |
| 108 | * @access public |
| 109 | * @return array |
| 110 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 111 | public function list_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 112 | { |
| 113 | $field_names = array(); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 114 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 115 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 116 | $field_names[] = oci_field_name($this->stmt_id, $c); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 117 | } |
| 118 | return $field_names; |
| 119 | } |
| 120 | |
| 121 | // -------------------------------------------------------------------- |
| 122 | |
| 123 | /** |
| 124 | * Field data |
| 125 | * |
| 126 | * Generates an array of objects containing field meta-data |
| 127 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 128 | * @access public |
| 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 | 5c3a202 | 2011-10-07 21:04:58 +0300 | [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 | * |
| 152 | * @return null |
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 | } |
| 161 | } |
| 162 | |
| 163 | // -------------------------------------------------------------------- |
| 164 | |
| 165 | /** |
| 166 | * Result - associative array |
| 167 | * |
| 168 | * Returns the result set as an array |
| 169 | * |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 170 | * @access protected |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 171 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 172 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 173 | protected function _fetch_assoc() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 174 | { |
| 175 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 176 | return oci_fetch_assoc($id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // -------------------------------------------------------------------- |
| 180 | |
| 181 | /** |
| 182 | * Result - object |
| 183 | * |
| 184 | * Returns the result set as an object |
| 185 | * |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 186 | * @access protected |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 187 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 188 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 189 | protected function _fetch_object() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 190 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 191 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
| 192 | return @oci_fetch_object($id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // -------------------------------------------------------------------- |
| 196 | |
| 197 | /** |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 198 | * Query result. "array" version. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 199 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 200 | * @access public |
| 201 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 202 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 203 | public function result_array() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 204 | { |
| 205 | if (count($this->result_array) > 0) |
| 206 | { |
| 207 | return $this->result_array; |
| 208 | } |
| 209 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 210 | $row = NULL; |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 211 | while ($row = $this->_fetch_assoc()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | { |
| 213 | $this->result_array[] = $row; |
| 214 | } |
| 215 | |
| 216 | return $this->result_array; |
| 217 | } |
| 218 | |
| 219 | // -------------------------------------------------------------------- |
| 220 | |
| 221 | /** |
| 222 | * Data Seek |
| 223 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 224 | * Moves the internal pointer to the desired offset. We call |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | * this internally before fetching results to make sure the |
| 226 | * result set starts at zero |
| 227 | * |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 228 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 229 | * @return array |
| 230 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 231 | protected function _data_seek($n = 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 232 | { |
| 233 | return FALSE; // Not needed |
| 234 | } |
| 235 | |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /* End of file oci8_result.php */ |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 240 | /* Location: ./system/database/drivers/oci8/oci8_result.php */ |