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 | { |
| 41 | // get the results, count them, |
| 42 | // rerun query - otherwise we |
| 43 | // won't have data after calling |
| 44 | // num_rows() |
| 45 | $this->result_array(); |
| 46 | $rowcount = count($this->result_array); |
| 47 | @ociexecute($this->stmt_id); |
| 48 | if ($this->curs_id) |
admin | 3cad41e | 2006-10-02 03:21:46 +0000 | [diff] [blame] | 49 | { |
| 50 | @ociexecute($this->curs_id); |
| 51 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 52 | return $rowcount; |
| 53 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 54 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 55 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 56 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 57 | /** |
| 58 | * Number of fields in the result set |
| 59 | * |
| 60 | * @access public |
| 61 | * @return integer |
| 62 | */ |
| 63 | function num_fields() |
| 64 | { |
| 65 | $count = @ocinumcols($this->stmt_id); |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 66 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 67 | // if we used a limit, we added a field, |
| 68 | // subtract it out |
| 69 | if ($this->limit_used) |
| 70 | { |
| 71 | $count = $count - 1; |
| 72 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 73 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 74 | return $count; |
| 75 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 76 | |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 77 | // -------------------------------------------------------------------- |
| 78 | |
| 79 | /** |
| 80 | * Fetch Field Names |
| 81 | * |
| 82 | * Generates an array of column names |
| 83 | * |
| 84 | * @access public |
| 85 | * @return array |
| 86 | */ |
admin | 606f99c | 2006-10-11 23:48:41 +0000 | [diff] [blame] | 87 | function list_fields() |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 88 | { |
| 89 | $field_names = array(); |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 90 | $fieldCount = $this->num_fields(); |
| 91 | for ($c = 1; $c <= $fieldCount; $c++) |
| 92 | { |
| 93 | $field_names[] = ocicolumnname($this->stmt_id, $c); |
| 94 | } |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 95 | return $field_names; |
| 96 | } |
| 97 | |
admin | 606f99c | 2006-10-11 23:48:41 +0000 | [diff] [blame] | 98 | // Deprecated |
| 99 | function field_names() |
| 100 | { |
| 101 | return $this->list_fields(); |
| 102 | } |
| 103 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 104 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 105 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 106 | /** |
| 107 | * Field data |
| 108 | * |
| 109 | * Generates an array of objects containing field meta-data |
| 110 | * |
| 111 | * @access public |
| 112 | * @return array |
| 113 | */ |
| 114 | function field_data() |
| 115 | { |
| 116 | $retval = array(); |
| 117 | $fieldCount = $this->num_fields(); |
| 118 | for ($c = 1; $c <= $fieldCount; $c++) |
| 119 | { |
| 120 | $F = new stdClass(); |
| 121 | $F->name = ocicolumnname($this->stmt_id, $c); |
| 122 | $F->type = ocicolumntype($this->stmt_id, $c); |
| 123 | $F->max_length = ocicolumnsize($this->stmt_id, $c); |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 124 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 125 | $retval[] = $F; |
| 126 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 127 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 128 | return $retval; |
| 129 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 130 | |
| 131 | // -------------------------------------------------------------------- |
| 132 | |
| 133 | /** |
| 134 | * Free the result |
| 135 | * |
| 136 | * @return null |
| 137 | */ |
| 138 | function free_result() |
| 139 | { |
| 140 | if (is_resource($this->result_id)) |
| 141 | { |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 142 | OCIFreeStatement($this->result_id); |
| 143 | $this->result_id = FALSE; |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 147 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 148 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 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(&$row) |
| 158 | { |
| 159 | // if pulling from a cursor, use curs_id |
| 160 | if ($this->curs_id) |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 161 | { |
| 162 | return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); |
| 167 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 168 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 169 | |
admin | d2dd031 | 2006-10-05 04:34:38 +0000 | [diff] [blame] | 170 | // -------------------------------------------------------------------- |
| 171 | |
| 172 | /** |
| 173 | * Data Seek |
| 174 | * |
| 175 | * Moves the internal pointer to the desired offset. We call |
| 176 | * this internally before fetching results to make sure the |
| 177 | * result set starts at zero |
| 178 | * |
| 179 | * @access private |
| 180 | * @return array |
| 181 | */ |
| 182 | function _data_seek($n = 0) |
| 183 | { |
| 184 | return FALSE; |
| 185 | } |
| 186 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 187 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 188 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 189 | /** |
| 190 | * Result - object |
| 191 | * |
| 192 | * Returns the result set as an object |
| 193 | * |
| 194 | * @access private |
| 195 | * @return object |
| 196 | */ |
| 197 | function _fetch_object() |
| 198 | { |
| 199 | // the PHP 4 version of the oracle functions do not |
| 200 | // have a fetch method so we call the array version |
| 201 | // and build an object from that |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 202 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 203 | $row = array(); |
| 204 | $res = $this->_fetch_assoc($row); |
| 205 | if ($res != FALSE) |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 206 | { |
| 207 | $obj = new stdClass(); |
| 208 | foreach ($row as $key => $value) |
| 209 | { |
| 210 | $obj->{$key} = $value; |
| 211 | } |
| 212 | |
| 213 | $res = $obj; |
| 214 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 215 | return $res; |
| 216 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 217 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 218 | // -------------------------------------------------------------------- |
admin | d2dd031 | 2006-10-05 04:34:38 +0000 | [diff] [blame] | 219 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 220 | /** |
| 221 | * Query result. "array" version. |
| 222 | * |
| 223 | * @access public |
| 224 | * @return array |
| 225 | */ |
| 226 | function result_array() |
| 227 | { |
| 228 | if (count($this->result_array) > 0) |
| 229 | { |
| 230 | return $this->result_array; |
| 231 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 232 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 233 | // oracle's fetch functions do not |
| 234 | // return arrays, the information |
| 235 | // is returned in reference parameters |
| 236 | // |
| 237 | $row = NULL; |
| 238 | while ($this->_fetch_assoc($row)) |
| 239 | { |
| 240 | $this->result_array[] = $row; |
| 241 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 242 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 243 | if (count($this->result_array) == 0) |
| 244 | { |
| 245 | return FALSE; |
| 246 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 247 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 248 | return $this->result_array; |
| 249 | } |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 250 | |
| 251 | } |
| 252 | |
| 253 | ?> |