Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * 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 Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 24 | * @since Version 1.0 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * oci8 Database Adapter Class |
| 30 | * |
| 31 | * Note: _DB is an extender class that the app controller |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 32 | * creates dynamically based on whether the query builder |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 33 | * class is being used or not. |
| 34 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 35 | * @package CodeIgniter |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 36 | * @subpackage Drivers |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 38 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | * @link http://codeigniter.com/user_guide/database/ |
| 40 | */ |
| 41 | |
| 42 | /** |
| 43 | * oci8 Database Adapter Class |
| 44 | * |
| 45 | * This is a modification of the DB_driver class to |
| 46 | * permit access to oracle databases |
| 47 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 48 | * @author Kelly McArdle |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 49 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 50 | class CI_DB_oci8_driver extends CI_DB { |
| 51 | |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 52 | public $dbdriver = 'oci8'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 53 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 54 | // The character used for excaping |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 55 | protected $_escape_char = '"'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 56 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 57 | /** |
| 58 | * The syntax to count rows is slightly different across different |
| 59 | * database engines, so this string appears in each driver and is |
| 60 | * used for the count_all() and count_all_results() functions. |
| 61 | */ |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 62 | protected $_count_string = 'SELECT COUNT(1) AS '; |
| 63 | protected $_random_keyword = ' ASC'; // not currently supported |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 64 | |
Andrey Andreev | d3f1367 | 2012-06-24 22:13:21 +0300 | [diff] [blame] | 65 | protected $_reserved_identifiers = array('*', 'rownum'); |
| 66 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 67 | // Set "auto commit" by default |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 68 | public $commit_mode = OCI_COMMIT_ON_SUCCESS; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 69 | |
| 70 | // need to track statement id and cursor id |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 71 | public $stmt_id; |
| 72 | public $curs_id; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | |
| 74 | // if we use a limit, we will add a field that will |
| 75 | // throw off num_fields later |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 76 | public $limit_used; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 77 | |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame^] | 78 | /** |
| 79 | * Constructor |
| 80 | * |
| 81 | * @param array $params |
| 82 | * @return void |
| 83 | */ |
Andrey Andreev | dad61c2 | 2012-02-13 01:08:06 +0200 | [diff] [blame] | 84 | public function __construct($params) |
| 85 | { |
| 86 | parent::__construct($params); |
| 87 | |
| 88 | $valid_dsns = array( |
Andrey Andreev | dad61c2 | 2012-02-13 01:08:06 +0200 | [diff] [blame] | 89 | 'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS |
Andrey Andreev | fcd1f47 | 2012-02-13 09:30:16 +0200 | [diff] [blame] | 90 | // Easy Connect string (Oracle 10g+) |
| 91 | 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i', |
Andrey Andreev | dad61c2 | 2012-02-13 01:08:06 +0200 | [diff] [blame] | 92 | 'in' => '/^[a-z0-9$_]+$/i' // Instance name (defined in tnsnames.ora) |
| 93 | ); |
| 94 | |
| 95 | /* Space characters don't have any effect when actually |
| 96 | * connecting, but can be a hassle while validating the DSN. |
| 97 | */ |
| 98 | $this->dsn = str_replace(array("\n", "\r", "\t", ' '), '', $this->dsn); |
| 99 | |
| 100 | if ($this->dsn !== '') |
| 101 | { |
| 102 | foreach ($valid_dsns as $regexp) |
| 103 | { |
| 104 | if (preg_match($regexp, $this->dsn)) |
| 105 | { |
| 106 | return; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // Legacy support for TNS in the hostname configuration field |
| 112 | $this->hostname = str_replace(array("\n", "\r", "\t", ' '), '', $this->hostname); |
| 113 | if (preg_match($valid_dsns['tns'], $this->hostname)) |
| 114 | { |
| 115 | $this->dsn = $this->hostname; |
| 116 | return; |
| 117 | } |
| 118 | elseif ($this->hostname !== '' && strpos($this->hostname, '/') === FALSE && strpos($this->hostname, ':') === FALSE |
| 119 | && (( ! empty($this->port) && ctype_digit($this->port)) OR $this->database !== '')) |
| 120 | { |
| 121 | /* If the hostname field isn't empty, doesn't contain |
| 122 | * ':' and/or '/' and if port and/or database aren't |
| 123 | * empty, then the hostname field is most likely indeed |
| 124 | * just a hostname. Therefore we'll try and build an |
| 125 | * Easy Connect string from these 3 settings, assuming |
| 126 | * that the database field is a service name. |
| 127 | */ |
| 128 | $this->dsn = $this->hostname |
| 129 | .(( ! empty($this->port) && ctype_digit($this->port)) ? ':'.$this->port : '') |
| 130 | .($this->database !== '' ? '/'.ltrim($this->database, '/') : ''); |
| 131 | |
| 132 | if (preg_match($valid_dsns['ec'], $this->dsn)) |
| 133 | { |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /* At this point, we can only try and validate the hostname and |
| 139 | * database fields separately as DSNs. |
| 140 | */ |
| 141 | if (preg_match($valid_dsns['ec'], $this->hostname) OR preg_match($valid_dsns['in'], $this->hostname)) |
| 142 | { |
| 143 | $this->dsn = $this->hostname; |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | $this->database = str_replace(array("\n", "\r", "\t", ' '), '', $this->database); |
| 148 | foreach ($valid_dsns as $regexp) |
| 149 | { |
| 150 | if (preg_match($regexp, $this->database)) |
| 151 | { |
| 152 | return; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /* Well - OK, an empty string should work as well. |
| 157 | * PHP will try to use environment variables to |
| 158 | * determine which Oracle instance to connect to. |
| 159 | */ |
| 160 | $this->dsn = ''; |
| 161 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 162 | |
Andrey Andreev | d580999 | 2012-06-28 14:06:54 +0300 | [diff] [blame] | 163 | // -------------------------------------------------------------------- |
| 164 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 165 | /** |
| 166 | * Non-persistent database connection |
| 167 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 168 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 170 | public function db_connect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | { |
Andrey Andreev | dad61c2 | 2012-02-13 01:08:06 +0200 | [diff] [blame] | 172 | return ( ! empty($this->char_set)) |
| 173 | ? @oci_connect($this->username, $this->password, $this->dsn, $this->char_set) |
| 174 | : @oci_connect($this->username, $this->password, $this->dsn); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | // -------------------------------------------------------------------- |
| 178 | |
| 179 | /** |
| 180 | * Persistent database connection |
| 181 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 182 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 184 | public function db_pconnect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | { |
Andrey Andreev | d580999 | 2012-06-28 14:06:54 +0300 | [diff] [blame] | 186 | return empty($this->char_set) |
| 187 | ? @oci_pconnect($this->username, $this->password, $this->dsn) |
| 188 | : @oci_pconnect($this->username, $this->password, $this->dsn, $this->char_set); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // -------------------------------------------------------------------- |
| 192 | |
| 193 | /** |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 194 | * Database version number |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | * |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 196 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 197 | */ |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 198 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 199 | { |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 200 | return isset($this->data_cache['version']) |
| 201 | ? $this->data_cache['version'] |
| 202 | : $this->data_cache['version'] = oci_server_version($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | // -------------------------------------------------------------------- |
| 206 | |
| 207 | /** |
| 208 | * Execute the query |
| 209 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 210 | * @param string an SQL query |
| 211 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 213 | protected function _execute($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | { |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 215 | /* Oracle must parse the query before it is run. All of the actions with |
| 216 | * the query are based on the statement id returned by oci_parse(). |
| 217 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 218 | $this->stmt_id = FALSE; |
| 219 | $this->_set_stmt_id($sql); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 220 | oci_set_prefetch($this->stmt_id, 1000); |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 221 | return @oci_execute($this->stmt_id, $this->commit_mode); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Andrey Andreev | d580999 | 2012-06-28 14:06:54 +0300 | [diff] [blame] | 224 | // -------------------------------------------------------------------- |
| 225 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 226 | /** |
| 227 | * Generate a statement ID |
| 228 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 229 | * @param string an SQL query |
| 230 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 231 | */ |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 232 | protected function _set_stmt_id($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 233 | { |
| 234 | if ( ! is_resource($this->stmt_id)) |
| 235 | { |
Timothy Warren | d2ff0bc | 2012-03-19 16:52:10 -0400 | [diff] [blame] | 236 | $this->stmt_id = oci_parse($this->conn_id, $sql); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
| 240 | // -------------------------------------------------------------------- |
| 241 | |
| 242 | /** |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 243 | * Get cursor. Returns a cursor from the database |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 244 | * |
Andrey Andreev | d580999 | 2012-06-28 14:06:54 +0300 | [diff] [blame] | 245 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 246 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 247 | public function get_cursor() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 248 | { |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 249 | return $this->curs_id = oci_new_cursor($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | // -------------------------------------------------------------------- |
| 253 | |
| 254 | /** |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 255 | * Stored Procedure. Executes a stored procedure |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 256 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 257 | * @param string package name in which the stored procedure is in |
| 258 | * @param string stored procedure name to execute |
| 259 | * @param array parameters |
| 260 | * @return mixed |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 261 | * |
| 262 | * params array keys |
| 263 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 264 | * KEY OPTIONAL NOTES |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 265 | * name no the name of the parameter should be in :<param_name> format |
| 266 | * value no the value of the parameter. If this is an OUT or IN OUT parameter, |
| 267 | * this should be a reference to a variable |
| 268 | * type yes the type of the parameter |
| 269 | * length yes the max size of the parameter |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 271 | public function stored_procedure($package, $procedure, $params) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 272 | { |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 273 | if ($package === '' OR $procedure === '' OR ! is_array($params)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 274 | { |
| 275 | if ($this->db_debug) |
| 276 | { |
| 277 | log_message('error', 'Invalid query: '.$package.'.'.$procedure); |
Derek Allard | fac8fbc | 2010-02-05 16:14:49 +0000 | [diff] [blame] | 278 | return $this->display_error('db_invalid_query'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 279 | } |
| 280 | return FALSE; |
| 281 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 282 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 283 | // build the query string |
Andrey Andreev | e35d778 | 2012-01-19 15:56:20 +0200 | [diff] [blame] | 284 | $sql = 'BEGIN '.$package.'.'.$procedure.'('; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 285 | |
| 286 | $have_cursor = FALSE; |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 287 | foreach ($params as $param) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | { |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 289 | $sql .= $param['name'].','; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 290 | |
Andrey Andreev | 85facfa | 2012-01-26 14:12:14 +0200 | [diff] [blame] | 291 | if (isset($param['type']) && $param['type'] === OCI_B_CURSOR) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 292 | { |
| 293 | $have_cursor = TRUE; |
| 294 | } |
| 295 | } |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 296 | $sql = trim($sql, ',') . '); END;'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 297 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 298 | $this->stmt_id = FALSE; |
| 299 | $this->_set_stmt_id($sql); |
| 300 | $this->_bind_params($params); |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 301 | return $this->query($sql, FALSE, $have_cursor); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 302 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 303 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 304 | // -------------------------------------------------------------------- |
| 305 | |
| 306 | /** |
| 307 | * Bind parameters |
| 308 | * |
Andrey Andreev | d580999 | 2012-06-28 14:06:54 +0300 | [diff] [blame] | 309 | * @param array |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 310 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 311 | */ |
Andrey Andreev | 1b5a856 | 2012-03-13 13:13:43 +0200 | [diff] [blame] | 312 | protected function _bind_params($params) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 313 | { |
| 314 | if ( ! is_array($params) OR ! is_resource($this->stmt_id)) |
| 315 | { |
| 316 | return; |
| 317 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 318 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | foreach ($params as $param) |
| 320 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 321 | foreach (array('name', 'value', 'type', 'length') as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | { |
| 323 | if ( ! isset($param[$val])) |
| 324 | { |
| 325 | $param[$val] = ''; |
| 326 | } |
| 327 | } |
| 328 | |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 329 | oci_bind_by_name($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
| 333 | // -------------------------------------------------------------------- |
| 334 | |
| 335 | /** |
| 336 | * Begin Transaction |
| 337 | * |
Andrey Andreev | d580999 | 2012-06-28 14:06:54 +0300 | [diff] [blame] | 338 | * @param bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 339 | * @return bool |
| 340 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 341 | public function trans_begin($test_mode = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 342 | { |
| 343 | if ( ! $this->trans_enabled) |
| 344 | { |
| 345 | return TRUE; |
| 346 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 347 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 348 | // When transactions are nested we only begin/commit/rollback the outermost ones |
| 349 | if ($this->_trans_depth > 0) |
| 350 | { |
| 351 | return TRUE; |
| 352 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 353 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 354 | // Reset the transaction failure flag. |
| 355 | // If the $test_mode flag is set to TRUE transactions will be rolled back |
| 356 | // even if the queries produce a successful result. |
| 357 | $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 358 | |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 359 | $this->commit_mode = (is_php('5.3.2')) ? OCI_NO_AUTO_COMMIT : OCI_DEFAULT; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 360 | return TRUE; |
| 361 | } |
| 362 | |
| 363 | // -------------------------------------------------------------------- |
| 364 | |
| 365 | /** |
| 366 | * Commit Transaction |
| 367 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 368 | * @return bool |
| 369 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 370 | public function trans_commit() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 371 | { |
| 372 | if ( ! $this->trans_enabled) |
| 373 | { |
| 374 | return TRUE; |
| 375 | } |
| 376 | |
| 377 | // When transactions are nested we only begin/commit/rollback the outermost ones |
| 378 | if ($this->_trans_depth > 0) |
| 379 | { |
| 380 | return TRUE; |
| 381 | } |
| 382 | |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 383 | $this->commit_mode = OCI_COMMIT_ON_SUCCESS; |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 384 | return oci_commit($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | // -------------------------------------------------------------------- |
| 388 | |
| 389 | /** |
| 390 | * Rollback Transaction |
| 391 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 392 | * @return bool |
| 393 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 394 | public function trans_rollback() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 395 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 396 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | e35d778 | 2012-01-19 15:56:20 +0200 | [diff] [blame] | 397 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 398 | { |
| 399 | return TRUE; |
| 400 | } |
| 401 | |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 402 | $this->commit_mode = OCI_COMMIT_ON_SUCCESS; |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 403 | return oci_rollback($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | // -------------------------------------------------------------------- |
| 407 | |
| 408 | /** |
| 409 | * Escape String |
| 410 | * |
Andrey Andreev | c2905f5 | 2012-03-01 14:39:26 +0200 | [diff] [blame] | 411 | * @param string |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 412 | * @param bool whether or not the string will be used in a LIKE condition |
Andrey Andreev | c2905f5 | 2012-03-01 14:39:26 +0200 | [diff] [blame] | 413 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 414 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 415 | public function escape_str($str, $like = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 416 | { |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 417 | if (is_array($str)) |
| 418 | { |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 419 | foreach ($str as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 420 | { |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 421 | $str[$key] = $this->escape_str($val, $like); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | return $str; |
| 425 | } |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 426 | |
Andrey Andreev | c2905f5 | 2012-03-01 14:39:26 +0200 | [diff] [blame] | 427 | $str = str_replace("'", "''", remove_invisible_characters($str)); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 428 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 429 | // escape LIKE condition wildcards |
| 430 | if ($like === TRUE) |
| 431 | { |
Andrey Andreev | c2905f5 | 2012-03-01 14:39:26 +0200 | [diff] [blame] | 432 | return str_replace(array($this->_like_escape_chr, '%', '_'), |
| 433 | array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), |
| 434 | $str); |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 435 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 436 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 437 | return $str; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | // -------------------------------------------------------------------- |
| 441 | |
| 442 | /** |
| 443 | * Affected Rows |
| 444 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 445 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 446 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 447 | public function affected_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 448 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 449 | return @oci_num_rows($this->stmt_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | // -------------------------------------------------------------------- |
| 453 | |
| 454 | /** |
| 455 | * Insert ID |
| 456 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 457 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 458 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 459 | public function insert_id() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 460 | { |
| 461 | // not supported in oracle |
Derek Allard | fac8fbc | 2010-02-05 16:14:49 +0000 | [diff] [blame] | 462 | return $this->display_error('db_unsupported_function'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | // -------------------------------------------------------------------- |
| 466 | |
| 467 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 468 | * Show table query |
| 469 | * |
| 470 | * Generates a platform-specific query string so that the table names can be fetched |
| 471 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 472 | * @param bool |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 473 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 474 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 475 | protected function _list_tables($prefix_limit = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 476 | { |
Andrey Andreev | d3f1367 | 2012-06-24 22:13:21 +0300 | [diff] [blame] | 477 | $sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 478 | |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 479 | if ($prefix_limit !== FALSE && $this->dbprefix !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 480 | { |
Andrey Andreev | d3f1367 | 2012-06-24 22:13:21 +0300 | [diff] [blame] | 481 | return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " |
| 482 | .sprintf($this->_like_escape_str, $this->_like_escape_chr); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 483 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 484 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 485 | return $sql; |
| 486 | } |
| 487 | |
| 488 | // -------------------------------------------------------------------- |
| 489 | |
| 490 | /** |
| 491 | * Show column query |
| 492 | * |
| 493 | * Generates a platform-specific query string so that the column names can be fetched |
| 494 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 495 | * @param string the table name |
| 496 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 497 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 498 | protected function _list_columns($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 499 | { |
Andrey Andreev | d3f1367 | 2012-06-24 22:13:21 +0300 | [diff] [blame] | 500 | return 'SELECT "COLUMN_NAME" FROM "all_tab_columns" WHERE "TABLE_NAME" = '.$this->escape($table); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | // -------------------------------------------------------------------- |
| 504 | |
| 505 | /** |
| 506 | * Field data query |
| 507 | * |
| 508 | * Generates a platform-specific query so that the column data can be retrieved |
| 509 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 510 | * @param string the table name |
| 511 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 512 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 513 | protected function _field_data($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 514 | { |
Andrey Andreev | d3f1367 | 2012-06-24 22:13:21 +0300 | [diff] [blame] | 515 | return 'SELECT * FROM '.$this->protect_identifiers($table).' WHERE rownum = 1'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | // -------------------------------------------------------------------- |
| 519 | |
| 520 | /** |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 521 | * Error |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 522 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 523 | * Returns an array containing code and message of the last |
| 524 | * database error that has occured. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 525 | * |
Andrey Andreev | 601f8b2 | 2012-03-01 20:11:15 +0200 | [diff] [blame] | 526 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 527 | */ |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 528 | public function error() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 529 | { |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 530 | /* oci_error() returns an array that already contains the |
| 531 | * 'code' and 'message' keys, so we can just return it. |
| 532 | */ |
Andrey Andreev | 601f8b2 | 2012-03-01 20:11:15 +0200 | [diff] [blame] | 533 | if (is_resource($this->curs_id)) |
| 534 | { |
| 535 | return oci_error($this->curs_id); |
| 536 | } |
| 537 | elseif (is_resource($this->stmt_id)) |
| 538 | { |
| 539 | return oci_error($this->stmt_id); |
| 540 | } |
| 541 | elseif (is_resource($this->conn_id)) |
| 542 | { |
| 543 | return oci_error($this->conn_id); |
| 544 | } |
| 545 | |
| 546 | return oci_error(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 547 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 548 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 549 | // -------------------------------------------------------------------- |
| 550 | |
| 551 | /** |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 552 | * Insert_batch statement |
| 553 | * |
| 554 | * Generates a platform-specific insert string from the supplied data |
| 555 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 556 | * @param string the table name |
| 557 | * @param array the insert keys |
| 558 | * @param array the insert values |
| 559 | * @return string |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 560 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 561 | protected function _insert_batch($table, $keys, $values) |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 562 | { |
| 563 | $keys = implode(', ', $keys); |
| 564 | $sql = "INSERT ALL\n"; |
| 565 | |
| 566 | for ($i = 0, $c = count($values); $i < $c; $i++) |
Andrey Andreev | b83c408 | 2011-09-23 03:32:45 +0300 | [diff] [blame] | 567 | { |
Andrey Andreev | 97f3697 | 2012-04-05 12:44:36 +0300 | [diff] [blame] | 568 | $sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n"; |
Andrey Andreev | b83c408 | 2011-09-23 03:32:45 +0300 | [diff] [blame] | 569 | } |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 570 | |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 571 | return $sql.'SELECT * FROM dual'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | // -------------------------------------------------------------------- |
| 575 | |
| 576 | /** |
| 577 | * Truncate statement |
| 578 | * |
| 579 | * Generates a platform-specific truncate string from the supplied data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 580 | * |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 581 | * If the database does not support the truncate() command, |
| 582 | * then this method maps to 'DELETE FROM table' |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 583 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 584 | * @param string the table name |
| 585 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 586 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 587 | protected function _truncate($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 588 | { |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 589 | return 'TRUNCATE TABLE '.$table; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 590 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 591 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 592 | // -------------------------------------------------------------------- |
| 593 | |
| 594 | /** |
| 595 | * Delete statement |
| 596 | * |
| 597 | * Generates a platform-specific delete string from the supplied data |
| 598 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 599 | * @param string the table name |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 600 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 601 | */ |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 602 | protected function _delete($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 603 | { |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 604 | if ($this->qb_limit) |
| 605 | { |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame] | 606 | $this->where('rownum <= ',$this->qb_limit, FALSE); |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 607 | $this->qb_limit = FALSE; |
| 608 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 609 | |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 610 | return parent::_delete($table); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | // -------------------------------------------------------------------- |
| 614 | |
| 615 | /** |
| 616 | * Limit string |
| 617 | * |
| 618 | * Generates a platform-specific LIMIT clause |
| 619 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 620 | * @param string the sql query string |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 621 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 622 | */ |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame] | 623 | protected function _limit($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 624 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 625 | $this->limit_used = TRUE; |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame] | 626 | return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')' |
| 627 | .($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1): ''); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 628 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 629 | |
| 630 | // -------------------------------------------------------------------- |
| 631 | |
| 632 | /** |
| 633 | * Close DB Connection |
| 634 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 635 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 636 | */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 637 | protected function _close() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 638 | { |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 639 | @oci_close($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 644 | /* End of file oci8_driver.php */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 645 | /* Location: ./system/database/drivers/oci8/oci8_driver.php */ |