Andrey Andreev | da12373 | 2012-03-20 22:27:40 +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 | da12373 | 2012-03-20 22:27:40 +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 | da12373 | 2012-03-20 22:27:40 +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 |
| 32 | * creates dynamically based on whether the active record |
| 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 | * |
| 50 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 51 | class CI_DB_oci8_driver extends CI_DB { |
| 52 | |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 53 | public $dbdriver = 'oci8'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 54 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 55 | // The character used for excaping |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 56 | protected $_escape_char = '"'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 57 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 58 | // clause and character used for LIKE escape sequences |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 59 | protected $_like_escape_str = " ESCAPE '%s' "; |
| 60 | protected $_like_escape_chr = '!'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 61 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 62 | /** |
| 63 | * The syntax to count rows is slightly different across different |
| 64 | * database engines, so this string appears in each driver and is |
| 65 | * used for the count_all() and count_all_results() functions. |
| 66 | */ |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 67 | protected $_count_string = 'SELECT COUNT(1) AS '; |
| 68 | protected $_random_keyword = ' ASC'; // not currently supported |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 69 | |
| 70 | // Set "auto commit" by default |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 71 | protected $_commit = OCI_COMMIT_ON_SUCCESS; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 72 | |
| 73 | // need to track statement id and cursor id |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 74 | public $stmt_id; |
| 75 | public $curs_id; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 76 | |
| 77 | // if we use a limit, we will add a field that will |
| 78 | // throw off num_fields later |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 79 | public $limit_used; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * Non-persistent database connection |
| 83 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 84 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 85 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 86 | public function db_connect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 88 | return @oci_connect($this->username, $this->password, $this->hostname, $this->char_set); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | // -------------------------------------------------------------------- |
| 92 | |
| 93 | /** |
| 94 | * Persistent database connection |
| 95 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 96 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 97 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 98 | public function db_pconnect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 99 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 100 | return @oci_pconnect($this->username, $this->password, $this->hostname, $this->char_set); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // -------------------------------------------------------------------- |
| 104 | |
| 105 | /** |
| 106 | * Select the database |
| 107 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 108 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 109 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 110 | public function db_select() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 111 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 112 | // Not in Oracle - schemas are actually usernames |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 113 | return TRUE; |
| 114 | } |
| 115 | |
| 116 | // -------------------------------------------------------------------- |
| 117 | |
| 118 | /** |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 119 | * Database version number |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 120 | * |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 121 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 122 | */ |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 123 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 124 | { |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 125 | return isset($this->data_cache['version']) |
| 126 | ? $this->data_cache['version'] |
| 127 | : $this->data_cache['version'] = oci_server_version($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | // -------------------------------------------------------------------- |
| 131 | |
| 132 | /** |
| 133 | * Execute the query |
| 134 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 135 | * @param string an SQL query |
| 136 | * @return resource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 137 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 138 | protected function _execute($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 139 | { |
| 140 | // oracle must parse the query before it is run. All of the actions with |
| 141 | // the query are based on the statement id returned by ociparse |
| 142 | $this->stmt_id = FALSE; |
| 143 | $this->_set_stmt_id($sql); |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 144 | oci_set_prefetch($this->stmt_id, 1000); |
| 145 | return @oci_execute($this->stmt_id, $this->_commit); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Generate a statement ID |
| 150 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 151 | * @param string an SQL query |
| 152 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 153 | */ |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 154 | protected function _set_stmt_id($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 155 | { |
| 156 | if ( ! is_resource($this->stmt_id)) |
| 157 | { |
Timothy Warren | d2ff0bc | 2012-03-19 16:52:10 -0400 | [diff] [blame] | 158 | $this->stmt_id = oci_parse($this->conn_id, $sql); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 159 | } |
| 160 | } |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 161 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 162 | // -------------------------------------------------------------------- |
| 163 | |
| 164 | /** |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 165 | * Get cursor. Returns a cursor from the database |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 166 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 167 | * @return cursor id |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 169 | public function get_cursor() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 170 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 171 | $this->curs_id = oci_new_cursor($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 172 | return $this->curs_id; |
| 173 | } |
| 174 | |
| 175 | // -------------------------------------------------------------------- |
| 176 | |
| 177 | /** |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 178 | * Stored Procedure. Executes a stored procedure |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 179 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 180 | * @param string package stored procedure is in |
| 181 | * @param string stored procedure to execute |
| 182 | * @param array parameters |
| 183 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 184 | * |
| 185 | * params array keys |
| 186 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 187 | * KEY OPTIONAL NOTES |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 188 | * name no the name of the parameter should be in :<param_name> format |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 189 | * value no the value of the parameter. If this is an OUT or IN OUT parameter, |
Timothy Warren | 48e1d2e | 2012-03-19 19:07:07 -0400 | [diff] [blame] | 190 | * this should be a reference to a variable |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | * type yes the type of the parameter |
| 192 | * length yes the max size of the parameter |
| 193 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 194 | public function stored_procedure($package, $procedure, $params) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | { |
| 196 | if ($package == '' OR $procedure == '' OR ! is_array($params)) |
| 197 | { |
| 198 | if ($this->db_debug) |
| 199 | { |
| 200 | log_message('error', 'Invalid query: '.$package.'.'.$procedure); |
Derek Allard | fac8fbc | 2010-02-05 16:14:49 +0000 | [diff] [blame] | 201 | return $this->display_error('db_invalid_query'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 202 | } |
| 203 | return FALSE; |
| 204 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 205 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 206 | // build the query string |
| 207 | $sql = "begin $package.$procedure("; |
| 208 | |
| 209 | $have_cursor = FALSE; |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 210 | foreach ($params as $param) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 211 | { |
| 212 | $sql .= $param['name'] . ","; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 213 | |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 214 | if (array_key_exists('type', $param) && ($param['type'] === OCI_B_CURSOR)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 215 | { |
| 216 | $have_cursor = TRUE; |
| 217 | } |
| 218 | } |
| 219 | $sql = trim($sql, ",") . "); end;"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 220 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 221 | $this->stmt_id = FALSE; |
| 222 | $this->_set_stmt_id($sql); |
| 223 | $this->_bind_params($params); |
| 224 | $this->query($sql, FALSE, $have_cursor); |
| 225 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 226 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 227 | // -------------------------------------------------------------------- |
| 228 | |
| 229 | /** |
| 230 | * Bind parameters |
| 231 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 232 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 233 | */ |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 234 | protected function _bind_params($params) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 235 | { |
| 236 | if ( ! is_array($params) OR ! is_resource($this->stmt_id)) |
| 237 | { |
| 238 | return; |
| 239 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 240 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 241 | foreach ($params as $param) |
| 242 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 243 | foreach (array('name', 'value', 'type', 'length') as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 244 | { |
| 245 | if ( ! isset($param[$val])) |
| 246 | { |
| 247 | $param[$val] = ''; |
| 248 | } |
| 249 | } |
| 250 | |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 251 | 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] | 252 | } |
| 253 | } |
| 254 | |
| 255 | // -------------------------------------------------------------------- |
| 256 | |
| 257 | /** |
| 258 | * Begin Transaction |
| 259 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 260 | * @return bool |
| 261 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 262 | public function trans_begin($test_mode = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 263 | { |
| 264 | if ( ! $this->trans_enabled) |
| 265 | { |
| 266 | return TRUE; |
| 267 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 268 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 269 | // When transactions are nested we only begin/commit/rollback the outermost ones |
| 270 | if ($this->_trans_depth > 0) |
| 271 | { |
| 272 | return TRUE; |
| 273 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 274 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 275 | // Reset the transaction failure flag. |
| 276 | // If the $test_mode flag is set to TRUE transactions will be rolled back |
| 277 | // even if the queries produce a successful result. |
| 278 | $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 279 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | $this->_commit = OCI_DEFAULT; |
| 281 | return TRUE; |
| 282 | } |
| 283 | |
| 284 | // -------------------------------------------------------------------- |
| 285 | |
| 286 | /** |
| 287 | * Commit Transaction |
| 288 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 289 | * @return bool |
| 290 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 291 | public function trans_commit() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 292 | { |
| 293 | if ( ! $this->trans_enabled) |
| 294 | { |
| 295 | return TRUE; |
| 296 | } |
| 297 | |
| 298 | // When transactions are nested we only begin/commit/rollback the outermost ones |
| 299 | if ($this->_trans_depth > 0) |
| 300 | { |
| 301 | return TRUE; |
| 302 | } |
| 303 | |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 304 | $ret = oci_commit($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 305 | $this->_commit = OCI_COMMIT_ON_SUCCESS; |
| 306 | return $ret; |
| 307 | } |
| 308 | |
| 309 | // -------------------------------------------------------------------- |
| 310 | |
| 311 | /** |
| 312 | * Rollback Transaction |
| 313 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 314 | * @return bool |
| 315 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 316 | public function trans_rollback() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 317 | { |
| 318 | if ( ! $this->trans_enabled) |
| 319 | { |
| 320 | return TRUE; |
| 321 | } |
| 322 | |
| 323 | // When transactions are nested we only begin/commit/rollback the outermost ones |
| 324 | if ($this->_trans_depth > 0) |
| 325 | { |
| 326 | return TRUE; |
| 327 | } |
| 328 | |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 329 | $ret = oci_rollback($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | $this->_commit = OCI_COMMIT_ON_SUCCESS; |
| 331 | return $ret; |
| 332 | } |
| 333 | |
| 334 | // -------------------------------------------------------------------- |
| 335 | |
| 336 | /** |
| 337 | * Escape String |
| 338 | * |
Andrey Andreev | c2905f5 | 2012-03-01 14:39:26 +0200 | [diff] [blame] | 339 | * @param string |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 340 | * @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] | 341 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 342 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 343 | public function escape_str($str, $like = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 344 | { |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 345 | if (is_array($str)) |
| 346 | { |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 347 | foreach ($str as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 348 | { |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 349 | $str[$key] = $this->escape_str($val, $like); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | return $str; |
| 353 | } |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 354 | |
Andrey Andreev | c2905f5 | 2012-03-01 14:39:26 +0200 | [diff] [blame] | 355 | $str = str_replace("'", "''", remove_invisible_characters($str)); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 356 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 357 | // escape LIKE condition wildcards |
| 358 | if ($like === TRUE) |
| 359 | { |
Andrey Andreev | c2905f5 | 2012-03-01 14:39:26 +0200 | [diff] [blame] | 360 | return str_replace(array($this->_like_escape_chr, '%', '_'), |
| 361 | array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), |
| 362 | $str); |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 363 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 364 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 365 | return $str; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | // -------------------------------------------------------------------- |
| 369 | |
| 370 | /** |
| 371 | * Affected Rows |
| 372 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 373 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 374 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 375 | public function affected_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 376 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 377 | return @oci_num_rows($this->stmt_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | // -------------------------------------------------------------------- |
| 381 | |
| 382 | /** |
| 383 | * Insert ID |
| 384 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 385 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 386 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 387 | public function insert_id() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 388 | { |
| 389 | // not supported in oracle |
Derek Allard | fac8fbc | 2010-02-05 16:14:49 +0000 | [diff] [blame] | 390 | return $this->display_error('db_unsupported_function'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | // -------------------------------------------------------------------- |
| 394 | |
| 395 | /** |
| 396 | * "Count All" query |
| 397 | * |
| 398 | * Generates a platform-specific query string that counts all records in |
| 399 | * the specified database |
| 400 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 401 | * @param string |
| 402 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 403 | */ |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 404 | public function count_all($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 405 | { |
| 406 | if ($table == '') |
Derek Allard | e37ab38 | 2009-02-03 16:13:57 +0000 | [diff] [blame] | 407 | { |
| 408 | return 0; |
| 409 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 410 | |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 411 | $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 412 | if ($query == FALSE) |
Derek Allard | e37ab38 | 2009-02-03 16:13:57 +0000 | [diff] [blame] | 413 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 414 | return 0; |
Derek Allard | e37ab38 | 2009-02-03 16:13:57 +0000 | [diff] [blame] | 415 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 416 | |
| 417 | $row = $query->row(); |
Greg Aker | 90248ab | 2011-08-20 14:23:14 -0500 | [diff] [blame] | 418 | $this->_reset_select(); |
Derek Allard | e37ab38 | 2009-02-03 16:13:57 +0000 | [diff] [blame] | 419 | return (int) $row->numrows; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | // -------------------------------------------------------------------- |
| 423 | |
| 424 | /** |
| 425 | * Show table query |
| 426 | * |
| 427 | * Generates a platform-specific query string so that the table names can be fetched |
| 428 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 429 | * @param bool |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 430 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 431 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 432 | protected function _list_tables($prefix_limit = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 433 | { |
| 434 | $sql = "SELECT TABLE_NAME FROM ALL_TABLES"; |
| 435 | |
| 436 | if ($prefix_limit !== FALSE AND $this->dbprefix != '') |
| 437 | { |
Greg Aker | 0d42489 | 2010-01-26 02:14:44 +0000 | [diff] [blame] | 438 | $sql .= " WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 439 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 440 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 441 | return $sql; |
| 442 | } |
| 443 | |
| 444 | // -------------------------------------------------------------------- |
| 445 | |
| 446 | /** |
| 447 | * Show column query |
| 448 | * |
| 449 | * Generates a platform-specific query string so that the column names can be fetched |
| 450 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 451 | * @param string the table name |
| 452 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 453 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 454 | protected function _list_columns($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 455 | { |
| 456 | return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; |
| 457 | } |
| 458 | |
| 459 | // -------------------------------------------------------------------- |
| 460 | |
| 461 | /** |
| 462 | * Field data query |
| 463 | * |
| 464 | * Generates a platform-specific query so that the column data can be retrieved |
| 465 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 466 | * @param string the table name |
| 467 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 468 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 469 | protected function _field_data($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 470 | { |
| 471 | return "SELECT * FROM ".$table." where rownum = 1"; |
| 472 | } |
| 473 | |
| 474 | // -------------------------------------------------------------------- |
| 475 | |
| 476 | /** |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 477 | * Error |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 478 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 479 | * Returns an array containing code and message of the last |
| 480 | * database error that has occured. |
Andrey Andreev | 601f8b2 | 2012-03-01 20:11:15 +0200 | [diff] [blame] | 481 | * |
| 482 | * @return array |
| 483 | */ |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 484 | public function error() |
Andrey Andreev | 601f8b2 | 2012-03-01 20:11:15 +0200 | [diff] [blame] | 485 | { |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 486 | /* oci_error() returns an array that already contains the |
| 487 | * 'code' and 'message' keys, so we can just return it. |
| 488 | */ |
Andrey Andreev | 601f8b2 | 2012-03-01 20:11:15 +0200 | [diff] [blame] | 489 | if (is_resource($this->curs_id)) |
| 490 | { |
| 491 | return oci_error($this->curs_id); |
| 492 | } |
| 493 | elseif (is_resource($this->stmt_id)) |
| 494 | { |
| 495 | return oci_error($this->stmt_id); |
| 496 | } |
| 497 | elseif (is_resource($this->conn_id)) |
| 498 | { |
| 499 | return oci_error($this->conn_id); |
| 500 | } |
| 501 | |
| 502 | return oci_error(); |
| 503 | } |
| 504 | |
| 505 | // -------------------------------------------------------------------- |
| 506 | |
| 507 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 508 | * Escape the SQL Identifiers |
| 509 | * |
| 510 | * This function escapes column and table names |
| 511 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 512 | * @param string |
| 513 | * @return string |
| 514 | */ |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 515 | public function _escape_identifiers($item) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 516 | { |
| 517 | if ($this->_escape_char == '') |
| 518 | { |
| 519 | return $item; |
| 520 | } |
| 521 | |
| 522 | foreach ($this->_reserved_identifiers as $id) |
| 523 | { |
| 524 | if (strpos($item, '.'.$id) !== FALSE) |
| 525 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 526 | $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); |
| 527 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 528 | // remove duplicates if the user already included the escape |
| 529 | return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 530 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 531 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 532 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 533 | if (strpos($item, '.') !== FALSE) |
| 534 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 535 | $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 536 | } |
| 537 | else |
| 538 | { |
| 539 | $str = $this->_escape_char.$item.$this->_escape_char; |
| 540 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 541 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 542 | // remove duplicates if the user already included the escape |
| 543 | return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); |
| 544 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 545 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 546 | // -------------------------------------------------------------------- |
| 547 | |
| 548 | /** |
| 549 | * From Tables |
| 550 | * |
| 551 | * This function implicitly groups FROM tables so there is no confusion |
| 552 | * about operator precedence in harmony with SQL standards |
| 553 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 554 | * @param array |
| 555 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 556 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 557 | protected function _from_tables($tables) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 558 | { |
| 559 | if ( ! is_array($tables)) |
| 560 | { |
| 561 | $tables = array($tables); |
| 562 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 563 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 564 | return implode(', ', $tables); |
| 565 | } |
| 566 | |
| 567 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 568 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 569 | /** |
| 570 | * Insert statement |
| 571 | * |
| 572 | * Generates a platform-specific insert string from the supplied data |
| 573 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 574 | * @param string the table name |
| 575 | * @param array the insert keys |
| 576 | * @param array the insert values |
| 577 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 578 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 579 | protected function _insert($table, $keys, $values) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 580 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 581 | return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | // -------------------------------------------------------------------- |
| 585 | |
| 586 | /** |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 587 | * Insert_batch statement |
| 588 | * |
| 589 | * Generates a platform-specific insert string from the supplied data |
| 590 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 591 | * @param string the table name |
| 592 | * @param array the insert keys |
| 593 | * @param array the insert values |
| 594 | * @return string |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 595 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 596 | protected function _insert_batch($table, $keys, $values) |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 597 | { |
| 598 | $keys = implode(', ', $keys); |
| 599 | $sql = "INSERT ALL\n"; |
| 600 | |
| 601 | for ($i = 0, $c = count($values); $i < $c; $i++) |
Andrey Andreev | b83c408 | 2011-09-23 03:32:45 +0300 | [diff] [blame] | 602 | { |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 603 | $sql .= ' INTO ' . $table . ' (' . $keys . ') VALUES ' . $values[$i] . "\n"; |
Andrey Andreev | b83c408 | 2011-09-23 03:32:45 +0300 | [diff] [blame] | 604 | } |
Andrey Andreev | 99c6dd4 | 2011-09-23 03:07:01 +0300 | [diff] [blame] | 605 | |
| 606 | $sql .= 'SELECT * FROM dual'; |
| 607 | |
| 608 | return $sql; |
| 609 | } |
| 610 | |
| 611 | // -------------------------------------------------------------------- |
| 612 | |
| 613 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 614 | * Update statement |
| 615 | * |
| 616 | * Generates a platform-specific update string from the supplied data |
| 617 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 618 | * @param string the table name |
| 619 | * @param array the update data |
| 620 | * @param array the where clause |
| 621 | * @param array the orderby clause |
| 622 | * @param array the limit clause |
| 623 | * @return string |
| 624 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 625 | protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 626 | { |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 627 | foreach ($values as $key => $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 628 | { |
| 629 | $valstr[] = $key." = ".$val; |
| 630 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 631 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 632 | $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 633 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 634 | $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 635 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 636 | $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); |
| 637 | |
| 638 | $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; |
| 639 | |
| 640 | $sql .= $orderby.$limit; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 641 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 642 | return $sql; |
| 643 | } |
| 644 | |
| 645 | // -------------------------------------------------------------------- |
| 646 | |
| 647 | /** |
| 648 | * Truncate statement |
| 649 | * |
| 650 | * Generates a platform-specific truncate string from the supplied data |
| 651 | * If the database does not support the truncate() command |
| 652 | * This function maps to "DELETE FROM table" |
| 653 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 654 | * @param string the table name |
| 655 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 656 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 657 | protected function _truncate($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 658 | { |
| 659 | return "TRUNCATE TABLE ".$table; |
| 660 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 661 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 662 | // -------------------------------------------------------------------- |
| 663 | |
| 664 | /** |
| 665 | * Delete statement |
| 666 | * |
| 667 | * Generates a platform-specific delete string from the supplied data |
| 668 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 669 | * @param string the table name |
| 670 | * @param array the where clause |
| 671 | * @param string the limit clause |
| 672 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 673 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 674 | protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 675 | { |
| 676 | $conditions = ''; |
| 677 | |
| 678 | if (count($where) > 0 OR count($like) > 0) |
| 679 | { |
| 680 | $conditions = "\nWHERE "; |
| 681 | $conditions .= implode("\n", $this->ar_where); |
| 682 | |
| 683 | if (count($where) > 0 && count($like) > 0) |
| 684 | { |
| 685 | $conditions .= " AND "; |
| 686 | } |
| 687 | $conditions .= implode("\n", $like); |
| 688 | } |
| 689 | |
| 690 | $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 691 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 692 | return "DELETE FROM ".$table.$conditions.$limit; |
| 693 | } |
| 694 | |
| 695 | // -------------------------------------------------------------------- |
| 696 | |
| 697 | /** |
| 698 | * Limit string |
| 699 | * |
| 700 | * Generates a platform-specific LIMIT clause |
| 701 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 702 | * @param string the sql query string |
| 703 | * @param int the number of rows to limit the query to |
| 704 | * @param int the offset value |
| 705 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 706 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 707 | protected function _limit($sql, $limit, $offset) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 708 | { |
| 709 | $limit = $offset + $limit; |
| 710 | $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; |
| 711 | |
| 712 | if ($offset != 0) |
| 713 | { |
| 714 | $newsql .= " WHERE rnum >= $offset"; |
| 715 | } |
| 716 | |
| 717 | // remember that we used limits |
| 718 | $this->limit_used = TRUE; |
| 719 | |
| 720 | return $newsql; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 721 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 722 | |
| 723 | // -------------------------------------------------------------------- |
| 724 | |
| 725 | /** |
| 726 | * Close DB Connection |
| 727 | * |
Andrey Andreev | da12373 | 2012-03-20 22:27:40 +0200 | [diff] [blame] | 728 | * @param resource |
| 729 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 730 | */ |
Andrey Andreev | bc95e47 | 2011-10-20 09:44:48 +0300 | [diff] [blame] | 731 | protected function _close($conn_id) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 732 | { |
Andrey Andreev | 5c3a202 | 2011-10-07 21:04:58 +0300 | [diff] [blame] | 733 | @oci_close($conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 738 | /* End of file oci8_driver.php */ |
Timothy Warren | 215890b | 2012-03-20 09:38:16 -0400 | [diff] [blame] | 739 | /* Location: ./system/database/drivers/oci8/oci8_driver.php */ |