blob: 4acfb056ec4adcb12bb4fd58fb3640f8cf9bb479 [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardd2df9bc2007-04-15 17:41:17 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * ODBC Result Class
20 *
21 * This class extends the parent result class: CI_DB_result
22 *
23 * @category Database
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/database/
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
27class CI_DB_odbc_result extends CI_DB_result {
28
29 /**
30 * Number of rows in the result set
31 *
32 * @access public
33 * @return integer
34 */
35 function num_rows()
36 {
37 return @odbc_num_rows($this->result_id);
38 }
39
40 // --------------------------------------------------------------------
41
42 /**
43 * Number of fields in the result set
44 *
45 * @access public
46 * @return integer
47 */
48 function num_fields()
49 {
50 return @odbc_num_fields($this->result_id);
51 }
52
53 // --------------------------------------------------------------------
54
55 /**
56 * Fetch Field Names
57 *
58 * Generates an array of column names
59 *
60 * @access public
61 * @return array
62 */
63 function list_fields()
64 {
65 $field_names = array();
66 for ($i = 0; $i < $this->num_fields(); $i++)
67 {
68 $field_names[] = odbc_field_name($this->result_id, $i);
69 }
70
71 return $field_names;
72 }
73
74 // Deprecated
75 function field_names()
76 {
77 return $this->list_fields();
78 }
79
80 // --------------------------------------------------------------------
81
82 /**
83 * Field data
84 *
85 * Generates an array of objects containing field meta-data
86 *
87 * @access public
88 * @return array
89 */
90 function field_data()
91 {
92 $retval = array();
93 for ($i = 0; $i < $this->num_fields(); $i++)
94 {
95 $F = new stdClass();
96 $F->name = odbc_field_name($this->result_id, $i);
97 $F->type = odbc_field_type($this->result_id, $i);
98 $F->max_length = odbc_field_len($this->result_id, $i);
99 $F->primary_key = 0;
100 $F->default = '';
101
102 $retval[] = $F;
103 }
104
105 return $retval;
106 }
107
108 // --------------------------------------------------------------------
109
110 /**
111 * Free the result
112 *
113 * @return null
114 */
115 function free_result()
116 {
117 if (is_resource($this->result_id))
118 {
119 odbc_free_result($this->result_id);
120 $this->result_id = FALSE;
121 }
122 }
123
124 // --------------------------------------------------------------------
125
126 /**
127 * Data Seek
128 *
129 * Moves the internal pointer to the desired offset. We call
130 * this internally before fetching results to make sure the
131 * result set starts at zero
132 *
133 * @access private
134 * @return array
135 */
136 function _data_seek($n = 0)
137 {
138 return FALSE;
139 }
140
141 // --------------------------------------------------------------------
142
143 /**
144 * Result - associative array
145 *
146 * Returns the result set as an array
147 *
148 * @access private
149 * @return array
150 */
151 function _fetch_assoc()
152 {
153 if (function_exists('odbc_fetch_object'))
154 {
155 return odbc_fetch_array($this->result_id);
156 }
157 else
158 {
159 return $this->_odbc_fetch_array($this->result_id);
160 }
161 }
162
163 // --------------------------------------------------------------------
164
165 /**
166 * Result - object
167 *
168 * Returns the result set as an object
169 *
170 * @access private
171 * @return object
172 */
173 function _fetch_object()
174 {
175 if (function_exists('odbc_fetch_object'))
176 {
177 return odbc_fetch_object($this->result_id);
178 }
179 else
180 {
181 return $this->_odbc_fetch_object($this->result_id);
182 }
183 }
184
185
186 /**
187 * Result - object
188 *
189 * subsititutes the odbc_fetch_object function when
190 * not available (odbc_fetch_object requires unixODBC)
191 *
192 * @access private
193 * @return object
194 */
Derek Allardd2df9bc2007-04-15 17:41:17 +0000195 function _odbc_fetch_object(& $odbc_result) {
196 $rs = array();
197 $rs_obj = false;
198 if (odbc_fetch_into($odbc_result, $rs)) {
199 foreach ($rs as $k=>$v) {
200 $field_name= odbc_field_name($odbc_result, $k+1);
201 $rs_obj->$field_name = $v;
202 }
203 }
204 return $rs_obj;
205 }
206
207
208 /**
209 * Result - array
210 *
211 * subsititutes the odbc_fetch_array function when
212 * not available (odbc_fetch_array requires unixODBC)
213 *
214 * @access private
215 * @return array
216 */
Derek Allardd2df9bc2007-04-15 17:41:17 +0000217 function _odbc_fetch_array(& $odbc_result) {
218 $rs = array();
219 $rs_assoc = false;
220 if (odbc_fetch_into($odbc_result, $rs)) {
221 $rs_assoc=array();
222 foreach ($rs as $k=>$v) {
223 $field_name= odbc_field_name($odbc_result, $k+1);
224 $rs_assoc[$field_name] = $v;
225 }
226 }
227 return $rs_assoc;
228 }
229
230}
231
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000232
233/* End of file odbc_result.php */
234/* Location: ./system/database/drivers/odbc/odbc_result.php */