blob: 7a3a41f2c05a302e893a8d47c0fb71f3efa6a9aa [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 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
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
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 */
39class CI_DB_interbase_result extends CI_DB_result {
40
Timothy Warren817af192012-02-16 08:28:00 -050041 public $num_rows;
42
Timothy Warren76e04352012-02-14 11:55:17 -050043 /**
44 * Number of rows in the result set
45 *
Timothy Warren76e04352012-02-14 11:55:17 -050046 * @return integer
47 */
Timothy Warren4be822b2012-02-14 12:07:34 -050048 public function num_rows()
Timothy Warren76e04352012-02-14 11:55:17 -050049 {
Timothy Warren817af192012-02-16 08:28:00 -050050 if( ! is_null($this->num_rows))
Timothy Warren76e04352012-02-14 11:55:17 -050051 {
Timothy Warren817af192012-02-16 08:28:00 -050052 return $this->num_rows;
Timothy Warren76e04352012-02-14 11:55:17 -050053 }
54
Timothy Warren7d42eb32012-02-17 14:21:18 -050055 //Get the results so that you can get an accurate rowcount
Timothy Warrenfa84d612012-02-20 12:51:45 -050056 $this->result();
Timothy Warren7d42eb32012-02-17 14:21:18 -050057
58 return $this->num_rows;
Timothy Warren76e04352012-02-14 11:55:17 -050059 }
60
61 // --------------------------------------------------------------------
62
63 /**
64 * Number of fields in the result set
65 *
Timothy Warren76e04352012-02-14 11:55:17 -050066 * @return integer
67 */
Timothy Warren4be822b2012-02-14 12:07:34 -050068 public function num_fields()
Timothy Warren76e04352012-02-14 11:55:17 -050069 {
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 Warren76e04352012-02-14 11:55:17 -050080 * @return array
81 */
Timothy Warren4be822b2012-02-14 12:07:34 -050082 public function list_fields()
Timothy Warren76e04352012-02-14 11:55:17 -050083 {
84 $field_names = array();
Timothy Warren817af192012-02-16 08:28:00 -050085 for ($i = 0, $num_fields=$this->num_fields(); $i < $num_fields; $i++)
Timothy Warren76e04352012-02-14 11:55:17 -050086 {
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 Warren76e04352012-02-14 11:55:17 -0500101 * @return array
102 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500103 public function field_data()
Timothy Warren76e04352012-02-14 11:55:17 -0500104 {
105
106 $retval = array();
Timothy Warren817af192012-02-16 08:28:00 -0500107 for ($i = 0, $num_fields=$this->num_fields(); $i < $num_fields; $i++)
Timothy Warren76e04352012-02-14 11:55:17 -0500108 {
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 Warren4be822b2012-02-14 12:07:34 -0500131 public function free_result()
Timothy Warren76e04352012-02-14 11:55:17 -0500132 {
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 Warren76e04352012-02-14 11:55:17 -0500145 * @return array
146 */
Timothy Warren95562142012-02-20 17:37:21 -0500147 protected function _data_seek($n = 0)
Timothy Warren76e04352012-02-14 11:55:17 -0500148 {
Timothy Warrene27216f2012-02-16 12:15:45 -0500149 //Set the row count to 0
150 $this->num_rows = 0;
151
Timothy Warren8be31a92012-02-15 11:48:57 -0500152 //Interbase driver doesn't implement a suitable function
Timothy Warren817af192012-02-16 08:28:00 -0500153 return FALSE;
Timothy Warren76e04352012-02-14 11:55:17 -0500154 }
155
156 // --------------------------------------------------------------------
157
158 /**
159 * Result - associative array
160 *
161 * Returns the result set as an array
162 *
Timothy Warren76e04352012-02-14 11:55:17 -0500163 * @return array
164 */
Timothy Warren95562142012-02-20 17:37:21 -0500165 protected function _fetch_assoc()
Timothy Warren76e04352012-02-14 11:55:17 -0500166 {
Timothy Warrene27216f2012-02-16 12:15:45 -0500167 //Increment row count
168 $this->num_rows++;
169
Timothy Warren0dcfd772012-02-17 17:42:34 -0500170 return @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS);
Timothy Warren76e04352012-02-14 11:55:17 -0500171 }
172
173 // --------------------------------------------------------------------
174
175 /**
176 * Result - object
177 *
178 * Returns the result set as an object
179 *
Timothy Warren76e04352012-02-14 11:55:17 -0500180 * @return object
181 */
Timothy Warren95562142012-02-20 17:37:21 -0500182 protected function _fetch_object()
Timothy Warren76e04352012-02-14 11:55:17 -0500183 {
Timothy Warrene27216f2012-02-16 12:15:45 -0500184 //Increment row count
185 $this->num_rows++;
186
Timothy Warren0dcfd772012-02-17 17:42:34 -0500187 return @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS);
Timothy Warren76e04352012-02-14 11:55:17 -0500188 }
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500189
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 Warren51ed4ed2012-02-20 16:01:42 -0500203
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 Warren3a4cdc62012-02-17 13:59:44 -0500224
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 Warrenfa84d612012-02-20 12:51:45 -0500255
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 Warren51ed4ed2012-02-20 16:01:42 -0500260 foreach($this->result_object as $obj)
261 {
262 $this->result_array[] = (array)$obj;
263 }
264
Timothy Warrenfa84d612012-02-20 12:51:45 -0500265 return $this->result_array;
266 }
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500267
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 Warren76e04352012-02-14 11:55:17 -0500284
285}
286
Timothy Warren76e04352012-02-14 11:55:17 -0500287/* End of file interbase_result.php */
288/* Location: ./system/database/drivers/interbase/interbase_result.php */