blob: 2b5748f65ba86fec4247d2d994968a1efaf3ba14 [file] [log] [blame]
Derek Jones4b9c6292011-07-01 17:40:48 -05001<?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 *
Barry Mienydd671972010-10-04 16:33:58 +02007 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Derek Jones4b9c6292011-07-01 17:40:48 -05009 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
Barry Mienydd671972010-10-04 16:33:58 +020010 * @license http://codeigniter.com/user_guide/license.html
Derek Allard2067d1a2008-11-13 22:59:24 +000011 * @link http://codeigniter.com
Barry Mienydd671972010-10-04 16:33:58 +020012 * @since Version 1.0
Derek Allard2067d1a2008-11-13 22:59:24 +000013 * @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
Barry Mienydd671972010-10-04 16:33:58 +020024 * @author ExpressionEngine Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000025 * @link http://codeigniter.com/user_guide/database/
26 */
27class 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.
Barry Mienydd671972010-10-04 16:33:58 +020038 *
Derek Allard2067d1a2008-11-13 22:59:24 +000039 *
Derek Jones4b9c6292011-07-01 17:40:48 -050040 * @access public
41 * @return integer
Derek Allard2067d1a2008-11-13 22:59:24 +000042 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030043 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000044 {
Andrey Andreevef3e2402011-09-21 14:39:29 +030045 if ($this->num_rows === 0 && count($this->result_array()) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +000046 {
Andrey Andreevef3e2402011-09-21 14:39:29 +030047 $this->num_rows = count($this->result_array());
Andrey Andreev5c3a2022011-10-07 21:04:58 +030048 @oci_execute($this->stmt_id);
Andrey Andreevef3e2402011-09-21 14:39:29 +030049
50 if ($this->curs_id)
51 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +030052 @oci_execute($this->curs_id);
Andrey Andreevef3e2402011-09-21 14:39:29 +030053 }
Derek Allard2067d1a2008-11-13 22:59:24 +000054 }
55
Andrey Andreevef3e2402011-09-21 14:39:29 +030056 return $this->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000057 }
58
59 // --------------------------------------------------------------------
60
61 /**
62 * Number of fields in the result set
63 *
Derek Jones4b9c6292011-07-01 17:40:48 -050064 * @access public
65 * @return integer
Derek Allard2067d1a2008-11-13 22:59:24 +000066 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030067 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000068 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +030069 $count = @oci_num_fields($this->stmt_id);
Derek Allard2067d1a2008-11-13 22:59:24 +000070
71 // if we used a limit we subtract it
72 if ($this->limit_used)
73 {
74 $count = $count - 1;
75 }
76
77 return $count;
78 }
79
80 // --------------------------------------------------------------------
81
82 /**
83 * Fetch Field Names
84 *
85 * Generates an array of column names
86 *
87 * @access public
88 * @return array
89 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030090 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
92 $field_names = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +030093 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +000094 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +030095 $field_names[] = oci_field_name($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +000096 }
97 return $field_names;
98 }
99
100 // --------------------------------------------------------------------
101
102 /**
103 * Field data
104 *
105 * Generates an array of objects containing field meta-data
106 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500107 * @access public
108 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300110 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 {
112 $retval = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300113 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300115 $F = new stdClass();
116 $F->name = oci_field_name($this->stmt_id, $c);
117 $F->type = oci_field_type($this->stmt_id, $c);
118 $F->max_length = oci_field_size($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000119
120 $retval[] = $F;
121 }
122
123 return $retval;
124 }
125
126 // --------------------------------------------------------------------
127
128 /**
129 * Free the result
130 *
131 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200132 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300133 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 {
135 if (is_resource($this->result_id))
136 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300137 oci_free_statement($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 $this->result_id = FALSE;
139 }
140 }
141
142 // --------------------------------------------------------------------
143
144 /**
145 * Result - associative array
146 *
147 * Returns the result set as an array
148 *
Andrey Andreevbc95e472011-10-20 09:44:48 +0300149 * @access protected
Derek Jones4b9c6292011-07-01 17:40:48 -0500150 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300152 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 {
154 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300155 return oci_fetch_assoc($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 }
157
158 // --------------------------------------------------------------------
159
160 /**
161 * Result - object
162 *
163 * Returns the result set as an object
164 *
Andrey Andreevbc95e472011-10-20 09:44:48 +0300165 * @access protected
Derek Jones4b9c6292011-07-01 17:40:48 -0500166 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300168 protected function _fetch_object()
Barry Mienydd671972010-10-04 16:33:58 +0200169 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300170 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
171 return @oci_fetch_object($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 }
173
174 // --------------------------------------------------------------------
175
176 /**
Derek Jones4b9c6292011-07-01 17:40:48 -0500177 * Query result. "array" version.
Derek Allard2067d1a2008-11-13 22:59:24 +0000178 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500179 * @access public
180 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000181 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300182 public function result_array()
Derek Allard2067d1a2008-11-13 22:59:24 +0000183 {
184 if (count($this->result_array) > 0)
185 {
186 return $this->result_array;
187 }
188
Derek Allard2067d1a2008-11-13 22:59:24 +0000189 $row = NULL;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300190 while ($row = $this->_fetch_assoc())
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 {
192 $this->result_array[] = $row;
193 }
194
195 return $this->result_array;
196 }
197
198 // --------------------------------------------------------------------
199
200 /**
201 * Data Seek
202 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500203 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 * this internally before fetching results to make sure the
205 * result set starts at zero
206 *
Andrey Andreevbc95e472011-10-20 09:44:48 +0300207 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 * @return array
209 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300210 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000211 {
212 return FALSE; // Not needed
213 }
214
215}
216
217
218/* End of file oci8_result.php */
Andrey Andreevef3e2402011-09-21 14:39:29 +0300219/* Location: ./system/database/drivers/oci8/oci8_result.php */