]>
Commit | Line | Data |
---|---|---|
59c06b17 CS |
1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
2 | /** | |
3 | * CodeIgniter | |
4 | * | |
5 | * An open source application development framework for PHP 5.1.6 or newer | |
6 | * | |
7 | * @package CodeIgniter | |
8 | * @author ExpressionEngine Dev Team | |
9 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. | |
10 | * @license http://codeigniter.com/user_guide/license.html | |
11 | * @link http://codeigniter.com | |
12 | * @since Version 1.0 | |
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 | |
24 | * @author ExpressionEngine Dev Team | |
25 | * @link http://codeigniter.com/user_guide/database/ | |
26 | */ | |
27 | class CI_DB_oci8_result extends CI_DB_result { | |
28 | ||
29 | public $stmt_id; | |
30 | public $curs_id; | |
31 | public $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 | * @return integer | |
40 | */ | |
41 | public function num_rows() | |
42 | { | |
43 | if ($this->num_rows === 0 && count($this->result_array()) > 0) | |
44 | { | |
45 | $this->num_rows = count($this->result_array()); | |
46 | @oci_execute($this->stmt_id); | |
47 | ||
48 | if ($this->curs_id) | |
49 | { | |
50 | @oci_execute($this->curs_id); | |
51 | } | |
52 | } | |
53 | ||
54 | return $this->num_rows; | |
55 | } | |
56 | ||
57 | // -------------------------------------------------------------------- | |
58 | ||
59 | /** | |
60 | * Number of fields in the result set | |
61 | * | |
62 | * @access public | |
63 | * @return integer | |
64 | */ | |
65 | public function num_fields() | |
66 | { | |
67 | $count = @oci_num_fields($this->stmt_id); | |
68 | ||
69 | // if we used a limit we subtract it | |
70 | if ($this->limit_used) | |
71 | { | |
72 | $count = $count - 1; | |
73 | } | |
74 | ||
75 | return $count; | |
76 | } | |
77 | ||
78 | // -------------------------------------------------------------------- | |
79 | ||
80 | /** | |
81 | * Fetch Field Names | |
82 | * | |
83 | * Generates an array of column names | |
84 | * | |
85 | * @access public | |
86 | * @return array | |
87 | */ | |
88 | public function list_fields() | |
89 | { | |
90 | $field_names = array(); | |
91 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) | |
92 | { | |
93 | $field_names[] = oci_field_name($this->stmt_id, $c); | |
94 | } | |
95 | return $field_names; | |
96 | } | |
97 | ||
98 | // -------------------------------------------------------------------- | |
99 | ||
100 | /** | |
101 | * Field data | |
102 | * | |
103 | * Generates an array of objects containing field meta-data | |
104 | * | |
105 | * @access public | |
106 | * @return array | |
107 | */ | |
108 | public function field_data() | |
109 | { | |
110 | $retval = array(); | |
111 | for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) | |
112 | { | |
113 | $F = new stdClass(); | |
114 | $F->name = oci_field_name($this->stmt_id, $c); | |
115 | $F->type = oci_field_type($this->stmt_id, $c); | |
116 | $F->max_length = oci_field_size($this->stmt_id, $c); | |
117 | ||
118 | $retval[] = $F; | |
119 | } | |
120 | ||
121 | return $retval; | |
122 | } | |
123 | ||
124 | // -------------------------------------------------------------------- | |
125 | ||
126 | /** | |
127 | * Free the result | |
128 | * | |
129 | * @return null | |
130 | */ | |
131 | public function free_result() | |
132 | { | |
133 | if (is_resource($this->result_id)) | |
134 | { | |
135 | oci_free_statement($this->result_id); | |
136 | $this->result_id = FALSE; | |
137 | } | |
138 | } | |
139 | ||
140 | // -------------------------------------------------------------------- | |
141 | ||
142 | /** | |
143 | * Result - associative array | |
144 | * | |
145 | * Returns the result set as an array | |
146 | * | |
147 | * @access protected | |
148 | * @return array | |
149 | */ | |
150 | protected function _fetch_assoc() | |
151 | { | |
152 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; | |
153 | return oci_fetch_assoc($id); | |
154 | } | |
155 | ||
156 | // -------------------------------------------------------------------- | |
157 | ||
158 | /** | |
159 | * Result - object | |
160 | * | |
161 | * Returns the result set as an object | |
162 | * | |
163 | * @access protected | |
164 | * @return object | |
165 | */ | |
166 | protected function _fetch_object() | |
167 | { | |
168 | $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; | |
169 | return @oci_fetch_object($id); | |
170 | } | |
171 | ||
172 | // -------------------------------------------------------------------- | |
173 | ||
174 | /** | |
175 | * Query result. "array" version. | |
176 | * | |
177 | * @access public | |
178 | * @return array | |
179 | */ | |
180 | public function result_array() | |
181 | { | |
182 | if (count($this->result_array) > 0) | |
183 | { | |
184 | return $this->result_array; | |
185 | } | |
186 | ||
187 | $row = NULL; | |
188 | while ($row = $this->_fetch_assoc()) | |
189 | { | |
190 | $this->result_array[] = $row; | |
191 | } | |
192 | ||
193 | return $this->result_array; | |
194 | } | |
195 | ||
196 | // -------------------------------------------------------------------- | |
197 | ||
198 | /** | |
199 | * Data Seek | |
200 | * | |
201 | * Moves the internal pointer to the desired offset. We call | |
202 | * this internally before fetching results to make sure the | |
203 | * result set starts at zero | |
204 | * | |
205 | * @access protected | |
206 | * @return array | |
207 | */ | |
208 | protected function _data_seek($n = 0) | |
209 | { | |
210 | return FALSE; // Not needed | |
211 | } | |
212 | ||
213 | } | |
214 | ||
215 | ||
216 | /* End of file oci8_result.php */ | |
217 | /* Location: ./system/database/drivers/oci8/oci8_result.php */ |