Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
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 |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
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 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * SQLite Database Adapter Class |
| 30 | * |
| 31 | * Note: _DB is an extender class that the app controller |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 32 | * creates dynamically based on whether the query builder |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 33 | * class is being used or not. |
| 34 | * |
| 35 | * @package CodeIgniter |
| 36 | * @subpackage Drivers |
| 37 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 38 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | * @link http://codeigniter.com/user_guide/database/ |
| 40 | */ |
| 41 | class CI_DB_sqlite_driver extends CI_DB { |
| 42 | |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 43 | public $dbdriver = 'sqlite'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 44 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 45 | // The character used to escape with - not needed for SQLite |
Andrey Andreev | d33e24c | 2012-02-12 03:23:07 +0200 | [diff] [blame] | 46 | protected $_escape_char = '"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 47 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 48 | // clause and character used for LIKE escape sequences |
Andrey Andreev | 979b528 | 2012-03-20 16:45:39 +0200 | [diff] [blame] | 49 | protected $_like_escape_str = " ESCAPE '%s' "; |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 50 | protected $_like_escape_chr = '!'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 51 | |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 52 | protected $_random_keyword = ' Random()'; // database specific random keyword |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Non-persistent database connection |
| 56 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 57 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 58 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 59 | public function db_connect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 60 | { |
| 61 | if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) |
| 62 | { |
| 63 | log_message('error', $error); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 64 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 65 | if ($this->db_debug) |
| 66 | { |
Derek Allard | fac8fbc | 2010-02-05 16:14:49 +0000 | [diff] [blame] | 67 | $this->display_error($error, '', TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 68 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 69 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 70 | return FALSE; |
| 71 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 72 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | return $conn_id; |
| 74 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 75 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 76 | // -------------------------------------------------------------------- |
| 77 | |
| 78 | /** |
| 79 | * Persistent database connection |
| 80 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 81 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 82 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 83 | public function db_pconnect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 84 | { |
| 85 | if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) |
| 86 | { |
| 87 | log_message('error', $error); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 88 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 89 | if ($this->db_debug) |
| 90 | { |
Derek Allard | fac8fbc | 2010-02-05 16:14:49 +0000 | [diff] [blame] | 91 | $this->display_error($error, '', TRUE); |
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 | return FALSE; |
| 95 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 96 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 97 | return $conn_id; |
| 98 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 99 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | // -------------------------------------------------------------------- |
| 101 | |
| 102 | /** |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 103 | * Database version number |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 104 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 105 | * @return string |
| 106 | */ |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 107 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 108 | { |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 109 | return isset($this->data_cache['version']) |
| 110 | ? $this->data_cache['version'] |
| 111 | : $this->data_cache['version'] = sqlite_libversion(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 112 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 113 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 114 | // -------------------------------------------------------------------- |
| 115 | |
| 116 | /** |
| 117 | * Execute the query |
| 118 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 119 | * @param string an SQL query |
| 120 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 121 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 122 | protected function _execute($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 123 | { |
Andrey Andreev | a0c2785 | 2012-03-02 13:49:28 +0200 | [diff] [blame] | 124 | return $this->is_write_type($sql) |
| 125 | ? @sqlite_exec($this->conn_id, $sql) |
| 126 | : @sqlite_query($this->conn_id, $sql); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 127 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 128 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | // -------------------------------------------------------------------- |
| 130 | |
| 131 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 132 | * Begin Transaction |
| 133 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 134 | * @return bool |
| 135 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 136 | public function trans_begin($test_mode = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 137 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 138 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 139 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 140 | { |
| 141 | return TRUE; |
| 142 | } |
| 143 | |
| 144 | // Reset the transaction failure flag. |
| 145 | // If the $test_mode flag is set to TRUE transactions will be rolled back |
| 146 | // even if the queries produce a successful result. |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 147 | $this->_trans_failure = ($test_mode === TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 148 | |
| 149 | $this->simple_query('BEGIN TRANSACTION'); |
| 150 | return TRUE; |
| 151 | } |
| 152 | |
| 153 | // -------------------------------------------------------------------- |
| 154 | |
| 155 | /** |
| 156 | * Commit 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_commit() |
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('COMMIT'); |
| 169 | return TRUE; |
| 170 | } |
| 171 | |
| 172 | // -------------------------------------------------------------------- |
| 173 | |
| 174 | /** |
| 175 | * Rollback Transaction |
| 176 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 177 | * @return bool |
| 178 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 179 | public function trans_rollback() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 180 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 181 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 182 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | { |
| 184 | return TRUE; |
| 185 | } |
| 186 | |
| 187 | $this->simple_query('ROLLBACK'); |
| 188 | return TRUE; |
| 189 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 190 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | // -------------------------------------------------------------------- |
| 192 | |
| 193 | /** |
| 194 | * Escape String |
| 195 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 196 | * @param string |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 197 | * @param bool whether or not the string will be used in a LIKE condition |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 198 | * @return string |
| 199 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 200 | public function escape_str($str, $like = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 201 | { |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 202 | if (is_array($str)) |
| 203 | { |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 204 | foreach ($str as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 205 | { |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 206 | $str[$key] = $this->escape_str($val, $like); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | return $str; |
| 210 | } |
| 211 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 212 | $str = sqlite_escape_string($str); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 213 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 214 | // escape LIKE condition wildcards |
| 215 | if ($like === TRUE) |
| 216 | { |
Andrey Andreev | 94708bd | 2012-03-26 12:09:28 +0300 | [diff] [blame] | 217 | return str_replace(array($this->_like_escape_chr, '%', '_'), |
Andrey Andreev | 830f5af | 2012-03-26 12:11:38 +0300 | [diff] [blame] | 218 | array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 219 | $str); |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 220 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 221 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 222 | return $str; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 223 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 224 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | // -------------------------------------------------------------------- |
| 226 | |
| 227 | /** |
| 228 | * Affected Rows |
| 229 | * |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 230 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 231 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 232 | public function affected_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 233 | { |
| 234 | return sqlite_changes($this->conn_id); |
| 235 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 236 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 237 | // -------------------------------------------------------------------- |
| 238 | |
| 239 | /** |
| 240 | * Insert ID |
| 241 | * |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 242 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 243 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 244 | public function insert_id() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 245 | { |
| 246 | return @sqlite_last_insert_rowid($this->conn_id); |
| 247 | } |
| 248 | |
| 249 | // -------------------------------------------------------------------- |
| 250 | |
| 251 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 252 | * List table query |
| 253 | * |
| 254 | * Generates a platform-specific query string so that the table names can be fetched |
| 255 | * |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 256 | * @param bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 257 | * @return string |
| 258 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 259 | protected function _list_tables($prefix_limit = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 260 | { |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 261 | $sql = "SELECT name FROM sqlite_master WHERE type='table'"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 262 | |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 263 | if ($prefix_limit !== FALSE && $this->dbprefix != '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 264 | { |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 265 | 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] | 266 | } |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 267 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 268 | return $sql; |
| 269 | } |
| 270 | |
| 271 | // -------------------------------------------------------------------- |
| 272 | |
| 273 | /** |
| 274 | * Show column query |
| 275 | * |
| 276 | * Generates a platform-specific query string so that the column names can be fetched |
| 277 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 278 | * @param string the table name |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 279 | * @return bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 281 | protected function _list_columns($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 282 | { |
| 283 | // Not supported |
| 284 | return FALSE; |
| 285 | } |
| 286 | |
| 287 | // -------------------------------------------------------------------- |
| 288 | |
| 289 | /** |
| 290 | * Field data query |
| 291 | * |
| 292 | * Generates a platform-specific query so that the column data can be retrieved |
| 293 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 294 | * @param string the table name |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 295 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 296 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 297 | protected function _field_data($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 298 | { |
Andrey Andreev | 9411557 | 2012-06-07 21:34:56 +0300 | [diff] [blame] | 299 | return 'SELECT * FROM '.$this->escape_identifiers($table).' LIMIT 1'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | // -------------------------------------------------------------------- |
| 303 | |
| 304 | /** |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 305 | * Error |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 306 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 307 | * Returns an array containing code and message of the last |
| 308 | * database error that has occured. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 309 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 310 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 311 | */ |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 312 | public function error() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 313 | { |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 314 | $error = array('code' => sqlite_last_error($this->conn_id)); |
| 315 | $error['message'] = sqlite_error_string($error['code']); |
| 316 | return $error; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | // -------------------------------------------------------------------- |
| 320 | |
| 321 | /** |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 322 | * Replace statement |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 323 | * |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 324 | * Generates a platform-specific replace string from the supplied data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 325 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 326 | * @param string the table name |
| 327 | * @param array the insert keys |
| 328 | * @param array the insert values |
| 329 | * @return string |
| 330 | */ |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 331 | protected function _replace($table, $keys, $values) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 332 | { |
Andrey Andreev | 17ceeae | 2012-04-05 15:38:30 +0300 | [diff] [blame] | 333 | return 'INSERT OR '.parent::_replace($table, $keys, $values); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 334 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 335 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 336 | // -------------------------------------------------------------------- |
| 337 | |
| 338 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 339 | * Truncate statement |
| 340 | * |
| 341 | * Generates a platform-specific truncate string from the supplied data |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 342 | * |
| 343 | * If the database does not support the truncate() command, |
| 344 | * then this function maps to 'DELETE FROM table' |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 345 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 346 | * @param string the table name |
| 347 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 348 | */ |
Andrey Andreev | d903878 | 2012-01-26 12:38:49 +0200 | [diff] [blame] | 349 | protected function _truncate($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 350 | { |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 351 | return 'DELETE FROM '.$table; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 352 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 353 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 354 | // -------------------------------------------------------------------- |
| 355 | |
| 356 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 357 | * Close DB Connection |
| 358 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 359 | * @return void |
| 360 | */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 361 | protected function _close() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 362 | { |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 363 | @sqlite_close($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 368 | /* End of file sqlite_driver.php */ |
Timothy Warren | 215890b | 2012-03-20 09:38:16 -0400 | [diff] [blame] | 369 | /* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ |