Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @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 Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/database/ |
| 38 | */ |
| 39 | class CI_DB_odbc_result extends CI_DB_result { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 40 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Number of rows in the result set |
| 43 | * |
| 44 | * @access public |
| 45 | * @return integer |
| 46 | */ |
| 47 | function num_rows() |
| 48 | { |
| 49 | return @odbc_num_rows($this->result_id); |
| 50 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 51 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | // -------------------------------------------------------------------- |
| 53 | |
| 54 | /** |
| 55 | * Number of fields in the result set |
| 56 | * |
Andrey Andreev | 41e46a9 | 2012-03-01 14:58:17 +0200 | [diff] [blame^] | 57 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 58 | */ |
Andrey Andreev | 41e46a9 | 2012-03-01 14:58:17 +0200 | [diff] [blame^] | 59 | public function num_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 60 | { |
| 61 | return @odbc_num_fields($this->result_id); |
| 62 | } |
| 63 | |
| 64 | // -------------------------------------------------------------------- |
| 65 | |
| 66 | /** |
| 67 | * Fetch Field Names |
| 68 | * |
| 69 | * Generates an array of column names |
| 70 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | * @return array |
| 72 | */ |
Andrey Andreev | 41e46a9 | 2012-03-01 14:58:17 +0200 | [diff] [blame^] | 73 | public function list_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 74 | { |
| 75 | $field_names = array(); |
Andrey Andreev | 41e46a9 | 2012-03-01 14:58:17 +0200 | [diff] [blame^] | 76 | $num_fields = $this->num_fields(); |
| 77 | |
| 78 | if ($num_fields > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 79 | { |
Andrey Andreev | 41e46a9 | 2012-03-01 14:58:17 +0200 | [diff] [blame^] | 80 | for ($i = 1; $i <= $num_fields; $i++) |
| 81 | { |
| 82 | $field_names[] = odbc_field_name($this->result_id, $i); |
| 83 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 84 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 85 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 86 | return $field_names; |
| 87 | } |
| 88 | |
| 89 | // -------------------------------------------------------------------- |
| 90 | |
| 91 | /** |
| 92 | * Field data |
| 93 | * |
| 94 | * Generates an array of objects containing field meta-data |
| 95 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 96 | * @return array |
| 97 | */ |
Andrey Andreev | 41e46a9 | 2012-03-01 14:58:17 +0200 | [diff] [blame^] | 98 | public function field_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 99 | { |
| 100 | $retval = array(); |
Andrey Andreev | 41e46a9 | 2012-03-01 14:58:17 +0200 | [diff] [blame^] | 101 | for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 102 | { |
Andrey Andreev | 41e46a9 | 2012-03-01 14:58:17 +0200 | [diff] [blame^] | 103 | $retval[$i] = new stdClass(); |
| 104 | $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index); |
| 105 | $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index); |
| 106 | $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index); |
| 107 | $retval[$i]->primary_key = 0; |
| 108 | $retval[$i]->default = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 109 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 110 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 111 | return $retval; |
| 112 | } |
| 113 | |
| 114 | // -------------------------------------------------------------------- |
| 115 | |
| 116 | /** |
| 117 | * Free the result |
| 118 | * |
| 119 | * @return null |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 120 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 121 | function free_result() |
| 122 | { |
| 123 | if (is_resource($this->result_id)) |
| 124 | { |
| 125 | odbc_free_result($this->result_id); |
| 126 | $this->result_id = FALSE; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // -------------------------------------------------------------------- |
| 131 | |
| 132 | /** |
| 133 | * Data Seek |
| 134 | * |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 135 | * Moves the internal pointer to the desired offset. We call |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 136 | * this internally before fetching results to make sure the |
| 137 | * result set starts at zero |
| 138 | * |
| 139 | * @access private |
| 140 | * @return array |
| 141 | */ |
| 142 | function _data_seek($n = 0) |
| 143 | { |
| 144 | return FALSE; |
| 145 | } |
| 146 | |
| 147 | // -------------------------------------------------------------------- |
| 148 | |
| 149 | /** |
| 150 | * Result - associative array |
| 151 | * |
| 152 | * Returns the result set as an array |
| 153 | * |
| 154 | * @access private |
| 155 | * @return array |
| 156 | */ |
| 157 | function _fetch_assoc() |
| 158 | { |
| 159 | if (function_exists('odbc_fetch_object')) |
| 160 | { |
| 161 | return odbc_fetch_array($this->result_id); |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | return $this->_odbc_fetch_array($this->result_id); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // -------------------------------------------------------------------- |
| 170 | |
| 171 | /** |
| 172 | * Result - object |
| 173 | * |
| 174 | * Returns the result set as an object |
| 175 | * |
| 176 | * @access private |
| 177 | * @return object |
| 178 | */ |
| 179 | function _fetch_object() |
| 180 | { |
| 181 | if (function_exists('odbc_fetch_object')) |
| 182 | { |
| 183 | return odbc_fetch_object($this->result_id); |
| 184 | } |
| 185 | else |
| 186 | { |
| 187 | return $this->_odbc_fetch_object($this->result_id); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | |
| 192 | /** |
| 193 | * Result - object |
| 194 | * |
| 195 | * subsititutes the odbc_fetch_object function when |
| 196 | * not available (odbc_fetch_object requires unixODBC) |
| 197 | * |
| 198 | * @access private |
| 199 | * @return object |
| 200 | */ |
| 201 | function _odbc_fetch_object(& $odbc_result) { |
| 202 | $rs = array(); |
Pascal Kriete | 8761ef5 | 2011-02-14 13:13:52 -0500 | [diff] [blame] | 203 | $rs_obj = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 204 | if (odbc_fetch_into($odbc_result, $rs)) { |
| 205 | foreach ($rs as $k=>$v) { |
| 206 | $field_name= odbc_field_name($odbc_result, $k+1); |
| 207 | $rs_obj->$field_name = $v; |
| 208 | } |
| 209 | } |
| 210 | return $rs_obj; |
| 211 | } |
| 212 | |
| 213 | |
| 214 | /** |
| 215 | * Result - array |
| 216 | * |
| 217 | * subsititutes the odbc_fetch_array function when |
| 218 | * not available (odbc_fetch_array requires unixODBC) |
| 219 | * |
| 220 | * @access private |
| 221 | * @return array |
| 222 | */ |
| 223 | function _odbc_fetch_array(& $odbc_result) { |
| 224 | $rs = array(); |
Pascal Kriete | 8761ef5 | 2011-02-14 13:13:52 -0500 | [diff] [blame] | 225 | $rs_assoc = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 226 | if (odbc_fetch_into($odbc_result, $rs)) { |
| 227 | $rs_assoc=array(); |
| 228 | foreach ($rs as $k=>$v) { |
| 229 | $field_name= odbc_field_name($odbc_result, $k+1); |
| 230 | $rs_assoc[$field_name] = $v; |
| 231 | } |
| 232 | } |
| 233 | return $rs_assoc; |
| 234 | } |
| 235 | |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /* End of file odbc_result.php */ |
Andrey Andreev | 41e46a9 | 2012-03-01 14:58:17 +0200 | [diff] [blame^] | 240 | /* Location: ./system/database/drivers/odbc/odbc_result.php */ |