blob: 572e110cae97e080a9101955c04e57f1209addd0 [file] [log] [blame]
Derek Jones37f4b9c2011-07-01 17:56:50 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * 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 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * ODBC Result Class
32 *
33 * This class extends the parent result class: CI_DB_result
34 *
35 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/database/
38 */
39class CI_DB_odbc_result extends CI_DB_result {
Barry Mienydd671972010-10-04 16:33:58 +020040
Andrey Andreevef795ac2012-03-01 15:15:31 +020041 public $num_rows;
42
Derek Allard2067d1a2008-11-13 22:59:24 +000043 /**
44 * Number of rows in the result set
45 *
Andrey Andreevef795ac2012-03-01 15:15:31 +020046 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000047 */
Andrey Andreevef795ac2012-03-01 15:15:31 +020048 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000049 {
Andrey Andreevef795ac2012-03-01 15:15:31 +020050 if (is_int($this->num_rows))
51 {
52 return $this->num_rows;
53 }
54
55 // Work-around for ODBC subdrivers that don't support num_rows()
56 if (($this->num_rows = @odbc_num_rows($this->result_id)) === -1)
57 {
58 $this->num_rows = count($this->result_array());
59 }
60
61 return $this->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000062 }
Barry Mienydd671972010-10-04 16:33:58 +020063
Derek Allard2067d1a2008-11-13 22:59:24 +000064 // --------------------------------------------------------------------
65
66 /**
67 * Number of fields in the result set
68 *
Andrey Andreev41e46a92012-03-01 14:58:17 +020069 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000070 */
Andrey Andreev41e46a92012-03-01 14:58:17 +020071 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000072 {
73 return @odbc_num_fields($this->result_id);
74 }
75
76 // --------------------------------------------------------------------
77
78 /**
79 * Fetch Field Names
80 *
81 * Generates an array of column names
82 *
Derek Allard2067d1a2008-11-13 22:59:24 +000083 * @return array
84 */
Andrey Andreev41e46a92012-03-01 14:58:17 +020085 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000086 {
87 $field_names = array();
Andrey Andreev41e46a92012-03-01 14:58:17 +020088 $num_fields = $this->num_fields();
89
90 if ($num_fields > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
Andrey Andreev41e46a92012-03-01 14:58:17 +020092 for ($i = 1; $i <= $num_fields; $i++)
93 {
94 $field_names[] = odbc_field_name($this->result_id, $i);
95 }
Derek Allard2067d1a2008-11-13 22:59:24 +000096 }
Barry Mienydd671972010-10-04 16:33:58 +020097
Derek Allard2067d1a2008-11-13 22:59:24 +000098 return $field_names;
99 }
100
101 // --------------------------------------------------------------------
102
103 /**
104 * Field data
105 *
106 * Generates an array of objects containing field meta-data
107 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 * @return array
109 */
Andrey Andreev41e46a92012-03-01 14:58:17 +0200110 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 {
112 $retval = array();
Andrey Andreev41e46a92012-03-01 14:58:17 +0200113 for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 {
Andrey Andreev41e46a92012-03-01 14:58:17 +0200115 $retval[$i] = new stdClass();
116 $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index);
117 $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index);
118 $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index);
119 $retval[$i]->primary_key = 0;
120 $retval[$i]->default = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 }
Barry Mienydd671972010-10-04 16:33:58 +0200122
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 return $retval;
124 }
125
126 // --------------------------------------------------------------------
127
128 /**
129 * Free the result
130 *
131 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200132 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 function free_result()
134 {
135 if (is_resource($this->result_id))
136 {
137 odbc_free_result($this->result_id);
138 $this->result_id = FALSE;
139 }
140 }
141
142 // --------------------------------------------------------------------
143
144 /**
145 * Data Seek
146 *
Derek Jones37f4b9c2011-07-01 17:56:50 -0500147 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 * this internally before fetching results to make sure the
149 * result set starts at zero
150 *
151 * @access private
152 * @return array
153 */
154 function _data_seek($n = 0)
155 {
156 return FALSE;
157 }
158
159 // --------------------------------------------------------------------
160
161 /**
162 * Result - associative array
163 *
164 * Returns the result set as an array
165 *
166 * @access private
167 * @return array
168 */
169 function _fetch_assoc()
170 {
171 if (function_exists('odbc_fetch_object'))
172 {
173 return odbc_fetch_array($this->result_id);
174 }
175 else
176 {
177 return $this->_odbc_fetch_array($this->result_id);
178 }
179 }
180
181 // --------------------------------------------------------------------
182
183 /**
184 * Result - object
185 *
186 * Returns the result set as an object
187 *
188 * @access private
189 * @return object
190 */
191 function _fetch_object()
192 {
193 if (function_exists('odbc_fetch_object'))
194 {
195 return odbc_fetch_object($this->result_id);
196 }
197 else
198 {
199 return $this->_odbc_fetch_object($this->result_id);
200 }
201 }
202
203
204 /**
205 * Result - object
206 *
207 * subsititutes the odbc_fetch_object function when
208 * not available (odbc_fetch_object requires unixODBC)
209 *
210 * @access private
211 * @return object
212 */
213 function _odbc_fetch_object(& $odbc_result) {
214 $rs = array();
Pascal Kriete8761ef52011-02-14 13:13:52 -0500215 $rs_obj = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000216 if (odbc_fetch_into($odbc_result, $rs)) {
217 foreach ($rs as $k=>$v) {
218 $field_name= odbc_field_name($odbc_result, $k+1);
219 $rs_obj->$field_name = $v;
220 }
221 }
222 return $rs_obj;
223 }
224
225
226 /**
227 * Result - array
228 *
229 * subsititutes the odbc_fetch_array function when
230 * not available (odbc_fetch_array requires unixODBC)
231 *
232 * @access private
233 * @return array
234 */
235 function _odbc_fetch_array(& $odbc_result) {
236 $rs = array();
Pascal Kriete8761ef52011-02-14 13:13:52 -0500237 $rs_assoc = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000238 if (odbc_fetch_into($odbc_result, $rs)) {
239 $rs_assoc=array();
240 foreach ($rs as $k=>$v) {
241 $field_name= odbc_field_name($odbc_result, $k+1);
242 $rs_assoc[$field_name] = $v;
243 }
244 }
245 return $rs_assoc;
246 }
247
248}
249
250
251/* End of file odbc_result.php */
Andrey Andreev41e46a92012-03-01 14:58:17 +0200252/* Location: ./system/database/drivers/odbc/odbc_result.php */