Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [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 |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 6 | * |
| 7 | * NOTICE OF LICENSE |
Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 8 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 10 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -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 | * |
| 19 | * @package CodeIgniter |
| 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
| 23 | * @link http://codeigniter.com |
| 24 | * @since Version 3.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 28 | /** |
| 29 | * Interbase/Firebird Result Class |
| 30 | * |
| 31 | * This class extends the parent result class: CI_DB_result |
| 32 | * |
| 33 | * @category Database |
| 34 | * @author EllisLab Dev Team |
| 35 | * @link http://codeigniter.com/user_guide/database/ |
| 36 | */ |
| 37 | class CI_DB_interbase_result extends CI_DB_result { |
| 38 | |
Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 39 | public $num_rows; |
| 40 | |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 41 | /** |
| 42 | * Number of rows in the result set |
| 43 | * |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 44 | * @return int |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 45 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 46 | public function num_rows() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 47 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 48 | if (is_int($this->num_rows)) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 49 | { |
Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 50 | return $this->num_rows; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 51 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 52 | |
| 53 | // Get the results so that you can get an accurate rowcount |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 54 | $this->result(); |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 55 | |
Timothy Warren | 7d42eb3 | 2012-02-17 14:21:18 -0500 | [diff] [blame] | 56 | return $this->num_rows; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | // -------------------------------------------------------------------- |
| 60 | |
| 61 | /** |
| 62 | * Number of fields in the result set |
| 63 | * |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 64 | * @return int |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 65 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 66 | public function num_fields() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 67 | { |
| 68 | return @ibase_num_fields($this->result_id); |
| 69 | } |
| 70 | |
| 71 | // -------------------------------------------------------------------- |
| 72 | |
| 73 | /** |
| 74 | * Fetch Field Names |
| 75 | * |
| 76 | * Generates an array of column names |
| 77 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 78 | * @return array |
| 79 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 80 | public function list_fields() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 81 | { |
| 82 | $field_names = array(); |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 83 | for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 84 | { |
| 85 | $info = ibase_field_info($this->result_id, $i); |
| 86 | $field_names[] = $info['name']; |
| 87 | } |
| 88 | |
| 89 | return $field_names; |
| 90 | } |
| 91 | |
| 92 | // -------------------------------------------------------------------- |
| 93 | |
| 94 | /** |
| 95 | * Field data |
| 96 | * |
| 97 | * Generates an array of objects containing field meta-data |
| 98 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 99 | * @return array |
| 100 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 101 | public function field_data() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 102 | { |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 103 | $retval = array(); |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 104 | for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 105 | { |
| 106 | $info = ibase_field_info($this->result_id, $i); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 107 | |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 108 | $retval[$i] = new stdClass(); |
| 109 | $retval[$i]->name = $info['name']; |
| 110 | $retval[$i]->type = $info['type']; |
| 111 | $retval[$i]->max_length = $info['length']; |
| 112 | $retval[$i]->primary_key = 0; |
| 113 | $retval[$i]->default = ''; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | return $retval; |
| 117 | } |
| 118 | |
| 119 | // -------------------------------------------------------------------- |
| 120 | |
| 121 | /** |
| 122 | * Free the result |
| 123 | * |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 124 | * @return void |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 125 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 126 | public function free_result() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 127 | { |
| 128 | @ibase_free_result($this->result_id); |
| 129 | } |
| 130 | |
| 131 | // -------------------------------------------------------------------- |
| 132 | |
| 133 | /** |
| 134 | * Data Seek |
| 135 | * |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 136 | * Moves the internal pointer to the desired offset. We call |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 137 | * this internally before fetching results to make sure the |
| 138 | * result set starts at zero |
| 139 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 140 | * @return array |
| 141 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 142 | protected function _data_seek($n = 0) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 143 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 144 | // Interbase driver doesn't implement a suitable function |
| 145 | return FALSE; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // -------------------------------------------------------------------- |
| 149 | |
| 150 | /** |
| 151 | * Result - associative array |
| 152 | * |
| 153 | * Returns the result set as an array |
| 154 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 155 | * @return array |
| 156 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 157 | protected function _fetch_assoc() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 158 | { |
Timothy Warren | 41a439b | 2012-02-20 18:40:00 -0500 | [diff] [blame] | 159 | if (($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 160 | { |
| 161 | //Increment row count |
| 162 | $this->num_rows++; |
| 163 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 164 | |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 165 | return $row; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | // -------------------------------------------------------------------- |
| 169 | |
| 170 | /** |
| 171 | * Result - object |
| 172 | * |
| 173 | * Returns the result set as an object |
| 174 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 175 | * @return object |
| 176 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 177 | protected function _fetch_object() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 178 | { |
Timothy Warren | 41a439b | 2012-02-20 18:40:00 -0500 | [diff] [blame] | 179 | if (($row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 180 | { |
| 181 | //Increment row count |
| 182 | $this->num_rows++; |
| 183 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 184 | |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 185 | return $row; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 186 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 187 | |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 188 | // -------------------------------------------------------------------- |
| 189 | |
| 190 | /** |
| 191 | * Query result. "object" version. |
| 192 | * |
| 193 | * @return object |
| 194 | */ |
| 195 | public function result_object() |
| 196 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 197 | if (count($this->result_object) === $this->num_rows) |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 198 | { |
| 199 | return $this->result_object; |
| 200 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 201 | |
| 202 | // Convert result array to object so that |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 203 | // We don't have to get the result again |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 204 | if (($c = count($this->result_array)) > 0) |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 205 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 206 | for ($i = 0; $i < $c; $i++) |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 207 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 208 | $this->result_object[$i] = (object) $this->result_array[$i]; |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 209 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 210 | |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 211 | return $this->result_object; |
| 212 | } |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 213 | |
| 214 | // In the event that query caching is on the result_id variable |
| 215 | // will return FALSE since there isn't a valid SQL resource so |
| 216 | // we'll simply return an empty array. |
| 217 | if ($this->result_id === FALSE) |
| 218 | { |
| 219 | return array(); |
| 220 | } |
| 221 | |
| 222 | $this->num_rows = 0; |
| 223 | while ($row = $this->_fetch_object()) |
| 224 | { |
| 225 | $this->result_object[] = $row; |
| 226 | } |
| 227 | |
| 228 | return $this->result_object; |
| 229 | } |
| 230 | |
| 231 | // -------------------------------------------------------------------- |
| 232 | |
| 233 | /** |
| 234 | * Query result. "array" version. |
| 235 | * |
| 236 | * @return array |
| 237 | */ |
| 238 | public function result_array() |
| 239 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 240 | if (count($this->result_array) === $this->num_rows) |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 241 | { |
| 242 | return $this->result_array; |
| 243 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 244 | |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 245 | // Since the object and array are really similar, just case |
| 246 | // the result object to an array if need be |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 247 | if (($c = count($this->result_object)) > 0) |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 248 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 249 | for ($i = 0; $i < $c; $i++) |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 250 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 251 | $this->result_array[$i] = (array) $this->result_object[$i]; |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 252 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame^] | 253 | |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 254 | return $this->result_array; |
| 255 | } |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 256 | |
| 257 | // In the event that query caching is on the result_id variable |
| 258 | // will return FALSE since there isn't a valid SQL resource so |
| 259 | // we'll simply return an empty array. |
| 260 | if ($this->result_id === FALSE) |
| 261 | { |
| 262 | return array(); |
| 263 | } |
| 264 | |
| 265 | $this->num_rows = 0; |
| 266 | while ($row = $this->_fetch_assoc()) |
| 267 | { |
| 268 | $this->result_array[] = $row; |
| 269 | } |
| 270 | |
| 271 | return $this->result_array; |
| 272 | } |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 273 | |
| 274 | } |
| 275 | |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 276 | /* End of file interbase_result.php */ |
| 277 | /* Location: ./system/database/drivers/interbase/interbase_result.php */ |