blob: ff6f7a40583f607fa7f1ab40358452b35d425fef [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 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;
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 {
Andrey Andreevb5e6f112012-01-16 13:25:07 +020069 return $this->num_rows = count($this->result_object);
Andrey Andreev24abcb92012-01-05 20:40:15 +020070 }
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 Andreeve35d7782012-01-19 15:56:20 +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 {
Andrey Andreev574c85d2012-02-12 20:40:53 +0200309 if (isset($this->custom_result_object[$class_name]))
Andrey Andreev24abcb92012-01-05 20:40:15 +0200310 {
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
Andrey Andreevb5e6f112012-01-16 13:25:07 +0200319 /* Even if we didn't have result_array or result_object
320 * set prior to custom_result_object() being called,
321 * num_rows() has already done so.
322 * Pass by reference, as we don't know how
Andrey Andreev24abcb92012-01-05 20:40:15 +0200323 * large it might be and we don't want 1000 row
324 * sets being copied.
325 */
326 if (count($this->result_array) > 0)
327 {
328 $data = &$this->result_array;
329 }
330 elseif (count($this->result_object) > 0)
331 {
332 $data = &$this->result_object;
333 }
334
Andrey Andreev574c85d2012-02-12 20:40:53 +0200335 $this->custom_result_object[$class_name] = array();
Andrey Andreevb5e6f112012-01-16 13:25:07 +0200336 for ($i = 0, $c = count($data); $i < $c; $i++)
Andrey Andreev24abcb92012-01-05 20:40:15 +0200337 {
Andrey Andreev574c85d2012-02-12 20:40:53 +0200338 $this->custom_result_object[$class_name][$i] = new $class_name();
Andrey Andreevb5e6f112012-01-16 13:25:07 +0200339 foreach ($data[$i] as $key => $value)
Andrey Andreev24abcb92012-01-05 20:40:15 +0200340 {
Andrey Andreev574c85d2012-02-12 20:40:53 +0200341 $this->custom_result_object[$class_name][$i]->$key = $value;
Andrey Andreev24abcb92012-01-05 20:40:15 +0200342 }
343 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200344
Andrey Andreev574c85d2012-02-12 20:40:53 +0200345 return $this->custom_result_object[$class_name];
Andrey Andreev74e50982012-02-12 20:46:10 +0200346 }
Andrey Andreev24abcb92012-01-05 20:40:15 +0200347
348 // --------------------------------------------------------------------
349
350 /* Single row result.
351 *
352 * Acts as a wrapper for row_object(), row_array()
353 * and custom_row_object(). Also used by first_row(), next_row()
354 * and previous_row().
355 *
356 * @param int row index
357 * @param string ('object', 'array' or a custom class name)
358 * @return mixed whatever was passed to the second parameter
359 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200360 public function row($n = 0, $type = 'object')
361 {
Andrey Andreevaa786c92012-01-16 12:14:45 +0200362 if ($type === 'object')
363 {
364 return $this->row_object($n);
365 }
366 elseif ($type === 'array')
367 {
368 return $this->row_array($n);
369 }
370
371 return $this->custom_row_object($n, $type);
Andrey Andreev24abcb92012-01-05 20:40:15 +0200372 }
373
374 // --------------------------------------------------------------------
375
376 /* Single row result. Array version.
377 *
378 * @param int row index
379 * @return array
380 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200381 public function row_array($n = 0)
382 {
383 // Make sure $n is not a string
384 if ( ! is_int($n))
385 {
386 $n = (int) $n;
387 }
388
389 /* If row_data is initialized, it means that we've already tried
390 * (at least) to fetch some data, so ... check if we already have
391 * this row.
392 */
393 if (is_array($this->row_data))
394 {
395 /* If we already have row_data[$n] - return it.
396 *
397 * If we enter the elseif, there's a number of reasons to
398 * return an empty array:
399 *
400 * - count($this->row_data) === 0 means there are no results
401 * - num_rows being set, result_array and/or result_object
402 * having count() > 0 means that we've already fetched all
403 * data and $n is greater than our highest row index available
404 * - $n < $this->current_row means that if such row existed,
405 * we would've already returned it, therefore $n is an
406 * invalid index
407 */
408 if (isset($this->row_data[$n])) // We already have this row
409 {
410 $this->current_row = $n;
411 return $this->row_data[$n];
412 }
413 elseif (count($this->row_data) === 0 OR is_int($this->num_rows)
414 OR count($this->result_array) > 0 OR count($this->result_object) > 0
415 OR $n < $this->current_row)
416 {
417 // No such row exists
418 return array();
419 }
420
421 // Get the next row index that would actually need to be fetched
422 $current_row = ($this->current_row < count($this->row_data)) ? count($this->row_data) : $this->current_row + 1;
423 }
424 else
425 {
426 $current_row = $this->current_row = 0;
427 $this->row_data = array();
428 }
429
430 /* Fetch more data, if available
431 *
432 * NOTE: Operator precedence is important here, if you change
433 * 'AND' with '&&' - it WILL BREAK the results, as
434 * $row will be assigned the scalar value of both
435 * expressions!
436 */
437 while ($row = $this->_fetch_assoc() AND $current_row <= $n)
438 {
439 $this->row_data[$current_row++] = $row;
440 }
441
442 // This would mean that there's no (more) data to fetch
443 if ( ! is_array($this->row_data) OR ! isset($this->row_data[$n]))
444 {
445 // Cache what we already have
446 if (is_array($this->row_data))
447 {
448 $this->num_rows = count($this->row_data);
449 /* Usually, row_data could have less elements than result_array,
450 * but at this point - they should be exactly the same.
451 */
452 $this->result_array = $this->row_data;
453 }
454 else
455 {
456 $this->num_rows = 0;
457 }
458
459 return array();
460 }
461
462 $this->current_row = $n;
463 return $this->row_data[$n];
464 }
465
466 // --------------------------------------------------------------------
467
468 /* Single row result. Object version.
469 *
470 * @param int row index
471 * @return mixed object if row found; empty array if not
472 */
473 public function row_object($n = 0)
474 {
475 // Make sure $n is not a string
476 if ( ! is_int($n))
477 {
478 $n = (int) $n;
479 }
480 /* Logic here is exactly the same as in row_array,
481 * except we have to cast row_data[$n] to an object.
482 *
483 * If we already have result_object though - we can
484 * directly return from it.
485 */
486 if (isset($this->result_object[$n]))
487 {
488 $this->current_row = $n;
489 // Set this, if not already done.
490 if ( ! is_int($this->num_rows))
491 {
492 $this->num_rows = count($this->result_object);
493 }
494
495 return $this->result_object[$n];
496 }
497
498 $row = $this->row_array($n);
499 // Cast only if the row exists
500 if (count($row) > 0)
501 {
502 $this->current_row = $n;
503 return (object) $row;
504 }
505
506 return array();
507 }
508
509 // --------------------------------------------------------------------
510
511 /* Single row result. Custom object version.
512 *
513 * @param int row index
514 * @param string custom class name
515 * @return mixed custom object if row found; empty array otherwise
516 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200517 public function custom_row_object($n = 0, $class_name)
518 {
519 // Make sure $n is not a string
520 if ( ! is_int($n))
521 {
522 $n = (int) $n;
523 }
524
525 if (array_key_exists($class_name, $this->custom_result_object))
526 {
527 /* We already have a the whole result set with this class_name,
528 * return the specified row if it exists, and an empty array if
529 * it doesn't.
530 */
531 if (isset($this->custom_result_object[$class_name][$n]))
532 {
533 $this->current_row = $n;
534 return $this->custom_result_object[$class_name][$n];
535 }
536 else
537 {
538 return array();
539 }
540 }
541 elseif ( ! class_exists($class_name)) // No such class exists
542 {
543 return array();
544 }
545
546 $row = $this->row_array($n);
547 // An array would mean that the row doesn't exist
548 if (is_array($row))
549 {
550 return $row;
551 }
552
553 // Convert to the desired class and return
554 $row_object = new $class_name();
555 foreach ($row as $key => $value)
556 {
557 $row_object->$key = $value;
558 }
559
560 $this->current_row = $n;
561 return $row_object;
562 }
563
564 // --------------------------------------------------------------------
565
566 /* First row result.
567 *
568 * @param string ('object', 'array' or a custom class name)
569 * @return mixed whatever was passed to the second parameter
570 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200571 public function first_row($type = 'object')
572 {
573 return $this->row(0, $type);
574 }
575
576 // --------------------------------------------------------------------
577
578 /* Last row result.
579 *
580 * @param string ('object', 'array' or a custom class name)
581 * @return mixed whatever was passed to the second parameter
582 */
583 public function last_row($type = 'object')
584 {
585 $result = &$this->result($type);
586 if ( ! isset($this->num_rows))
587 {
588 $this->num_rows = count($result);
589 }
590 $this->current_row = $this->num_rows - 1;
591 return $result[$this->current_row];
592 }
593
594 // --------------------------------------------------------------------
595
596 /* Next row result.
597 *
598 * @param string ('object', 'array' or a custom class name)
599 * @return mixed whatever was passed to the second parameter
600 */
601 public function next_row($type = 'object')
602 {
603 if (is_array($this->row_data))
604 {
605 $count = count($this->row_data);
606 if ($this->current_row > $count OR ($this->current_row === 0 && $count === 0))
607 {
608 $n = $count;
609 }
610 else
611 {
612 $n = $this->current_row + 1;
613 }
614 }
615 else
616 {
617 $n = 0;
618 }
619
620 return $this->row($n, $type);
621 }
622
623 // --------------------------------------------------------------------
624
625 /* Previous row result.
626 *
627 * @param string ('object', 'array' or a custom class name)
628 * @return mixed whatever was passed to the second parameter
629 */
630 public function previous_row($type = 'object')
631 {
632 $n = ($this->current_row !== 0) ? $this->current_row - 1 : 0;
633 return $this->row($n, $type);
Derek Allard2067d1a2008-11-13 22:59:24 +0000634 }
635
636 // --------------------------------------------------------------------
637
638 /**
639 * Data Seek
640 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200641 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000642 * this internally before fetching results to make sure the
Andrey Andreev24abcb92012-01-05 20:40:15 +0200643 * result set starts at zero.
Derek Allard2067d1a2008-11-13 22:59:24 +0000644 *
Andrey Andreev24abcb92012-01-05 20:40:15 +0200645 * Oracle's PHP extension doesn't have an easy way of doing this
646 * and the only workaround is to (re)execute the statement or cursor
647 * in order to go to the first (zero) index of the result set.
648 * Then, we would need to "dummy" fetch ($n - 1) rows to get to the
649 * right one.
650 *
651 * This is as ridiculous as it sounds and it's the reason why every
652 * other method that is fetching data tries to use an already "cached"
653 * result set. Keeping this just in case it becomes needed at
654 * some point in the future, but it will only work for resetting the
655 * pointer to zero.
656 *
657 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000658 */
Andrey Andreev24abcb92012-01-05 20:40:15 +0200659 protected function _data_seek()
Derek Allard2067d1a2008-11-13 22:59:24 +0000660 {
Andrey Andreev24abcb92012-01-05 20:40:15 +0200661 /* The PHP manual says that if OCI_NO_AUTO_COMMIT mode
662 * is used, and oci_rollback() and/or oci_commit() are
663 * not subsequently called - this will cause an unnecessary
664 * rollback to be triggered at the end of the script execution.
665 *
666 * Therefore we'll try to avoid using that mode flag
667 * if we're not currently in the middle of a transaction.
668 */
669 if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS)
670 {
671 $result = @oci_execute($this->stmt_id, $this->commit_mode);
672 }
673 else
674 {
675 $result = @oci_execute($this->stmt_id);
676 }
677
678 if ($result && $this->curs_id)
679 {
680 if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS)
681 {
682 return @oci_execute($this->curs_id, $this->commit_mode);
683 }
684 else
685 {
686 return @oci_execute($this->curs_id);
687 }
688 }
689
690 return $result;
Derek Allard2067d1a2008-11-13 22:59:24 +0000691 }
692
693}
694
Derek Allard2067d1a2008-11-13 22:59:24 +0000695/* End of file oci8_result.php */
Andrey Andreevef3e2402011-09-21 14:39:29 +0300696/* Location: ./system/database/drivers/oci8/oci8_result.php */