blob: d2354a1c6259e317d71a21c7fd5e4af99d4a8c9e [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
77 // --------------------------------------------------------------------
78
79 /**
80 * Field data
81 *
82 * Generates an array of objects containing field meta-data
83 *
84 * @access public
85 * @return array
86 */
87 function field_data()
88 {
89 $retval = array();
90 $fieldCount = $this->num_fields();
91 for ($c = 1; $c <= $fieldCount; $c++)
92 {
93 $F = new stdClass();
94 $F->name = ocicolumnname($this->stmt_id, $c);
95 $F->type = ocicolumntype($this->stmt_id, $c);
96 $F->max_length = ocicolumnsize($this->stmt_id, $c);
97
98 $retval[] = $F;
99 }
100
101 return $retval;
102 }
103
104 // --------------------------------------------------------------------
105
106 /**
107 * Free the result
108 *
109 * @return null
110 */
111 function free_result()
112 {
113 if (is_resource($this->result_id))
114 {
115 OCIFreeStatement($this->result_id);
116 $this->result_id = FALSE;
117 }
118 }
119
120 // --------------------------------------------------------------------
121
122 /**
123 * Result - associative array
124 *
125 * Returns the result set as an array
126 *
127 * @access private
128 * @return array
129 */
130 function _fetch_assoc(&$row)
131 {
132 // if pulling from a cursor, use curs_id
133 if ($this->curs_id)
134 {
135 return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
136 }
137 else
138 {
139 return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
140 }
141 }
142
143 // --------------------------------------------------------------------
144
145 /**
146 * Result - object
147 *
148 * Returns the result set as an object
149 *
150 * @access private
151 * @return object
152 */
153 function _fetch_object()
154 {
155 // the PHP 4 version of the oracle functions do not
156 // have a fetch method so we call the array version
157 // and build an object from that
158
159 $row = array();
160 $res = $this->_fetch_assoc($row);
161 if ($res != FALSE)
162 {
163 $obj = new stdClass();
164 foreach ($row as $key => $value)
165 {
166 $obj->{$key} = $value;
167 }
168
169 $res = $obj;
170 }
171 return $res;
172 }
173
174 /**
175 * Query result. "array" version.
176 *
177 * @access public
178 * @return array
179 */
180 function result_array()
181 {
182 if (count($this->result_array) > 0)
183 {
184 return $this->result_array;
185 }
186
187 // oracle's fetch functions do not
188 // return arrays, the information
189 // is returned in reference parameters
190 //
191 $row = NULL;
192 while ($this->_fetch_assoc($row))
193 {
194 $this->result_array[] = $row;
195 }
196
197 if (count($this->result_array) == 0)
198 {
199 return FALSE;
200 }
201
202 return $this->result_array;
203 }
204
205}
206
207?>