blob: aad24cfd9e0dbc153170741e98fe823f73485e22 [file] [log] [blame]
Andrey Andreev24abcb92012-01-05 20:40:15 +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 Andreev24abcb92012-01-05 20:40:15 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev24abcb92012-01-05 20:40:15 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
Andrey Andreev342a4662012-01-24 15:24:00 +020012 * bundled with this package in the files license.txt / license.rst. It is
Derek Jonesf4a4bd82011-10-20 12:18:42 -050013 * 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 Andreev24abcb92012-01-05 20:40:15 +020039 public $stmt_id;
40 public $curs_id;
41 public $limit_used;
Andrey Andreev99013ed2012-03-05 16:17:32 +020042 public $commit_mode;
Andrey Andreev24abcb92012-01-05 20:40:15 +020043
44 /* Overwriting the parent here, so we have a way to know if it's
45 * already called or not:
46 */
47 public $num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000048
Andrey Andreev57bdeb62012-03-05 15:59:16 +020049 public function __construct(&$driver_object)
50 {
51 parent::__construct($driver_object);
52 $this->stmt_id = $driver_object->stmt_id;
53 $this->curs_id = $driver_object->curs_id;
54 $this->limit_used = $driver_object->limit_used;
Andrey Andreev99013ed2012-03-05 16:17:32 +020055 $this->commit_mode =& $driver_object->commit_mode;
Andrey Andreev57bdeb62012-03-05 15:59:16 +020056 $driver_object->stmt_id = FALSE;
57 }
Derek Allard2067d1a2008-11-13 22:59:24 +000058
59 /**
60 * Number of rows in the result set.
61 *
Andrey Andreev24abcb92012-01-05 20:40:15 +020062 * Oracle doesn't have a graceful way to return the number of rows
Derek Allard2067d1a2008-11-13 22:59:24 +000063 * so we have to use what amounts to a hack.
Barry Mienydd671972010-10-04 16:33:58 +020064 *
Andrey Andreevaa786c92012-01-16 12:14:45 +020065 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000066 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030067 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000068 {
Andrey Andreev24abcb92012-01-05 20:40:15 +020069 if ( ! is_int($this->num_rows))
Derek Allard2067d1a2008-11-13 22:59:24 +000070 {
Andrey Andreev24abcb92012-01-05 20:40:15 +020071 if (count($this->result_array) > 0)
Andrey Andreevef3e2402011-09-21 14:39:29 +030072 {
Andrey Andreev24abcb92012-01-05 20:40:15 +020073 return $this->num_rows = count($this->result_array);
Andrey Andreevef3e2402011-09-21 14:39:29 +030074 }
Andrey Andreev24abcb92012-01-05 20:40:15 +020075 elseif (count($this->result_object) > 0)
76 {
Andrey Andreevb5e6f112012-01-16 13:25:07 +020077 return $this->num_rows = count($this->result_object);
Andrey Andreev24abcb92012-01-05 20:40:15 +020078 }
79
80 return $this->num_rows = count($this->result_array());
Derek Allard2067d1a2008-11-13 22:59:24 +000081 }
82
Andrey Andreevef3e2402011-09-21 14:39:29 +030083 return $this->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000084 }
85
86 // --------------------------------------------------------------------
87
88 /**
89 * Number of fields in the result set
90 *
Andrey Andreevaa786c92012-01-16 12:14:45 +020091 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000092 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030093 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000094 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +030095 $count = @oci_num_fields($this->stmt_id);
Derek Allard2067d1a2008-11-13 22:59:24 +000096
97 // if we used a limit we subtract it
Andrey Andreevaa786c92012-01-16 12:14:45 +020098 return ($this->limit_used) ? $count - 1 : $count;
Derek Allard2067d1a2008-11-13 22:59:24 +000099 }
100
101 // --------------------------------------------------------------------
102
103 /**
104 * Fetch Field Names
105 *
106 * Generates an array of column names
107 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 * @return array
109 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300110 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 {
112 $field_names = 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 $field_names[] = oci_field_name($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 }
117 return $field_names;
118 }
119
120 // --------------------------------------------------------------------
121
122 /**
123 * Field data
124 *
125 * Generates an array of objects containing field meta-data
126 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200127 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300129 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000130 {
131 $retval = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300132 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 {
Andrey Andreevaa786c92012-01-16 12:14:45 +0200134 $F = new stdClass();
135 $F->name = oci_field_name($this->stmt_id, $c);
136 $F->type = oci_field_type($this->stmt_id, $c);
137 $F->max_length = oci_field_size($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000138
139 $retval[] = $F;
140 }
141
142 return $retval;
143 }
144
145 // --------------------------------------------------------------------
146
147 /**
148 * Free the result
149 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200150 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200151 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300152 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 {
154 if (is_resource($this->result_id))
155 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300156 oci_free_statement($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 $this->result_id = FALSE;
158 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200159
160 if (is_resource($this->stmt_id))
161 {
162 oci_free_statement($this->stmt_id);
163 }
164
165 if (is_resource($this->curs_id))
166 {
167 oci_cancel($this->curs_id);
168 $this->curs_id = NULL;
169 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 }
171
172 // --------------------------------------------------------------------
173
174 /**
175 * Result - associative array
176 *
177 * Returns the result set as an array
178 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200179 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000180 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300181 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 {
183 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300184 return oci_fetch_assoc($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000185 }
186
187 // --------------------------------------------------------------------
188
189 /**
190 * Result - object
191 *
192 * Returns the result set as an object
193 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200194 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000195 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300196 protected function _fetch_object()
Barry Mienydd671972010-10-04 16:33:58 +0200197 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300198 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Andrey Andreev24abcb92012-01-05 20:40:15 +0200199 return oci_fetch_object($id);
200 }
201
202 // --------------------------------------------------------------------
203
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 /**
Andrey Andreeve35d7782012-01-19 15:56:20 +0200205 * Query result. Array version.
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200207 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300209 public function result_array()
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 {
211 if (count($this->result_array) > 0)
212 {
213 return $this->result_array;
214 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200215 elseif (count($this->result_object) > 0)
216 {
217 for ($i = 0, $c = count($this->result_object); $i < $c; $i++)
218 {
219 $this->result_array[$i] = (array) $this->result_object[$i];
220 }
221
222 return $this->result_array;
223 }
224 elseif (is_array($this->row_data))
225 {
226 if (count($this->row_data) === 0)
227 {
228 return $this->result_array;
229 }
230 else
231 {
232 $row_index = count($this->row_data);
233 }
234 }
235 else
236 {
237 $row_index = 0;
238 $this->row_data = array();
239 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000240
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 $row = NULL;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300242 while ($row = $this->_fetch_assoc())
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 {
Andrey Andreev24abcb92012-01-05 20:40:15 +0200244 $this->row_data[$row_index++] = $row;
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 }
246
Andrey Andreev24abcb92012-01-05 20:40:15 +0200247 // Un-comment the following line, in case it becomes needed
248 // $this->_data_seek();
249 return $this->result_array = $this->row_data;
250 }
251
252 // --------------------------------------------------------------------
253
254 /**
255 * Query result. "object" version.
256 *
257 * @return array
258 */
259 public function result_object()
260 {
261 if (count($this->result_object) > 0)
262 {
263 return $this->result_object;
264 }
265 elseif (count($this->result_array) > 0)
266 {
267 for ($i = 0, $c = count($this->result_array); $i < $c; $i++)
268 {
269 $this->result_object[] = (object) $this->result_array[$i];
270 }
271
272 return $this->result_object;
273 }
274 elseif (is_array($this->row_data))
275 {
276 if (count($this->row_data) === 0)
277 {
278 return $this->result_object;
279 }
280 else
281 {
282 $row_index = count($this->row_data);
283 for ($i = 0; $i < $row_index; $i++)
284 {
285 $this->result_object[$i] = (object) $this->row_data[$i];
286 }
287 }
288 }
289 else
290 {
291 $row_index = 0;
292 $this->row_data = array();
293 }
294
295 $row = NULL;
296 while ($row = $this->_fetch_object())
297 {
298 $this->row_data[$row_index] = (array) $row;
299 $this->result_object[$row_index++] = $row;
300 }
301
302 // Un-comment the following line, in case it becomes needed
303 // $this->_data_seek();
304 return $this->result_object;
305 }
306
307 // --------------------------------------------------------------------
308
309 /**
310 * Query result. Custom object version.
311 *
312 * @param string class name used to instantiate rows to
313 * @return array
314 */
315 public function custom_result_object($class_name)
316 {
Andrey Andreev574c85d2012-02-12 20:40:53 +0200317 if (isset($this->custom_result_object[$class_name]))
Andrey Andreev24abcb92012-01-05 20:40:15 +0200318 {
319 return $this->custom_result_object[$class_name];
320 }
321
322 if ( ! class_exists($class_name) OR $this->result_id === FALSE OR $this->num_rows() === 0)
323 {
324 return array();
325 }
326
Andrey Andreevb5e6f112012-01-16 13:25:07 +0200327 /* Even if we didn't have result_array or result_object
328 * set prior to custom_result_object() being called,
329 * num_rows() has already done so.
330 * Pass by reference, as we don't know how
Andrey Andreev24abcb92012-01-05 20:40:15 +0200331 * large it might be and we don't want 1000 row
332 * sets being copied.
333 */
334 if (count($this->result_array) > 0)
335 {
336 $data = &$this->result_array;
337 }
338 elseif (count($this->result_object) > 0)
339 {
340 $data = &$this->result_object;
341 }
342
Andrey Andreev574c85d2012-02-12 20:40:53 +0200343 $this->custom_result_object[$class_name] = array();
Andrey Andreevb5e6f112012-01-16 13:25:07 +0200344 for ($i = 0, $c = count($data); $i < $c; $i++)
Andrey Andreev24abcb92012-01-05 20:40:15 +0200345 {
Andrey Andreev574c85d2012-02-12 20:40:53 +0200346 $this->custom_result_object[$class_name][$i] = new $class_name();
Andrey Andreevb5e6f112012-01-16 13:25:07 +0200347 foreach ($data[$i] as $key => $value)
Andrey Andreev24abcb92012-01-05 20:40:15 +0200348 {
Andrey Andreev574c85d2012-02-12 20:40:53 +0200349 $this->custom_result_object[$class_name][$i]->$key = $value;
Andrey Andreev24abcb92012-01-05 20:40:15 +0200350 }
351 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200352
Andrey Andreev574c85d2012-02-12 20:40:53 +0200353 return $this->custom_result_object[$class_name];
Andrey Andreev74e50982012-02-12 20:46:10 +0200354 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200355
356 // --------------------------------------------------------------------
357
358 /* Single row result.
359 *
360 * Acts as a wrapper for row_object(), row_array()
361 * and custom_row_object(). Also used by first_row(), next_row()
362 * and previous_row().
363 *
364 * @param int row index
365 * @param string ('object', 'array' or a custom class name)
366 * @return mixed whatever was passed to the second parameter
367 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200368 public function row($n = 0, $type = 'object')
369 {
Andrey Andreevaa786c92012-01-16 12:14:45 +0200370 if ($type === 'object')
371 {
372 return $this->row_object($n);
373 }
374 elseif ($type === 'array')
375 {
376 return $this->row_array($n);
377 }
378
379 return $this->custom_row_object($n, $type);
Andrey Andreev24abcb92012-01-05 20:40:15 +0200380 }
381
382 // --------------------------------------------------------------------
383
384 /* Single row result. Array version.
385 *
386 * @param int row index
387 * @return array
388 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200389 public function row_array($n = 0)
390 {
391 // Make sure $n is not a string
392 if ( ! is_int($n))
393 {
394 $n = (int) $n;
395 }
396
397 /* If row_data is initialized, it means that we've already tried
398 * (at least) to fetch some data, so ... check if we already have
399 * this row.
400 */
401 if (is_array($this->row_data))
402 {
403 /* If we already have row_data[$n] - return it.
404 *
405 * If we enter the elseif, there's a number of reasons to
406 * return an empty array:
407 *
408 * - count($this->row_data) === 0 means there are no results
409 * - num_rows being set, result_array and/or result_object
410 * having count() > 0 means that we've already fetched all
411 * data and $n is greater than our highest row index available
412 * - $n < $this->current_row means that if such row existed,
413 * we would've already returned it, therefore $n is an
414 * invalid index
415 */
416 if (isset($this->row_data[$n])) // We already have this row
417 {
418 $this->current_row = $n;
419 return $this->row_data[$n];
420 }
421 elseif (count($this->row_data) === 0 OR is_int($this->num_rows)
422 OR count($this->result_array) > 0 OR count($this->result_object) > 0
423 OR $n < $this->current_row)
424 {
425 // No such row exists
426 return array();
427 }
428
429 // Get the next row index that would actually need to be fetched
430 $current_row = ($this->current_row < count($this->row_data)) ? count($this->row_data) : $this->current_row + 1;
431 }
432 else
433 {
434 $current_row = $this->current_row = 0;
435 $this->row_data = array();
436 }
437
438 /* Fetch more data, if available
439 *
440 * NOTE: Operator precedence is important here, if you change
441 * 'AND' with '&&' - it WILL BREAK the results, as
442 * $row will be assigned the scalar value of both
443 * expressions!
444 */
445 while ($row = $this->_fetch_assoc() AND $current_row <= $n)
446 {
447 $this->row_data[$current_row++] = $row;
448 }
449
450 // This would mean that there's no (more) data to fetch
451 if ( ! is_array($this->row_data) OR ! isset($this->row_data[$n]))
452 {
453 // Cache what we already have
454 if (is_array($this->row_data))
455 {
456 $this->num_rows = count($this->row_data);
457 /* Usually, row_data could have less elements than result_array,
458 * but at this point - they should be exactly the same.
459 */
460 $this->result_array = $this->row_data;
461 }
462 else
463 {
464 $this->num_rows = 0;
465 }
466
467 return array();
468 }
469
470 $this->current_row = $n;
471 return $this->row_data[$n];
472 }
473
474 // --------------------------------------------------------------------
475
476 /* Single row result. Object version.
477 *
478 * @param int row index
479 * @return mixed object if row found; empty array if not
480 */
481 public function row_object($n = 0)
482 {
483 // Make sure $n is not a string
484 if ( ! is_int($n))
485 {
486 $n = (int) $n;
487 }
488 /* Logic here is exactly the same as in row_array,
489 * except we have to cast row_data[$n] to an object.
490 *
491 * If we already have result_object though - we can
492 * directly return from it.
493 */
494 if (isset($this->result_object[$n]))
495 {
496 $this->current_row = $n;
497 // Set this, if not already done.
498 if ( ! is_int($this->num_rows))
499 {
500 $this->num_rows = count($this->result_object);
501 }
502
503 return $this->result_object[$n];
504 }
505
506 $row = $this->row_array($n);
507 // Cast only if the row exists
508 if (count($row) > 0)
509 {
510 $this->current_row = $n;
511 return (object) $row;
512 }
513
514 return array();
515 }
516
517 // --------------------------------------------------------------------
518
519 /* Single row result. Custom object version.
520 *
521 * @param int row index
522 * @param string custom class name
523 * @return mixed custom object if row found; empty array otherwise
524 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200525 public function custom_row_object($n = 0, $class_name)
526 {
527 // Make sure $n is not a string
528 if ( ! is_int($n))
529 {
530 $n = (int) $n;
531 }
532
533 if (array_key_exists($class_name, $this->custom_result_object))
534 {
535 /* We already have a the whole result set with this class_name,
536 * return the specified row if it exists, and an empty array if
537 * it doesn't.
538 */
539 if (isset($this->custom_result_object[$class_name][$n]))
540 {
541 $this->current_row = $n;
542 return $this->custom_result_object[$class_name][$n];
543 }
544 else
545 {
546 return array();
547 }
548 }
549 elseif ( ! class_exists($class_name)) // No such class exists
550 {
551 return array();
552 }
553
554 $row = $this->row_array($n);
555 // An array would mean that the row doesn't exist
556 if (is_array($row))
557 {
558 return $row;
559 }
560
561 // Convert to the desired class and return
562 $row_object = new $class_name();
563 foreach ($row as $key => $value)
564 {
565 $row_object->$key = $value;
566 }
567
568 $this->current_row = $n;
569 return $row_object;
570 }
571
572 // --------------------------------------------------------------------
573
574 /* First row result.
575 *
576 * @param string ('object', 'array' or a custom class name)
577 * @return mixed whatever was passed to the second parameter
578 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200579 public function first_row($type = 'object')
580 {
581 return $this->row(0, $type);
582 }
583
584 // --------------------------------------------------------------------
585
586 /* Last row result.
587 *
588 * @param string ('object', 'array' or a custom class name)
589 * @return mixed whatever was passed to the second parameter
590 */
591 public function last_row($type = 'object')
592 {
593 $result = &$this->result($type);
594 if ( ! isset($this->num_rows))
595 {
596 $this->num_rows = count($result);
597 }
598 $this->current_row = $this->num_rows - 1;
599 return $result[$this->current_row];
600 }
601
602 // --------------------------------------------------------------------
603
604 /* Next row result.
605 *
606 * @param string ('object', 'array' or a custom class name)
607 * @return mixed whatever was passed to the second parameter
608 */
609 public function next_row($type = 'object')
610 {
611 if (is_array($this->row_data))
612 {
613 $count = count($this->row_data);
614 if ($this->current_row > $count OR ($this->current_row === 0 && $count === 0))
615 {
616 $n = $count;
617 }
618 else
619 {
620 $n = $this->current_row + 1;
621 }
622 }
623 else
624 {
625 $n = 0;
626 }
627
628 return $this->row($n, $type);
629 }
630
631 // --------------------------------------------------------------------
632
633 /* Previous row result.
634 *
635 * @param string ('object', 'array' or a custom class name)
636 * @return mixed whatever was passed to the second parameter
637 */
638 public function previous_row($type = 'object')
639 {
640 $n = ($this->current_row !== 0) ? $this->current_row - 1 : 0;
641 return $this->row($n, $type);
Derek Allard2067d1a2008-11-13 22:59:24 +0000642 }
643
644 // --------------------------------------------------------------------
645
646 /**
647 * Data Seek
648 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200649 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000650 * this internally before fetching results to make sure the
Andrey Andreev24abcb92012-01-05 20:40:15 +0200651 * result set starts at zero.
Derek Allard2067d1a2008-11-13 22:59:24 +0000652 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200653 * Oracle's PHP extension doesn't have an easy way of doing this
654 * and the only workaround is to (re)execute the statement or cursor
655 * in order to go to the first (zero) index of the result set.
656 * Then, we would need to "dummy" fetch ($n - 1) rows to get to the
657 * right one.
658 *
659 * This is as ridiculous as it sounds and it's the reason why every
660 * other method that is fetching data tries to use an already "cached"
661 * result set. Keeping this just in case it becomes needed at
662 * some point in the future, but it will only work for resetting the
663 * pointer to zero.
664 *
665 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000666 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200667 protected function _data_seek()
Derek Allard2067d1a2008-11-13 22:59:24 +0000668 {
Andrey Andreev24abcb92012-01-05 20:40:15 +0200669 /* The PHP manual says that if OCI_NO_AUTO_COMMIT mode
670 * is used, and oci_rollback() and/or oci_commit() are
671 * not subsequently called - this will cause an unnecessary
672 * rollback to be triggered at the end of the script execution.
673 *
674 * Therefore we'll try to avoid using that mode flag
675 * if we're not currently in the middle of a transaction.
676 */
677 if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS)
678 {
679 $result = @oci_execute($this->stmt_id, $this->commit_mode);
680 }
681 else
682 {
683 $result = @oci_execute($this->stmt_id);
684 }
685
686 if ($result && $this->curs_id)
687 {
688 if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS)
689 {
690 return @oci_execute($this->curs_id, $this->commit_mode);
691 }
692 else
693 {
694 return @oci_execute($this->curs_id);
695 }
696 }
697
698 return $result;
Derek Allard2067d1a2008-11-13 22:59:24 +0000699 }
700
701}
702
Derek Allard2067d1a2008-11-13 22:59:24 +0000703/* End of file oci8_result.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400704/* Location: ./system/database/drivers/oci8/oci8_result.php */