Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [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 | * |
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 | 2f56fba | 2012-03-20 22:32:20 +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 | 2f56fba | 2012-03-20 22:32:20 +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 |
| 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 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * oci8 Result Class |
| 30 | * |
| 31 | * This class extends the parent result class: CI_DB_result |
| 32 | * |
| 33 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 34 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/database/ |
| 36 | */ |
| 37 | class CI_DB_oci8_result extends CI_DB_result { |
| 38 | |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 39 | public $stmt_id; |
| 40 | public $curs_id; |
| 41 | public $limit_used; |
| 42 | |
| 43 | public function __construct(&$driver_object) |
| 44 | { |
| 45 | parent::__construct($driver_object); |
| 46 | $this->stmt_id = $driver_object->stmt_id; |
| 47 | $this->curs_id = $driver_object->curs_id; |
| 48 | $this->limit_used = $driver_object->limit_used; |
| 49 | $driver_object->stmt_id = FALSE; |
| 50 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Number of rows in the result set. |
| 54 | * |
| 55 | * Oracle doesn't have a graceful way to retun the number of rows |
| 56 | * so we have to use what amounts to a hack. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 57 | * |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 58 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 59 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 60 | public function num_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 61 | { |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 62 | if ($this->num_rows === 0 && count($this->result_array()) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 63 | { |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 64 | $this->num_rows = count($this->result_array()); |
a-krebs | 0372f1a | 2011-11-23 00:04:34 -0700 | [diff] [blame] | 65 | @oci_execute($this->stmt_id, OCI_DEFAULT); |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 66 | |
| 67 | if ($this->curs_id) |
| 68 | { |
a-krebs | 0372f1a | 2011-11-23 00:04:34 -0700 | [diff] [blame] | 69 | @oci_execute($this->curs_id, OCI_DEFAULT); |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 70 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 73 | return $this->num_rows; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | // -------------------------------------------------------------------- |
| 77 | |
| 78 | /** |
| 79 | * Number of fields in the result set |
| 80 | * |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 81 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 82 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 83 | public function num_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 84 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 85 | $count = @oci_num_fields($this->stmt_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 86 | |
| 87 | // if we used a limit we subtract it |
| 88 | if ($this->limit_used) |
| 89 | { |
| 90 | $count = $count - 1; |
| 91 | } |
| 92 | |
| 93 | return $count; |
| 94 | } |
| 95 | |
| 96 | // -------------------------------------------------------------------- |
| 97 | |
| 98 | /** |
| 99 | * Fetch Field Names |
| 100 | * |
| 101 | * Generates an array of column names |
| 102 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 103 | * @return array |
| 104 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 105 | public function list_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 106 | { |
| 107 | $field_names = array(); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 108 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 109 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 110 | $field_names[] = oci_field_name($this->stmt_id, $c); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 111 | } |
| 112 | return $field_names; |
| 113 | } |
| 114 | |
| 115 | // -------------------------------------------------------------------- |
| 116 | |
| 117 | /** |
| 118 | * Field data |
| 119 | * |
| 120 | * Generates an array of objects containing field meta-data |
| 121 | * |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 122 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 123 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 124 | public function field_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 125 | { |
| 126 | $retval = array(); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 127 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 128 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 129 | $F = new stdClass(); |
| 130 | $F->name = oci_field_name($this->stmt_id, $c); |
| 131 | $F->type = oci_field_type($this->stmt_id, $c); |
| 132 | $F->max_length = oci_field_size($this->stmt_id, $c); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 133 | |
| 134 | $retval[] = $F; |
| 135 | } |
| 136 | |
| 137 | return $retval; |
| 138 | } |
| 139 | |
| 140 | // -------------------------------------------------------------------- |
| 141 | |
| 142 | /** |
| 143 | * Free the result |
| 144 | * |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 145 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 146 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 147 | public function free_result() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 148 | { |
| 149 | if (is_resource($this->result_id)) |
| 150 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 151 | oci_free_statement($this->result_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 152 | $this->result_id = FALSE; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // -------------------------------------------------------------------- |
| 157 | |
| 158 | /** |
| 159 | * Result - associative array |
| 160 | * |
| 161 | * Returns the result set as an array |
| 162 | * |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 163 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 164 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 165 | protected function _fetch_assoc() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 166 | { |
| 167 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 168 | return oci_fetch_assoc($id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | // -------------------------------------------------------------------- |
| 172 | |
| 173 | /** |
| 174 | * Result - object |
| 175 | * |
| 176 | * Returns the result set as an object |
| 177 | * |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 178 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 179 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 180 | protected function _fetch_object() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 181 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 182 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
| 183 | return @oci_fetch_object($id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | // -------------------------------------------------------------------- |
| 187 | |
| 188 | /** |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 189 | * Query result. "array" version. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 190 | * |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 191 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 192 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 193 | public function result_array() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 194 | { |
| 195 | if (count($this->result_array) > 0) |
| 196 | { |
| 197 | return $this->result_array; |
| 198 | } |
| 199 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 200 | $row = NULL; |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 201 | while ($row = $this->_fetch_assoc()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 202 | { |
| 203 | $this->result_array[] = $row; |
| 204 | } |
| 205 | |
| 206 | return $this->result_array; |
| 207 | } |
| 208 | |
| 209 | // -------------------------------------------------------------------- |
| 210 | |
| 211 | /** |
| 212 | * Data Seek |
| 213 | * |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 214 | * Moves the internal pointer to the desired offset. We call |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 215 | * this internally before fetching results to make sure the |
| 216 | * result set starts at zero |
| 217 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 218 | * @return array |
| 219 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 220 | protected function _data_seek($n = 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 221 | { |
| 222 | return FALSE; // Not needed |
| 223 | } |
| 224 | |
| 225 | } |
| 226 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 227 | /* End of file oci8_result.php */ |
Timothy Warren | 215890b | 2012-03-20 09:38:16 -0400 | [diff] [blame] | 228 | /* Location: ./system/database/drivers/oci8/oci8_result.php */ |