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