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 |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 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 | |
| 41 | var $stmt_id; |
| 42 | var $curs_id; |
| 43 | var $limit_used; |
| 44 | |
| 45 | /** |
| 46 | * Number of rows in the result set. |
| 47 | * |
| 48 | * Oracle doesn't have a graceful way to retun the number of rows |
| 49 | * so we have to use what amounts to a hack. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 50 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 51 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 52 | * @access public |
| 53 | * @return integer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 54 | */ |
| 55 | function num_rows() |
| 56 | { |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 57 | if ($this->num_rows === 0 && count($this->result_array()) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 58 | { |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 59 | $this->num_rows = count($this->result_array()); |
| 60 | @ociexecute($this->stmt_id); |
| 61 | |
| 62 | if ($this->curs_id) |
| 63 | { |
| 64 | @ociexecute($this->curs_id); |
| 65 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 68 | return $this->num_rows; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | // -------------------------------------------------------------------- |
| 72 | |
| 73 | /** |
| 74 | * Number of fields in the result set |
| 75 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 76 | * @access public |
| 77 | * @return integer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 78 | */ |
| 79 | function num_fields() |
| 80 | { |
| 81 | $count = @ocinumcols($this->stmt_id); |
| 82 | |
| 83 | // if we used a limit we subtract it |
| 84 | if ($this->limit_used) |
| 85 | { |
| 86 | $count = $count - 1; |
| 87 | } |
| 88 | |
| 89 | return $count; |
| 90 | } |
| 91 | |
| 92 | // -------------------------------------------------------------------- |
| 93 | |
| 94 | /** |
| 95 | * Fetch Field Names |
| 96 | * |
| 97 | * Generates an array of column names |
| 98 | * |
| 99 | * @access public |
| 100 | * @return array |
| 101 | */ |
| 102 | function list_fields() |
| 103 | { |
| 104 | $field_names = array(); |
| 105 | $fieldCount = $this->num_fields(); |
| 106 | for ($c = 1; $c <= $fieldCount; $c++) |
| 107 | { |
| 108 | $field_names[] = ocicolumnname($this->stmt_id, $c); |
| 109 | } |
| 110 | return $field_names; |
| 111 | } |
| 112 | |
| 113 | // -------------------------------------------------------------------- |
| 114 | |
| 115 | /** |
| 116 | * Field data |
| 117 | * |
| 118 | * Generates an array of objects containing field meta-data |
| 119 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 120 | * @access public |
| 121 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 122 | */ |
| 123 | function field_data() |
| 124 | { |
| 125 | $retval = array(); |
| 126 | $fieldCount = $this->num_fields(); |
| 127 | for ($c = 1; $c <= $fieldCount; $c++) |
| 128 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 129 | $F = new stdClass(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 130 | $F->name = ocicolumnname($this->stmt_id, $c); |
| 131 | $F->type = ocicolumntype($this->stmt_id, $c); |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 132 | $F->max_length = ocicolumnsize($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 | * |
| 145 | * @return null |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 146 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 147 | function free_result() |
| 148 | { |
| 149 | if (is_resource($this->result_id)) |
| 150 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 151 | ocifreestatement($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 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 163 | * @access private |
| 164 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 165 | */ |
| 166 | function _fetch_assoc(&$row) |
| 167 | { |
| 168 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 169 | |
| 170 | return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // -------------------------------------------------------------------- |
| 174 | |
| 175 | /** |
| 176 | * Result - object |
| 177 | * |
| 178 | * Returns the result set as an object |
| 179 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 180 | * @access private |
| 181 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | */ |
| 183 | function _fetch_object() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 184 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | $result = array(); |
| 186 | |
| 187 | // If PHP 5 is being used we can fetch an result object |
| 188 | if (function_exists('oci_fetch_object')) |
| 189 | { |
| 190 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 191 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 192 | return @oci_fetch_object($id); |
| 193 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 194 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | // If PHP 4 is being used we have to build our own result |
| 196 | foreach ($this->result_array() as $key => $val) |
| 197 | { |
| 198 | $obj = new stdClass(); |
| 199 | if (is_array($val)) |
| 200 | { |
| 201 | foreach ($val as $k => $v) |
| 202 | { |
| 203 | $obj->$k = $v; |
| 204 | } |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | $obj->$key = $val; |
| 209 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 210 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 211 | $result[] = $obj; |
| 212 | } |
| 213 | |
| 214 | return $result; |
| 215 | } |
| 216 | |
| 217 | // -------------------------------------------------------------------- |
| 218 | |
| 219 | /** |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 220 | * Query result. "array" version. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 221 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 222 | * @access public |
| 223 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 224 | */ |
| 225 | function result_array() |
| 226 | { |
| 227 | if (count($this->result_array) > 0) |
| 228 | { |
| 229 | return $this->result_array; |
| 230 | } |
| 231 | |
| 232 | // oracle's fetch functions do not return arrays. |
| 233 | // The information is returned in reference parameters |
| 234 | $row = NULL; |
| 235 | while ($this->_fetch_assoc($row)) |
| 236 | { |
| 237 | $this->result_array[] = $row; |
| 238 | } |
| 239 | |
| 240 | return $this->result_array; |
| 241 | } |
| 242 | |
| 243 | // -------------------------------------------------------------------- |
| 244 | |
| 245 | /** |
| 246 | * Data Seek |
| 247 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 248 | * Moves the internal pointer to the desired offset. We call |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 249 | * this internally before fetching results to make sure the |
| 250 | * result set starts at zero |
| 251 | * |
| 252 | * @access private |
| 253 | * @return array |
| 254 | */ |
| 255 | function _data_seek($n = 0) |
| 256 | { |
| 257 | return FALSE; // Not needed |
| 258 | } |
| 259 | |
| 260 | } |
| 261 | |
| 262 | |
| 263 | /* End of file oci8_result.php */ |
Andrey Andreev | ef3e240 | 2011-09-21 14:39:29 +0300 | [diff] [blame] | 264 | /* Location: ./system/database/drivers/oci8/oci8_result.php */ |