Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [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 |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [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 | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 9 | * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +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: |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [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 |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014 - 2015, 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 |
| 34 | * @link http://codeigniter.com |
| 35 | * @since Version 3.0.0 |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [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'); |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * SQLite3 Database Adapter Class |
| 42 | * |
| 43 | * Note: _DB is an extender class that the app controller |
Jamie Rumbelow | ffe7a0a | 2012-04-26 13:48:18 +0100 | [diff] [blame] | 44 | * creates dynamically based on whether the query builder |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 45 | * class is being used or not. |
| 46 | * |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 47 | * @package CodeIgniter |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 48 | * @subpackage Drivers |
| 49 | * @category Database |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 50 | * @author Andrey Andreev |
| 51 | * @link http://codeigniter.com/user_guide/database/ |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 52 | */ |
| 53 | class CI_DB_sqlite3_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 | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 60 | public $dbdriver = 'sqlite3'; |
| 61 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 62 | // -------------------------------------------------------------------- |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 63 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 64 | /** |
| 65 | * ORDER BY random keyword |
| 66 | * |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 67 | * @var array |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 68 | */ |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 69 | protected $_random_keyword = array('RANDOM()', 'RANDOM()'); |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 70 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 71 | // -------------------------------------------------------------------- |
| 72 | |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 73 | /** |
| 74 | * Non-persistent database connection |
| 75 | * |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame] | 76 | * @param bool $persistent |
| 77 | * @return SQLite3 |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 78 | */ |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame] | 79 | public function db_connect($persistent = FALSE) |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 80 | { |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame] | 81 | if ($persistent) |
| 82 | { |
| 83 | log_message('debug', 'SQLite3 doesn\'t support persistent connections'); |
| 84 | } |
| 85 | |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 86 | try |
| 87 | { |
| 88 | return ( ! $this->password) |
| 89 | ? new SQLite3($this->database) |
| 90 | : new SQLite3($this->database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password); |
| 91 | } |
| 92 | catch (Exception $e) |
| 93 | { |
| 94 | return FALSE; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // -------------------------------------------------------------------- |
| 99 | |
| 100 | /** |
Andrey Andreev | 80e34f9 | 2012-03-03 03:25:23 +0200 | [diff] [blame] | 101 | * Database version number |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 102 | * |
| 103 | * @return string |
| 104 | */ |
Andrey Andreev | 80e34f9 | 2012-03-03 03:25:23 +0200 | [diff] [blame] | 105 | public function version() |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 106 | { |
Andrey Andreev | 80e34f9 | 2012-03-03 03:25:23 +0200 | [diff] [blame] | 107 | if (isset($this->data_cache['version'])) |
| 108 | { |
| 109 | return $this->data_cache['version']; |
| 110 | } |
| 111 | |
Andrey Andreev | fc11dcc | 2012-06-04 16:39:19 +0300 | [diff] [blame] | 112 | $version = SQLite3::version(); |
Andrey Andreev | 80e34f9 | 2012-03-03 03:25:23 +0200 | [diff] [blame] | 113 | return $this->data_cache['version'] = $version['versionString']; |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | // -------------------------------------------------------------------- |
| 117 | |
| 118 | /** |
| 119 | * Execute the query |
| 120 | * |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 121 | * @todo Implement use of SQLite3::querySingle(), if needed |
| 122 | * @param string $sql |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 123 | * @return mixed SQLite3Result object or bool |
| 124 | */ |
| 125 | protected function _execute($sql) |
| 126 | { |
Andrey Andreev | a92c7cd | 2012-03-02 13:51:22 +0200 | [diff] [blame] | 127 | return $this->is_write_type($sql) |
| 128 | ? $this->conn_id->exec($sql) |
| 129 | : $this->conn_id->query($sql); |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // -------------------------------------------------------------------- |
| 133 | |
| 134 | /** |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 135 | * Begin Transaction |
| 136 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 137 | * @param bool $test_mode |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 138 | * @return bool |
| 139 | */ |
| 140 | public function trans_begin($test_mode = FALSE) |
| 141 | { |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 142 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 72d7a6e | 2012-01-19 16:02:32 +0200 | [diff] [blame] | 143 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 144 | { |
| 145 | return TRUE; |
| 146 | } |
| 147 | |
| 148 | // Reset the transaction failure flag. |
| 149 | // If the $test_mode flag is set to TRUE transactions will be rolled back |
| 150 | // even if the queries produce a successful result. |
| 151 | $this->_trans_failure = ($test_mode === TRUE); |
| 152 | |
| 153 | return $this->conn_id->exec('BEGIN TRANSACTION'); |
| 154 | } |
| 155 | |
| 156 | // -------------------------------------------------------------------- |
| 157 | |
| 158 | /** |
| 159 | * Commit Transaction |
| 160 | * |
| 161 | * @return bool |
| 162 | */ |
| 163 | public function trans_commit() |
| 164 | { |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 165 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 72d7a6e | 2012-01-19 16:02:32 +0200 | [diff] [blame] | 166 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 167 | { |
| 168 | return TRUE; |
| 169 | } |
| 170 | |
| 171 | return $this->conn_id->exec('END TRANSACTION'); |
| 172 | } |
| 173 | |
| 174 | // -------------------------------------------------------------------- |
| 175 | |
| 176 | /** |
| 177 | * Rollback Transaction |
| 178 | * |
| 179 | * @return bool |
| 180 | */ |
| 181 | public function trans_rollback() |
| 182 | { |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 183 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 72d7a6e | 2012-01-19 16:02:32 +0200 | [diff] [blame] | 184 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 185 | { |
| 186 | return TRUE; |
| 187 | } |
| 188 | |
| 189 | return $this->conn_id->exec('ROLLBACK'); |
| 190 | } |
| 191 | |
| 192 | // -------------------------------------------------------------------- |
| 193 | |
| 194 | /** |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 195 | * Platform-dependant string escape |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 196 | * |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 197 | * @param string |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 198 | * @return string |
| 199 | */ |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 200 | protected function _escape_str($str) |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 201 | { |
Andrey Andreev | 62fad28 | 2014-06-19 15:25:40 +0300 | [diff] [blame] | 202 | return $this->conn_id->escapeString($str); |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | // -------------------------------------------------------------------- |
| 206 | |
| 207 | /** |
| 208 | * Affected Rows |
| 209 | * |
| 210 | * @return int |
| 211 | */ |
| 212 | public function affected_rows() |
| 213 | { |
| 214 | return $this->conn_id->changes(); |
| 215 | } |
| 216 | |
| 217 | // -------------------------------------------------------------------- |
| 218 | |
| 219 | /** |
| 220 | * Insert ID |
| 221 | * |
| 222 | * @return int |
| 223 | */ |
| 224 | public function insert_id() |
| 225 | { |
| 226 | return $this->conn_id->lastInsertRowID(); |
| 227 | } |
| 228 | |
| 229 | // -------------------------------------------------------------------- |
| 230 | |
| 231 | /** |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 232 | * Show table query |
| 233 | * |
| 234 | * Generates a platform-specific query string so that the table names can be fetched |
| 235 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 236 | * @param bool $prefix_limit |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 237 | * @return string |
| 238 | */ |
| 239 | protected function _list_tables($prefix_limit = FALSE) |
| 240 | { |
| 241 | return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' |
| 242 | .(($prefix_limit !== FALSE && $this->dbprefix != '') |
| 243 | ? ' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix).'%\' '.sprintf($this->_like_escape_str, $this->_like_escape_chr) |
| 244 | : ''); |
| 245 | } |
| 246 | |
| 247 | // -------------------------------------------------------------------- |
| 248 | |
| 249 | /** |
Andrey Andreev | 0f85090 | 2015-04-29 12:33:11 +0300 | [diff] [blame^] | 250 | * Fetch Field Names |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 251 | * |
Andrey Andreev | 0f85090 | 2015-04-29 12:33:11 +0300 | [diff] [blame^] | 252 | * @param string $table Table name |
| 253 | * @return array |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 254 | */ |
Andrey Andreev | 0f85090 | 2015-04-29 12:33:11 +0300 | [diff] [blame^] | 255 | public function list_fields($table) |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 256 | { |
Andrey Andreev | 0f85090 | 2015-04-29 12:33:11 +0300 | [diff] [blame^] | 257 | // Is there a cached result? |
| 258 | if (isset($this->data_cache['field_names'][$table])) |
| 259 | { |
| 260 | return $this->data_cache['field_names'][$table]; |
| 261 | } |
| 262 | |
| 263 | if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) |
| 264 | { |
| 265 | return FALSE; |
| 266 | } |
| 267 | |
| 268 | $this->data_cache['field_names'][$table] = array(); |
| 269 | foreach ($result as $row) |
| 270 | { |
| 271 | $this->data_cache['field_names'][$table][] = $row['name']; |
| 272 | } |
| 273 | |
| 274 | return $this->data_cache['field_names'][$table]; |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | // -------------------------------------------------------------------- |
| 278 | |
| 279 | /** |
Andrey Andreev | 822e74e | 2012-11-16 02:33:30 +0200 | [diff] [blame] | 280 | * Returns an object with field data |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 281 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 282 | * @param string $table |
Andrey Andreev | 822e74e | 2012-11-16 02:33:30 +0200 | [diff] [blame] | 283 | * @return array |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 284 | */ |
Andrey Andreev | 5350f05 | 2015-01-12 12:33:37 +0200 | [diff] [blame] | 285 | public function field_data($table) |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 286 | { |
Andrey Andreev | 822e74e | 2012-11-16 02:33:30 +0200 | [diff] [blame] | 287 | if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) |
| 288 | { |
| 289 | return FALSE; |
| 290 | } |
| 291 | |
| 292 | $query = $query->result_array(); |
| 293 | if (empty($query)) |
| 294 | { |
| 295 | return FALSE; |
| 296 | } |
| 297 | |
| 298 | $retval = array(); |
| 299 | for ($i = 0, $c = count($query); $i < $c; $i++) |
| 300 | { |
| 301 | $retval[$i] = new stdClass(); |
| 302 | $retval[$i]->name = $query[$i]['name']; |
| 303 | $retval[$i]->type = $query[$i]['type']; |
| 304 | $retval[$i]->max_length = NULL; |
| 305 | $retval[$i]->default = $query[$i]['dflt_value']; |
| 306 | $retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0; |
| 307 | } |
| 308 | |
| 309 | return $retval; |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | // -------------------------------------------------------------------- |
| 313 | |
| 314 | /** |
Andrey Andreev | ebbfefa | 2012-10-05 17:46:47 +0300 | [diff] [blame] | 315 | * Error |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 316 | * |
Andrey Andreev | ebbfefa | 2012-10-05 17:46:47 +0300 | [diff] [blame] | 317 | * Returns an array containing code and message of the last |
| 318 | * database error that has occured. |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 319 | * |
Andrey Andreev | ebbfefa | 2012-10-05 17:46:47 +0300 | [diff] [blame] | 320 | * @return array |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 321 | */ |
Andrey Andreev | ebbfefa | 2012-10-05 17:46:47 +0300 | [diff] [blame] | 322 | public function error() |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 323 | { |
Andrey Andreev | ebbfefa | 2012-10-05 17:46:47 +0300 | [diff] [blame] | 324 | return array('code' => $this->conn_id->lastErrorCode(), 'message' => $this->conn_id->lastErrorMsg()); |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | // -------------------------------------------------------------------- |
| 328 | |
| 329 | /** |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 330 | * Replace statement |
| 331 | * |
| 332 | * Generates a platform-specific replace string from the supplied data |
| 333 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 334 | * @param string $table Table name |
| 335 | * @param array $keys INSERT keys |
| 336 | * @param array $values INSERT values |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 337 | * @return string |
| 338 | */ |
| 339 | protected function _replace($table, $keys, $values) |
| 340 | { |
| 341 | return 'INSERT OR '.parent::_replace($table, $keys, $values); |
| 342 | } |
| 343 | |
| 344 | // -------------------------------------------------------------------- |
| 345 | |
| 346 | /** |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 347 | * Truncate statement |
| 348 | * |
| 349 | * Generates a platform-specific truncate string from the supplied data |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 350 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 351 | * If the database does not support the TRUNCATE statement, |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 352 | * then this method maps to 'DELETE FROM table' |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 353 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 354 | * @param string $table |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 355 | * @return string |
| 356 | */ |
| 357 | protected function _truncate($table) |
| 358 | { |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 359 | return 'DELETE FROM '.$table; |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | // -------------------------------------------------------------------- |
| 363 | |
| 364 | /** |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 365 | * Close DB Connection |
| 366 | * |
| 367 | * @return void |
| 368 | */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 369 | protected function _close() |
Andrey Andreev | 8ae24c5 | 2012-01-16 13:05:23 +0200 | [diff] [blame] | 370 | { |
| 371 | $this->conn_id->close(); |
| 372 | } |
| 373 | |
| 374 | } |