blob: 006e6ef1f74b8cf5e9a8f5760e2a61b367b2b0a9 [file] [log] [blame]
Derek Jones0b59f272008-05-13 04:22:33 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allardd2df9bc2007-04-15 17:41:17 +00002/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
Derek Allard3d879d52008-01-18 19:41:32 +00007 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Rick Ellis37b3ecf2008-09-12 23:34:18 +00009 * @copyright Copyright (c) 2008, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allard3d879d52008-01-18 19:41:32 +000012 * @since Version 1.0
Derek Allardd2df9bc2007-04-15 17:41:17 +000013 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * oci8 Database Adapter Class
20 *
21 * Note: _DB is an extender class that the app controller
22 * creates dynamically based on whether the active record
23 * class is being used or not.
24 *
Derek Allard3d879d52008-01-18 19:41:32 +000025 * @package CodeIgniter
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 * @subpackage Drivers
27 * @category Database
Derek Allard3d879d52008-01-18 19:41:32 +000028 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000029 * @link http://codeigniter.com/user_guide/database/
Derek Allardd2df9bc2007-04-15 17:41:17 +000030 */
31
32/**
33 * oci8 Database Adapter Class
34 *
35 * This is a modification of the DB_driver class to
36 * permit access to oracle databases
37 *
38 * NOTE: this uses the PHP 4 oci methods
39 *
40 * @author Kelly McArdle
41 *
42 */
43
44class CI_DB_oci8_driver extends CI_DB {
45
Rick Ellis5aa8c602008-10-07 01:24:07 +000046 var $dbdriver = 'oci8';
47
Derek Allard694b5b82007-12-18 15:58:03 +000048 /**
49 * The syntax to count rows is slightly different across different
50 * database engines, so this string appears in each driver and is
51 * used for the count_all() and count_all_results() functions.
52 */
Derek Allard39b622d2008-01-16 21:10:09 +000053 var $_count_string = "SELECT COUNT(1) AS ";
54 var $_random_keyword = ' ASC'; // not currently supported
Derek Allard694b5b82007-12-18 15:58:03 +000055
Derek Allardd2df9bc2007-04-15 17:41:17 +000056 // Set "auto commit" by default
57 var $_commit = OCI_COMMIT_ON_SUCCESS;
58
59 // need to track statement id and cursor id
60 var $stmt_id;
61 var $curs_id;
62
63 // if we use a limit, we will add a field that will
64 // throw off num_fields later
65 var $limit_used;
66
67 /**
68 * Non-persistent database connection
69 *
70 * @access private called by the base class
71 * @return resource
72 */
73 function db_connect()
74 {
75 return @ocilogon($this->username, $this->password, $this->hostname);
76 }
77
78 // --------------------------------------------------------------------
79
80 /**
81 * Persistent database connection
82 *
83 * @access private called by the base class
84 * @return resource
85 */
86 function db_pconnect()
87 {
88 return @ociplogon($this->username, $this->password, $this->hostname);
89 }
90
91 // --------------------------------------------------------------------
92
93 /**
94 * Select the database
95 *
96 * @access private called by the base class
97 * @return resource
98 */
99 function db_select()
100 {
101 return TRUE;
102 }
103
104 // --------------------------------------------------------------------
105
106 /**
Derek Allard39b622d2008-01-16 21:10:09 +0000107 * Set client character set
108 *
109 * @access public
110 * @param string
111 * @param string
112 * @return resource
113 */
114 function db_set_charset($charset, $collation)
115 {
Rick Ellisff734012008-09-30 20:38:12 +0000116 // @todo - add support if needed
Derek Allard39b622d2008-01-16 21:10:09 +0000117 return TRUE;
118 }
119
120 // --------------------------------------------------------------------
121
122 /**
Derek Allardd2df9bc2007-04-15 17:41:17 +0000123 * Version number query string
124 *
125 * @access public
126 * @return string
127 */
128 function _version()
129 {
130 return ociserverversion($this->conn_id);
131 }
132
133 // --------------------------------------------------------------------
134
135 /**
136 * Execute the query
137 *
138 * @access private called by the base class
139 * @param string an SQL query
140 * @return resource
141 */
142 function _execute($sql)
143 {
144 // oracle must parse the query before it is run. All of the actions with
145 // the query are based on the statement id returned by ociparse
Rick Ellis482ee432008-10-07 00:59:08 +0000146 $this->stmt_id = FALSE;
Derek Allardd2df9bc2007-04-15 17:41:17 +0000147 $this->_set_stmt_id($sql);
148 ocisetprefetch($this->stmt_id, 1000);
149 return @ociexecute($this->stmt_id, $this->_commit);
150 }
151
152 /**
153 * Generate a statement ID
154 *
155 * @access private
156 * @param string an SQL query
157 * @return none
158 */
159 function _set_stmt_id($sql)
160 {
Derek Jones0b59f272008-05-13 04:22:33 +0000161 if ( ! is_resource($this->stmt_id))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000162 {
163 $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql));
164 }
165 }
166
167 // --------------------------------------------------------------------
168
169 /**
170 * Prep the query
171 *
172 * If needed, each database adapter can prep the query string
173 *
174 * @access private called by execute()
175 * @param string an SQL query
176 * @return string
177 */
178 function _prep_query($sql)
179 {
180 return $sql;
181 }
182
183 // --------------------------------------------------------------------
184
185 /**
186 * getCursor. Returns a cursor from the datbase
187 *
188 * @access public
189 * @return cursor id
190 */
191 function get_cursor()
192 {
193 $this->curs_id = ocinewcursor($this->conn_id);
194 return $this->curs_id;
195 }
196
197 // --------------------------------------------------------------------
198
199 /**
200 * Stored Procedure. Executes a stored procedure
201 *
202 * @access public
203 * @param package package stored procedure is in
204 * @param procedure stored procedure to execute
205 * @param params array of parameters
206 * @return array
207 *
208 * params array keys
209 *
210 * KEY OPTIONAL NOTES
211 * name no the name of the parameter should be in :<param_name> format
212 * value no the value of the parameter. If this is an OUT or IN OUT parameter,
213 * this should be a reference to a variable
214 * type yes the type of the parameter
215 * length yes the max size of the parameter
216 */
217 function stored_procedure($package, $procedure, $params)
218 {
219 if ($package == '' OR $procedure == '' OR ! is_array($params))
220 {
221 if ($this->db_debug)
222 {
223 log_message('error', 'Invalid query: '.$package.'.'.$procedure);
224 return $this->display_error('db_invalid_query');
225 }
226 return FALSE;
227 }
228
229 // build the query string
230 $sql = "begin $package.$procedure(";
231
232 $have_cursor = FALSE;
233 foreach($params as $param)
234 {
235 $sql .= $param['name'] . ",";
236
237 if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR))
238 {
239 $have_cursor = TRUE;
240 }
241 }
242 $sql = trim($sql, ",") . "); end;";
243
244 $this->stmt_id = FALSE;
245 $this->_set_stmt_id($sql);
246 $this->_bind_params($params);
247 $this->query($sql, FALSE, $have_cursor);
248 }
249
250 // --------------------------------------------------------------------
251
252 /**
253 * Bind parameters
254 *
255 * @access private
256 * @return none
257 */
258 function _bind_params($params)
259 {
Derek Jones0b59f272008-05-13 04:22:33 +0000260 if ( ! is_array($params) OR ! is_resource($this->stmt_id))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000261 {
262 return;
263 }
264
265 foreach ($params as $param)
266 {
267 foreach (array('name', 'value', 'type', 'length') as $val)
268 {
Derek Jones0b59f272008-05-13 04:22:33 +0000269 if ( ! isset($param[$val]))
Derek Allardd2df9bc2007-04-15 17:41:17 +0000270 {
271 $param[$val] = '';
272 }
273 }
274
275 ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']);
276 }
277 }
278
279 // --------------------------------------------------------------------
280
281 /**
282 * Begin Transaction
283 *
284 * @access public
285 * @return bool
286 */
287 function trans_begin($test_mode = FALSE)
288 {
Derek Jones0b59f272008-05-13 04:22:33 +0000289 if ( ! $this->trans_enabled)
Derek Allardd2df9bc2007-04-15 17:41:17 +0000290 {
291 return TRUE;
292 }
293
294 // When transactions are nested we only begin/commit/rollback the outermost ones
295 if ($this->_trans_depth > 0)
296 {
297 return TRUE;
298 }
299
300 // Reset the transaction failure flag.
301 // If the $test_mode flag is set to TRUE transactions will be rolled back
302 // even if the queries produce a successful result.
303 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
304
305 $this->_commit = OCI_DEFAULT;
306 return TRUE;
307 }
308
309 // --------------------------------------------------------------------
310
311 /**
312 * Commit Transaction
313 *
314 * @access public
315 * @return bool
316 */
317 function trans_commit()
318 {
Derek Jones0b59f272008-05-13 04:22:33 +0000319 if ( ! $this->trans_enabled)
Derek Allardd2df9bc2007-04-15 17:41:17 +0000320 {
321 return TRUE;
322 }
323
324 // When transactions are nested we only begin/commit/rollback the outermost ones
325 if ($this->_trans_depth > 0)
326 {
327 return TRUE;
328 }
329
330 $ret = OCIcommit($this->conn_id);
331 $this->_commit = OCI_COMMIT_ON_SUCCESS;
332 return $ret;
333 }
334
335 // --------------------------------------------------------------------
336
337 /**
338 * Rollback Transaction
339 *
340 * @access public
341 * @return bool
342 */
343 function trans_rollback()
344 {
Derek Jones0b59f272008-05-13 04:22:33 +0000345 if ( ! $this->trans_enabled)
Derek Allardd2df9bc2007-04-15 17:41:17 +0000346 {
347 return TRUE;
348 }
349
350 // When transactions are nested we only begin/commit/rollback the outermost ones
351 if ($this->_trans_depth > 0)
352 {
353 return TRUE;
354 }
355
356 $ret = OCIrollback($this->conn_id);
357 $this->_commit = OCI_COMMIT_ON_SUCCESS;
358 return $ret;
359 }
360
361 // --------------------------------------------------------------------
362
363 /**
364 * Escape String
365 *
366 * @access public
367 * @param string
368 * @return string
369 */
370 function escape_str($str)
371 {
Rick Ellis06a2e742008-10-07 01:04:15 +0000372 // Access the CI object
Rick Ellisca86a7c2008-10-07 01:16:57 +0000373 $CI =& get_instance();
Rick Ellis06a2e742008-10-07 01:04:15 +0000374
375 return $CI->_remove_invisible_characters($str);
Derek Allardd2df9bc2007-04-15 17:41:17 +0000376 }
377
378 // --------------------------------------------------------------------
379
380 /**
381 * Affected Rows
382 *
383 * @access public
384 * @return integer
385 */
386 function affected_rows()
387 {
388 return @ocirowcount($this->stmt_id);
389 }
390
391 // --------------------------------------------------------------------
392
393 /**
394 * Insert ID
395 *
396 * @access public
397 * @return integer
398 */
399 function insert_id()
400 {
401 // not supported in oracle
Derek Allarddb708af2008-01-23 17:18:41 +0000402 return $this->display_error('db_unsupported_function');
Derek Allardd2df9bc2007-04-15 17:41:17 +0000403 }
404
405 // --------------------------------------------------------------------
406
407 /**
408 * "Count All" query
409 *
410 * Generates a platform-specific query string that counts all records in
411 * the specified database
412 *
413 * @access public
414 * @param string
415 * @return string
416 */
417 function count_all($table = '')
418 {
419 if ($table == '')
420 return '0';
421
Derek Allardf6cd45c2008-01-18 14:31:51 +0000422 $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table));
Derek Allardd2df9bc2007-04-15 17:41:17 +0000423
424 if ($query == FALSE)
425 {
426 return 0;
427 }
428
429 $row = $query->row();
430 return $row->NUMROWS;
431 }
432
433 // --------------------------------------------------------------------
434
435 /**
436 * Show table query
437 *
438 * Generates a platform-specific query string so that the table names can be fetched
439 *
440 * @access private
Derek Allard39b622d2008-01-16 21:10:09 +0000441 * @param boolean
Derek Allardd2df9bc2007-04-15 17:41:17 +0000442 * @return string
443 */
Derek Allard39b622d2008-01-16 21:10:09 +0000444 function _list_tables($prefix_limit = FALSE)
Derek Allardd2df9bc2007-04-15 17:41:17 +0000445 {
Derek Allard39b622d2008-01-16 21:10:09 +0000446 $sql = "SELECT TABLE_NAME FROM ALL_TABLES";
447
448 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
449 {
450 $sql .= " WHERE TABLE_NAME LIKE '".$this->dbprefix."%'";
451 }
452
453 return $sql;
Derek Allardd2df9bc2007-04-15 17:41:17 +0000454 }
455
456 // --------------------------------------------------------------------
457
458 /**
459 * Show column query
460 *
461 * Generates a platform-specific query string so that the column names can be fetched
462 *
463 * @access public
464 * @param string the table name
465 * @return string
466 */
467 function _list_columns($table = '')
468 {
469 return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'";
470 }
471
472 // --------------------------------------------------------------------
473
474 /**
475 * Field data query
476 *
477 * Generates a platform-specific query so that the column data can be retrieved
478 *
479 * @access public
480 * @param string the table name
481 * @return object
482 */
483 function _field_data($table)
484 {
485 return "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1";
486 }
487
488 // --------------------------------------------------------------------
489
490 /**
491 * The error message string
492 *
493 * @access private
494 * @return string
495 */
496 function _error_message()
497 {
498 $error = ocierror($this->conn_id);
499 return $error['message'];
500 }
501
502 // --------------------------------------------------------------------
503
504 /**
505 * The error message number
506 *
507 * @access private
508 * @return integer
509 */
510 function _error_number()
511 {
512 $error = ocierror($this->conn_id);
513 return $error['code'];
514 }
Rick Ellis52dc8ca2008-09-30 19:53:52 +0000515
516 // --------------------------------------------------------------------
517
518 /**
519 * Escape Column Name
520 *
521 * This function adds backticks around supplied column name
522 *
523 * @access private
524 * @param string the column name
525 * @return string
526 */
527 function _escape_column($column)
528 {
529 // Probably not necessary with Oracle so we simply return the value
530 return $column;
531 }
Derek Allardd2df9bc2007-04-15 17:41:17 +0000532
533 // --------------------------------------------------------------------
534
535 /**
536 * Escape Table Name
537 *
538 * This function adds backticks if the table name has a period
539 * in it. Some DBs will get cranky unless periods are escaped
540 *
541 * @access private
542 * @param string the table name
543 * @return string
544 */
545 function _escape_table($table)
546 {
Derek Allardc0743382008-02-11 05:54:44 +0000547 if (strpos($table, '.') !== FALSE)
Derek Allardd2df9bc2007-04-15 17:41:17 +0000548 {
Derek Allardc0743382008-02-11 05:54:44 +0000549 $table = '"' . str_replace('.', '"."', $table) . '"';
Derek Allardd2df9bc2007-04-15 17:41:17 +0000550 }
551
552 return $table;
553 }
554
555 // --------------------------------------------------------------------
556
557 /**
Derek Allard39b622d2008-01-16 21:10:09 +0000558 * Protect Identifiers
559 *
560 * This function adds backticks if appropriate based on db type
561 *
562 * @access private
563 * @param mixed the item to escape
564 * @param boolean only affect the first word
565 * @return mixed the item with backticks
566 */
567 function _protect_identifiers($item, $first_word_only = FALSE)
568 {
569 if (is_array($item))
570 {
571 $escaped_array = array();
572
573 foreach($item as $k=>$v)
574 {
575 $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);
576 }
577
578 return $escaped_array;
579 }
580
581 // This function may get "item1 item2" as a string, and so
Derek Allard15648132008-02-10 21:46:18 +0000582 // we may need ""item1" "item2"" and not ""item1 item2""
Derek Allard61579382008-01-16 22:22:42 +0000583 if (ctype_alnum($item) === FALSE)
Derek Allard39b622d2008-01-16 21:10:09 +0000584 {
Derek Allard9b3e7b52008-02-04 23:20:34 +0000585 if (strpos($item, '.') !== FALSE)
586 {
587 $aliased_tables = implode(".",$this->ar_aliased_tables).'.';
588 $table_name = substr($item, 0, strpos($item, '.')+1);
589 $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item;
590 }
591
Derek Allard15648132008-02-10 21:46:18 +0000592 // This function may get "field >= 1", and need it to return ""field" >= 1"
Derek Allard61579382008-01-16 22:22:42 +0000593 $lbound = ($first_word_only === TRUE) ? '' : '|\s|\(';
Derek Allard39b622d2008-01-16 21:10:09 +0000594
Derek Allard15648132008-02-10 21:46:18 +0000595 $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item);
Derek Allard61579382008-01-16 22:22:42 +0000596 }
597 else
598 {
Derek Allard15648132008-02-10 21:46:18 +0000599 return "\"{$item}\"";
Derek Allard39b622d2008-01-16 21:10:09 +0000600 }
601
Derek Allard9a4d1da2008-02-25 14:18:38 +0000602 $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS');
Derek Allard39b622d2008-01-16 21:10:09 +0000603
604 foreach ($exceptions as $exception)
605 {
Derek Allard61579382008-01-16 22:22:42 +0000606
Derek Allard15648132008-02-10 21:46:18 +0000607 if (stristr($item, " \"{$exception}\" ") !== FALSE)
Derek Allard39b622d2008-01-16 21:10:09 +0000608 {
Derek Allard15648132008-02-10 21:46:18 +0000609 $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item);
Derek Allard39b622d2008-01-16 21:10:09 +0000610 }
611 }
Derek Allard39b622d2008-01-16 21:10:09 +0000612 return $item;
613 }
614
615 // --------------------------------------------------------------------
616
617 /**
Derek Jonesc6ad0232008-01-29 18:44:54 +0000618 * From Tables
619 *
620 * This function implicitly groups FROM tables so there is no confusion
621 * about operator precedence in harmony with SQL standards
622 *
623 * @access public
624 * @param type
625 * @return type
626 */
627 function _from_tables($tables)
628 {
Derek Jones0b59f272008-05-13 04:22:33 +0000629 if ( ! is_array($tables))
Derek Jonesc6ad0232008-01-29 18:44:54 +0000630 {
631 $tables = array($tables);
632 }
633
Derek Allard15648132008-02-10 21:46:18 +0000634 return implode(', ', $tables);
Derek Jonesc6ad0232008-01-29 18:44:54 +0000635 }
636
637 // --------------------------------------------------------------------
638
639 /**
Derek Allardd2df9bc2007-04-15 17:41:17 +0000640 * Insert statement
641 *
642 * Generates a platform-specific insert string from the supplied data
643 *
644 * @access public
645 * @param string the table name
646 * @param array the insert keys
647 * @param array the insert values
648 * @return string
649 */
650 function _insert($table, $keys, $values)
651 {
652 return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
653 }
654
655 // --------------------------------------------------------------------
656
657 /**
658 * Update statement
659 *
660 * Generates a platform-specific update string from the supplied data
661 *
Derek Allard39b622d2008-01-16 21:10:09 +0000662 * @access public
663 * @param string the table name
664 * @param array the update data
665 * @param array the where clause
666 * @param array the orderby clause
667 * @param array the limit clause
668 * @return string
Derek Allardd2df9bc2007-04-15 17:41:17 +0000669 */
Derek Allard39b622d2008-01-16 21:10:09 +0000670 function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Derek Allardd2df9bc2007-04-15 17:41:17 +0000671 {
672 foreach($values as $key => $val)
673 {
674 $valstr[] = $key." = ".$val;
675 }
Derek Allardda6d2402007-12-19 14:49:29 +0000676
Derek Jones0b59f272008-05-13 04:22:33 +0000677 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Derek Allard39b622d2008-01-16 21:10:09 +0000678
679 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Derek Allardda6d2402007-12-19 14:49:29 +0000680
Derek Allard32cf7eb2008-02-05 16:03:50 +0000681 $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr);
682 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
683 $sql .= $orderby.$limit;
684
685 return $sql;
Derek Allardd2df9bc2007-04-15 17:41:17 +0000686 }
687
688 // --------------------------------------------------------------------
689
690 /**
Derek Allard39b622d2008-01-16 21:10:09 +0000691 * Truncate statement
692 *
693 * Generates a platform-specific truncate string from the supplied data
694 * If the database does not support the truncate() command
695 * This function maps to "DELETE FROM table"
696 *
697 * @access public
698 * @param string the table name
699 * @return string
700 */
701 function _truncate($table)
702 {
703 return "TRUNCATE TABLE ".$this->_escape_table($table);
704 }
705
706 // --------------------------------------------------------------------
707
708 /**
Derek Allardd2df9bc2007-04-15 17:41:17 +0000709 * Delete statement
710 *
711 * Generates a platform-specific delete string from the supplied data
712 *
Derek Allard39b622d2008-01-16 21:10:09 +0000713 * @access public
714 * @param string the table name
715 * @param array the where clause
716 * @param string the limit clause
717 * @return string
718 */
719 function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Derek Allardd2df9bc2007-04-15 17:41:17 +0000720 {
Derek Allard39b622d2008-01-16 21:10:09 +0000721 $conditions = '';
722
Derek Jones0b59f272008-05-13 04:22:33 +0000723 if (count($where) > 0 OR count($like) > 0)
Derek Allard39b622d2008-01-16 21:10:09 +0000724 {
725 $conditions = "\nWHERE ";
726 $conditions .= implode("\n", $this->ar_where);
727
728 if (count($where) > 0 && count($like) > 0)
729 {
730 $conditions .= " AND ";
731 }
732 $conditions .= implode("\n", $like);
733 }
734
Derek Jones0b59f272008-05-13 04:22:33 +0000735 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Derek Allarde77d77c2007-12-19 15:01:55 +0000736
Derek Allard39b622d2008-01-16 21:10:09 +0000737 return "DELETE FROM ".$table.$conditions.$limit;
Derek Allardd2df9bc2007-04-15 17:41:17 +0000738 }
739
740 // --------------------------------------------------------------------
741
742 /**
743 * Limit string
744 *
745 * Generates a platform-specific LIMIT clause
746 *
747 * @access public
748 * @param string the sql query string
749 * @param integer the number of rows to limit the query to
750 * @param integer the offset value
751 * @return string
752 */
753 function _limit($sql, $limit, $offset)
754 {
755 $limit = $offset + $limit;
756 $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)";
757
758 if ($offset != 0)
759 {
760 $newsql .= " WHERE rnum >= $offset";
761 }
762
763 // remember that we used limits
764 $this->limit_used = TRUE;
765
766 return $newsql;
767 }
768
769 // --------------------------------------------------------------------
770
771 /**
772 * Close DB Connection
773 *
774 * @access public
775 * @param resource
776 * @return void
777 */
778 function _close($conn_id)
779 {
780 @ocilogoff($conn_id);
781 }
782
783
784}
785
786
Derek Jones0b59f272008-05-13 04:22:33 +0000787
788/* End of file oci8_driver.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000789/* Location: ./system/database/drivers/oci8/oci8_driver.php */