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 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014 - 2018, British Columbia Institute of Technology |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 2.1.0 |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 39 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 40 | /** |
| 41 | * CUBRID Database Adapter Class |
| 42 | * |
| 43 | * Note: _DB is an extender class that the app controller |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 44 | * creates dynamically based on whether the query builder |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 45 | * class is being used or not. |
| 46 | * |
| 47 | * @package CodeIgniter |
| 48 | * @subpackage Drivers |
| 49 | * @category Database |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 50 | * @author Esen Sagynov |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 51 | * @link https://codeigniter.com/user_guide/database/ |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 52 | */ |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 53 | class CI_DB_cubrid_driver extends CI_DB { |
| 54 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 55 | /** |
| 56 | * Database driver |
| 57 | * |
| 58 | * @var string |
| 59 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 60 | public $dbdriver = 'cubrid'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 61 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 62 | /** |
| 63 | * Auto-commit flag |
| 64 | * |
| 65 | * @var bool |
| 66 | */ |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 67 | public $auto_commit = TRUE; |
| 68 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 69 | // -------------------------------------------------------------------- |
| 70 | |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 71 | /** |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 72 | * Identifier escape character |
| 73 | * |
| 74 | * @var string |
| 75 | */ |
| 76 | protected $_escape_char = '`'; |
| 77 | |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 78 | /** |
| 79 | * ORDER BY random keyword |
| 80 | * |
| 81 | * @var array |
| 82 | */ |
| 83 | protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)'); |
| 84 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 85 | // -------------------------------------------------------------------- |
| 86 | |
| 87 | /** |
| 88 | * Class constructor |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 89 | * |
| 90 | * @param array $params |
| 91 | * @return void |
| 92 | */ |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 93 | public function __construct($params) |
| 94 | { |
| 95 | parent::__construct($params); |
| 96 | |
| 97 | if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches)) |
| 98 | { |
| 99 | if (stripos($matches[2], 'autocommit=off') !== FALSE) |
| 100 | { |
| 101 | $this->auto_commit = FALSE; |
| 102 | } |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | // If no port is defined by the user, use the default value |
Andrey Andreev | e4c3019 | 2012-06-04 15:08:24 +0300 | [diff] [blame] | 107 | empty($this->port) OR $this->port = 33000; |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 108 | } |
| 109 | } |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 110 | |
Andrey Andreev | 2ea33c3 | 2012-10-04 12:37:51 +0300 | [diff] [blame] | 111 | // -------------------------------------------------------------------- |
| 112 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 113 | /** |
| 114 | * Non-persistent database connection |
| 115 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 116 | * @param bool $persistent |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 117 | * @return resource |
| 118 | */ |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame] | 119 | public function db_connect($persistent = FALSE) |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 120 | { |
| 121 | if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches)) |
| 122 | { |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame] | 123 | $func = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url'; |
| 124 | return ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '') |
| 125 | ? $func($this->dsn, $this->username, $this->password) |
| 126 | : $func($this->dsn); |
Andrey Andreev | a00e504 | 2012-03-26 12:23:13 +0300 | [diff] [blame] | 127 | } |
| 128 | |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame] | 129 | $func = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect'; |
| 130 | return ($this->username !== '') |
| 131 | ? $func($this->hostname, $this->port, $this->database, $this->username, $this->password) |
| 132 | : $func($this->hostname, $this->port, $this->database); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | // -------------------------------------------------------------------- |
| 136 | |
| 137 | /** |
| 138 | * Reconnect |
| 139 | * |
| 140 | * Keep / reestablish the db connection if no queries have been |
| 141 | * sent for a length of time exceeding the server's idle timeout |
| 142 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 143 | * @return void |
| 144 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 145 | public function reconnect() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 146 | { |
| 147 | if (cubrid_ping($this->conn_id) === FALSE) |
| 148 | { |
| 149 | $this->conn_id = FALSE; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // -------------------------------------------------------------------- |
| 154 | |
| 155 | /** |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 156 | * Database version number |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 157 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 158 | * @return string |
| 159 | */ |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 160 | public function version() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 161 | { |
Andrey Andreev | 2b73037 | 2012-11-05 17:01:11 +0200 | [diff] [blame] | 162 | if (isset($this->data_cache['version'])) |
| 163 | { |
| 164 | return $this->data_cache['version']; |
| 165 | } |
Andrey Andreev | 2b73037 | 2012-11-05 17:01:11 +0200 | [diff] [blame] | 166 | |
| 167 | return ( ! $this->conn_id OR ($version = cubrid_get_server_info($this->conn_id)) === FALSE) |
| 168 | ? FALSE |
| 169 | : $this->data_cache['version'] = $version; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | // -------------------------------------------------------------------- |
| 173 | |
| 174 | /** |
| 175 | * Execute the query |
| 176 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 177 | * @param string $sql an SQL query |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 178 | * @return resource |
| 179 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 180 | protected function _execute($sql) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 181 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame] | 182 | return cubrid_query($sql, $this->conn_id); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | // -------------------------------------------------------------------- |
| 186 | |
| 187 | /** |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 188 | * Begin Transaction |
| 189 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 190 | * @return bool |
| 191 | */ |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 192 | protected function _trans_begin() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 193 | { |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 194 | if (($autocommit = cubrid_get_autocommit($this->conn_id)) === NULL) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 195 | { |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 196 | return FALSE; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 197 | } |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 198 | elseif ($autocommit === TRUE) |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 199 | { |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 200 | return cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE); |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 201 | } |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 202 | |
| 203 | return TRUE; |
| 204 | } |
| 205 | |
| 206 | // -------------------------------------------------------------------- |
| 207 | |
| 208 | /** |
| 209 | * Commit Transaction |
| 210 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 211 | * @return bool |
| 212 | */ |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 213 | protected function _trans_commit() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 214 | { |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 215 | if ( ! cubrid_commit($this->conn_id)) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 216 | { |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 217 | return FALSE; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 220 | if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) |
| 221 | { |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 222 | return cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 225 | return TRUE; |
| 226 | } |
| 227 | |
| 228 | // -------------------------------------------------------------------- |
| 229 | |
| 230 | /** |
| 231 | * Rollback Transaction |
| 232 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 233 | * @return bool |
| 234 | */ |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 235 | protected function _trans_rollback() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 236 | { |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 237 | if ( ! cubrid_rollback($this->conn_id)) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 238 | { |
Andrey Andreev | a7d4aba | 2015-10-19 14:39:44 +0300 | [diff] [blame] | 239 | return FALSE; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 242 | if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) |
| 243 | { |
| 244 | cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); |
| 245 | } |
| 246 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 247 | return TRUE; |
| 248 | } |
| 249 | |
| 250 | // -------------------------------------------------------------------- |
| 251 | |
| 252 | /** |
Andrey Andreev | 71d8f72 | 2017-01-17 12:01:00 +0200 | [diff] [blame] | 253 | * Platform-dependent string escape |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 254 | * |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 255 | * @param string |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 256 | * @return string |
| 257 | */ |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 258 | protected function _escape_str($str) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 259 | { |
Andrey Andreev | 62fad28 | 2014-06-19 15:25:40 +0300 | [diff] [blame] | 260 | return cubrid_real_escape_string($str, $this->conn_id); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | // -------------------------------------------------------------------- |
| 264 | |
| 265 | /** |
| 266 | * Affected Rows |
| 267 | * |
Andrey Andreev | ea3eec9 | 2012-03-01 19:16:23 +0200 | [diff] [blame] | 268 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 269 | */ |
Andrey Andreev | ea3eec9 | 2012-03-01 19:16:23 +0200 | [diff] [blame] | 270 | public function affected_rows() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 271 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame] | 272 | return cubrid_affected_rows(); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | // -------------------------------------------------------------------- |
| 276 | |
| 277 | /** |
| 278 | * Insert ID |
| 279 | * |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 280 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 281 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 282 | public function insert_id() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 283 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame] | 284 | return cubrid_insert_id($this->conn_id); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | // -------------------------------------------------------------------- |
| 288 | |
| 289 | /** |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 290 | * List table query |
| 291 | * |
| 292 | * Generates a platform-specific query string so that the table names can be fetched |
| 293 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 294 | * @param bool $prefix_limit |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 295 | * @return string |
| 296 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 297 | protected function _list_tables($prefix_limit = FALSE) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 298 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 299 | $sql = 'SHOW TABLES'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 300 | |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 301 | if ($prefix_limit !== FALSE && $this->dbprefix !== '') |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 302 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 303 | return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | return $sql; |
| 307 | } |
| 308 | |
| 309 | // -------------------------------------------------------------------- |
| 310 | |
| 311 | /** |
| 312 | * Show column query |
| 313 | * |
| 314 | * Generates a platform-specific query string so that the column names can be fetched |
| 315 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 316 | * @param string $table |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 317 | * @return string |
| 318 | */ |
Andrey Andreev | 592f4ec | 2012-03-20 15:10:08 +0200 | [diff] [blame] | 319 | protected function _list_columns($table = '') |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 320 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 321 | return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | // -------------------------------------------------------------------- |
| 325 | |
| 326 | /** |
Andrey Andreev | 10ecc84 | 2012-11-16 01:06:20 +0200 | [diff] [blame] | 327 | * Returns an object with field data |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 328 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 329 | * @param string $table |
Andrey Andreev | 10ecc84 | 2012-11-16 01:06:20 +0200 | [diff] [blame] | 330 | * @return array |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 331 | */ |
Andrey Andreev | 5350f05 | 2015-01-12 12:33:37 +0200 | [diff] [blame] | 332 | public function field_data($table) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 333 | { |
Andrey Andreev | 10ecc84 | 2012-11-16 01:06:20 +0200 | [diff] [blame] | 334 | if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) |
| 335 | { |
| 336 | return FALSE; |
| 337 | } |
| 338 | $query = $query->result_object(); |
| 339 | |
| 340 | $retval = array(); |
| 341 | for ($i = 0, $c = count($query); $i < $c; $i++) |
| 342 | { |
| 343 | $retval[$i] = new stdClass(); |
| 344 | $retval[$i]->name = $query[$i]->Field; |
| 345 | |
| 346 | sscanf($query[$i]->Type, '%[a-z](%d)', |
| 347 | $retval[$i]->type, |
| 348 | $retval[$i]->max_length |
| 349 | ); |
| 350 | |
| 351 | $retval[$i]->default = $query[$i]->Default; |
| 352 | $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); |
| 353 | } |
| 354 | |
| 355 | return $retval; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | // -------------------------------------------------------------------- |
| 359 | |
| 360 | /** |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 361 | * Error |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 362 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 363 | * Returns an array containing code and message of the last |
Andrey Andreev | 71d8f72 | 2017-01-17 12:01:00 +0200 | [diff] [blame] | 364 | * database error that has occurred. |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 365 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 366 | * @return array |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 367 | */ |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 368 | public function error() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 369 | { |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 370 | 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] | 371 | } |
| 372 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 373 | // -------------------------------------------------------------------- |
| 374 | |
| 375 | /** |
Andrey Andreev | 7eaa14f | 2012-10-09 11:34:01 +0300 | [diff] [blame] | 376 | * FROM tables |
| 377 | * |
| 378 | * Groups tables in FROM clauses if needed, so there is no confusion |
| 379 | * about operator precedence. |
| 380 | * |
| 381 | * @return string |
| 382 | */ |
| 383 | protected function _from_tables() |
| 384 | { |
Andrey Andreev | fce9abe | 2012-10-09 11:37:00 +0300 | [diff] [blame] | 385 | if ( ! empty($this->qb_join) && count($this->qb_from) > 1) |
Andrey Andreev | 7eaa14f | 2012-10-09 11:34:01 +0300 | [diff] [blame] | 386 | { |
| 387 | return '('.implode(', ', $this->qb_from).')'; |
| 388 | } |
| 389 | |
| 390 | return implode(', ', $this->qb_from); |
| 391 | } |
| 392 | |
| 393 | // -------------------------------------------------------------------- |
| 394 | |
| 395 | /** |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 396 | * Close DB Connection |
| 397 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 398 | * @return void |
| 399 | */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 400 | protected function _close() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 401 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame] | 402 | cubrid_close($this->conn_id); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | } |