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 |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame^] | 24 | * @since Version 1.0 |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 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/ |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame^] | 36 | * @since 3.0 |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 37 | */ |
Andrey Andreev | 2608687 | 2012-07-05 11:21:58 +0300 | [diff] [blame] | 38 | class CI_DB_ibase_result extends CI_DB_result { |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Number of rows in the result set |
| 42 | * |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 43 | * @return int |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 44 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 45 | public function num_rows() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 46 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 47 | if (is_int($this->num_rows)) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 48 | { |
Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 49 | return $this->num_rows; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 50 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 51 | |
| 52 | // Get the results so that you can get an accurate rowcount |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 53 | $this->result(); |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 54 | |
Timothy Warren | 7d42eb3 | 2012-02-17 14:21:18 -0500 | [diff] [blame] | 55 | return $this->num_rows; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | // -------------------------------------------------------------------- |
| 59 | |
| 60 | /** |
| 61 | * Number of fields in the result set |
| 62 | * |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 63 | * @return int |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 64 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 65 | public function num_fields() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 66 | { |
| 67 | return @ibase_num_fields($this->result_id); |
| 68 | } |
| 69 | |
| 70 | // -------------------------------------------------------------------- |
| 71 | |
| 72 | /** |
| 73 | * Fetch Field Names |
| 74 | * |
| 75 | * Generates an array of column names |
| 76 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 77 | * @return array |
| 78 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 79 | public function list_fields() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 80 | { |
| 81 | $field_names = array(); |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 82 | for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 83 | { |
| 84 | $info = ibase_field_info($this->result_id, $i); |
| 85 | $field_names[] = $info['name']; |
| 86 | } |
| 87 | |
| 88 | return $field_names; |
| 89 | } |
| 90 | |
| 91 | // -------------------------------------------------------------------- |
| 92 | |
| 93 | /** |
| 94 | * Field data |
| 95 | * |
| 96 | * Generates an array of objects containing field meta-data |
| 97 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 98 | * @return array |
| 99 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 100 | public function field_data() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 101 | { |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 102 | $retval = array(); |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 103 | for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 104 | { |
| 105 | $info = ibase_field_info($this->result_id, $i); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 106 | |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 107 | $retval[$i] = new stdClass(); |
| 108 | $retval[$i]->name = $info['name']; |
| 109 | $retval[$i]->type = $info['type']; |
| 110 | $retval[$i]->max_length = $info['length']; |
| 111 | $retval[$i]->primary_key = 0; |
| 112 | $retval[$i]->default = ''; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | return $retval; |
| 116 | } |
| 117 | |
| 118 | // -------------------------------------------------------------------- |
| 119 | |
| 120 | /** |
| 121 | * Free the result |
| 122 | * |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 123 | * @return void |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 124 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 125 | public function free_result() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 126 | { |
| 127 | @ibase_free_result($this->result_id); |
| 128 | } |
| 129 | |
| 130 | // -------------------------------------------------------------------- |
| 131 | |
| 132 | /** |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 133 | * Result - associative array |
| 134 | * |
| 135 | * Returns the result set as an array |
| 136 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 137 | * @return array |
| 138 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 139 | protected function _fetch_assoc() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 140 | { |
Timothy Warren | 41a439b | 2012-02-20 18:40:00 -0500 | [diff] [blame] | 141 | if (($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 142 | { |
| 143 | //Increment row count |
| 144 | $this->num_rows++; |
| 145 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 146 | |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 147 | return $row; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // -------------------------------------------------------------------- |
| 151 | |
| 152 | /** |
| 153 | * Result - object |
| 154 | * |
| 155 | * Returns the result set as an object |
| 156 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 157 | * @return object |
| 158 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 159 | protected function _fetch_object() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 160 | { |
Timothy Warren | 41a439b | 2012-02-20 18:40:00 -0500 | [diff] [blame] | 161 | if (($row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 162 | { |
| 163 | //Increment row count |
| 164 | $this->num_rows++; |
| 165 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 166 | |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 167 | return $row; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 168 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 169 | |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 170 | // -------------------------------------------------------------------- |
| 171 | |
| 172 | /** |
| 173 | * Query result. "object" version. |
| 174 | * |
| 175 | * @return object |
| 176 | */ |
| 177 | public function result_object() |
| 178 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 179 | if (count($this->result_object) === $this->num_rows) |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 180 | { |
| 181 | return $this->result_object; |
| 182 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 183 | |
| 184 | // Convert result array to object so that |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 185 | // We don't have to get the result again |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 186 | if (($c = count($this->result_array)) > 0) |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 187 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 188 | for ($i = 0; $i < $c; $i++) |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 189 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 190 | $this->result_object[$i] = (object) $this->result_array[$i]; |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 191 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 192 | |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 193 | return $this->result_object; |
| 194 | } |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 195 | |
| 196 | // In the event that query caching is on the result_id variable |
| 197 | // will return FALSE since there isn't a valid SQL resource so |
| 198 | // we'll simply return an empty array. |
| 199 | if ($this->result_id === FALSE) |
| 200 | { |
| 201 | return array(); |
| 202 | } |
| 203 | |
| 204 | $this->num_rows = 0; |
| 205 | while ($row = $this->_fetch_object()) |
| 206 | { |
| 207 | $this->result_object[] = $row; |
| 208 | } |
| 209 | |
| 210 | return $this->result_object; |
| 211 | } |
| 212 | |
| 213 | // -------------------------------------------------------------------- |
| 214 | |
| 215 | /** |
| 216 | * Query result. "array" version. |
| 217 | * |
| 218 | * @return array |
| 219 | */ |
| 220 | public function result_array() |
| 221 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 222 | if (count($this->result_array) === $this->num_rows) |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 223 | { |
| 224 | return $this->result_array; |
| 225 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 226 | |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 227 | // Since the object and array are really similar, just case |
| 228 | // the result object to an array if need be |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 229 | if (($c = count($this->result_object)) > 0) |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 230 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 231 | for ($i = 0; $i < $c; $i++) |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 232 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 233 | $this->result_array[$i] = (array) $this->result_object[$i]; |
Timothy Warren | 51ed4ed | 2012-02-20 16:01:42 -0500 | [diff] [blame] | 234 | } |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 235 | |
Timothy Warren | fa84d61 | 2012-02-20 12:51:45 -0500 | [diff] [blame] | 236 | return $this->result_array; |
| 237 | } |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 238 | |
| 239 | // In the event that query caching is on the result_id variable |
| 240 | // will return FALSE since there isn't a valid SQL resource so |
| 241 | // we'll simply return an empty array. |
| 242 | if ($this->result_id === FALSE) |
| 243 | { |
| 244 | return array(); |
| 245 | } |
| 246 | |
| 247 | $this->num_rows = 0; |
| 248 | while ($row = $this->_fetch_assoc()) |
| 249 | { |
| 250 | $this->result_array[] = $row; |
| 251 | } |
| 252 | |
| 253 | return $this->result_array; |
| 254 | } |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 255 | |
| 256 | } |
| 257 | |
Andrey Andreev | 2608687 | 2012-07-05 11:21:58 +0300 | [diff] [blame] | 258 | /* End of file ibase_result.php */ |
| 259 | /* Location: ./system/database/drivers/ibase/ibase_result.php */ |