Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [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 |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +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 | 592f4ec | 2012-03-20 15:10:08 +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 |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2014, 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 |
Andrey Andreev | cf63120 | 2012-02-16 11:36:28 +0200 | [diff] [blame] | 24 | * @since Version 2.1 |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 28 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 29 | /** |
| 30 | * CUBRID Database Adapter Class |
| 31 | * |
| 32 | * Note: _DB is an extender class that the app controller |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 33 | * creates dynamically based on whether the query builder |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 34 | * class is being used or not. |
| 35 | * |
| 36 | * @package CodeIgniter |
| 37 | * @subpackage Drivers |
| 38 | * @category Database |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 39 | * @author Esen Sagynov |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 40 | * @link http://codeigniter.com/user_guide/database/ |
| 41 | */ |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 42 | class CI_DB_cubrid_driver extends CI_DB { |
| 43 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 44 | /** |
| 45 | * Database driver |
| 46 | * |
| 47 | * @var string |
| 48 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 49 | public $dbdriver = 'cubrid'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 50 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 51 | /** |
| 52 | * Auto-commit flag |
| 53 | * |
| 54 | * @var bool |
| 55 | */ |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 56 | public $auto_commit = TRUE; |
| 57 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 58 | // -------------------------------------------------------------------- |
| 59 | |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 60 | /** |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 61 | * Identifier escape character |
| 62 | * |
| 63 | * @var string |
| 64 | */ |
| 65 | protected $_escape_char = '`'; |
| 66 | |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 67 | /** |
| 68 | * ORDER BY random keyword |
| 69 | * |
| 70 | * @var array |
| 71 | */ |
| 72 | protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)'); |
| 73 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 74 | // -------------------------------------------------------------------- |
| 75 | |
| 76 | /** |
| 77 | * Class constructor |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 78 | * |
| 79 | * @param array $params |
| 80 | * @return void |
| 81 | */ |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 82 | public function __construct($params) |
| 83 | { |
| 84 | parent::__construct($params); |
| 85 | |
| 86 | if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches)) |
| 87 | { |
| 88 | if (stripos($matches[2], 'autocommit=off') !== FALSE) |
| 89 | { |
| 90 | $this->auto_commit = FALSE; |
| 91 | } |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | // If no port is defined by the user, use the default value |
Andrey Andreev | e4c3019 | 2012-06-04 15:08:24 +0300 | [diff] [blame] | 96 | empty($this->port) OR $this->port = 33000; |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 97 | } |
| 98 | } |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 99 | |
Andrey Andreev | 2ea33c3 | 2012-10-04 12:37:51 +0300 | [diff] [blame] | 100 | // -------------------------------------------------------------------- |
| 101 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Non-persistent database connection |
| 104 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 105 | * @param bool $persistent |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 106 | * @return resource |
| 107 | */ |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame^] | 108 | public function db_connect($persistent = FALSE) |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 109 | { |
| 110 | if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches)) |
| 111 | { |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame^] | 112 | $func = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url'; |
| 113 | return ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '') |
| 114 | ? $func($this->dsn, $this->username, $this->password) |
| 115 | : $func($this->dsn); |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 116 | } |
| 117 | |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame^] | 118 | $func = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect'; |
| 119 | return ($this->username !== '') |
| 120 | ? $func($this->hostname, $this->port, $this->database, $this->username, $this->password) |
| 121 | : $func($this->hostname, $this->port, $this->database); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | // -------------------------------------------------------------------- |
| 125 | |
| 126 | /** |
| 127 | * Reconnect |
| 128 | * |
| 129 | * Keep / reestablish the db connection if no queries have been |
| 130 | * sent for a length of time exceeding the server's idle timeout |
| 131 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 132 | * @return void |
| 133 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 134 | public function reconnect() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 135 | { |
| 136 | if (cubrid_ping($this->conn_id) === FALSE) |
| 137 | { |
| 138 | $this->conn_id = FALSE; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // -------------------------------------------------------------------- |
| 143 | |
| 144 | /** |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 145 | * Database version number |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 146 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 147 | * @return string |
| 148 | */ |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 149 | public function version() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 150 | { |
Andrey Andreev | 2b73037 | 2012-11-05 17:01:11 +0200 | [diff] [blame] | 151 | if (isset($this->data_cache['version'])) |
| 152 | { |
| 153 | return $this->data_cache['version']; |
| 154 | } |
| 155 | elseif ( ! $this->conn_id) |
| 156 | { |
| 157 | $this->initialize(); |
| 158 | } |
| 159 | |
| 160 | return ( ! $this->conn_id OR ($version = cubrid_get_server_info($this->conn_id)) === FALSE) |
| 161 | ? FALSE |
| 162 | : $this->data_cache['version'] = $version; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | // -------------------------------------------------------------------- |
| 166 | |
| 167 | /** |
| 168 | * Execute the query |
| 169 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 170 | * @param string $sql an SQL query |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 171 | * @return resource |
| 172 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 173 | protected function _execute($sql) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 174 | { |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 175 | return @cubrid_query($sql, $this->conn_id); |
| 176 | } |
| 177 | |
| 178 | // -------------------------------------------------------------------- |
| 179 | |
| 180 | /** |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 181 | * Begin Transaction |
| 182 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 183 | * @param bool $test_mode |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 184 | * @return bool |
| 185 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 186 | public function trans_begin($test_mode = FALSE) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 187 | { |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 188 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 189 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 190 | { |
| 191 | return TRUE; |
| 192 | } |
| 193 | |
| 194 | // Reset the transaction failure flag. |
| 195 | // If the $test_mode flag is set to TRUE transactions will be rolled back |
| 196 | // even if the queries produce a successful result. |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 197 | $this->_trans_failure = ($test_mode === TRUE); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 198 | |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 199 | if (cubrid_get_autocommit($this->conn_id)) |
| 200 | { |
| 201 | cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE); |
| 202 | } |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 203 | |
| 204 | return TRUE; |
| 205 | } |
| 206 | |
| 207 | // -------------------------------------------------------------------- |
| 208 | |
| 209 | /** |
| 210 | * Commit Transaction |
| 211 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 212 | * @return bool |
| 213 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 214 | public function trans_commit() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 215 | { |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 216 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 217 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 218 | { |
| 219 | return TRUE; |
| 220 | } |
| 221 | |
| 222 | cubrid_commit($this->conn_id); |
| 223 | |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 224 | if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) |
| 225 | { |
| 226 | cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); |
| 227 | } |
| 228 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 229 | return TRUE; |
| 230 | } |
| 231 | |
| 232 | // -------------------------------------------------------------------- |
| 233 | |
| 234 | /** |
| 235 | * Rollback Transaction |
| 236 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 237 | * @return bool |
| 238 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 239 | public function trans_rollback() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 240 | { |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 241 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 242 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 243 | { |
| 244 | return TRUE; |
| 245 | } |
| 246 | |
| 247 | cubrid_rollback($this->conn_id); |
| 248 | |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 249 | if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) |
| 250 | { |
| 251 | cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); |
| 252 | } |
| 253 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 254 | return TRUE; |
| 255 | } |
| 256 | |
| 257 | // -------------------------------------------------------------------- |
| 258 | |
| 259 | /** |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 260 | * Platform-dependant string escape |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 261 | * |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 262 | * @param string |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 263 | * @return string |
| 264 | */ |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 265 | protected function _escape_str($str) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 266 | { |
Andrey Andreev | 394a3f1 | 2012-02-15 14:35:11 +0200 | [diff] [blame] | 267 | if (function_exists('cubrid_real_escape_string') && |
| 268 | (is_resource($this->conn_id) |
| 269 | OR (get_resource_type($this->conn_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->conn_id))))) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 270 | { |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 271 | return cubrid_real_escape_string($str, $this->conn_id); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 274 | return addslashes($str); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | // -------------------------------------------------------------------- |
| 278 | |
| 279 | /** |
| 280 | * Affected Rows |
| 281 | * |
Andrey Andreev | ea3eec9 | 2012-03-01 19:16:23 +0200 | [diff] [blame] | 282 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 283 | */ |
Andrey Andreev | ea3eec9 | 2012-03-01 19:16:23 +0200 | [diff] [blame] | 284 | public function affected_rows() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 285 | { |
Andrey Andreev | ea3eec9 | 2012-03-01 19:16:23 +0200 | [diff] [blame] | 286 | return @cubrid_affected_rows(); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // -------------------------------------------------------------------- |
| 290 | |
| 291 | /** |
| 292 | * Insert ID |
| 293 | * |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 294 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 295 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 296 | public function insert_id() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 297 | { |
| 298 | return @cubrid_insert_id($this->conn_id); |
| 299 | } |
| 300 | |
| 301 | // -------------------------------------------------------------------- |
| 302 | |
| 303 | /** |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 304 | * List table query |
| 305 | * |
| 306 | * Generates a platform-specific query string so that the table names can be fetched |
| 307 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 308 | * @param bool $prefix_limit |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 309 | * @return string |
| 310 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 311 | protected function _list_tables($prefix_limit = FALSE) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 312 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 313 | $sql = 'SHOW TABLES'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 314 | |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 315 | if ($prefix_limit !== FALSE && $this->dbprefix !== '') |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 316 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 317 | return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | return $sql; |
| 321 | } |
| 322 | |
| 323 | // -------------------------------------------------------------------- |
| 324 | |
| 325 | /** |
| 326 | * Show column query |
| 327 | * |
| 328 | * Generates a platform-specific query string so that the column names can be fetched |
| 329 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 330 | * @param string $table |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 331 | * @return string |
| 332 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 333 | protected function _list_columns($table = '') |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 334 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 335 | return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | // -------------------------------------------------------------------- |
| 339 | |
| 340 | /** |
Andrey Andreev | 10ecc84 | 2012-11-16 01:06:20 +0200 | [diff] [blame] | 341 | * Returns an object with field data |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 342 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 343 | * @param string $table |
Andrey Andreev | 10ecc84 | 2012-11-16 01:06:20 +0200 | [diff] [blame] | 344 | * @return array |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 345 | */ |
Andrey Andreev | 10ecc84 | 2012-11-16 01:06:20 +0200 | [diff] [blame] | 346 | public function field_data($table = '') |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 347 | { |
Andrey Andreev | 10ecc84 | 2012-11-16 01:06:20 +0200 | [diff] [blame] | 348 | if ($table === '') |
| 349 | { |
| 350 | return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; |
| 351 | } |
| 352 | |
| 353 | if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) |
| 354 | { |
| 355 | return FALSE; |
| 356 | } |
| 357 | $query = $query->result_object(); |
| 358 | |
| 359 | $retval = array(); |
| 360 | for ($i = 0, $c = count($query); $i < $c; $i++) |
| 361 | { |
| 362 | $retval[$i] = new stdClass(); |
| 363 | $retval[$i]->name = $query[$i]->Field; |
| 364 | |
| 365 | sscanf($query[$i]->Type, '%[a-z](%d)', |
| 366 | $retval[$i]->type, |
| 367 | $retval[$i]->max_length |
| 368 | ); |
| 369 | |
| 370 | $retval[$i]->default = $query[$i]->Default; |
| 371 | $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); |
| 372 | } |
| 373 | |
| 374 | return $retval; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | // -------------------------------------------------------------------- |
| 378 | |
| 379 | /** |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 380 | * Error |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 381 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 382 | * Returns an array containing code and message of the last |
| 383 | * database error that has occured. |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 384 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 385 | * @return array |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 386 | */ |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 387 | public function error() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 388 | { |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 389 | return array('code' => cubrid_errno($this->conn_id), 'message' => cubrid_error($this->conn_id)); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 392 | // -------------------------------------------------------------------- |
| 393 | |
| 394 | /** |
Andrey Andreev | 7eaa14f | 2012-10-09 11:34:01 +0300 | [diff] [blame] | 395 | * FROM tables |
| 396 | * |
| 397 | * Groups tables in FROM clauses if needed, so there is no confusion |
| 398 | * about operator precedence. |
| 399 | * |
| 400 | * @return string |
| 401 | */ |
| 402 | protected function _from_tables() |
| 403 | { |
Andrey Andreev | fce9abe | 2012-10-09 11:37:00 +0300 | [diff] [blame] | 404 | if ( ! empty($this->qb_join) && count($this->qb_from) > 1) |
Andrey Andreev | 7eaa14f | 2012-10-09 11:34:01 +0300 | [diff] [blame] | 405 | { |
| 406 | return '('.implode(', ', $this->qb_from).')'; |
| 407 | } |
| 408 | |
| 409 | return implode(', ', $this->qb_from); |
| 410 | } |
| 411 | |
| 412 | // -------------------------------------------------------------------- |
| 413 | |
| 414 | /** |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 415 | * Close DB Connection |
| 416 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 417 | * @return void |
| 418 | */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 419 | protected function _close() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 420 | { |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 421 | @cubrid_close($this->conn_id); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | } |
| 425 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 426 | /* End of file cubrid_driver.php */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 427 | /* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ |