Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 5.1.6 or newer |
| 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +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 | 7f55d61 | 2012-01-26 13:44:28 +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 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [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) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 2.0.2 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 28 | /** |
| 29 | * CUBRID 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 | * |
| 35 | * @package CodeIgniter |
| 36 | * @subpackage Drivers |
| 37 | * @category Database |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 38 | * @author Esen Sagynov |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 39 | * @link http://codeigniter.com/user_guide/database/ |
| 40 | */ |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 41 | class CI_DB_cubrid_driver extends CI_DB { |
| 42 | |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 43 | public $dbdriver = 'cubrid'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 44 | |
| 45 | // The character used for escaping - no need in CUBRID |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 46 | protected $_escape_char = ''; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 47 | |
| 48 | // clause and character used for LIKE escape sequences - not used in CUBRID |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 49 | protected $_like_escape_str = ''; |
| 50 | protected $_like_escape_chr = ''; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * The syntax to count rows is slightly different across different |
| 54 | * database engines, so this string appears in each driver and is |
| 55 | * used for the count_all() and count_all_results() functions. |
| 56 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 57 | protected $_count_string = 'SELECT COUNT(*) AS '; |
| 58 | protected $_random_keyword = ' RAND()'; // database specific random keyword |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 59 | |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 60 | // CUBRID-specific properties |
| 61 | public $auto_commit = TRUE; |
| 62 | |
Andrey Andreev | ca7e5f1 | 2012-01-26 17:58:28 +0200 | [diff] [blame] | 63 | public function __construct($params) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 64 | { |
Andrey Andreev | ca7e5f1 | 2012-01-26 17:58:28 +0200 | [diff] [blame] | 65 | parent::__construct($params); |
| 66 | |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 67 | if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches)) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 68 | { |
Andrey Andreev | cac407d | 2012-02-14 11:45:36 +0200 | [diff] [blame^] | 69 | if (stripos($matches[2], 'autocommit=off') !== FALSE) |
Andrey Andreev | 36cd531 | 2012-02-13 01:40:55 +0200 | [diff] [blame] | 70 | { |
| 71 | $this->auto_commit = FALSE; |
| 72 | } |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 73 | } |
| 74 | else |
| 75 | { |
| 76 | // If no port is defined by the user, use the default value |
| 77 | $this->port == '' OR $this->port = 33000; |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 78 | } |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 79 | } |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 80 | |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 81 | /** |
| 82 | * Non-persistent database connection |
| 83 | * |
| 84 | * @return resource |
| 85 | */ |
| 86 | public function db_connect() |
| 87 | { |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 88 | return $this->_cubrid_connect(); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | // -------------------------------------------------------------------- |
| 92 | |
| 93 | /** |
| 94 | * Persistent database connection |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 95 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 96 | * In CUBRID persistent DB connection is supported natively in CUBRID |
| 97 | * engine which can be configured in the CUBRID Broker configuration |
| 98 | * file by setting the CCI_PCONNECT parameter to ON. In that case, all |
| 99 | * connections established between the client application and the |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 100 | * server will become persistent. |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 101 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 102 | * @return resource |
| 103 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 104 | public function db_pconnect() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 105 | { |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 106 | return $this->_cubrid_connect(TRUE); |
| 107 | } |
| 108 | |
| 109 | // -------------------------------------------------------------------- |
| 110 | |
| 111 | /** |
| 112 | * CUBRID connection |
| 113 | * |
| 114 | * A CUBRID-specific method to create a connection to the database. |
| 115 | * Except for determining if a persistent connection should be used, |
| 116 | * the rest of the logic is the same for db_connect() and db_pconnect(). |
| 117 | * |
| 118 | * @param bool |
| 119 | * @return resource |
| 120 | */ |
| 121 | protected function _cubrid_connect($persistent = FALSE) |
| 122 | { |
| 123 | if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches)) |
| 124 | { |
Andrey Andreev | fe4b4e9 | 2012-02-13 05:40:25 +0200 | [diff] [blame] | 125 | $_temp = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url'; |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 126 | $conn_id = ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '') |
Andrey Andreev | fe4b4e9 | 2012-02-13 05:40:25 +0200 | [diff] [blame] | 127 | ? $_temp($this->dsn, $this->username, $this->password) |
| 128 | : $_temp($this->dsn); |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 129 | } |
| 130 | else |
| 131 | { |
| 132 | $_temp = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect'; |
| 133 | $conn_id = ($this->username !== '') |
| 134 | ? $_temp($this->hostname, $this->port, $this->database, $this->username, $this->password) |
| 135 | : $_temp($this->hostname, $this->port, $this->database); |
| 136 | } |
| 137 | |
| 138 | if ($conn_id) |
| 139 | { |
| 140 | $_temp = ($this->auto_commit) ? CUBRID_AUTOCOMMIT_TRUE : CUBRID_AUTOCOMMIT_FALSE; |
| 141 | cubrid_set_autocommit($conn_id, $_temp); |
| 142 | } |
| 143 | |
| 144 | return $conn_id; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | // -------------------------------------------------------------------- |
| 148 | |
| 149 | /** |
| 150 | * Reconnect |
| 151 | * |
| 152 | * Keep / reestablish the db connection if no queries have been |
| 153 | * sent for a length of time exceeding the server's idle timeout |
| 154 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 155 | * @return void |
| 156 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 157 | public function reconnect() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 158 | { |
| 159 | if (cubrid_ping($this->conn_id) === FALSE) |
| 160 | { |
| 161 | $this->conn_id = FALSE; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // -------------------------------------------------------------------- |
| 166 | |
| 167 | /** |
| 168 | * Select the database |
| 169 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 170 | * @return resource |
| 171 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 172 | public function db_select() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 173 | { |
| 174 | // In CUBRID there is no need to select a database as the database |
| 175 | // is chosen at the connection time. |
| 176 | // So, to determine if the database is "selected", all we have to |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 177 | // do is ping the server and return that value. |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 178 | return cubrid_ping($this->conn_id); |
| 179 | } |
| 180 | |
| 181 | // -------------------------------------------------------------------- |
| 182 | |
| 183 | /** |
| 184 | * Set client character set |
| 185 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 186 | * @param string |
| 187 | * @param string |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 188 | * @return bool |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 189 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 190 | public function db_set_charset($charset, $collation) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 191 | { |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 192 | // Not supported in CUBRID |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 193 | return TRUE; |
| 194 | } |
| 195 | |
| 196 | // -------------------------------------------------------------------- |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 197 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 198 | /** |
| 199 | * Version number query string |
| 200 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 201 | * @return string |
| 202 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 203 | protected function _version() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 204 | { |
| 205 | return cubrid_get_server_info($this->conn_id); |
| 206 | } |
| 207 | |
| 208 | // -------------------------------------------------------------------- |
| 209 | |
| 210 | /** |
| 211 | * Execute the query |
| 212 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 213 | * @param string an SQL query |
| 214 | * @return resource |
| 215 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 216 | protected function _execute($sql) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 217 | { |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 218 | return @cubrid_query($this->_prep_query($sql), $this->conn_id); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | // -------------------------------------------------------------------- |
| 222 | |
| 223 | /** |
| 224 | * Prep the query |
| 225 | * |
| 226 | * If needed, each database adapter can prep the query string |
| 227 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 228 | * @param string an SQL query |
| 229 | * @return string |
| 230 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 231 | protected function _prep_query($sql) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 232 | { |
| 233 | return $sql; |
| 234 | } |
| 235 | |
| 236 | // -------------------------------------------------------------------- |
| 237 | |
| 238 | /** |
| 239 | * Begin Transaction |
| 240 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 241 | * @return bool |
| 242 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 243 | public function trans_begin($test_mode = FALSE) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 244 | { |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 245 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 246 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 247 | { |
| 248 | return TRUE; |
| 249 | } |
| 250 | |
| 251 | // Reset the transaction failure flag. |
| 252 | // If the $test_mode flag is set to TRUE transactions will be rolled back |
| 253 | // even if the queries produce a successful result. |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 254 | $this->_trans_failure = ($test_mode === TRUE); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 255 | |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 256 | if (cubrid_get_autocommit($this->conn_id)) |
| 257 | { |
| 258 | cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE); |
| 259 | } |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 260 | |
| 261 | return TRUE; |
| 262 | } |
| 263 | |
| 264 | // -------------------------------------------------------------------- |
| 265 | |
| 266 | /** |
| 267 | * Commit Transaction |
| 268 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 269 | * @return bool |
| 270 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 271 | public function trans_commit() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 272 | { |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 273 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 274 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 275 | { |
| 276 | return TRUE; |
| 277 | } |
| 278 | |
| 279 | cubrid_commit($this->conn_id); |
| 280 | |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 281 | if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) |
| 282 | { |
| 283 | cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); |
| 284 | } |
| 285 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 286 | return TRUE; |
| 287 | } |
| 288 | |
| 289 | // -------------------------------------------------------------------- |
| 290 | |
| 291 | /** |
| 292 | * Rollback Transaction |
| 293 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 294 | * @return bool |
| 295 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 296 | public function trans_rollback() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 297 | { |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 298 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 299 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 300 | { |
| 301 | return TRUE; |
| 302 | } |
| 303 | |
| 304 | cubrid_rollback($this->conn_id); |
| 305 | |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 306 | if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) |
| 307 | { |
| 308 | cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); |
| 309 | } |
| 310 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 311 | return TRUE; |
| 312 | } |
| 313 | |
| 314 | // -------------------------------------------------------------------- |
| 315 | |
| 316 | /** |
| 317 | * Escape String |
| 318 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 319 | * @param string |
| 320 | * @param bool whether or not the string will be used in a LIKE condition |
| 321 | * @return string |
| 322 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 323 | public function escape_str($str, $like = FALSE) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 324 | { |
| 325 | if (is_array($str)) |
| 326 | { |
| 327 | foreach ($str as $key => $val) |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 328 | { |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 329 | $str[$key] = $this->escape_str($val, $like); |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 330 | } |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 331 | |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 332 | return $str; |
| 333 | } |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 334 | |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 335 | if (function_exists('cubrid_real_escape_string') && is_resource($this->conn_id)) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 336 | { |
| 337 | $str = cubrid_real_escape_string($str, $this->conn_id); |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | $str = addslashes($str); |
| 342 | } |
| 343 | |
| 344 | // escape LIKE condition wildcards |
| 345 | if ($like === TRUE) |
| 346 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 347 | return str_replace(array('%', '_'), array('\\%', '\\_'), $str); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | return $str; |
| 351 | } |
| 352 | |
| 353 | // -------------------------------------------------------------------- |
| 354 | |
| 355 | /** |
| 356 | * Affected Rows |
| 357 | * |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 358 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 359 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 360 | public function affected_rows() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 361 | { |
| 362 | return @cubrid_affected_rows($this->conn_id); |
| 363 | } |
| 364 | |
| 365 | // -------------------------------------------------------------------- |
| 366 | |
| 367 | /** |
| 368 | * Insert ID |
| 369 | * |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 370 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 371 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 372 | public function insert_id() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 373 | { |
| 374 | return @cubrid_insert_id($this->conn_id); |
| 375 | } |
| 376 | |
| 377 | // -------------------------------------------------------------------- |
| 378 | |
| 379 | /** |
| 380 | * "Count All" query |
| 381 | * |
| 382 | * Generates a platform-specific query string that counts all records in |
| 383 | * the specified table |
| 384 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 385 | * @param string |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 386 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 387 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 388 | public function count_all($table = '') |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 389 | { |
| 390 | if ($table == '') |
| 391 | { |
| 392 | return 0; |
| 393 | } |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 394 | $query = $this->query($this->_count_string.$this->_protect_identifiers('numrows').' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE)); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 395 | if ($query->num_rows() == 0) |
| 396 | { |
| 397 | return 0; |
| 398 | } |
| 399 | |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 400 | $query = $query->row(); |
Greg Aker | 90248ab | 2011-08-20 14:23:14 -0500 | [diff] [blame] | 401 | $this->_reset_select(); |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 402 | return (int) $query->numrows; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | // -------------------------------------------------------------------- |
| 406 | |
| 407 | /** |
| 408 | * List table query |
| 409 | * |
| 410 | * Generates a platform-specific query string so that the table names can be fetched |
| 411 | * |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 412 | * @param bool |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 413 | * @return string |
| 414 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 415 | protected function _list_tables($prefix_limit = FALSE) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 416 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 417 | $sql = 'SHOW TABLES'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 418 | |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 419 | if ($prefix_limit !== FALSE && $this->dbprefix != '') |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 420 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 421 | return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | return $sql; |
| 425 | } |
| 426 | |
| 427 | // -------------------------------------------------------------------- |
| 428 | |
| 429 | /** |
| 430 | * Show column query |
| 431 | * |
| 432 | * Generates a platform-specific query string so that the column names can be fetched |
| 433 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 434 | * @param string the table name |
| 435 | * @return string |
| 436 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 437 | protected function _list_columns($table = '') |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 438 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 439 | return 'SHOW COLUMNS FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | // -------------------------------------------------------------------- |
| 443 | |
| 444 | /** |
| 445 | * Field data query |
| 446 | * |
| 447 | * Generates a platform-specific query so that the column data can be retrieved |
| 448 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 449 | * @param string the table name |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 450 | * @return string |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 451 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 452 | protected function _field_data($table) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 453 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 454 | return 'SELECT * FROM '.$table.' LIMIT 1'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | // -------------------------------------------------------------------- |
| 458 | |
| 459 | /** |
| 460 | * The error message string |
| 461 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 462 | * @return string |
| 463 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 464 | protected function _error_message() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 465 | { |
| 466 | return cubrid_error($this->conn_id); |
| 467 | } |
| 468 | |
| 469 | // -------------------------------------------------------------------- |
| 470 | |
| 471 | /** |
| 472 | * The error message number |
| 473 | * |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 474 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 475 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 476 | protected function _error_number() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 477 | { |
| 478 | return cubrid_errno($this->conn_id); |
| 479 | } |
| 480 | |
| 481 | // -------------------------------------------------------------------- |
| 482 | |
| 483 | /** |
| 484 | * Escape the SQL Identifiers |
| 485 | * |
| 486 | * This function escapes column and table names |
| 487 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 488 | * @param string |
| 489 | * @return string |
| 490 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 491 | public function _escape_identifiers($item) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 492 | { |
| 493 | if ($this->_escape_char == '') |
| 494 | { |
| 495 | return $item; |
| 496 | } |
| 497 | |
| 498 | foreach ($this->_reserved_identifiers as $id) |
| 499 | { |
| 500 | if (strpos($item, '.'.$id) !== FALSE) |
| 501 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 502 | $item = str_replace('.', $this->_escape_char.'.', $item); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 503 | |
| 504 | // remove duplicates if the user already included the escape |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 505 | return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
| 509 | if (strpos($item, '.') !== FALSE) |
| 510 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 511 | $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | // remove duplicates if the user already included the escape |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 515 | return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | // -------------------------------------------------------------------- |
| 519 | |
| 520 | /** |
| 521 | * From Tables |
| 522 | * |
| 523 | * This function implicitly groups FROM tables so there is no confusion |
| 524 | * about operator precedence in harmony with SQL standards |
| 525 | * |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 526 | * @param string the table name |
| 527 | * @return string |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 528 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 529 | protected function _from_tables($tables) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 530 | { |
| 531 | if ( ! is_array($tables)) |
| 532 | { |
| 533 | $tables = array($tables); |
| 534 | } |
| 535 | |
| 536 | return '('.implode(', ', $tables).')'; |
| 537 | } |
| 538 | |
| 539 | // -------------------------------------------------------------------- |
| 540 | |
| 541 | /** |
| 542 | * Insert statement |
| 543 | * |
| 544 | * Generates a platform-specific insert string from the supplied data |
| 545 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 546 | * @param string the table name |
| 547 | * @param array the insert keys |
| 548 | * @param array the insert values |
| 549 | * @return string |
| 550 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 551 | protected function _insert($table, $keys, $values) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 552 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 553 | return 'INSERT INTO '.$table.' ("'.implode('", "', $keys).'") VALUES ('.implode(', ', $values).')'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | // -------------------------------------------------------------------- |
| 557 | |
| 558 | |
| 559 | /** |
| 560 | * Replace statement |
| 561 | * |
| 562 | * Generates a platform-specific replace string from the supplied data |
| 563 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 564 | * @param string the table name |
| 565 | * @param array the insert keys |
| 566 | * @param array the insert values |
| 567 | * @return string |
| 568 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 569 | protected function _replace($table, $keys, $values) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 570 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 571 | return 'REPLACE INTO '.$table.' ("'.implode('", "', $keys).'") VALUES ('.implode(', ', $values).')'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | // -------------------------------------------------------------------- |
| 575 | |
| 576 | /** |
| 577 | * Insert_batch statement |
| 578 | * |
| 579 | * Generates a platform-specific insert string from the supplied data |
| 580 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 581 | * @param string the table name |
| 582 | * @param array the insert keys |
| 583 | * @param array the insert values |
| 584 | * @return string |
| 585 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 586 | protected function _insert_batch($table, $keys, $values) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 587 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 588 | return 'INSERT INTO '.$table.' ("'.implode('", "', $keys).'") VALUES '.implode(', ', $values); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | // -------------------------------------------------------------------- |
| 592 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 593 | /** |
| 594 | * Update statement |
| 595 | * |
| 596 | * Generates a platform-specific update string from the supplied data |
| 597 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 598 | * @param string the table name |
| 599 | * @param array the update data |
| 600 | * @param array the where clause |
| 601 | * @param array the orderby clause |
| 602 | * @param array the limit clause |
| 603 | * @return string |
| 604 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 605 | protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 606 | { |
| 607 | foreach ($values as $key => $val) |
| 608 | { |
Esen Sagynov | ee3e594 | 2011-08-10 03:22:58 -0700 | [diff] [blame] | 609 | $valstr[] = sprintf('"%s" = %s', $key, $val); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 612 | return 'UPDATE '.$table.' SET '.implode(', ', $valstr) |
| 613 | .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '') |
| 614 | .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') |
| 615 | .( ! $limit ? '' : ' LIMIT '.$limit); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | // -------------------------------------------------------------------- |
| 619 | |
| 620 | |
| 621 | /** |
| 622 | * Update_Batch statement |
| 623 | * |
| 624 | * Generates a platform-specific batch update string from the supplied data |
| 625 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 626 | * @param string the table name |
| 627 | * @param array the update data |
| 628 | * @param array the where clause |
| 629 | * @return string |
| 630 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 631 | protected function _update_batch($table, $values, $index, $where = NULL) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 632 | { |
| 633 | $ids = array(); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 634 | foreach ($values as $key => $val) |
| 635 | { |
| 636 | $ids[] = $val[$index]; |
| 637 | |
| 638 | foreach (array_keys($val) as $field) |
| 639 | { |
| 640 | if ($field != $index) |
| 641 | { |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 642 | $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | } |
| 646 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 647 | $cases = ''; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 648 | foreach ($final as $k => $v) |
| 649 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 650 | $cases .= $k." = CASE \n" |
| 651 | .implode("\n", $v) |
| 652 | .'ELSE '.$k.' END, '; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 655 | return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 656 | .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') |
| 657 | .$index.' IN ('.implode(',', $ids).')'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | // -------------------------------------------------------------------- |
| 661 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 662 | /** |
| 663 | * Truncate statement |
| 664 | * |
| 665 | * Generates a platform-specific truncate string from the supplied data |
| 666 | * If the database does not support the truncate() command |
| 667 | * This function maps to "DELETE FROM table" |
| 668 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 669 | * @param string the table name |
| 670 | * @return string |
| 671 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 672 | protected function _truncate($table) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 673 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 674 | return 'TRUNCATE '.$table; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | // -------------------------------------------------------------------- |
| 678 | |
| 679 | /** |
| 680 | * Delete statement |
| 681 | * |
| 682 | * Generates a platform-specific delete string from the supplied data |
| 683 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 684 | * @param string the table name |
| 685 | * @param array the where clause |
| 686 | * @param string the limit clause |
| 687 | * @return string |
| 688 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 689 | protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 690 | { |
| 691 | $conditions = ''; |
| 692 | |
| 693 | if (count($where) > 0 OR count($like) > 0) |
| 694 | { |
Andrey Andreev | 2e430a3 | 2012-02-12 23:37:58 +0200 | [diff] [blame] | 695 | $conditions = "\nWHERE ".implode("\n", $where) |
| 696 | .((count($where) > 0 && count($like) > 0) ? ' AND ' : '') |
| 697 | .implode("\n", $like); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 700 | return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | // -------------------------------------------------------------------- |
| 704 | |
| 705 | /** |
| 706 | * Limit string |
| 707 | * |
| 708 | * Generates a platform-specific LIMIT clause |
| 709 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 710 | * @param string the sql query string |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 711 | * @param int the number of rows to limit the query to |
| 712 | * @param int the offset value |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 713 | * @return string |
| 714 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 715 | protected function _limit($sql, $limit, $offset) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 716 | { |
Andrey Andreev | c6953f4 | 2012-01-26 14:43:16 +0200 | [diff] [blame] | 717 | return $sql.'LIMIT '.($offset == 0 ? '' : $offset.', ').$limit; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | // -------------------------------------------------------------------- |
| 721 | |
| 722 | /** |
| 723 | * Close DB Connection |
| 724 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 725 | * @param resource |
| 726 | * @return void |
| 727 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 728 | protected function _close($conn_id) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 729 | { |
| 730 | @cubrid_close($conn_id); |
| 731 | } |
| 732 | |
| 733 | } |
| 734 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 735 | /* End of file cubrid_driver.php */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 736 | /* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ |