blob: fad2465df5a02a478ee3de1c96b6bb8b93bd78eb [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 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 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 Andreevaa786c92012-01-16 12:14:45 +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;
42
43 // This will be changed by CI_DB_driver, but it's good to have a default:
44 public $commit_mode = OCI_DEFAULT;
45
46 /* Overwriting the parent here, so we have a way to know if it's
47 * already called or not:
48 */
49 public $num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000050
51 /**
52 * Number of rows in the result set.
53 *
Andrey Andreev24abcb92012-01-05 20:40:15 +020054 * Oracle doesn't have a graceful way to return the number of rows
Derek Allard2067d1a2008-11-13 22:59:24 +000055 * so we have to use what amounts to a hack.
Barry Mienydd671972010-10-04 16:33:58 +020056 *
Andrey Andreevaa786c92012-01-16 12:14:45 +020057 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000058 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030059 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000060 {
Andrey Andreev24abcb92012-01-05 20:40:15 +020061 if ( ! is_int($this->num_rows))
Derek Allard2067d1a2008-11-13 22:59:24 +000062 {
Andrey Andreev24abcb92012-01-05 20:40:15 +020063 if (count($this->result_array) > 0)
Andrey Andreevef3e2402011-09-21 14:39:29 +030064 {
Andrey Andreev24abcb92012-01-05 20:40:15 +020065 return $this->num_rows = count($this->result_array);
Andrey Andreevef3e2402011-09-21 14:39:29 +030066 }
Andrey Andreev24abcb92012-01-05 20:40:15 +020067 elseif (count($this->result_object) > 0)
68 {
69 return $this->num_rows = count($this->result_array);
70 }
71
72 return $this->num_rows = count($this->result_array());
Derek Allard2067d1a2008-11-13 22:59:24 +000073 }
74
Andrey Andreevef3e2402011-09-21 14:39:29 +030075 return $this->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000076 }
77
78 // --------------------------------------------------------------------
79
80 /**
81 * Number of fields in the result set
82 *
Andrey Andreevaa786c92012-01-16 12:14:45 +020083 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000084 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +030085 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000086 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +030087 $count = @oci_num_fields($this->stmt_id);
Derek Allard2067d1a2008-11-13 22:59:24 +000088
89 // if we used a limit we subtract it
Andrey Andreevaa786c92012-01-16 12:14:45 +020090 return ($this->limit_used) ? $count - 1 : $count;
Derek Allard2067d1a2008-11-13 22:59:24 +000091 }
92
93 // --------------------------------------------------------------------
94
95 /**
96 * Fetch Field Names
97 *
98 * Generates an array of column names
99 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000100 * @return array
101 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300102 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +0000103 {
104 $field_names = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300105 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300107 $field_names[] = oci_field_name($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 }
109 return $field_names;
110 }
111
112 // --------------------------------------------------------------------
113
114 /**
115 * Field data
116 *
117 * Generates an array of objects containing field meta-data
118 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200119 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300121 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000122 {
123 $retval = array();
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300124 for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000125 {
Andrey Andreevaa786c92012-01-16 12:14:45 +0200126 $F = new stdClass();
127 $F->name = oci_field_name($this->stmt_id, $c);
128 $F->type = oci_field_type($this->stmt_id, $c);
129 $F->max_length = oci_field_size($this->stmt_id, $c);
Derek Allard2067d1a2008-11-13 22:59:24 +0000130
131 $retval[] = $F;
132 }
133
134 return $retval;
135 }
136
137 // --------------------------------------------------------------------
138
139 /**
140 * Free the result
141 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200142 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200143 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300144 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 {
146 if (is_resource($this->result_id))
147 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300148 oci_free_statement($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000149 $this->result_id = FALSE;
150 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200151
152 if (is_resource($this->stmt_id))
153 {
154 oci_free_statement($this->stmt_id);
155 }
156
157 if (is_resource($this->curs_id))
158 {
159 oci_cancel($this->curs_id);
160 $this->curs_id = NULL;
161 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000162 }
163
164 // --------------------------------------------------------------------
165
166 /**
167 * Result - associative array
168 *
169 * Returns the result set as an array
170 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200171 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300173 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000174 {
175 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300176 return oci_fetch_assoc($id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 }
178
179 // --------------------------------------------------------------------
180
181 /**
182 * Result - object
183 *
184 * Returns the result set as an object
185 *
Andrey Andreevaa786c92012-01-16 12:14:45 +0200186 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000187 */
Andrey Andreevbc95e472011-10-20 09:44:48 +0300188 protected function _fetch_object()
Barry Mienydd671972010-10-04 16:33:58 +0200189 {
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300190 $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
Andrey Andreev24abcb92012-01-05 20:40:15 +0200191 return oci_fetch_object($id);
192 }
193
194 // --------------------------------------------------------------------
195
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 /**
Andrey Andreev24abcb92012-01-05 20:40:15 +0200197 * Query result. "array" version.
Derek Allard2067d1a2008-11-13 22:59:24 +0000198 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200199 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 */
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300201 public function result_array()
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 {
203 if (count($this->result_array) > 0)
204 {
205 return $this->result_array;
206 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200207 elseif (count($this->result_object) > 0)
208 {
209 for ($i = 0, $c = count($this->result_object); $i < $c; $i++)
210 {
211 $this->result_array[$i] = (array) $this->result_object[$i];
212 }
213
214 return $this->result_array;
215 }
216 elseif (is_array($this->row_data))
217 {
218 if (count($this->row_data) === 0)
219 {
220 return $this->result_array;
221 }
222 else
223 {
224 $row_index = count($this->row_data);
225 }
226 }
227 else
228 {
229 $row_index = 0;
230 $this->row_data = array();
231 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000232
Derek Allard2067d1a2008-11-13 22:59:24 +0000233 $row = NULL;
Andrey Andreev5c3a2022011-10-07 21:04:58 +0300234 while ($row = $this->_fetch_assoc())
Derek Allard2067d1a2008-11-13 22:59:24 +0000235 {
Andrey Andreev24abcb92012-01-05 20:40:15 +0200236 $this->row_data[$row_index++] = $row;
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 }
238
Andrey Andreev24abcb92012-01-05 20:40:15 +0200239 // Un-comment the following line, in case it becomes needed
240 // $this->_data_seek();
241 return $this->result_array = $this->row_data;
242 }
243
244 // --------------------------------------------------------------------
245
246 /**
247 * Query result. "object" version.
248 *
249 * @return array
250 */
251 public function result_object()
252 {
253 if (count($this->result_object) > 0)
254 {
255 return $this->result_object;
256 }
257 elseif (count($this->result_array) > 0)
258 {
259 for ($i = 0, $c = count($this->result_array); $i < $c; $i++)
260 {
261 $this->result_object[] = (object) $this->result_array[$i];
262 }
263
264 return $this->result_object;
265 }
266 elseif (is_array($this->row_data))
267 {
268 if (count($this->row_data) === 0)
269 {
270 return $this->result_object;
271 }
272 else
273 {
274 $row_index = count($this->row_data);
275 for ($i = 0; $i < $row_index; $i++)
276 {
277 $this->result_object[$i] = (object) $this->row_data[$i];
278 }
279 }
280 }
281 else
282 {
283 $row_index = 0;
284 $this->row_data = array();
285 }
286
287 $row = NULL;
288 while ($row = $this->_fetch_object())
289 {
290 $this->row_data[$row_index] = (array) $row;
291 $this->result_object[$row_index++] = $row;
292 }
293
294 // Un-comment the following line, in case it becomes needed
295 // $this->_data_seek();
296 return $this->result_object;
297 }
298
299 // --------------------------------------------------------------------
300
301 /**
302 * Query result. Custom object version.
303 *
304 * @param string class name used to instantiate rows to
305 * @return array
306 */
307 public function custom_result_object($class_name)
308 {
309 if (array_key_exists($class_name, $this->custom_result_object))
310 {
311 return $this->custom_result_object[$class_name];
312 }
313
314 if ( ! class_exists($class_name) OR $this->result_id === FALSE OR $this->num_rows() === 0)
315 {
316 return array();
317 }
318
319 // add the data to the object
320 $result_object = array();
321 $data = NULL;
322
323 /* First check if we don't already have the data.
324 * If so - pass by reference, as we don't know how
325 * large it might be and we don't want 1000 row
326 * sets being copied.
327 */
328 if (count($this->result_array) > 0)
329 {
330 $data = &$this->result_array;
331 }
332 elseif (count($this->result_object) > 0)
333 {
334 $data = &$this->result_object;
335 }
336
337 if ( ! is_null($data))
338 {
339 for ($i = 0, $c = count($data); $i < $c; $i++)
340 {
341 $result_object[$i] = new $class_name();
342 foreach ($data[$i] as $key => $value)
343 {
344 $result_object[$i]->$key = $value;
345 }
346 }
347 }
348 else
349 {
350 // No prefetched result set
351 if (is_array($this->row_data))
352 {
353 $row_index = count($this->row_data);
354 if ($row_index === 0)
355 {
356 return array();
357 }
358 else
359 {
360 for ($i = 0; $i < $row_index; $i++)
361 {
362 $result_object[$i] = new $class_name();
363 foreach ($this->row_data[$i] as $key => $value)
364 {
365 $result_object[$i]->$key = $value;
366 }
367 }
368 }
369 }
370 else
371 {
372 $row_index = 0;
373 $this->row_data = array();
374 }
375
376 while ($row = $this->_fetch_assoc())
377 {
378 $data = new $class_name();
379 foreach ($row as $key => $value)
380 {
381 $data->$key = $value;
382 }
383
384 $this->row_data[$row_index] = $row;
385 $result_object[$row_index++] = $data;
386 }
387 // Un-comment the following line, in case it becomes needed
388 // $this->_data_seek();
389 }
390
391 /* As described for the num_rows() method - there's no easy
392 * way to get the number of rows selected. Our work-around
393 * solution (as in here as well) first checks if result_array
394 * or result_object exist and returns their count. It doesn't
395 * however check for a custom_object_result, so - do it here.
396 */
397 if ( ! is_int($this->num_rows))
398 {
399 $this->num_rows = count($result_object);
400 }
401
402 // Cache and return the array
403 return $this->custom_result_object[$class_name] = $result_object;
404 }
405
406 // --------------------------------------------------------------------
407
408 /* Single row result.
409 *
410 * Acts as a wrapper for row_object(), row_array()
411 * and custom_row_object(). Also used by first_row(), next_row()
412 * and previous_row().
413 *
414 * @param int row index
415 * @param string ('object', 'array' or a custom class name)
416 * @return mixed whatever was passed to the second parameter
417 */
418
419 public function row($n = 0, $type = 'object')
420 {
Andrey Andreevaa786c92012-01-16 12:14:45 +0200421 if ($type === 'object')
422 {
423 return $this->row_object($n);
424 }
425 elseif ($type === 'array')
426 {
427 return $this->row_array($n);
428 }
429
430 return $this->custom_row_object($n, $type);
Andrey Andreev24abcb92012-01-05 20:40:15 +0200431 }
432
433 // --------------------------------------------------------------------
434
435 /* Single row result. Array version.
436 *
437 * @param int row index
438 * @return array
439 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200440 public function row_array($n = 0)
441 {
442 // Make sure $n is not a string
443 if ( ! is_int($n))
444 {
445 $n = (int) $n;
446 }
447
448 /* If row_data is initialized, it means that we've already tried
449 * (at least) to fetch some data, so ... check if we already have
450 * this row.
451 */
452 if (is_array($this->row_data))
453 {
454 /* If we already have row_data[$n] - return it.
455 *
456 * If we enter the elseif, there's a number of reasons to
457 * return an empty array:
458 *
459 * - count($this->row_data) === 0 means there are no results
460 * - num_rows being set, result_array and/or result_object
461 * having count() > 0 means that we've already fetched all
462 * data and $n is greater than our highest row index available
463 * - $n < $this->current_row means that if such row existed,
464 * we would've already returned it, therefore $n is an
465 * invalid index
466 */
467 if (isset($this->row_data[$n])) // We already have this row
468 {
469 $this->current_row = $n;
470 return $this->row_data[$n];
471 }
472 elseif (count($this->row_data) === 0 OR is_int($this->num_rows)
473 OR count($this->result_array) > 0 OR count($this->result_object) > 0
474 OR $n < $this->current_row)
475 {
476 // No such row exists
477 return array();
478 }
479
480 // Get the next row index that would actually need to be fetched
481 $current_row = ($this->current_row < count($this->row_data)) ? count($this->row_data) : $this->current_row + 1;
482 }
483 else
484 {
485 $current_row = $this->current_row = 0;
486 $this->row_data = array();
487 }
488
489 /* Fetch more data, if available
490 *
491 * NOTE: Operator precedence is important here, if you change
492 * 'AND' with '&&' - it WILL BREAK the results, as
493 * $row will be assigned the scalar value of both
494 * expressions!
495 */
496 while ($row = $this->_fetch_assoc() AND $current_row <= $n)
497 {
498 $this->row_data[$current_row++] = $row;
499 }
500
501 // This would mean that there's no (more) data to fetch
502 if ( ! is_array($this->row_data) OR ! isset($this->row_data[$n]))
503 {
504 // Cache what we already have
505 if (is_array($this->row_data))
506 {
507 $this->num_rows = count($this->row_data);
508 /* Usually, row_data could have less elements than result_array,
509 * but at this point - they should be exactly the same.
510 */
511 $this->result_array = $this->row_data;
512 }
513 else
514 {
515 $this->num_rows = 0;
516 }
517
518 return array();
519 }
520
521 $this->current_row = $n;
522 return $this->row_data[$n];
523 }
524
525 // --------------------------------------------------------------------
526
527 /* Single row result. Object version.
528 *
529 * @param int row index
530 * @return mixed object if row found; empty array if not
531 */
532 public function row_object($n = 0)
533 {
534 // Make sure $n is not a string
535 if ( ! is_int($n))
536 {
537 $n = (int) $n;
538 }
539 /* Logic here is exactly the same as in row_array,
540 * except we have to cast row_data[$n] to an object.
541 *
542 * If we already have result_object though - we can
543 * directly return from it.
544 */
545 if (isset($this->result_object[$n]))
546 {
547 $this->current_row = $n;
548 // Set this, if not already done.
549 if ( ! is_int($this->num_rows))
550 {
551 $this->num_rows = count($this->result_object);
552 }
553
554 return $this->result_object[$n];
555 }
556
557 $row = $this->row_array($n);
558 // Cast only if the row exists
559 if (count($row) > 0)
560 {
561 $this->current_row = $n;
562 return (object) $row;
563 }
564
565 return array();
566 }
567
568 // --------------------------------------------------------------------
569
570 /* Single row result. Custom object version.
571 *
572 * @param int row index
573 * @param string custom class name
574 * @return mixed custom object if row found; empty array otherwise
575 */
576
577 public function custom_row_object($n = 0, $class_name)
578 {
579 // Make sure $n is not a string
580 if ( ! is_int($n))
581 {
582 $n = (int) $n;
583 }
584
585 if (array_key_exists($class_name, $this->custom_result_object))
586 {
587 /* We already have a the whole result set with this class_name,
588 * return the specified row if it exists, and an empty array if
589 * it doesn't.
590 */
591 if (isset($this->custom_result_object[$class_name][$n]))
592 {
593 $this->current_row = $n;
594 return $this->custom_result_object[$class_name][$n];
595 }
596 else
597 {
598 return array();
599 }
600 }
601 elseif ( ! class_exists($class_name)) // No such class exists
602 {
603 return array();
604 }
605
606 $row = $this->row_array($n);
607 // An array would mean that the row doesn't exist
608 if (is_array($row))
609 {
610 return $row;
611 }
612
613 // Convert to the desired class and return
614 $row_object = new $class_name();
615 foreach ($row as $key => $value)
616 {
617 $row_object->$key = $value;
618 }
619
620 $this->current_row = $n;
621 return $row_object;
622 }
623
624 // --------------------------------------------------------------------
625
626 /* First row result.
627 *
628 * @param string ('object', 'array' or a custom class name)
629 * @return mixed whatever was passed to the second parameter
630 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200631 public function first_row($type = 'object')
632 {
633 return $this->row(0, $type);
634 }
635
636 // --------------------------------------------------------------------
637
638 /* Last row result.
639 *
640 * @param string ('object', 'array' or a custom class name)
641 * @return mixed whatever was passed to the second parameter
642 */
643 public function last_row($type = 'object')
644 {
645 $result = &$this->result($type);
646 if ( ! isset($this->num_rows))
647 {
648 $this->num_rows = count($result);
649 }
650 $this->current_row = $this->num_rows - 1;
651 return $result[$this->current_row];
652 }
653
654 // --------------------------------------------------------------------
655
656 /* Next row result.
657 *
658 * @param string ('object', 'array' or a custom class name)
659 * @return mixed whatever was passed to the second parameter
660 */
661 public function next_row($type = 'object')
662 {
663 if (is_array($this->row_data))
664 {
665 $count = count($this->row_data);
666 if ($this->current_row > $count OR ($this->current_row === 0 && $count === 0))
667 {
668 $n = $count;
669 }
670 else
671 {
672 $n = $this->current_row + 1;
673 }
674 }
675 else
676 {
677 $n = 0;
678 }
679
680 return $this->row($n, $type);
681 }
682
683 // --------------------------------------------------------------------
684
685 /* Previous row result.
686 *
687 * @param string ('object', 'array' or a custom class name)
688 * @return mixed whatever was passed to the second parameter
689 */
690 public function previous_row($type = 'object')
691 {
692 $n = ($this->current_row !== 0) ? $this->current_row - 1 : 0;
693 return $this->row($n, $type);
Derek Allard2067d1a2008-11-13 22:59:24 +0000694 }
695
696 // --------------------------------------------------------------------
697
698 /**
699 * Data Seek
700 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200701 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000702 * this internally before fetching results to make sure the
Andrey Andreev24abcb92012-01-05 20:40:15 +0200703 * result set starts at zero.
Derek Allard2067d1a2008-11-13 22:59:24 +0000704 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200705 * Oracle's PHP extension doesn't have an easy way of doing this
706 * and the only workaround is to (re)execute the statement or cursor
707 * in order to go to the first (zero) index of the result set.
708 * Then, we would need to "dummy" fetch ($n - 1) rows to get to the
709 * right one.
710 *
711 * This is as ridiculous as it sounds and it's the reason why every
712 * other method that is fetching data tries to use an already "cached"
713 * result set. Keeping this just in case it becomes needed at
714 * some point in the future, but it will only work for resetting the
715 * pointer to zero.
716 *
717 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000718 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200719 protected function _data_seek()
Derek Allard2067d1a2008-11-13 22:59:24 +0000720 {
Andrey Andreev24abcb92012-01-05 20:40:15 +0200721 /* The PHP manual says that if OCI_NO_AUTO_COMMIT mode
722 * is used, and oci_rollback() and/or oci_commit() are
723 * not subsequently called - this will cause an unnecessary
724 * rollback to be triggered at the end of the script execution.
725 *
726 * Therefore we'll try to avoid using that mode flag
727 * if we're not currently in the middle of a transaction.
728 */
729 if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS)
730 {
731 $result = @oci_execute($this->stmt_id, $this->commit_mode);
732 }
733 else
734 {
735 $result = @oci_execute($this->stmt_id);
736 }
737
738 if ($result && $this->curs_id)
739 {
740 if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS)
741 {
742 return @oci_execute($this->curs_id, $this->commit_mode);
743 }
744 else
745 {
746 return @oci_execute($this->curs_id);
747 }
748 }
749
750 return $result;
Derek Allard2067d1a2008-11-13 22:59:24 +0000751 }
752
753}
754
Derek Allard2067d1a2008-11-13 22:59:24 +0000755/* End of file oci8_result.php */
Andrey Andreevef3e2402011-09-21 14:39:29 +0300756/* Location: ./system/database/drivers/oci8/oci8_result.php */