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