blob: c3f7757303618444086fdbfed48a58ed72f9e269 [file] [log] [blame]
Andrey Andreev2f56fba2012-03-20 22:32:20 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev2f56fba2012-03-20 22:32:20 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev2f56fba2012-03-20 22:32:20 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Barry Mienydd671972010-10-04 16:33:58 +020019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
Barry Mienydd671972010-10-04 16:33:58 +020024 * @since Version 1.0
Derek Allard2067d1a2008-11-13 22:59:24 +000025 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * oci8 Result Class
30 *
31 * This class extends the parent result class: CI_DB_result
32 *
33 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/database/
36 */
37class CI_DB_oci8_result extends CI_DB_result {
38
Andrey Andreev57bdeb62012-03-05 15:59:16 +020039 public $stmt_id;
40 public $curs_id;
41 public $limit_used;
42
43 public function __construct(&$driver_object)
44 {
45 parent::__construct($driver_object);
46 $this->stmt_id = $driver_object->stmt_id;
47 $this->curs_id = $driver_object->curs_id;
48 $this->limit_used = $driver_object->limit_used;
49 $driver_object->stmt_id = FALSE;
50 }
Derek Allard2067d1a2008-11-13 22:59:24 +000051
52 /**
53 * Number of rows in the result set.
54 *
55 * Oracle doesn't have a graceful way to retun the number of rows
56 * so we have to use what amounts to a hack.
Barry Mienydd671972010-10-04 16:33:58 +020057 *
Andrey Andreev2f56fba2012-03-20 22:32:20 +020058 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000059 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030060 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000061 {
Andrey Andreevef3e2402011-09-21 14:39:29 +030062 if ($this->num_rows === 0 && count($this->result_array()) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +000063 {
Andrey Andreevef3e2402011-09-21 14:39:29 +030064 $this->num_rows = count($this->result_array());
a-krebs0372f1a2011-11-23 00:04:34 -070065 @oci_execute($this->stmt_id, OCI_DEFAULT);
Andrey Andreevef3e2402011-09-21 14:39:29 +030066
67 if ($this->curs_id)
68 {
a-krebs0372f1a2011-11-23 00:04:34 -070069 @oci_execute($this->curs_id, OCI_DEFAULT);
Andrey Andreevef3e2402011-09-21 14:39:29 +030070 }
Derek Allard2067d1a2008-11-13 22:59:24 +000071 }
72
Andrey Andreevef3e2402011-09-21 14:39:29 +030073 return $this->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000074 }
75
76 // --------------------------------------------------------------------
77
78 /**
79 * Number of fields in the result set
80 *
Andrey Andreev2f56fba2012-03-20 22:32:20 +020081 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000082 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030083 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000084 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +030085 $count = @oci_num_fields($this->stmt_id);
Derek Allard2067d1a2008-11-13 22:59:24 +000086
87 // if we used a limit we subtract it
88 if ($this->limit_used)
89 {
90 $count = $count - 1;
91 }
92
93 return $count;
94 }
95
96 // --------------------------------------------------------------------
97
98 /**
99 * Fetch Field Names
100 *
101 * Generates an array of column names
102 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000103 * @return array
104 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300105 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 {
107 $field_names = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300108 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300110 $field_names[] = oci_field_name($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 }
112 return $field_names;
113 }
114
115 // --------------------------------------------------------------------
116
117 /**
118 * Field data
119 *
120 * Generates an array of objects containing field meta-data
121 *
Andrey Andreev2f56fba2012-03-20 22:32:20 +0200122 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300124 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000125 {
126 $retval = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300127 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300129 $F = new stdClass();
130 $F->name = oci_field_name($this->stmt_id, $c);
131 $F->type = oci_field_type($this->stmt_id, $c);
132 $F->max_length = oci_field_size($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000133
134 $retval[] = $F;
135 }
136
137 return $retval;
138 }
139
140 // --------------------------------------------------------------------
141
142 /**
143 * Free the result
144 *
Andrey Andreev2f56fba2012-03-20 22:32:20 +0200145 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200146 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300147 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 {
149 if (is_resource($this->result_id))
150 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300151 oci_free_statement($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 $this->result_id = FALSE;
153 }
154 }
155
156 // --------------------------------------------------------------------
157
158 /**
159 * Result - associative array
160 *
161 * Returns the result set as an array
162 *
Andrey Andreev2f56fba2012-03-20 22:32:20 +0200163 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300165 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 {
167 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300168 return oci_fetch_assoc($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 }
170
171 // --------------------------------------------------------------------
172
173 /**
174 * Result - object
175 *
176 * Returns the result set as an object
177 *
Andrey Andreev2f56fba2012-03-20 22:32:20 +0200178 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000179 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300180 protected function _fetch_object()
Barry Mienydd671972010-10-04 16:33:58 +0200181 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300182 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
183 return @oci_fetch_object($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 }
185
186 // --------------------------------------------------------------------
187
188 /**
Derek Jones4b9c6292011-07-01 17:40:48 -0500189 * Query result. "array" version.
Derek Allard2067d1a2008-11-13 22:59:24 +0000190 *
Andrey Andreev2f56fba2012-03-20 22:32:20 +0200191 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300193 public function result_array()
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 {
195 if (count($this->result_array) > 0)
196 {
197 return $this->result_array;
198 }
199
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 $row = NULL;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300201 while ($row = $this->_fetch_assoc())
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 {
203 $this->result_array[] = $row;
204 }
205
206 return $this->result_array;
207 }
208
209 // --------------------------------------------------------------------
210
211 /**
212 * Data Seek
213 *
Andrey Andreev2f56fba2012-03-20 22:32:20 +0200214 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 * this internally before fetching results to make sure the
216 * result set starts at zero
217 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000218 * @return array
219 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300220 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000221 {
222 return FALSE; // Not needed
223 }
224
225}
226
Derek Allard2067d1a2008-11-13 22:59:24 +0000227/* End of file oci8_result.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400228/* Location: ./system/database/drivers/oci8/oci8_result.php */