blob: 7b05e0a4318b632f1108e96ac0247f13705cbbd1 [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 return $this->result_array = $this->row_data;
248 }
249
250 // --------------------------------------------------------------------
251
252 /**
253 * Query result. "object" version.
254 *
255 * @return array
256 */
257 public function result_object()
258 {
259 if (count($this->result_object) > 0)
260 {
261 return $this->result_object;
262 }
263 elseif (count($this->result_array) > 0)
264 {
265 for ($i = 0, $c = count($this->result_array); $i < $c; $i++)
266 {
267 $this->result_object[] = (object) $this->result_array[$i];
268 }
269
270 return $this->result_object;
271 }
272 elseif (is_array($this->row_data))
273 {
274 if (count($this->row_data) === 0)
275 {
276 return $this->result_object;
277 }
278 else
279 {
280 $row_index = count($this->row_data);
281 for ($i = 0; $i < $row_index; $i++)
282 {
283 $this->result_object[$i] = (object) $this->row_data[$i];
284 }
285 }
286 }
287 else
288 {
289 $row_index = 0;
290 $this->row_data = array();
291 }
292
293 $row = NULL;
294 while ($row = $this->_fetch_object())
295 {
296 $this->row_data[$row_index] = (array) $row;
297 $this->result_object[$row_index++] = $row;
298 }
299
Andrey Andreev24abcb92012-01-05 20:40:15 +0200300 return $this->result_object;
301 }
302
303 // --------------------------------------------------------------------
304
305 /**
306 * Query result. Custom object version.
307 *
308 * @param string class name used to instantiate rows to
309 * @return array
310 */
311 public function custom_result_object($class_name)
312 {
Andrey Andreev574c85d2012-02-12 20:40:53 +0200313 if (isset($this->custom_result_object[$class_name]))
Andrey Andreev24abcb92012-01-05 20:40:15 +0200314 {
315 return $this->custom_result_object[$class_name];
316 }
317
318 if ( ! class_exists($class_name) OR $this->result_id === FALSE OR $this->num_rows() === 0)
319 {
320 return array();
321 }
322
Andrey Andreevb5e6f112012-01-16 13:25:07 +0200323 /* Even if we didn't have result_array or result_object
324 * set prior to custom_result_object() being called,
325 * num_rows() has already done so.
326 * Pass by reference, as we don't know how
Andrey Andreev24abcb92012-01-05 20:40:15 +0200327 * large it might be and we don't want 1000 row
328 * sets being copied.
329 */
330 if (count($this->result_array) > 0)
331 {
332 $data = &$this->result_array;
333 }
334 elseif (count($this->result_object) > 0)
335 {
336 $data = &$this->result_object;
337 }
338
Andrey Andreev574c85d2012-02-12 20:40:53 +0200339 $this->custom_result_object[$class_name] = array();
Andrey Andreevb5e6f112012-01-16 13:25:07 +0200340 for ($i = 0, $c = count($data); $i < $c; $i++)
Andrey Andreev24abcb92012-01-05 20:40:15 +0200341 {
Andrey Andreev574c85d2012-02-12 20:40:53 +0200342 $this->custom_result_object[$class_name][$i] = new $class_name();
Andrey Andreevb5e6f112012-01-16 13:25:07 +0200343 foreach ($data[$i] as $key => $value)
Andrey Andreev24abcb92012-01-05 20:40:15 +0200344 {
Andrey Andreev574c85d2012-02-12 20:40:53 +0200345 $this->custom_result_object[$class_name][$i]->$key = $value;
Andrey Andreev24abcb92012-01-05 20:40:15 +0200346 }
347 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200348
Andrey Andreev574c85d2012-02-12 20:40:53 +0200349 return $this->custom_result_object[$class_name];
Andrey Andreev74e50982012-02-12 20:46:10 +0200350 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200351
352 // --------------------------------------------------------------------
353
354 /* Single row result.
355 *
356 * Acts as a wrapper for row_object(), row_array()
357 * and custom_row_object(). Also used by first_row(), next_row()
358 * and previous_row().
359 *
360 * @param int row index
361 * @param string ('object', 'array' or a custom class name)
362 * @return mixed whatever was passed to the second parameter
363 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200364 public function row($n = 0, $type = 'object')
365 {
Andrey Andreevaa786c92012-01-16 12:14:45 +0200366 if ($type === 'object')
367 {
368 return $this->row_object($n);
369 }
370 elseif ($type === 'array')
371 {
372 return $this->row_array($n);
373 }
374
375 return $this->custom_row_object($n, $type);
Andrey Andreev24abcb92012-01-05 20:40:15 +0200376 }
377
378 // --------------------------------------------------------------------
379
380 /* Single row result. Array version.
381 *
382 * @param int row index
383 * @return array
384 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200385 public function row_array($n = 0)
386 {
387 // Make sure $n is not a string
388 if ( ! is_int($n))
389 {
390 $n = (int) $n;
391 }
392
393 /* If row_data is initialized, it means that we've already tried
394 * (at least) to fetch some data, so ... check if we already have
395 * this row.
396 */
397 if (is_array($this->row_data))
398 {
399 /* If we already have row_data[$n] - return it.
400 *
401 * If we enter the elseif, there's a number of reasons to
402 * return an empty array:
403 *
404 * - count($this->row_data) === 0 means there are no results
405 * - num_rows being set, result_array and/or result_object
406 * having count() > 0 means that we've already fetched all
407 * data and $n is greater than our highest row index available
408 * - $n < $this->current_row means that if such row existed,
409 * we would've already returned it, therefore $n is an
410 * invalid index
411 */
412 if (isset($this->row_data[$n])) // We already have this row
413 {
414 $this->current_row = $n;
415 return $this->row_data[$n];
416 }
417 elseif (count($this->row_data) === 0 OR is_int($this->num_rows)
418 OR count($this->result_array) > 0 OR count($this->result_object) > 0
419 OR $n < $this->current_row)
420 {
421 // No such row exists
422 return array();
423 }
424
425 // Get the next row index that would actually need to be fetched
426 $current_row = ($this->current_row < count($this->row_data)) ? count($this->row_data) : $this->current_row + 1;
427 }
428 else
429 {
430 $current_row = $this->current_row = 0;
431 $this->row_data = array();
432 }
433
434 /* Fetch more data, if available
435 *
436 * NOTE: Operator precedence is important here, if you change
437 * 'AND' with '&&' - it WILL BREAK the results, as
438 * $row will be assigned the scalar value of both
439 * expressions!
440 */
441 while ($row = $this->_fetch_assoc() AND $current_row <= $n)
442 {
443 $this->row_data[$current_row++] = $row;
444 }
445
446 // This would mean that there's no (more) data to fetch
447 if ( ! is_array($this->row_data) OR ! isset($this->row_data[$n]))
448 {
449 // Cache what we already have
450 if (is_array($this->row_data))
451 {
452 $this->num_rows = count($this->row_data);
453 /* Usually, row_data could have less elements than result_array,
454 * but at this point - they should be exactly the same.
455 */
456 $this->result_array = $this->row_data;
457 }
458 else
459 {
460 $this->num_rows = 0;
461 }
462
463 return array();
464 }
465
466 $this->current_row = $n;
467 return $this->row_data[$n];
468 }
469
470 // --------------------------------------------------------------------
471
472 /* Single row result. Object version.
473 *
474 * @param int row index
475 * @return mixed object if row found; empty array if not
476 */
477 public function row_object($n = 0)
478 {
479 // Make sure $n is not a string
480 if ( ! is_int($n))
481 {
482 $n = (int) $n;
483 }
484 /* Logic here is exactly the same as in row_array,
485 * except we have to cast row_data[$n] to an object.
486 *
487 * If we already have result_object though - we can
488 * directly return from it.
489 */
490 if (isset($this->result_object[$n]))
491 {
492 $this->current_row = $n;
493 // Set this, if not already done.
494 if ( ! is_int($this->num_rows))
495 {
496 $this->num_rows = count($this->result_object);
497 }
498
499 return $this->result_object[$n];
500 }
501
502 $row = $this->row_array($n);
503 // Cast only if the row exists
504 if (count($row) > 0)
505 {
506 $this->current_row = $n;
507 return (object) $row;
508 }
509
510 return array();
511 }
512
513 // --------------------------------------------------------------------
514
515 /* Single row result. Custom object version.
516 *
517 * @param int row index
518 * @param string custom class name
519 * @return mixed custom object if row found; empty array otherwise
520 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200521 public function custom_row_object($n = 0, $class_name)
522 {
523 // Make sure $n is not a string
524 if ( ! is_int($n))
525 {
526 $n = (int) $n;
527 }
528
529 if (array_key_exists($class_name, $this->custom_result_object))
530 {
531 /* We already have a the whole result set with this class_name,
532 * return the specified row if it exists, and an empty array if
533 * it doesn't.
534 */
535 if (isset($this->custom_result_object[$class_name][$n]))
536 {
537 $this->current_row = $n;
538 return $this->custom_result_object[$class_name][$n];
539 }
540 else
541 {
542 return array();
543 }
544 }
545 elseif ( ! class_exists($class_name)) // No such class exists
546 {
547 return array();
548 }
549
550 $row = $this->row_array($n);
551 // An array would mean that the row doesn't exist
552 if (is_array($row))
553 {
554 return $row;
555 }
556
557 // Convert to the desired class and return
558 $row_object = new $class_name();
559 foreach ($row as $key => $value)
560 {
561 $row_object->$key = $value;
562 }
563
564 $this->current_row = $n;
565 return $row_object;
566 }
567
568 // --------------------------------------------------------------------
569
570 /* First row result.
571 *
572 * @param string ('object', 'array' or a custom class name)
573 * @return mixed whatever was passed to the second parameter
574 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200575 public function first_row($type = 'object')
576 {
577 return $this->row(0, $type);
578 }
579
580 // --------------------------------------------------------------------
581
582 /* Last row result.
583 *
584 * @param string ('object', 'array' or a custom class name)
585 * @return mixed whatever was passed to the second parameter
586 */
587 public function last_row($type = 'object')
588 {
589 $result = &$this->result($type);
590 if ( ! isset($this->num_rows))
591 {
592 $this->num_rows = count($result);
593 }
594 $this->current_row = $this->num_rows - 1;
595 return $result[$this->current_row];
596 }
597
598 // --------------------------------------------------------------------
599
600 /* Next row result.
601 *
602 * @param string ('object', 'array' or a custom class name)
603 * @return mixed whatever was passed to the second parameter
604 */
605 public function next_row($type = 'object')
606 {
607 if (is_array($this->row_data))
608 {
609 $count = count($this->row_data);
610 if ($this->current_row > $count OR ($this->current_row === 0 && $count === 0))
611 {
612 $n = $count;
613 }
614 else
615 {
616 $n = $this->current_row + 1;
617 }
618 }
619 else
620 {
621 $n = 0;
622 }
623
624 return $this->row($n, $type);
625 }
626
627 // --------------------------------------------------------------------
628
629 /* Previous row result.
630 *
631 * @param string ('object', 'array' or a custom class name)
632 * @return mixed whatever was passed to the second parameter
633 */
634 public function previous_row($type = 'object')
635 {
636 $n = ($this->current_row !== 0) ? $this->current_row - 1 : 0;
637 return $this->row($n, $type);
Derek Allard2067d1a2008-11-13 22:59:24 +0000638 }
639
640 // --------------------------------------------------------------------
641
642 /**
643 * Data Seek
644 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200645 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000646 * this internally before fetching results to make sure the
Andrey Andreev24abcb92012-01-05 20:40:15 +0200647 * result set starts at zero.
Derek Allard2067d1a2008-11-13 22:59:24 +0000648 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200649 * Oracle's PHP extension doesn't have an easy way of doing this
650 * and the only workaround is to (re)execute the statement or cursor
651 * in order to go to the first (zero) index of the result set.
652 * Then, we would need to "dummy" fetch ($n - 1) rows to get to the
653 * right one.
654 *
655 * This is as ridiculous as it sounds and it's the reason why every
656 * other method that is fetching data tries to use an already "cached"
657 * result set. Keeping this just in case it becomes needed at
658 * some point in the future, but it will only work for resetting the
659 * pointer to zero.
660 *
661 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000662 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200663 protected function _data_seek()
Derek Allard2067d1a2008-11-13 22:59:24 +0000664 {
Andrey Andreev24abcb92012-01-05 20:40:15 +0200665 /* The PHP manual says that if OCI_NO_AUTO_COMMIT mode
666 * is used, and oci_rollback() and/or oci_commit() are
667 * not subsequently called - this will cause an unnecessary
668 * rollback to be triggered at the end of the script execution.
669 *
670 * Therefore we'll try to avoid using that mode flag
671 * if we're not currently in the middle of a transaction.
672 */
673 if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS)
674 {
675 $result = @oci_execute($this->stmt_id, $this->commit_mode);
676 }
677 else
678 {
679 $result = @oci_execute($this->stmt_id);
680 }
681
682 if ($result && $this->curs_id)
683 {
684 if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS)
685 {
686 return @oci_execute($this->curs_id, $this->commit_mode);
687 }
688 else
689 {
690 return @oci_execute($this->curs_id);
691 }
692 }
693
694 return $result;
Derek Allard2067d1a2008-11-13 22:59:24 +0000695 }
696
697}
698
Derek Allard2067d1a2008-11-13 22:59:24 +0000699/* End of file oci8_result.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400700/* Location: ./system/database/drivers/oci8/oci8_result.php */