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 | */ |
Andrey Andreev | 2608687 | 2012-07-05 11:21:58 +0300 | [diff] [blame^] | 37 | class CI_DB_ibase_result extends CI_DB_result { |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 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 | /** |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 134 | * Result - associative array |
| 135 | * |
| 136 | * Returns the result set as an array |
| 137 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 138 | * @return array |
| 139 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 140 | protected function _fetch_assoc() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 141 | { |
Timothy Warren | 41a439b | 2012-02-20 18:40:00 -0500 | [diff] [blame] | 142 | if (($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 143 | { |
| 144 | //Increment row count |
| 145 | $this->num_rows++; |
| 146 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 147 | |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 148 | return $row; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | // -------------------------------------------------------------------- |
| 152 | |
| 153 | /** |
| 154 | * Result - object |
| 155 | * |
| 156 | * Returns the result set as an object |
| 157 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 158 | * @return object |
| 159 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 160 | protected function _fetch_object() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 161 | { |
Timothy Warren | 41a439b | 2012-02-20 18:40:00 -0500 | [diff] [blame] | 162 | if (($row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 163 | { |
| 164 | //Increment row count |
| 165 | $this->num_rows++; |
| 166 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 167 | |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 168 | return $row; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 169 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 170 | |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 171 | // -------------------------------------------------------------------- |
| 172 | |
| 173 | /** |
| 174 | * Query result. "object" version. |
| 175 | * |
| 176 | * @return object |
| 177 | */ |
| 178 | public function result_object() |
| 179 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 180 | if (count($this->result_object) === $this->num_rows) |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 181 | { |
| 182 | return $this->result_object; |
| 183 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 184 | |
| 185 | // Convert result array to object so that |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 186 | // We don't have to get the result again |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 187 | if (($c = count($this->result_array)) > 0) |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 188 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 189 | for ($i = 0; $i < $c; $i++) |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 190 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 191 | $this->result_object[$i] = (object) $this->result_array[$i]; |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 192 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 193 | |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 194 | return $this->result_object; |
| 195 | } |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 196 | |
| 197 | // In the event that query caching is on the result_id variable |
| 198 | // will return FALSE since there isn't a valid SQL resource so |
| 199 | // we'll simply return an empty array. |
| 200 | if ($this->result_id === FALSE) |
| 201 | { |
| 202 | return array(); |
| 203 | } |
| 204 | |
| 205 | $this->num_rows = 0; |
| 206 | while ($row = $this->_fetch_object()) |
| 207 | { |
| 208 | $this->result_object[] = $row; |
| 209 | } |
| 210 | |
| 211 | return $this->result_object; |
| 212 | } |
| 213 | |
| 214 | // -------------------------------------------------------------------- |
| 215 | |
| 216 | /** |
| 217 | * Query result. "array" version. |
| 218 | * |
| 219 | * @return array |
| 220 | */ |
| 221 | public function result_array() |
| 222 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 223 | if (count($this->result_array) === $this->num_rows) |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 224 | { |
| 225 | return $this->result_array; |
| 226 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 227 | |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 228 | // Since the object and array are really similar, just case |
| 229 | // the result object to an array if need be |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 230 | if (($c = count($this->result_object)) > 0) |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 231 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 232 | for ($i = 0; $i < $c; $i++) |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 233 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 234 | $this->result_array[$i] = (array) $this->result_object[$i]; |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 235 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 236 | |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 237 | return $this->result_array; |
| 238 | } |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 239 | |
| 240 | // In the event that query caching is on the result_id variable |
| 241 | // will return FALSE since there isn't a valid SQL resource so |
| 242 | // we'll simply return an empty array. |
| 243 | if ($this->result_id === FALSE) |
| 244 | { |
| 245 | return array(); |
| 246 | } |
| 247 | |
| 248 | $this->num_rows = 0; |
| 249 | while ($row = $this->_fetch_assoc()) |
| 250 | { |
| 251 | $this->result_array[] = $row; |
| 252 | } |
| 253 | |
| 254 | return $this->result_array; |
| 255 | } |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 256 | |
| 257 | } |
| 258 | |
Andrey Andreev | 2608687 | 2012-07-05 11:21:58 +0300 | [diff] [blame^] | 259 | /* End of file ibase_result.php */ |
| 260 | /* Location: ./system/database/drivers/ibase/ibase_result.php */ |