blob: fd4178dec81672643bf636574b3cf0e786d18e7e [file] [log] [blame]
Timothy Warren817af192012-02-16 08:28:00 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Timothy Warren76e04352012-02-14 11:55:17 -05002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Timothy Warren76e04352012-02-14 11:55:17 -05006 *
7 * NOTICE OF LICENSE
Timothy Warren817af192012-02-16 08:28:00 -05008 *
Timothy Warren76e04352012-02-14 11:55:17 -05009 * Licensed under the Open Software License version 3.0
Timothy Warren817af192012-02-16 08:28:00 -050010 *
Timothy Warren76e04352012-02-14 11:55:17 -050011 * 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 Warren76e04352012-02-14 11:55:17 -050028/**
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 */
37class CI_DB_interbase_result extends CI_DB_result {
38
Timothy Warren817af192012-02-16 08:28:00 -050039 public $num_rows;
40
Timothy Warren76e04352012-02-14 11:55:17 -050041 /**
42 * Number of rows in the result set
43 *
Andrey Andreev60c9c992012-03-20 23:46:09 +020044 * @return int
Timothy Warren76e04352012-02-14 11:55:17 -050045 */
Timothy Warren4be822b2012-02-14 12:07:34 -050046 public function num_rows()
Timothy Warren76e04352012-02-14 11:55:17 -050047 {
Andrey Andreev60c9c992012-03-20 23:46:09 +020048 if (is_int($this->num_rows))
Timothy Warren76e04352012-02-14 11:55:17 -050049 {
Timothy Warren817af192012-02-16 08:28:00 -050050 return $this->num_rows;
Timothy Warren76e04352012-02-14 11:55:17 -050051 }
Andrey Andreev60c9c992012-03-20 23:46:09 +020052
53 // Get the results so that you can get an accurate rowcount
Timothy Warrenfa84d612012-02-20 12:51:45 -050054 $this->result();
Andrey Andreev60c9c992012-03-20 23:46:09 +020055
Timothy Warren7d42eb32012-02-17 14:21:18 -050056 return $this->num_rows;
Timothy Warren76e04352012-02-14 11:55:17 -050057 }
58
59 // --------------------------------------------------------------------
60
61 /**
62 * Number of fields in the result set
63 *
Andrey Andreev60c9c992012-03-20 23:46:09 +020064 * @return int
Timothy Warren76e04352012-02-14 11:55:17 -050065 */
Timothy Warren4be822b2012-02-14 12:07:34 -050066 public function num_fields()
Timothy Warren76e04352012-02-14 11:55:17 -050067 {
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 Warren76e04352012-02-14 11:55:17 -050078 * @return array
79 */
Timothy Warren4be822b2012-02-14 12:07:34 -050080 public function list_fields()
Timothy Warren76e04352012-02-14 11:55:17 -050081 {
82 $field_names = array();
Timothy Warren2da66ed2012-02-20 17:54:39 -050083 for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++)
Timothy Warren76e04352012-02-14 11:55:17 -050084 {
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 Warren76e04352012-02-14 11:55:17 -050099 * @return array
100 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500101 public function field_data()
Timothy Warren76e04352012-02-14 11:55:17 -0500102 {
Timothy Warren76e04352012-02-14 11:55:17 -0500103 $retval = array();
Andrey Andreev60c9c992012-03-20 23:46:09 +0200104 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Timothy Warren76e04352012-02-14 11:55:17 -0500105 {
106 $info = ibase_field_info($this->result_id, $i);
Timothy Warren76e04352012-02-14 11:55:17 -0500107
Andrey Andreev60c9c992012-03-20 23:46:09 +0200108 $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 Warren76e04352012-02-14 11:55:17 -0500114 }
115
116 return $retval;
117 }
118
119 // --------------------------------------------------------------------
120
121 /**
122 * Free the result
123 *
Andrey Andreev60c9c992012-03-20 23:46:09 +0200124 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500125 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500126 public function free_result()
Timothy Warren76e04352012-02-14 11:55:17 -0500127 {
128 @ibase_free_result($this->result_id);
129 }
130
131 // --------------------------------------------------------------------
132
133 /**
134 * Data Seek
135 *
Andrey Andreev60c9c992012-03-20 23:46:09 +0200136 * Moves the internal pointer to the desired offset. We call
Timothy Warren76e04352012-02-14 11:55:17 -0500137 * this internally before fetching results to make sure the
138 * result set starts at zero
139 *
Timothy Warren76e04352012-02-14 11:55:17 -0500140 * @return array
141 */
Timothy Warren95562142012-02-20 17:37:21 -0500142 protected function _data_seek($n = 0)
Timothy Warren76e04352012-02-14 11:55:17 -0500143 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200144 // Interbase driver doesn't implement a suitable function
145 return FALSE;
Timothy Warren76e04352012-02-14 11:55:17 -0500146 }
147
148 // --------------------------------------------------------------------
149
150 /**
151 * Result - associative array
152 *
153 * Returns the result set as an array
154 *
Timothy Warren76e04352012-02-14 11:55:17 -0500155 * @return array
156 */
Timothy Warren95562142012-02-20 17:37:21 -0500157 protected function _fetch_assoc()
Timothy Warren76e04352012-02-14 11:55:17 -0500158 {
Timothy Warren41a439b2012-02-20 18:40:00 -0500159 if (($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE)
Timothy Warren2da66ed2012-02-20 17:54:39 -0500160 {
161 //Increment row count
162 $this->num_rows++;
163 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200164
Timothy Warren2da66ed2012-02-20 17:54:39 -0500165 return $row;
Timothy Warren76e04352012-02-14 11:55:17 -0500166 }
167
168 // --------------------------------------------------------------------
169
170 /**
171 * Result - object
172 *
173 * Returns the result set as an object
174 *
Timothy Warren76e04352012-02-14 11:55:17 -0500175 * @return object
176 */
Timothy Warren95562142012-02-20 17:37:21 -0500177 protected function _fetch_object()
Timothy Warren76e04352012-02-14 11:55:17 -0500178 {
Timothy Warren41a439b2012-02-20 18:40:00 -0500179 if (($row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE)
Timothy Warren2da66ed2012-02-20 17:54:39 -0500180 {
181 //Increment row count
182 $this->num_rows++;
183 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200184
Timothy Warren2da66ed2012-02-20 17:54:39 -0500185 return $row;
Timothy Warren76e04352012-02-14 11:55:17 -0500186 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200187
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500188 // --------------------------------------------------------------------
189
190 /**
191 * Query result. "object" version.
192 *
193 * @return object
194 */
195 public function result_object()
196 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200197 if (count($this->result_object) === $this->num_rows)
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500198 {
199 return $this->result_object;
200 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200201
202 // Convert result array to object so that
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500203 // We don't have to get the result again
Andrey Andreev60c9c992012-03-20 23:46:09 +0200204 if (($c = count($this->result_array)) > 0)
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500205 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200206 for ($i = 0; $i < $c; $i++)
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500207 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200208 $this->result_object[$i] = (object) $this->result_array[$i];
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500209 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200210
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500211 return $this->result_object;
212 }
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500213
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 Andreev60c9c992012-03-20 23:46:09 +0200240 if (count($this->result_array) === $this->num_rows)
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500241 {
242 return $this->result_array;
243 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200244
Timothy Warrenfa84d612012-02-20 12:51:45 -0500245 // Since the object and array are really similar, just case
246 // the result object to an array if need be
Andrey Andreev60c9c992012-03-20 23:46:09 +0200247 if (($c = count($this->result_object)) > 0)
Timothy Warrenfa84d612012-02-20 12:51:45 -0500248 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200249 for ($i = 0; $i < $c; $i++)
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500250 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200251 $this->result_array[$i] = (array) $this->result_object[$i];
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500252 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200253
Timothy Warrenfa84d612012-02-20 12:51:45 -0500254 return $this->result_array;
255 }
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500256
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 Warren76e04352012-02-14 11:55:17 -0500273
274}
275
Timothy Warren76e04352012-02-14 11:55:17 -0500276/* End of file interbase_result.php */
277/* Location: ./system/database/drivers/interbase/interbase_result.php */