blob: 59adda76b4b36f5359b2fac3f9e349b2ceafdae5 [file] [log] [blame]
admin7b613c72006-09-24 18:05:17 +00001<?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 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.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 Rick Ellis
25 * @link http://www.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 * @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)
49 {
50 @ociexecute($this->curs_id);
51 }
52 return $rowcount;
53 }
54
55 // --------------------------------------------------------------------
56
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);
66
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 }
73
74 return $count;
75 }
76
adminab4f61b2006-09-25 22:12:32 +000077 // --------------------------------------------------------------------
78
79 /**
80 * Fetch Field Names
81 *
82 * Generates an array of column names
83 *
84 * @access public
85 * @return array
86 */
87 function field_names()
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
admin7b613c72006-09-24 18:05:17 +000098 // --------------------------------------------------------------------
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 function field_data()
109 {
110 $retval = array();
111 $fieldCount = $this->num_fields();
112 for ($c = 1; $c <= $fieldCount; $c++)
113 {
114 $F = new stdClass();
115 $F->name = ocicolumnname($this->stmt_id, $c);
116 $F->type = ocicolumntype($this->stmt_id, $c);
117 $F->max_length = ocicolumnsize($this->stmt_id, $c);
118
119 $retval[] = $F;
120 }
121
122 return $retval;
123 }
124
125 // --------------------------------------------------------------------
126
127 /**
128 * Free the result
129 *
130 * @return null
131 */
132 function free_result()
133 {
134 if (is_resource($this->result_id))
135 {
136 OCIFreeStatement($this->result_id);
137 $this->result_id = FALSE;
138 }
139 }
140
141 // --------------------------------------------------------------------
142
143 /**
144 * Result - associative array
145 *
146 * Returns the result set as an array
147 *
148 * @access private
149 * @return array
150 */
151 function _fetch_assoc(&$row)
152 {
153 // if pulling from a cursor, use curs_id
154 if ($this->curs_id)
155 {
156 return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
157 }
158 else
159 {
160 return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
161 }
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 // the PHP 4 version of the oracle functions do not
177 // have a fetch method so we call the array version
178 // and build an object from that
179
180 $row = array();
181 $res = $this->_fetch_assoc($row);
182 if ($res != FALSE)
183 {
184 $obj = new stdClass();
185 foreach ($row as $key => $value)
186 {
187 $obj->{$key} = $value;
188 }
189
190 $res = $obj;
191 }
192 return $res;
193 }
194
195 /**
196 * Query result. "array" version.
197 *
198 * @access public
199 * @return array
200 */
201 function result_array()
202 {
203 if (count($this->result_array) > 0)
204 {
205 return $this->result_array;
206 }
207
208 // oracle's fetch functions do not
209 // return arrays, the information
210 // is returned in reference parameters
211 //
212 $row = NULL;
213 while ($this->_fetch_assoc($row))
214 {
215 $this->result_array[] = $row;
216 }
217
218 if (count($this->result_array) == 0)
219 {
220 return FALSE;
221 }
222
223 return $this->result_array;
224 }
225
226}
227
228?>