blob: c7b40d2eaebc9ddb52cb4c7ceba66e1df55b4616 [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 Warren4be822b2012-02-14 12:07:34 -0500147 public 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 Warren4be822b2012-02-14 12:07:34 -0500165 public 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 Warren4be822b2012-02-14 12:07:34 -0500182 public 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 }
203
204 // In the event that query caching is on the result_id variable
205 // will return FALSE since there isn't a valid SQL resource so
206 // we'll simply return an empty array.
207 if ($this->result_id === FALSE)
208 {
209 return array();
210 }
211
212 $this->num_rows = 0;
213 while ($row = $this->_fetch_object())
214 {
215 $this->result_object[] = $row;
216 }
217
218 return $this->result_object;
219 }
220
221 // --------------------------------------------------------------------
222
223 /**
224 * Query result. "array" version.
225 *
226 * @return array
227 */
228 public function result_array()
229 {
230 if (count($this->result_array) > 0)
231 {
232 return $this->result_array;
233 }
Timothy Warrenfa84d612012-02-20 12:51:45 -0500234
235 // Since the object and array are really similar, just case
236 // the result object to an array if need be
237 if(count($this->result_object) > 0)
238 {
Timothy Warren934e8532012-02-20 15:42:14 -0500239 $this->result_array = (array)$this->result_object;
Timothy Warrenfa84d612012-02-20 12:51:45 -0500240 return $this->result_array;
241 }
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500242
243 // In the event that query caching is on the result_id variable
244 // will return FALSE since there isn't a valid SQL resource so
245 // we'll simply return an empty array.
246 if ($this->result_id === FALSE)
247 {
248 return array();
249 }
250
251 $this->num_rows = 0;
252 while ($row = $this->_fetch_assoc())
253 {
254 $this->result_array[] = $row;
255 }
256
257 return $this->result_array;
258 }
Timothy Warren76e04352012-02-14 11:55:17 -0500259
260}
261
Timothy Warren76e04352012-02-14 11:55:17 -0500262/* End of file interbase_result.php */
263/* Location: ./system/database/drivers/interbase/interbase_result.php */