blob: 320b9327ccec46528f58adb2f3f081151acce0df [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 {
Andrey Andreevbb8a6832012-02-14 12:17:13 +020070 $num_fields = $this->num_fields();
71 if ($num_fields > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +000072 {
Andrey Andreevbb8a6832012-02-14 12:17:13 +020073 $field_names = array();
74 for ($i = 1; $i <= $num_fields; $i++)
75 {
76 $field_names[] = odbc_field_name($this->result_id, $i);
77 }
78
79 return $field_names;
Derek Allard2067d1a2008-11-13 22:59:24 +000080 }
Barry Mienydd671972010-10-04 16:33:58 +020081
Andrey Andreevbb8a6832012-02-14 12:17:13 +020082 return array();
Derek Allard2067d1a2008-11-13 22:59:24 +000083 }
84
85 // --------------------------------------------------------------------
86
87 /**
88 * Field data
89 *
90 * Generates an array of objects containing field meta-data
91 *
Derek Allard2067d1a2008-11-13 22:59:24 +000092 * @return array
93 */
Andrey Andreevb76029d2012-01-26 15:13:19 +020094 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +000095 {
96 $retval = array();
Andrey Andreevbb8a6832012-02-14 12:17:13 +020097 for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++)
Derek Allard2067d1a2008-11-13 22:59:24 +000098 {
Andrey Andreevb76029d2012-01-26 15:13:19 +020099 $retval[$i] = new stdClass();
Andrey Andreevbb8a6832012-02-14 12:17:13 +0200100 $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index);
101 $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index);
102 $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index);
Andrey Andreevb76029d2012-01-26 15:13:19 +0200103 $retval[$i]->primary_key = 0;
104 $retval[$i]->default = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 }
Barry Mienydd671972010-10-04 16:33:58 +0200106
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 return $retval;
108 }
109
110 // --------------------------------------------------------------------
111
112 /**
113 * Free the result
114 *
Andrey Andreevb76029d2012-01-26 15:13:19 +0200115 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200116 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200117 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 {
119 if (is_resource($this->result_id))
120 {
121 odbc_free_result($this->result_id);
122 $this->result_id = FALSE;
123 }
124 }
125
126 // --------------------------------------------------------------------
127
128 /**
129 * Data Seek
130 *
Andrey Andreevb76029d2012-01-26 15:13:19 +0200131 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 * this internally before fetching results to make sure the
133 * result set starts at zero
134 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 * @return array
136 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200137 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200139 // Not supported
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 return FALSE;
141 }
142
143 // --------------------------------------------------------------------
144
145 /**
146 * Result - associative array
147 *
148 * Returns the result set as an array
149 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000150 * @return array
151 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200152 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 {
Andrey Andreev7e934892012-02-12 03:29:06 +0200154 return function_exists('odbc_fetch_array')
Andrey Andreevb76029d2012-01-26 15:13:19 +0200155 ? odbc_fetch_array($this->result_id)
156 : $this->_odbc_fetch_array($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 }
158
159 // --------------------------------------------------------------------
160
161 /**
162 * Result - object
163 *
164 * Returns the result set as an object
165 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 * @return object
167 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200168 protected function _fetch_object()
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200170 return function_exists('odbc_fetch_object')
171 ? odbc_fetch_object($this->result_id)
172 : $this->_odbc_fetch_object($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 }
174
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 /**
176 * Result - object
177 *
178 * subsititutes the odbc_fetch_object function when
179 * not available (odbc_fetch_object requires unixODBC)
180 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000181 * @return object
182 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200183 private function _odbc_fetch_object(& $odbc_result)
184 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000185 $rs = array();
Andrey Andreevb76029d2012-01-26 15:13:19 +0200186 if ( ! odbc_fetch_into($odbc_result, $rs))
187 {
188 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000189 }
Andrey Andreevb76029d2012-01-26 15:13:19 +0200190
191 $rs_obj = new stdClass();
192 foreach ($rs as $k => $v)
193 {
Andrey Andreevd0b256f2012-02-13 12:20:11 +0200194 $field_name = odbc_field_name($odbc_result, $k+1);
Andrey Andreevb76029d2012-01-26 15:13:19 +0200195 $rs_obj->$field_name = $v;
196 }
197
Derek Allard2067d1a2008-11-13 22:59:24 +0000198 return $rs_obj;
199 }
200
201
202 /**
203 * Result - array
204 *
205 * subsititutes the odbc_fetch_array function when
206 * not available (odbc_fetch_array requires unixODBC)
207 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 * @return array
209 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200210 private function _odbc_fetch_array(& $odbc_result)
211 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 $rs = array();
Andrey Andreevb76029d2012-01-26 15:13:19 +0200213 if ( ! odbc_fetch_into($odbc_result, $rs))
214 {
215 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000216 }
Andrey Andreevb76029d2012-01-26 15:13:19 +0200217
218 $rs_assoc = array();
219 foreach ($rs as $k => $v)
220 {
Andrey Andreevd0b256f2012-02-13 12:20:11 +0200221 $field_name = odbc_field_name($odbc_result, $k+1);
Andrey Andreevb76029d2012-01-26 15:13:19 +0200222 $rs_assoc[$field_name] = $v;
223 }
224
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 return $rs_assoc;
226 }
227
228}
229
Derek Allard2067d1a2008-11-13 22:59:24 +0000230/* End of file odbc_result.php */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200231/* Location: ./system/database/drivers/odbc/odbc_result.php */