admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 10 | * @license http://www.codeignitor.com/user_guide/license.html |
| 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * oci8 Result Class |
| 20 | * |
| 21 | * This class extends the parent result class: CI_DB_result |
| 22 | * |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 23 | * @category Database |
| 24 | * @author Rick Ellis |
| 25 | * @link http://www.codeigniter.com/user_guide/database/ |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 26 | */ |
| 27 | class CI_DB_oci8_result extends CI_DB_result { |
| 28 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 29 | var $stmt_id; |
| 30 | var $curs_id; |
| 31 | var $limit_used; |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 32 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 33 | /** |
| 34 | * Number of rows in the result set |
| 35 | * |
| 36 | * @access public |
| 37 | * @return integer |
| 38 | */ |
| 39 | function num_rows() |
| 40 | { |
admin | 3f643e6 | 2006-10-27 06:25:31 +0000 | [diff] [blame^] | 41 | if (function_exists('oci_num_rows')) |
admin | 3cad41e | 2006-10-02 03:21:46 +0000 | [diff] [blame] | 42 | { |
admin | 3f643e6 | 2006-10-27 06:25:31 +0000 | [diff] [blame^] | 43 | return @oci_num_rows($this->stmt_id); |
admin | 3cad41e | 2006-10-02 03:21:46 +0000 | [diff] [blame] | 44 | } |
admin | 3f643e6 | 2006-10-27 06:25:31 +0000 | [diff] [blame^] | 45 | else |
| 46 | { |
| 47 | return @ocirowcount($this->stmt_id) |
| 48 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 49 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 50 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 51 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 52 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 53 | /** |
| 54 | * Number of fields in the result set |
| 55 | * |
| 56 | * @access public |
| 57 | * @return integer |
| 58 | */ |
| 59 | function num_fields() |
| 60 | { |
| 61 | $count = @ocinumcols($this->stmt_id); |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 62 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 63 | // if we used a limit, we added a field, |
| 64 | // subtract it out |
| 65 | if ($this->limit_used) |
| 66 | { |
| 67 | $count = $count - 1; |
| 68 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 69 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 70 | return $count; |
| 71 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 72 | |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 73 | // -------------------------------------------------------------------- |
| 74 | |
| 75 | /** |
| 76 | * Fetch Field Names |
| 77 | * |
| 78 | * Generates an array of column names |
| 79 | * |
| 80 | * @access public |
| 81 | * @return array |
| 82 | */ |
admin | 606f99c | 2006-10-11 23:48:41 +0000 | [diff] [blame] | 83 | function list_fields() |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 84 | { |
| 85 | $field_names = array(); |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 86 | $fieldCount = $this->num_fields(); |
| 87 | for ($c = 1; $c <= $fieldCount; $c++) |
| 88 | { |
| 89 | $field_names[] = ocicolumnname($this->stmt_id, $c); |
| 90 | } |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 91 | return $field_names; |
| 92 | } |
| 93 | |
admin | 606f99c | 2006-10-11 23:48:41 +0000 | [diff] [blame] | 94 | // Deprecated |
| 95 | function field_names() |
| 96 | { |
| 97 | return $this->list_fields(); |
| 98 | } |
| 99 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 100 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 101 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 102 | /** |
| 103 | * Field data |
| 104 | * |
| 105 | * Generates an array of objects containing field meta-data |
| 106 | * |
| 107 | * @access public |
| 108 | * @return array |
| 109 | */ |
| 110 | function field_data() |
| 111 | { |
| 112 | $retval = array(); |
| 113 | $fieldCount = $this->num_fields(); |
| 114 | for ($c = 1; $c <= $fieldCount; $c++) |
| 115 | { |
| 116 | $F = new stdClass(); |
| 117 | $F->name = ocicolumnname($this->stmt_id, $c); |
| 118 | $F->type = ocicolumntype($this->stmt_id, $c); |
| 119 | $F->max_length = ocicolumnsize($this->stmt_id, $c); |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 120 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 121 | $retval[] = $F; |
| 122 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 123 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 124 | return $retval; |
| 125 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 126 | |
| 127 | // -------------------------------------------------------------------- |
| 128 | |
| 129 | /** |
| 130 | * Free the result |
| 131 | * |
| 132 | * @return null |
| 133 | */ |
| 134 | function free_result() |
| 135 | { |
| 136 | if (is_resource($this->result_id)) |
| 137 | { |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 138 | OCIFreeStatement($this->result_id); |
| 139 | $this->result_id = FALSE; |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 143 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 144 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 145 | /** |
| 146 | * Result - associative array |
| 147 | * |
| 148 | * Returns the result set as an array |
| 149 | * |
| 150 | * @access private |
| 151 | * @return array |
| 152 | */ |
| 153 | function _fetch_assoc(&$row) |
| 154 | { |
| 155 | // if pulling from a cursor, use curs_id |
| 156 | if ($this->curs_id) |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 157 | { |
| 158 | return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); |
| 159 | } |
| 160 | else |
| 161 | { |
| 162 | return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); |
| 163 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 164 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 165 | |
admin | d2dd031 | 2006-10-05 04:34:38 +0000 | [diff] [blame] | 166 | // -------------------------------------------------------------------- |
| 167 | |
| 168 | /** |
| 169 | * Data Seek |
| 170 | * |
| 171 | * Moves the internal pointer to the desired offset. We call |
| 172 | * this internally before fetching results to make sure the |
| 173 | * result set starts at zero |
| 174 | * |
| 175 | * @access private |
| 176 | * @return array |
| 177 | */ |
| 178 | function _data_seek($n = 0) |
| 179 | { |
| 180 | return FALSE; |
| 181 | } |
| 182 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 183 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 184 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 185 | /** |
| 186 | * Result - object |
| 187 | * |
| 188 | * Returns the result set as an object |
| 189 | * |
| 190 | * @access private |
| 191 | * @return object |
| 192 | */ |
| 193 | function _fetch_object() |
| 194 | { |
| 195 | // the PHP 4 version of the oracle functions do not |
| 196 | // have a fetch method so we call the array version |
| 197 | // and build an object from that |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 198 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 199 | $row = array(); |
| 200 | $res = $this->_fetch_assoc($row); |
| 201 | if ($res != FALSE) |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 202 | { |
| 203 | $obj = new stdClass(); |
| 204 | foreach ($row as $key => $value) |
| 205 | { |
| 206 | $obj->{$key} = $value; |
| 207 | } |
| 208 | |
| 209 | $res = $obj; |
| 210 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 211 | return $res; |
| 212 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 213 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 214 | // -------------------------------------------------------------------- |
admin | d2dd031 | 2006-10-05 04:34:38 +0000 | [diff] [blame] | 215 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 216 | /** |
| 217 | * Query result. "array" version. |
| 218 | * |
| 219 | * @access public |
| 220 | * @return array |
| 221 | */ |
| 222 | function result_array() |
| 223 | { |
| 224 | if (count($this->result_array) > 0) |
| 225 | { |
| 226 | return $this->result_array; |
| 227 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 228 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 229 | // oracle's fetch functions do not |
| 230 | // return arrays, the information |
| 231 | // is returned in reference parameters |
| 232 | // |
| 233 | $row = NULL; |
| 234 | while ($this->_fetch_assoc($row)) |
| 235 | { |
| 236 | $this->result_array[] = $row; |
| 237 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 238 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 239 | if (count($this->result_array) == 0) |
| 240 | { |
| 241 | return FALSE; |
| 242 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 243 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 244 | return $this->result_array; |
| 245 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 246 | |
| 247 | } |
| 248 | |
| 249 | ?> |