Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 7 | * @package CodeIgniter
|
| 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 12 | * @since Version 1.0
|
Derek Allard | d2df9bc | 2007-04-15 17:41: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 | *
|
| 23 | * @category Database
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 25 | * @link http://codeigniter.com/user_guide/database/
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 26 | */
|
| 27 | class CI_DB_oci8_result extends CI_DB_result {
|
| 28 |
|
| 29 | var $stmt_id;
|
| 30 | var $curs_id;
|
| 31 | var $limit_used;
|
| 32 |
|
| 33 | /**
|
| 34 | * Number of rows in the result set.
|
| 35 | *
|
| 36 | * Oracle doesn't have a graceful way to retun the number of rows
|
| 37 | * so we have to use what amounts to a hack.
|
| 38 | *
|
| 39 | *
|
| 40 | * @access public
|
| 41 | * @return integer
|
| 42 | */
|
| 43 | function num_rows()
|
| 44 | {
|
Derek Allard | 993925b | 2008-08-21 12:43:31 +0000 | [diff] [blame] | 45 | $rowcount = count($this->result_array());
|
| 46 | @ociexecute($this->stmt_id);
|
| 47 |
|
| 48 | if ($this->curs_id)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 49 | {
|
| 50 | @ociexecute($this->curs_id);
|
| 51 | }
|
Derek Allard | 993925b | 2008-08-21 12:43:31 +0000 | [diff] [blame] | 52 |
|
| 53 | return $rowcount;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 54 | }
|
| 55 |
|
| 56 | // --------------------------------------------------------------------
|
| 57 |
|
| 58 | /**
|
| 59 | * Number of fields in the result set
|
| 60 | *
|
| 61 | * @access public
|
| 62 | * @return integer
|
| 63 | */
|
| 64 | function num_fields()
|
| 65 | {
|
| 66 | $count = @ocinumcols($this->stmt_id);
|
| 67 |
|
| 68 | // if we used a limit we subtract it
|
| 69 | if ($this->limit_used)
|
| 70 | {
|
| 71 | $count = $count - 1;
|
| 72 | }
|
| 73 |
|
| 74 | return $count;
|
| 75 | }
|
| 76 |
|
| 77 | // --------------------------------------------------------------------
|
| 78 |
|
| 79 | /**
|
| 80 | * Fetch Field Names
|
| 81 | *
|
| 82 | * Generates an array of column names
|
| 83 | *
|
| 84 | * @access public
|
| 85 | * @return array
|
| 86 | */
|
| 87 | function list_fields()
|
| 88 | {
|
| 89 | $field_names = array();
|
| 90 | $fieldCount = $this->num_fields();
|
| 91 | for ($c = 1; $c <= $fieldCount; $c++)
|
| 92 | {
|
| 93 | $field_names[] = ocicolumnname($this->stmt_id, $c);
|
| 94 | }
|
| 95 | return $field_names;
|
| 96 | }
|
| 97 |
|
| 98 | // Deprecated
|
| 99 | function field_names()
|
| 100 | {
|
| 101 | return $this->list_fields();
|
| 102 | }
|
| 103 |
|
| 104 | // --------------------------------------------------------------------
|
| 105 |
|
| 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);
|
| 124 |
|
| 125 | $retval[] = $F;
|
| 126 | }
|
| 127 |
|
| 128 | return $retval;
|
| 129 | }
|
| 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 | {
|
| 142 | ocifreestatement($this->result_id);
|
| 143 | $this->result_id = FALSE;
|
| 144 | }
|
| 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(&$row)
|
| 158 | {
|
| 159 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
|
| 160 |
|
| 161 | return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
|
| 162 | }
|
| 163 |
|
| 164 | // --------------------------------------------------------------------
|
| 165 |
|
| 166 | /**
|
| 167 | * Result - object
|
| 168 | *
|
| 169 | * Returns the result set as an object
|
| 170 | *
|
| 171 | * @access private
|
| 172 | * @return object
|
| 173 | */
|
| 174 | function _fetch_object()
|
| 175 | {
|
| 176 | $result = array();
|
| 177 |
|
| 178 | // If PHP 5 is being used we can fetch an result object
|
| 179 | if (function_exists('oci_fetch_object'))
|
| 180 | {
|
| 181 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
|
| 182 |
|
| 183 | return @oci_fetch_object($id);
|
| 184 | }
|
| 185 |
|
| 186 | // If PHP 4 is being used we have to build our own result
|
| 187 | foreach ($this->result_array() as $key => $val)
|
| 188 | {
|
| 189 | $obj = new stdClass();
|
| 190 | if (is_array($val))
|
| 191 | {
|
| 192 | foreach ($val as $k => $v)
|
| 193 | {
|
| 194 | $obj->$k = $v;
|
| 195 | }
|
| 196 | }
|
| 197 | else
|
| 198 | {
|
| 199 | $obj->$key = $val;
|
| 200 | }
|
| 201 |
|
| 202 | $result[] = $obj;
|
| 203 | }
|
| 204 |
|
| 205 | return $result;
|
| 206 | }
|
| 207 |
|
| 208 | // --------------------------------------------------------------------
|
| 209 |
|
| 210 | /**
|
| 211 | * Query result. "array" version.
|
| 212 | *
|
| 213 | * @access public
|
| 214 | * @return array
|
| 215 | */
|
| 216 | function result_array()
|
| 217 | {
|
| 218 | if (count($this->result_array) > 0)
|
| 219 | {
|
| 220 | return $this->result_array;
|
| 221 | }
|
| 222 |
|
| 223 | // oracle's fetch functions do not return arrays.
|
| 224 | // The information is returned in reference parameters
|
| 225 | $row = NULL;
|
| 226 | while ($this->_fetch_assoc($row))
|
| 227 | {
|
| 228 | $this->result_array[] = $row;
|
| 229 | }
|
| 230 |
|
| 231 | return $this->result_array;
|
| 232 | }
|
| 233 |
|
| 234 | // --------------------------------------------------------------------
|
| 235 |
|
| 236 | /**
|
| 237 | * Data Seek
|
| 238 | *
|
| 239 | * Moves the internal pointer to the desired offset. We call
|
| 240 | * this internally before fetching results to make sure the
|
| 241 | * result set starts at zero
|
| 242 | *
|
| 243 | * @access private
|
| 244 | * @return array
|
| 245 | */
|
| 246 | function _data_seek($n = 0)
|
| 247 | {
|
| 248 | return FALSE; // Not needed
|
| 249 | }
|
| 250 |
|
| 251 | }
|
| 252 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 253 |
|
| 254 | /* End of file oci8_result.php */
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 255 | /* Location: ./system/database/drivers/oci8/oci8_result.php */ |