Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame] | 9 | * Copyright (c) 2014 - 2018, British Columbia Institute of Technology |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 1.4.1 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | /** |
| 41 | * oci8 Database Adapter Class |
| 42 | * |
| 43 | * Note: _DB is an extender class that the app controller |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 44 | * creates dynamically based on whether the query builder |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 45 | * class is being used or not. |
| 46 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 47 | * @package CodeIgniter |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 48 | * @subpackage Drivers |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 49 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 50 | * @author EllisLab Dev Team |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 51 | * @link https://codeigniter.com/user_guide/database/ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | */ |
| 53 | |
| 54 | /** |
| 55 | * oci8 Database Adapter Class |
| 56 | * |
| 57 | * This is a modification of the DB_driver class to |
| 58 | * permit access to oracle databases |
| 59 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 60 | * @author Kelly McArdle |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 61 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 62 | class CI_DB_oci8_driver extends CI_DB { |
| 63 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 64 | /** |
| 65 | * Database driver |
| 66 | * |
| 67 | * @var string |
| 68 | */ |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 69 | public $dbdriver = 'oci8'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 70 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 71 | /** |
| 72 | * Statement ID |
| 73 | * |
| 74 | * @var resource |
| 75 | */ |
| 76 | public $stmt_id; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 77 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 78 | /** |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 79 | * Cursor ID |
| 80 | * |
| 81 | * @var resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 82 | */ |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 83 | public $curs_id; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 84 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 85 | /** |
| 86 | * Commit mode flag |
| 87 | * |
| 88 | * @var int |
| 89 | */ |
| 90 | public $commit_mode = OCI_COMMIT_ON_SUCCESS; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 91 | |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 92 | /** |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 93 | * Limit used flag |
| 94 | * |
| 95 | * If we use LIMIT, we'll add a field that will |
| 96 | * throw off num_fields later. |
| 97 | * |
| 98 | * @var bool |
| 99 | */ |
Andrey Andreev | 6efd42e | 2018-03-15 16:24:42 +0200 | [diff] [blame^] | 100 | public $limit_used = FALSE; |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 101 | |
| 102 | // -------------------------------------------------------------------- |
| 103 | |
| 104 | /** |
Andrey Andreev | 611e1fd | 2015-07-17 12:24:29 +0300 | [diff] [blame] | 105 | * Reset $stmt_id flag |
| 106 | * |
| 107 | * Used by stored_procedure() to prevent _execute() from |
| 108 | * re-setting the statement ID. |
| 109 | */ |
| 110 | protected $_reset_stmt_id = TRUE; |
| 111 | |
| 112 | /** |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 113 | * List of reserved identifiers |
| 114 | * |
| 115 | * Identifiers that must NOT be escaped. |
| 116 | * |
| 117 | * @var string[] |
| 118 | */ |
| 119 | protected $_reserved_identifiers = array('*', 'rownum'); |
| 120 | |
| 121 | /** |
| 122 | * ORDER BY random keyword |
| 123 | * |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 124 | * @var array |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 125 | */ |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 126 | protected $_random_keyword = array('ASC', 'ASC'); // not currently supported |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * COUNT string |
| 130 | * |
| 131 | * @used-by CI_DB_driver::count_all() |
| 132 | * @used-by CI_DB_query_builder::count_all_results() |
| 133 | * |
| 134 | * @var string |
| 135 | */ |
| 136 | protected $_count_string = 'SELECT COUNT(1) AS '; |
| 137 | |
| 138 | // -------------------------------------------------------------------- |
| 139 | |
| 140 | /** |
| 141 | * Class constructor |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 142 | * |
| 143 | * @param array $params |
| 144 | * @return void |
| 145 | */ |
Andrey Andreev | dad61c2 | 2012-02-13 01:08:06 +0200 | [diff] [blame] | 146 | public function __construct($params) |
| 147 | { |
| 148 | parent::__construct($params); |
| 149 | |
| 150 | $valid_dsns = array( |
Andrey Andreev | 1a61ba4 | 2014-03-24 16:53:16 +0200 | [diff] [blame] | 151 | 'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS |
| 152 | // Easy Connect string (Oracle 10g+) |
| 153 | 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i', |
| 154 | 'in' => '/^[a-z0-9$_]+$/i' // Instance name (defined in tnsnames.ora) |
| 155 | ); |
Andrey Andreev | dad61c2 | 2012-02-13 01:08:06 +0200 | [diff] [blame] | 156 | |
| 157 | /* Space characters don't have any effect when actually |
| 158 | * connecting, but can be a hassle while validating the DSN. |
| 159 | */ |
| 160 | $this->dsn = str_replace(array("\n", "\r", "\t", ' '), '', $this->dsn); |
| 161 | |
| 162 | if ($this->dsn !== '') |
| 163 | { |
| 164 | foreach ($valid_dsns as $regexp) |
| 165 | { |
| 166 | if (preg_match($regexp, $this->dsn)) |
| 167 | { |
| 168 | return; |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // Legacy support for TNS in the hostname configuration field |
| 174 | $this->hostname = str_replace(array("\n", "\r", "\t", ' '), '', $this->hostname); |
| 175 | if (preg_match($valid_dsns['tns'], $this->hostname)) |
| 176 | { |
| 177 | $this->dsn = $this->hostname; |
| 178 | return; |
| 179 | } |
| 180 | elseif ($this->hostname !== '' && strpos($this->hostname, '/') === FALSE && strpos($this->hostname, ':') === FALSE |
| 181 | && (( ! empty($this->port) && ctype_digit($this->port)) OR $this->database !== '')) |
| 182 | { |
| 183 | /* If the hostname field isn't empty, doesn't contain |
| 184 | * ':' and/or '/' and if port and/or database aren't |
| 185 | * empty, then the hostname field is most likely indeed |
| 186 | * just a hostname. Therefore we'll try and build an |
| 187 | * Easy Connect string from these 3 settings, assuming |
| 188 | * that the database field is a service name. |
| 189 | */ |
| 190 | $this->dsn = $this->hostname |
Andrey Andreev | 1a61ba4 | 2014-03-24 16:53:16 +0200 | [diff] [blame] | 191 | .(( ! empty($this->port) && ctype_digit($this->port)) ? ':'.$this->port : '') |
| 192 | .($this->database !== '' ? '/'.ltrim($this->database, '/') : ''); |
Andrey Andreev | dad61c2 | 2012-02-13 01:08:06 +0200 | [diff] [blame] | 193 | |
| 194 | if (preg_match($valid_dsns['ec'], $this->dsn)) |
| 195 | { |
| 196 | return; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | /* At this point, we can only try and validate the hostname and |
| 201 | * database fields separately as DSNs. |
| 202 | */ |
| 203 | if (preg_match($valid_dsns['ec'], $this->hostname) OR preg_match($valid_dsns['in'], $this->hostname)) |
| 204 | { |
| 205 | $this->dsn = $this->hostname; |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | $this->database = str_replace(array("\n", "\r", "\t", ' '), '', $this->database); |
| 210 | foreach ($valid_dsns as $regexp) |
| 211 | { |
| 212 | if (preg_match($regexp, $this->database)) |
| 213 | { |
| 214 | return; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /* Well - OK, an empty string should work as well. |
| 219 | * PHP will try to use environment variables to |
| 220 | * determine which Oracle instance to connect to. |
| 221 | */ |
| 222 | $this->dsn = ''; |
| 223 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 224 | |
Andrey Andreev | d580999 | 2012-06-28 14:06:54 +0300 | [diff] [blame] | 225 | // -------------------------------------------------------------------- |
| 226 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 227 | /** |
| 228 | * Non-persistent database connection |
| 229 | * |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame] | 230 | * @param bool $persistent |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 231 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 232 | */ |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame] | 233 | public function db_connect($persistent = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 234 | { |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame] | 235 | $func = ($persistent === TRUE) ? 'oci_pconnect' : 'oci_connect'; |
Andrey Andreev | d580999 | 2012-06-28 14:06:54 +0300 | [diff] [blame] | 236 | return empty($this->char_set) |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame] | 237 | ? $func($this->username, $this->password, $this->dsn) |
| 238 | : $func($this->username, $this->password, $this->dsn, $this->char_set); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | // -------------------------------------------------------------------- |
| 242 | |
| 243 | /** |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 244 | * Database version number |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 245 | * |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 246 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 247 | */ |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 248 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 249 | { |
Andrey Andreev | 2b73037 | 2012-11-05 17:01:11 +0200 | [diff] [blame] | 250 | if (isset($this->data_cache['version'])) |
| 251 | { |
| 252 | return $this->data_cache['version']; |
| 253 | } |
Andrey Andreev | 2b73037 | 2012-11-05 17:01:11 +0200 | [diff] [blame] | 254 | |
Andrey Andreev | bc05b84 | 2015-12-14 16:22:33 +0200 | [diff] [blame] | 255 | if ( ! $this->conn_id OR ($version_string = oci_server_version($this->conn_id)) === FALSE) |
Andrey Andreev | 2b73037 | 2012-11-05 17:01:11 +0200 | [diff] [blame] | 256 | { |
| 257 | return FALSE; |
| 258 | } |
Andrey Andreev | bc05b84 | 2015-12-14 16:22:33 +0200 | [diff] [blame] | 259 | elseif (preg_match('#Release\s(\d+(?:\.\d+)+)#', $version_string, $match)) |
| 260 | { |
| 261 | return $this->data_cache['version'] = $match[1]; |
| 262 | } |
Andrey Andreev | 2b73037 | 2012-11-05 17:01:11 +0200 | [diff] [blame] | 263 | |
Andrey Andreev | bc05b84 | 2015-12-14 16:22:33 +0200 | [diff] [blame] | 264 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | // -------------------------------------------------------------------- |
| 268 | |
| 269 | /** |
| 270 | * Execute the query |
| 271 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 272 | * @param string $sql an SQL query |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 273 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 274 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 275 | protected function _execute($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 276 | { |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 277 | /* Oracle must parse the query before it is run. All of the actions with |
| 278 | * the query are based on the statement id returned by oci_parse(). |
| 279 | */ |
Andrey Andreev | 611e1fd | 2015-07-17 12:24:29 +0300 | [diff] [blame] | 280 | if ($this->_reset_stmt_id === TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 281 | { |
Timothy Warren | d2ff0bc | 2012-03-19 16:52:10 -0400 | [diff] [blame] | 282 | $this->stmt_id = oci_parse($this->conn_id, $sql); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 283 | } |
Andrey Andreev | 611e1fd | 2015-07-17 12:24:29 +0300 | [diff] [blame] | 284 | |
| 285 | oci_set_prefetch($this->stmt_id, 1000); |
| 286 | return oci_execute($this->stmt_id, $this->commit_mode); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // -------------------------------------------------------------------- |
| 290 | |
| 291 | /** |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 292 | * Get cursor. Returns a cursor from the database |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 293 | * |
Andrey Andreev | d580999 | 2012-06-28 14:06:54 +0300 | [diff] [blame] | 294 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 295 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 296 | public function get_cursor() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 297 | { |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 298 | return $this->curs_id = oci_new_cursor($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | // -------------------------------------------------------------------- |
| 302 | |
| 303 | /** |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 304 | * Stored Procedure. Executes a stored procedure |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 305 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 306 | * @param string package name in which the stored procedure is in |
| 307 | * @param string stored procedure name to execute |
| 308 | * @param array parameters |
| 309 | * @return mixed |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 310 | * |
| 311 | * params array keys |
| 312 | * |
Andrey Andreev | 10fb7d1 | 2015-08-03 10:05:29 +0300 | [diff] [blame] | 313 | * KEY OPTIONAL NOTES |
| 314 | * name no the name of the parameter should be in :<param_name> format |
| 315 | * value no the value of the parameter. If this is an OUT or IN OUT parameter, |
| 316 | * this should be a reference to a variable |
| 317 | * type yes the type of the parameter |
| 318 | * length yes the max size of the parameter |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | */ |
Andrey Andreev | 611e1fd | 2015-07-17 12:24:29 +0300 | [diff] [blame] | 320 | public function stored_procedure($package, $procedure, array $params) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 321 | { |
Andrey Andreev | 611e1fd | 2015-07-17 12:24:29 +0300 | [diff] [blame] | 322 | if ($package === '' OR $procedure === '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 323 | { |
Andrey Andreev | e18de50 | 2013-07-17 19:59:20 +0300 | [diff] [blame] | 324 | log_message('error', 'Invalid query: '.$package.'.'.$procedure); |
| 325 | return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 326 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 327 | |
Andrey Andreev | 611e1fd | 2015-07-17 12:24:29 +0300 | [diff] [blame] | 328 | // Build the query string |
Andrey Andreev | e35d778 | 2012-01-19 15:56:20 +0200 | [diff] [blame] | 329 | $sql = 'BEGIN '.$package.'.'.$procedure.'('; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | |
| 331 | $have_cursor = FALSE; |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 332 | foreach ($params as $param) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | { |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 334 | $sql .= $param['name'].','; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 335 | |
Andrey Andreev | 85facfa | 2012-01-26 14:12:14 +0200 | [diff] [blame] | 336 | if (isset($param['type']) && $param['type'] === OCI_B_CURSOR) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 337 | { |
| 338 | $have_cursor = TRUE; |
| 339 | } |
| 340 | } |
Andrey Andreev | 3ca060a | 2013-11-27 16:30:31 +0200 | [diff] [blame] | 341 | $sql = trim($sql, ',').'); END;'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 342 | |
Andrey Andreev | 611e1fd | 2015-07-17 12:24:29 +0300 | [diff] [blame] | 343 | $this->_reset_stmt_id = FALSE; |
| 344 | $this->stmt_id = oci_parse($this->conn_id, $sql); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 345 | $this->_bind_params($params); |
Andrey Andreev | 611e1fd | 2015-07-17 12:24:29 +0300 | [diff] [blame] | 346 | $result = $this->query($sql, FALSE, $have_cursor); |
| 347 | $this->_reset_stmt_id = TRUE; |
| 348 | return $result; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 349 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 350 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 351 | // -------------------------------------------------------------------- |
| 352 | |
| 353 | /** |
| 354 | * Bind parameters |
| 355 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 356 | * @param array $params |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 357 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 358 | */ |
Andrey Andreev | 1b5a856 | 2012-03-13 13:13:43 +0200 | [diff] [blame] | 359 | protected function _bind_params($params) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 360 | { |
| 361 | if ( ! is_array($params) OR ! is_resource($this->stmt_id)) |
| 362 | { |
| 363 | return; |
| 364 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 365 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 366 | foreach ($params as $param) |
| 367 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 368 | foreach (array('name', 'value', 'type', 'length') as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 369 | { |
| 370 | if ( ! isset($param[$val])) |
| 371 | { |
| 372 | $param[$val] = ''; |
| 373 | } |
| 374 | } |
| 375 | |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 376 | 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] | 377 | } |
| 378 | } |
| 379 | |
| 380 | // -------------------------------------------------------------------- |
| 381 | |
| 382 | /** |
| 383 | * Begin Transaction |
| 384 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 385 | * @return bool |
| 386 | */ |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 387 | protected function _trans_begin() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 388 | { |
Andrey Andreev | a838279 | 2016-07-28 16:40:12 +0300 | [diff] [blame] | 389 | $this->commit_mode = OCI_NO_AUTO_COMMIT; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 390 | return TRUE; |
| 391 | } |
| 392 | |
| 393 | // -------------------------------------------------------------------- |
| 394 | |
| 395 | /** |
| 396 | * Commit Transaction |
| 397 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 398 | * @return bool |
| 399 | */ |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 400 | protected function _trans_commit() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 401 | { |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 402 | $this->commit_mode = OCI_COMMIT_ON_SUCCESS; |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 403 | |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 404 | return oci_commit($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | // -------------------------------------------------------------------- |
| 408 | |
| 409 | /** |
| 410 | * Rollback Transaction |
| 411 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 412 | * @return bool |
| 413 | */ |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 414 | protected function _trans_rollback() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 415 | { |
Andrey Andreev | 99013ed | 2012-03-05 16:17:32 +0200 | [diff] [blame] | 416 | $this->commit_mode = OCI_COMMIT_ON_SUCCESS; |
Andrey Andreev | 24abcb9 | 2012-01-05 20:40:15 +0200 | [diff] [blame] | 417 | return oci_rollback($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | // -------------------------------------------------------------------- |
| 421 | |
| 422 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 423 | * Affected Rows |
| 424 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 425 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 426 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 427 | public function affected_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 428 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame] | 429 | return oci_num_rows($this->stmt_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | // -------------------------------------------------------------------- |
| 433 | |
| 434 | /** |
| 435 | * Insert ID |
| 436 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 437 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 439 | public function insert_id() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 440 | { |
| 441 | // not supported in oracle |
Derek Allard | fac8fbc | 2010-02-05 16:14:49 +0000 | [diff] [blame] | 442 | return $this->display_error('db_unsupported_function'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | // -------------------------------------------------------------------- |
| 446 | |
| 447 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 448 | * Show table query |
| 449 | * |
| 450 | * Generates a platform-specific query string so that the table names can be fetched |
| 451 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 452 | * @param bool $prefix_limit |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 453 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 454 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 455 | protected function _list_tables($prefix_limit = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 456 | { |
Andrey Andreev | d3f1367 | 2012-06-24 22:13:21 +0300 | [diff] [blame] | 457 | $sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 458 | |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 459 | if ($prefix_limit !== FALSE && $this->dbprefix !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 460 | { |
Andrey Andreev | d3f1367 | 2012-06-24 22:13:21 +0300 | [diff] [blame] | 461 | return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " |
| 462 | .sprintf($this->_like_escape_str, $this->_like_escape_chr); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 463 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 464 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 465 | return $sql; |
| 466 | } |
| 467 | |
| 468 | // -------------------------------------------------------------------- |
| 469 | |
| 470 | /** |
| 471 | * Show column query |
| 472 | * |
| 473 | * Generates a platform-specific query string so that the column names can be fetched |
| 474 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 475 | * @param string $table |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 476 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 477 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 478 | protected function _list_columns($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 479 | { |
Andrey Andreev | e158057 | 2012-11-16 16:17:54 +0200 | [diff] [blame] | 480 | if (strpos($table, '.') !== FALSE) |
| 481 | { |
| 482 | sscanf($table, '%[^.].%s', $owner, $table); |
| 483 | } |
| 484 | else |
| 485 | { |
| 486 | $owner = $this->username; |
| 487 | } |
| 488 | |
| 489 | return 'SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS |
| 490 | WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).' |
| 491 | AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | // -------------------------------------------------------------------- |
| 495 | |
| 496 | /** |
Andrey Andreev | e158057 | 2012-11-16 16:17:54 +0200 | [diff] [blame] | 497 | * Returns an object with field data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 498 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 499 | * @param string $table |
Andrey Andreev | e158057 | 2012-11-16 16:17:54 +0200 | [diff] [blame] | 500 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 501 | */ |
Andrey Andreev | 5350f05 | 2015-01-12 12:33:37 +0200 | [diff] [blame] | 502 | public function field_data($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 503 | { |
Andrey Andreev | 5350f05 | 2015-01-12 12:33:37 +0200 | [diff] [blame] | 504 | if (strpos($table, '.') !== FALSE) |
Andrey Andreev | e158057 | 2012-11-16 16:17:54 +0200 | [diff] [blame] | 505 | { |
| 506 | sscanf($table, '%[^.].%s', $owner, $table); |
| 507 | } |
| 508 | else |
| 509 | { |
| 510 | $owner = $this->username; |
| 511 | } |
| 512 | |
| 513 | $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHAR_LENGTH, DATA_PRECISION, DATA_LENGTH, DATA_DEFAULT, NULLABLE |
| 514 | FROM ALL_TAB_COLUMNS |
| 515 | WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).' |
| 516 | AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); |
| 517 | |
| 518 | if (($query = $this->query($sql)) === FALSE) |
| 519 | { |
| 520 | return FALSE; |
| 521 | } |
| 522 | $query = $query->result_object(); |
| 523 | |
| 524 | $retval = array(); |
| 525 | for ($i = 0, $c = count($query); $i < $c; $i++) |
| 526 | { |
| 527 | $retval[$i] = new stdClass(); |
| 528 | $retval[$i]->name = $query[$i]->COLUMN_NAME; |
| 529 | $retval[$i]->type = $query[$i]->DATA_TYPE; |
| 530 | |
| 531 | $length = ($query[$i]->CHAR_LENGTH > 0) |
| 532 | ? $query[$i]->CHAR_LENGTH : $query[$i]->DATA_PRECISION; |
| 533 | if ($length === NULL) |
| 534 | { |
| 535 | $length = $query[$i]->DATA_LENGTH; |
| 536 | } |
| 537 | $retval[$i]->max_length = $length; |
| 538 | |
| 539 | $default = $query[$i]->DATA_DEFAULT; |
| 540 | if ($default === NULL && $query[$i]->NULLABLE === 'N') |
| 541 | { |
| 542 | $default = ''; |
| 543 | } |
Leandro Mangini Antunes | 4c08ea9 | 2015-05-13 11:15:01 -0300 | [diff] [blame] | 544 | $retval[$i]->default = $default; |
Andrey Andreev | e158057 | 2012-11-16 16:17:54 +0200 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | return $retval; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | // -------------------------------------------------------------------- |
| 551 | |
| 552 | /** |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 553 | * Error |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 554 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 555 | * Returns an array containing code and message of the last |
Andrey Andreev | 71d8f72 | 2017-01-17 12:01:00 +0200 | [diff] [blame] | 556 | * database error that has occurred. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 557 | * |
Andrey Andreev | 601f8b2 | 2012-03-01 20:11:15 +0200 | [diff] [blame] | 558 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 559 | */ |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 560 | public function error() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 561 | { |
Andrey Andreev | 45520a5 | 2016-05-19 18:51:25 +0300 | [diff] [blame] | 562 | // oci_error() returns an array that already contains |
| 563 | // 'code' and 'message' keys, but it can return false |
| 564 | // if there was no error .... |
Andrey Andreev | 601f8b2 | 2012-03-01 20:11:15 +0200 | [diff] [blame] | 565 | if (is_resource($this->curs_id)) |
| 566 | { |
Andrey Andreev | 45520a5 | 2016-05-19 18:51:25 +0300 | [diff] [blame] | 567 | $error = oci_error($this->curs_id); |
Andrey Andreev | 601f8b2 | 2012-03-01 20:11:15 +0200 | [diff] [blame] | 568 | } |
| 569 | elseif (is_resource($this->stmt_id)) |
| 570 | { |
Andrey Andreev | 45520a5 | 2016-05-19 18:51:25 +0300 | [diff] [blame] | 571 | $error = oci_error($this->stmt_id); |
Andrey Andreev | 601f8b2 | 2012-03-01 20:11:15 +0200 | [diff] [blame] | 572 | } |
| 573 | elseif (is_resource($this->conn_id)) |
| 574 | { |
Andrey Andreev | 45520a5 | 2016-05-19 18:51:25 +0300 | [diff] [blame] | 575 | $error = oci_error($this->conn_id); |
| 576 | } |
| 577 | else |
| 578 | { |
| 579 | $error = oci_error(); |
Andrey Andreev | 601f8b2 | 2012-03-01 20:11:15 +0200 | [diff] [blame] | 580 | } |
| 581 | |
Andrey Andreev | 45520a5 | 2016-05-19 18:51:25 +0300 | [diff] [blame] | 582 | return is_array($error) |
| 583 | ? $error |
Andrey Andreev | ad20f71 | 2016-05-25 09:58:03 +0300 | [diff] [blame] | 584 | : array('code' => '', 'message' => ''); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 585 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 586 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 587 | // -------------------------------------------------------------------- |
| 588 | |
| 589 | /** |
Andrey Andreev | 083e3c8 | 2012-11-06 12:48:32 +0200 | [diff] [blame] | 590 | * Insert batch statement |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 591 | * |
| 592 | * Generates a platform-specific insert string from the supplied data |
| 593 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 594 | * @param string $table Table name |
| 595 | * @param array $keys INSERT keys |
| 596 | * @param array $values INSERT values |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 597 | * @return string |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 598 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 599 | protected function _insert_batch($table, $keys, $values) |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 600 | { |
| 601 | $keys = implode(', ', $keys); |
| 602 | $sql = "INSERT ALL\n"; |
| 603 | |
| 604 | for ($i = 0, $c = count($values); $i < $c; $i++) |
Andrey Andreev | b83c408 | 2011-09-23 03:32:45 +0300 | [diff] [blame] | 605 | { |
Andrey Andreev | 97f3697 | 2012-04-05 12:44:36 +0300 | [diff] [blame] | 606 | $sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n"; |
Andrey Andreev | b83c408 | 2011-09-23 03:32:45 +0300 | [diff] [blame] | 607 | } |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 608 | |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 609 | return $sql.'SELECT * FROM dual'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | // -------------------------------------------------------------------- |
| 613 | |
| 614 | /** |
| 615 | * Truncate statement |
| 616 | * |
| 617 | * Generates a platform-specific truncate string from the supplied data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 618 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 619 | * If the database does not support the TRUNCATE statement, |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 620 | * then this method maps to 'DELETE FROM table' |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 621 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 622 | * @param string $table |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 623 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 624 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 625 | protected function _truncate($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 626 | { |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 627 | return 'TRUNCATE TABLE '.$table; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 628 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 629 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 630 | // -------------------------------------------------------------------- |
| 631 | |
| 632 | /** |
| 633 | * Delete statement |
| 634 | * |
| 635 | * Generates a platform-specific delete string from the supplied data |
| 636 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 637 | * @param string $table |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 638 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 639 | */ |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 640 | protected function _delete($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 641 | { |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 642 | if ($this->qb_limit) |
| 643 | { |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame] | 644 | $this->where('rownum <= ',$this->qb_limit, FALSE); |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 645 | $this->qb_limit = FALSE; |
| 646 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 647 | |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 648 | return parent::_delete($table); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | // -------------------------------------------------------------------- |
| 652 | |
| 653 | /** |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 654 | * LIMIT |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 655 | * |
| 656 | * Generates a platform-specific LIMIT clause |
| 657 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 658 | * @param string $sql SQL Query |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 659 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 660 | */ |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame] | 661 | protected function _limit($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 662 | { |
Andrey Andreev | e8de9eb | 2016-01-06 15:53:19 +0200 | [diff] [blame] | 663 | if (version_compare($this->version(), '12.1', '>=')) |
| 664 | { |
| 665 | // OFFSET-FETCH can be used only with the ORDER BY clause |
| 666 | empty($this->qb_orderby) && $sql .= ' ORDER BY 1'; |
| 667 | |
| 668 | return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; |
| 669 | } |
| 670 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 671 | $this->limit_used = TRUE; |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame] | 672 | return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')' |
Andrey Andreev | 1a61ba4 | 2014-03-24 16:53:16 +0200 | [diff] [blame] | 673 | .($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1) : ''); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 674 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 675 | |
| 676 | // -------------------------------------------------------------------- |
| 677 | |
| 678 | /** |
| 679 | * Close DB Connection |
| 680 | * |
Andrey Andreev | aa786c9 | 2012-01-16 12:14:45 +0200 | [diff] [blame] | 681 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 682 | */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 683 | protected function _close() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 684 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame] | 685 | oci_close($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Andrey Andreev | 6efd42e | 2018-03-15 16:24:42 +0200 | [diff] [blame^] | 688 | // -------------------------------------------------------------------- |
| 689 | |
| 690 | /** |
| 691 | * We need to reset our $limit_used hack flag, so it doesn't propagate |
| 692 | * to subsequent queries. |
| 693 | * |
| 694 | * @return void |
| 695 | */ |
| 696 | protected function _reset_select() |
| 697 | { |
| 698 | $this->limit_used = FALSE; |
| 699 | parent::_reset_select(); |
| 700 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 701 | } |