blob: 4aaaaba4a8a947c50d4939b6b62b46f8d5907d62 [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 */
Andrey Andreev26086872012-07-05 11:21:58 +030037class CI_DB_ibase_result extends CI_DB_result {
Timothy Warren76e04352012-02-14 11:55:17 -050038
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 /**
Timothy Warren76e04352012-02-14 11:55:17 -0500134 * Result - associative array
135 *
136 * Returns the result set as an array
137 *
Timothy Warren76e04352012-02-14 11:55:17 -0500138 * @return array
139 */
Timothy Warren95562142012-02-20 17:37:21 -0500140 protected function _fetch_assoc()
Timothy Warren76e04352012-02-14 11:55:17 -0500141 {
Timothy Warren41a439b2012-02-20 18:40:00 -0500142 if (($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE)
Timothy Warren2da66ed2012-02-20 17:54:39 -0500143 {
144 //Increment row count
145 $this->num_rows++;
146 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200147
Timothy Warren2da66ed2012-02-20 17:54:39 -0500148 return $row;
Timothy Warren76e04352012-02-14 11:55:17 -0500149 }
150
151 // --------------------------------------------------------------------
152
153 /**
154 * Result - object
155 *
156 * Returns the result set as an object
157 *
Timothy Warren76e04352012-02-14 11:55:17 -0500158 * @return object
159 */
Timothy Warren95562142012-02-20 17:37:21 -0500160 protected function _fetch_object()
Timothy Warren76e04352012-02-14 11:55:17 -0500161 {
Timothy Warren41a439b2012-02-20 18:40:00 -0500162 if (($row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE)
Timothy Warren2da66ed2012-02-20 17:54:39 -0500163 {
164 //Increment row count
165 $this->num_rows++;
166 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200167
Timothy Warren2da66ed2012-02-20 17:54:39 -0500168 return $row;
Timothy Warren76e04352012-02-14 11:55:17 -0500169 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200170
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500171 // --------------------------------------------------------------------
172
173 /**
174 * Query result. "object" version.
175 *
176 * @return object
177 */
178 public function result_object()
179 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200180 if (count($this->result_object) === $this->num_rows)
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500181 {
182 return $this->result_object;
183 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200184
185 // Convert result array to object so that
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500186 // We don't have to get the result again
Andrey Andreev60c9c992012-03-20 23:46:09 +0200187 if (($c = count($this->result_array)) > 0)
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500188 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200189 for ($i = 0; $i < $c; $i++)
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500190 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200191 $this->result_object[$i] = (object) $this->result_array[$i];
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500192 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200193
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500194 return $this->result_object;
195 }
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500196
197 // In the event that query caching is on the result_id variable
198 // will return FALSE since there isn't a valid SQL resource so
199 // we'll simply return an empty array.
200 if ($this->result_id === FALSE)
201 {
202 return array();
203 }
204
205 $this->num_rows = 0;
206 while ($row = $this->_fetch_object())
207 {
208 $this->result_object[] = $row;
209 }
210
211 return $this->result_object;
212 }
213
214 // --------------------------------------------------------------------
215
216 /**
217 * Query result. "array" version.
218 *
219 * @return array
220 */
221 public function result_array()
222 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200223 if (count($this->result_array) === $this->num_rows)
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500224 {
225 return $this->result_array;
226 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200227
Timothy Warrenfa84d612012-02-20 12:51:45 -0500228 // Since the object and array are really similar, just case
229 // the result object to an array if need be
Andrey Andreev60c9c992012-03-20 23:46:09 +0200230 if (($c = count($this->result_object)) > 0)
Timothy Warrenfa84d612012-02-20 12:51:45 -0500231 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200232 for ($i = 0; $i < $c; $i++)
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500233 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200234 $this->result_array[$i] = (array) $this->result_object[$i];
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500235 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200236
Timothy Warrenfa84d612012-02-20 12:51:45 -0500237 return $this->result_array;
238 }
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500239
240 // In the event that query caching is on the result_id variable
241 // will return FALSE since there isn't a valid SQL resource so
242 // we'll simply return an empty array.
243 if ($this->result_id === FALSE)
244 {
245 return array();
246 }
247
248 $this->num_rows = 0;
249 while ($row = $this->_fetch_assoc())
250 {
251 $this->result_array[] = $row;
252 }
253
254 return $this->result_array;
255 }
Timothy Warren76e04352012-02-14 11:55:17 -0500256
257}
258
Andrey Andreev26086872012-07-05 11:21:58 +0300259/* End of file ibase_result.php */
260/* Location: ./system/database/drivers/ibase/ibase_result.php */