blob: 6a607f589b5c309bb1a325935b45d6cab0d5a901 [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
Andrey Andreev5ca05132012-07-05 12:06:34 +030024 * @since Version 1.0
Timothy Warren76e04352012-02-14 11:55:17 -050025 * @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/
Andrey Andreev5ca05132012-07-05 12:06:34 +030036 * @since 3.0
Timothy Warren76e04352012-02-14 11:55:17 -050037 */
Andrey Andreev26086872012-07-05 11:21:58 +030038class CI_DB_ibase_result extends CI_DB_result {
Timothy Warren76e04352012-02-14 11:55:17 -050039
40 /**
41 * Number of rows in the result set
42 *
Andrey Andreev60c9c992012-03-20 23:46:09 +020043 * @return int
Timothy Warren76e04352012-02-14 11:55:17 -050044 */
Timothy Warren4be822b2012-02-14 12:07:34 -050045 public function num_rows()
Timothy Warren76e04352012-02-14 11:55:17 -050046 {
Andrey Andreev60c9c992012-03-20 23:46:09 +020047 if (is_int($this->num_rows))
Timothy Warren76e04352012-02-14 11:55:17 -050048 {
Timothy Warren817af192012-02-16 08:28:00 -050049 return $this->num_rows;
Timothy Warren76e04352012-02-14 11:55:17 -050050 }
Andrey Andreev60c9c992012-03-20 23:46:09 +020051
52 // Get the results so that you can get an accurate rowcount
Timothy Warrenfa84d612012-02-20 12:51:45 -050053 $this->result();
Andrey Andreev60c9c992012-03-20 23:46:09 +020054
Timothy Warren7d42eb32012-02-17 14:21:18 -050055 return $this->num_rows;
Timothy Warren76e04352012-02-14 11:55:17 -050056 }
57
58 // --------------------------------------------------------------------
59
60 /**
61 * Number of fields in the result set
62 *
Andrey Andreev60c9c992012-03-20 23:46:09 +020063 * @return int
Timothy Warren76e04352012-02-14 11:55:17 -050064 */
Timothy Warren4be822b2012-02-14 12:07:34 -050065 public function num_fields()
Timothy Warren76e04352012-02-14 11:55:17 -050066 {
67 return @ibase_num_fields($this->result_id);
68 }
69
70 // --------------------------------------------------------------------
71
72 /**
73 * Fetch Field Names
74 *
75 * Generates an array of column names
76 *
Timothy Warren76e04352012-02-14 11:55:17 -050077 * @return array
78 */
Timothy Warren4be822b2012-02-14 12:07:34 -050079 public function list_fields()
Timothy Warren76e04352012-02-14 11:55:17 -050080 {
81 $field_names = array();
Timothy Warren2da66ed2012-02-20 17:54:39 -050082 for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++)
Timothy Warren76e04352012-02-14 11:55:17 -050083 {
84 $info = ibase_field_info($this->result_id, $i);
85 $field_names[] = $info['name'];
86 }
87
88 return $field_names;
89 }
90
91 // --------------------------------------------------------------------
92
93 /**
94 * Field data
95 *
96 * Generates an array of objects containing field meta-data
97 *
Timothy Warren76e04352012-02-14 11:55:17 -050098 * @return array
99 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500100 public function field_data()
Timothy Warren76e04352012-02-14 11:55:17 -0500101 {
Timothy Warren76e04352012-02-14 11:55:17 -0500102 $retval = array();
Andrey Andreev60c9c992012-03-20 23:46:09 +0200103 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Timothy Warren76e04352012-02-14 11:55:17 -0500104 {
105 $info = ibase_field_info($this->result_id, $i);
Timothy Warren76e04352012-02-14 11:55:17 -0500106
Andrey Andreev60c9c992012-03-20 23:46:09 +0200107 $retval[$i] = new stdClass();
108 $retval[$i]->name = $info['name'];
109 $retval[$i]->type = $info['type'];
110 $retval[$i]->max_length = $info['length'];
111 $retval[$i]->primary_key = 0;
112 $retval[$i]->default = '';
Timothy Warren76e04352012-02-14 11:55:17 -0500113 }
114
115 return $retval;
116 }
117
118 // --------------------------------------------------------------------
119
120 /**
121 * Free the result
122 *
Andrey Andreev60c9c992012-03-20 23:46:09 +0200123 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500124 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500125 public function free_result()
Timothy Warren76e04352012-02-14 11:55:17 -0500126 {
127 @ibase_free_result($this->result_id);
128 }
129
130 // --------------------------------------------------------------------
131
132 /**
Timothy Warren76e04352012-02-14 11:55:17 -0500133 * Result - associative array
134 *
135 * Returns the result set as an array
136 *
Timothy Warren76e04352012-02-14 11:55:17 -0500137 * @return array
138 */
Timothy Warren95562142012-02-20 17:37:21 -0500139 protected function _fetch_assoc()
Timothy Warren76e04352012-02-14 11:55:17 -0500140 {
Timothy Warren41a439b2012-02-20 18:40:00 -0500141 if (($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE)
Timothy Warren2da66ed2012-02-20 17:54:39 -0500142 {
143 //Increment row count
144 $this->num_rows++;
145 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200146
Timothy Warren2da66ed2012-02-20 17:54:39 -0500147 return $row;
Timothy Warren76e04352012-02-14 11:55:17 -0500148 }
149
150 // --------------------------------------------------------------------
151
152 /**
153 * Result - object
154 *
155 * Returns the result set as an object
156 *
Timothy Warren76e04352012-02-14 11:55:17 -0500157 * @return object
158 */
Timothy Warren95562142012-02-20 17:37:21 -0500159 protected function _fetch_object()
Timothy Warren76e04352012-02-14 11:55:17 -0500160 {
Timothy Warren41a439b2012-02-20 18:40:00 -0500161 if (($row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE)
Timothy Warren2da66ed2012-02-20 17:54:39 -0500162 {
163 //Increment row count
164 $this->num_rows++;
165 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200166
Timothy Warren2da66ed2012-02-20 17:54:39 -0500167 return $row;
Timothy Warren76e04352012-02-14 11:55:17 -0500168 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200169
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500170 // --------------------------------------------------------------------
171
172 /**
173 * Query result. "object" version.
174 *
175 * @return object
176 */
177 public function result_object()
178 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200179 if (count($this->result_object) === $this->num_rows)
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500180 {
181 return $this->result_object;
182 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200183
184 // Convert result array to object so that
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500185 // We don't have to get the result again
Andrey Andreev60c9c992012-03-20 23:46:09 +0200186 if (($c = count($this->result_array)) > 0)
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500187 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200188 for ($i = 0; $i < $c; $i++)
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500189 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200190 $this->result_object[$i] = (object) $this->result_array[$i];
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500191 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200192
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500193 return $this->result_object;
194 }
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500195
196 // In the event that query caching is on the result_id variable
197 // will return FALSE since there isn't a valid SQL resource so
198 // we'll simply return an empty array.
199 if ($this->result_id === FALSE)
200 {
201 return array();
202 }
203
204 $this->num_rows = 0;
205 while ($row = $this->_fetch_object())
206 {
207 $this->result_object[] = $row;
208 }
209
210 return $this->result_object;
211 }
212
213 // --------------------------------------------------------------------
214
215 /**
216 * Query result. "array" version.
217 *
218 * @return array
219 */
220 public function result_array()
221 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200222 if (count($this->result_array) === $this->num_rows)
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500223 {
224 return $this->result_array;
225 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200226
Timothy Warrenfa84d612012-02-20 12:51:45 -0500227 // Since the object and array are really similar, just case
228 // the result object to an array if need be
Andrey Andreev60c9c992012-03-20 23:46:09 +0200229 if (($c = count($this->result_object)) > 0)
Timothy Warrenfa84d612012-02-20 12:51:45 -0500230 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200231 for ($i = 0; $i < $c; $i++)
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500232 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200233 $this->result_array[$i] = (array) $this->result_object[$i];
Timothy Warren51ed4ed2012-02-20 16:01:42 -0500234 }
Andrey Andreev60c9c992012-03-20 23:46:09 +0200235
Timothy Warrenfa84d612012-02-20 12:51:45 -0500236 return $this->result_array;
237 }
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500238
239 // In the event that query caching is on the result_id variable
240 // will return FALSE since there isn't a valid SQL resource so
241 // we'll simply return an empty array.
242 if ($this->result_id === FALSE)
243 {
244 return array();
245 }
246
247 $this->num_rows = 0;
248 while ($row = $this->_fetch_assoc())
249 {
250 $this->result_array[] = $row;
251 }
252
253 return $this->result_array;
254 }
Timothy Warren76e04352012-02-14 11:55:17 -0500255
256}
257
Andrey Andreev26086872012-07-05 11:21:58 +0300258/* End of file ibase_result.php */
259/* Location: ./system/database/drivers/ibase/ibase_result.php */