Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +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 | d903878 | 2012-01-26 12:38:49 +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 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [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) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 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'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 29 | /** |
| 30 | * SQLite 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 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 34 | * class is being used or not. |
| 35 | * |
| 36 | * @package CodeIgniter |
| 37 | * @subpackage Drivers |
| 38 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 39 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | * @link http://codeigniter.com/user_guide/database/ |
| 41 | */ |
| 42 | class CI_DB_sqlite_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 | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 49 | public $dbdriver = 'sqlite'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 50 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 51 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 53 | /** |
| 54 | * ORDER BY random keyword |
| 55 | * |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 56 | * @var array |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 57 | */ |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 58 | protected $_random_keyword = array('RANDOM()', 'RANDOM()'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 59 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 60 | // -------------------------------------------------------------------- |
| 61 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 62 | /** |
| 63 | * Non-persistent database connection |
| 64 | * |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame^] | 65 | * @param bool $persistent |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 66 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 67 | */ |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame^] | 68 | public function db_connect($persistent = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 69 | { |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame^] | 70 | $error = NULL; |
| 71 | $conn_id = ($persistent === TRUE) |
| 72 | ? sqlite_popen($this->database, 0666, $error) |
| 73 | : sqlite_open($this->database, 0666, $error); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 74 | |
Andrey Andreev | 2e17102 | 2014-02-25 15:21:41 +0200 | [diff] [blame^] | 75 | isset($error) && log_message('error', $error); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 76 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 77 | return $conn_id; |
| 78 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 79 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 80 | // -------------------------------------------------------------------- |
| 81 | |
| 82 | /** |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 83 | * Database version number |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 84 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 85 | * @return string |
| 86 | */ |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 87 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 88 | { |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 89 | return isset($this->data_cache['version']) |
| 90 | ? $this->data_cache['version'] |
| 91 | : $this->data_cache['version'] = sqlite_libversion(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 92 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 93 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 94 | // -------------------------------------------------------------------- |
| 95 | |
| 96 | /** |
| 97 | * Execute the query |
| 98 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 99 | * @param string $sql an SQL query |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 101 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 102 | protected function _execute($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 103 | { |
Andrey Andreev | a0c2785 | 2012-03-02 13:49:28 +0200 | [diff] [blame] | 104 | return $this->is_write_type($sql) |
| 105 | ? @sqlite_exec($this->conn_id, $sql) |
| 106 | : @sqlite_query($this->conn_id, $sql); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 107 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 108 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 109 | // -------------------------------------------------------------------- |
| 110 | |
| 111 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 112 | * Begin Transaction |
| 113 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 114 | * @param bool $test_mode |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 115 | * @return bool |
| 116 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 117 | public function trans_begin($test_mode = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 119 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 120 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 121 | { |
| 122 | return TRUE; |
| 123 | } |
| 124 | |
| 125 | // Reset the transaction failure flag. |
| 126 | // If the $test_mode flag is set to TRUE transactions will be rolled back |
| 127 | // even if the queries produce a successful result. |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 128 | $this->_trans_failure = ($test_mode === TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | |
| 130 | $this->simple_query('BEGIN TRANSACTION'); |
| 131 | return TRUE; |
| 132 | } |
| 133 | |
| 134 | // -------------------------------------------------------------------- |
| 135 | |
| 136 | /** |
| 137 | * Commit Transaction |
| 138 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 139 | * @return bool |
| 140 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 141 | public function trans_commit() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 142 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 144 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 145 | { |
| 146 | return TRUE; |
| 147 | } |
| 148 | |
| 149 | $this->simple_query('COMMIT'); |
| 150 | return TRUE; |
| 151 | } |
| 152 | |
| 153 | // -------------------------------------------------------------------- |
| 154 | |
| 155 | /** |
| 156 | * Rollback Transaction |
| 157 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 158 | * @return bool |
| 159 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 160 | public function trans_rollback() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 161 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 162 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 163 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 164 | { |
| 165 | return TRUE; |
| 166 | } |
| 167 | |
| 168 | $this->simple_query('ROLLBACK'); |
| 169 | return TRUE; |
| 170 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 171 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 172 | // -------------------------------------------------------------------- |
| 173 | |
| 174 | /** |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 175 | * Platform-dependant string escape |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 176 | * |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 177 | * @param string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 178 | * @return string |
| 179 | */ |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 180 | protected function _escape_str($str) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 181 | { |
Andrey Andreev | 0b6a492 | 2013-01-10 16:53:44 +0200 | [diff] [blame] | 182 | return sqlite_escape_string($str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 184 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | // -------------------------------------------------------------------- |
| 186 | |
| 187 | /** |
| 188 | * Affected Rows |
| 189 | * |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 190 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 192 | public function affected_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 193 | { |
| 194 | return sqlite_changes($this->conn_id); |
| 195 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 196 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 197 | // -------------------------------------------------------------------- |
| 198 | |
| 199 | /** |
| 200 | * Insert ID |
| 201 | * |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 202 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 203 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 204 | public function insert_id() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 205 | { |
| 206 | return @sqlite_last_insert_rowid($this->conn_id); |
| 207 | } |
| 208 | |
| 209 | // -------------------------------------------------------------------- |
| 210 | |
| 211 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | * List table query |
| 213 | * |
| 214 | * Generates a platform-specific query string so that the table names can be fetched |
| 215 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 216 | * @param bool $prefix_limit |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 217 | * @return string |
| 218 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 219 | protected function _list_tables($prefix_limit = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 220 | { |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 221 | $sql = "SELECT name FROM sqlite_master WHERE type='table'"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 222 | |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 223 | if ($prefix_limit !== FALSE && $this->dbprefix != '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 224 | { |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 225 | return $sql." AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 226 | } |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 227 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 228 | return $sql; |
| 229 | } |
| 230 | |
| 231 | // -------------------------------------------------------------------- |
| 232 | |
| 233 | /** |
| 234 | * Show column query |
| 235 | * |
| 236 | * Generates a platform-specific query string so that the column names can be fetched |
| 237 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 238 | * @param string $table |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 239 | * @return bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 240 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 241 | protected function _list_columns($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 242 | { |
| 243 | // Not supported |
| 244 | return FALSE; |
| 245 | } |
| 246 | |
| 247 | // -------------------------------------------------------------------- |
| 248 | |
| 249 | /** |
Andrey Andreev | 822e74e | 2012-11-16 02:33:30 +0200 | [diff] [blame] | 250 | * Returns an object with field data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 251 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 252 | * @param string $table |
Andrey Andreev | 822e74e | 2012-11-16 02:33:30 +0200 | [diff] [blame] | 253 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 254 | */ |
Andrey Andreev | 822e74e | 2012-11-16 02:33:30 +0200 | [diff] [blame] | 255 | public function field_data($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 256 | { |
Andrey Andreev | 822e74e | 2012-11-16 02:33:30 +0200 | [diff] [blame] | 257 | if ($table === '') |
| 258 | { |
| 259 | return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; |
| 260 | } |
| 261 | |
| 262 | if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) |
| 263 | { |
| 264 | return FALSE; |
| 265 | } |
| 266 | |
| 267 | $query = $query->result_array(); |
| 268 | if (empty($query)) |
| 269 | { |
| 270 | return FALSE; |
| 271 | } |
| 272 | |
| 273 | $retval = array(); |
| 274 | for ($i = 0, $c = count($query); $i < $c; $i++) |
| 275 | { |
| 276 | $retval[$i] = new stdClass(); |
| 277 | $retval[$i]->name = $query[$i]['name']; |
| 278 | $retval[$i]->type = $query[$i]['type']; |
| 279 | $retval[$i]->max_length = NULL; |
| 280 | $retval[$i]->default = $query[$i]['dflt_value']; |
| 281 | $retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0; |
| 282 | } |
| 283 | |
| 284 | return $retval; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | // -------------------------------------------------------------------- |
| 288 | |
| 289 | /** |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 290 | * Error |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 291 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 292 | * Returns an array containing code and message of the last |
| 293 | * database error that has occured. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 294 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 295 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 296 | */ |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 297 | public function error() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 298 | { |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 299 | $error = array('code' => sqlite_last_error($this->conn_id)); |
| 300 | $error['message'] = sqlite_error_string($error['code']); |
| 301 | return $error; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | // -------------------------------------------------------------------- |
| 305 | |
| 306 | /** |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 307 | * Replace statement |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 308 | * |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 309 | * Generates a platform-specific replace string from the supplied data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 310 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 311 | * @param string $table Table name |
| 312 | * @param array $keys INSERT keys |
| 313 | * @param array $values INSERT values |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 314 | * @return string |
| 315 | */ |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 316 | protected function _replace($table, $keys, $values) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 317 | { |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 318 | return 'INSERT OR '.parent::_replace($table, $keys, $values); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 320 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 321 | // -------------------------------------------------------------------- |
| 322 | |
| 323 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 324 | * Truncate statement |
| 325 | * |
| 326 | * Generates a platform-specific truncate string from the supplied data |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 327 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 328 | * If the database does not support the TRUNCATE statement, |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 329 | * then this function maps to 'DELETE FROM table' |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 331 | * @param string $table |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 332 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 333 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 334 | protected function _truncate($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 335 | { |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 336 | return 'DELETE FROM '.$table; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 337 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 338 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 339 | // -------------------------------------------------------------------- |
| 340 | |
| 341 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 342 | * Close DB Connection |
| 343 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 344 | * @return void |
| 345 | */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 346 | protected function _close() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 347 | { |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 348 | @sqlite_close($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 353 | /* End of file sqlite_driver.php */ |
Timothy Warren | 215890b | 2012-03-20 09:38:16 -0400 | [diff] [blame] | 354 | /* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ |