blob: 509c77a1b85f604ca3b6d615c587edb1ee92bc50 [file] [log] [blame]
Andrey Andreevb76029d2012-01-26 15:13:19 +02001<?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
Andrey Andreevb76029d2012-01-26 15:13:19 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevb76029d2012-01-26 15:13:19 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -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 *
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
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * ODBC Result Class
30 *
31 * This class extends the parent result class: CI_DB_result
32 *
33 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/database/
36 */
37class CI_DB_odbc_result extends CI_DB_result {
Barry Mienydd671972010-10-04 16:33:58 +020038
Derek Allard2067d1a2008-11-13 22:59:24 +000039 /**
40 * Number of rows in the result set
41 *
Andrey Andreevb76029d2012-01-26 15:13:19 +020042 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000043 */
Andrey Andreevb76029d2012-01-26 15:13:19 +020044 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000045 {
46 return @odbc_num_rows($this->result_id);
47 }
Barry Mienydd671972010-10-04 16:33:58 +020048
Derek Allard2067d1a2008-11-13 22:59:24 +000049 /**
50 * Number of fields in the result set
51 *
Andrey Andreevb76029d2012-01-26 15:13:19 +020052 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000053 */
Andrey Andreevb76029d2012-01-26 15:13:19 +020054 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000055 {
56 return @odbc_num_fields($this->result_id);
57 }
58
59 // --------------------------------------------------------------------
60
61 /**
62 * Fetch Field Names
63 *
64 * Generates an array of column names
65 *
Derek Allard2067d1a2008-11-13 22:59:24 +000066 * @return array
67 */
Andrey Andreevb76029d2012-01-26 15:13:19 +020068 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000069 {
70 $field_names = array();
Andrey Andreevb76029d2012-01-26 15:13:19 +020071 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +000072 {
Barry Mienydd671972010-10-04 16:33:58 +020073 $field_names[] = odbc_field_name($this->result_id, $i);
Derek Allard2067d1a2008-11-13 22:59:24 +000074 }
Barry Mienydd671972010-10-04 16:33:58 +020075
Derek Allard2067d1a2008-11-13 22:59:24 +000076 return $field_names;
77 }
78
79 // --------------------------------------------------------------------
80
81 /**
82 * Field data
83 *
84 * Generates an array of objects containing field meta-data
85 *
Derek Allard2067d1a2008-11-13 22:59:24 +000086 * @return array
87 */
Andrey Andreevb76029d2012-01-26 15:13:19 +020088 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +000089 {
90 $retval = array();
Andrey Andreevb76029d2012-01-26 15:13:19 +020091 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +000092 {
Andrey Andreevb76029d2012-01-26 15:13:19 +020093 $retval[$i] = new stdClass();
94 $retval[$i]->name = odbc_field_name($this->result_id, $i);
95 $retval[$i]->type = odbc_field_type($this->result_id, $i);
96 $retval[$i]->max_length = odbc_field_len($this->result_id, $i);
97 $retval[$i]->primary_key = 0;
98 $retval[$i]->default = '';
Derek Allard2067d1a2008-11-13 22:59:24 +000099 }
Barry Mienydd671972010-10-04 16:33:58 +0200100
Derek Allard2067d1a2008-11-13 22:59:24 +0000101 return $retval;
102 }
103
104 // --------------------------------------------------------------------
105
106 /**
107 * Free the result
108 *
Andrey Andreevb76029d2012-01-26 15:13:19 +0200109 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200110 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200111 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 {
113 if (is_resource($this->result_id))
114 {
115 odbc_free_result($this->result_id);
116 $this->result_id = FALSE;
117 }
118 }
119
120 // --------------------------------------------------------------------
121
122 /**
123 * Data Seek
124 *
Andrey Andreevb76029d2012-01-26 15:13:19 +0200125 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000126 * this internally before fetching results to make sure the
127 * result set starts at zero
128 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 * @return array
130 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200131 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200133 // Not supported
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 return FALSE;
135 }
136
137 // --------------------------------------------------------------------
138
139 /**
140 * Result - associative array
141 *
142 * Returns the result set as an array
143 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000144 * @return array
145 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200146 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200148 return function_exists('odbc_fetch_object')
149 ? odbc_fetch_array($this->result_id)
150 : $this->_odbc_fetch_array($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 }
152
153 // --------------------------------------------------------------------
154
155 /**
156 * Result - object
157 *
158 * Returns the result set as an object
159 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 * @return object
161 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200162 protected function _fetch_object()
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200164 return function_exists('odbc_fetch_object')
165 ? odbc_fetch_object($this->result_id)
166 : $this->_odbc_fetch_object($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 }
168
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 /**
170 * Result - object
171 *
172 * subsititutes the odbc_fetch_object function when
173 * not available (odbc_fetch_object requires unixODBC)
174 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 * @return object
176 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200177 private function _odbc_fetch_object(& $odbc_result)
178 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000179 $rs = array();
Andrey Andreevb76029d2012-01-26 15:13:19 +0200180 if ( ! odbc_fetch_into($odbc_result, $rs))
181 {
182 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000183 }
Andrey Andreevb76029d2012-01-26 15:13:19 +0200184
185 $rs_obj = new stdClass();
186 foreach ($rs as $k => $v)
187 {
188 $field_name = odbc_field_name($odbc_result, $k+1);
189 $rs_obj->$field_name = $v;
190 }
191
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 return $rs_obj;
193 }
194
195
196 /**
197 * Result - array
198 *
199 * subsititutes the odbc_fetch_array function when
200 * not available (odbc_fetch_array requires unixODBC)
201 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 * @return array
203 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200204 private function _odbc_fetch_array(& $odbc_result)
205 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 $rs = array();
Andrey Andreevb76029d2012-01-26 15:13:19 +0200207 if ( ! odbc_fetch_into($odbc_result, $rs))
208 {
209 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 }
Andrey Andreevb76029d2012-01-26 15:13:19 +0200211
212 $rs_assoc = array();
213 foreach ($rs as $k => $v)
214 {
215 $field_name = odbc_field_name($odbc_result, $k+1);
216 $rs_assoc[$field_name] = $v;
217 }
218
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 return $rs_assoc;
220 }
221
222}
223
Derek Allard2067d1a2008-11-13 22:59:24 +0000224/* End of file odbc_result.php */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200225/* Location: ./system/database/drivers/odbc/odbc_result.php */