admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
| 10 | * @license http://www.codeignitor.com/user_guide/license.html |
| 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * SQLite Utility Class |
| 20 | * |
| 21 | * @category Database |
| 22 | * @author Rick Ellis |
| 23 | * @link http://www.codeigniter.com/user_guide/database/ |
| 24 | */ |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 25 | class CI_DB_sqlite_utility extends CI_DB_utility { |
| 26 | |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Create database |
| 30 | * |
| 31 | * @access public |
| 32 | * @param string the database name |
| 33 | * @return bool |
| 34 | */ |
admin | 6cec6a5 | 2006-09-25 06:56:49 +0000 | [diff] [blame] | 35 | function _create_database() |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 36 | { |
| 37 | // In SQLite, a database is created when you connect to the database |
| 38 | return TRUE; |
| 39 | } |
| 40 | |
| 41 | // -------------------------------------------------------------------- |
| 42 | |
| 43 | /** |
| 44 | * Drop database |
| 45 | * |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 46 | * @access private |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 47 | * @param string the database name |
| 48 | * @return bool |
| 49 | */ |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 50 | function _drop_database($name) |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 51 | { |
| 52 | if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) |
| 53 | { |
| 54 | if ($this->db_debug) |
| 55 | { |
| 56 | return $this->display_error('db_unable_to_drop'); |
| 57 | } |
| 58 | return FALSE; |
| 59 | } |
| 60 | return TRUE; |
| 61 | } |
| 62 | |
| 63 | // -------------------------------------------------------------------- |
| 64 | |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 65 | /** |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 66 | * List databases |
| 67 | * |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 68 | * @access private |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 69 | * @return bool |
| 70 | */ |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 71 | function _list_databases() |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 72 | { |
| 73 | if ($this->db_debug) |
| 74 | { |
| 75 | return $this->display_error('db_unsuported_feature'); |
| 76 | } |
| 77 | return array(); |
| 78 | } |
| 79 | |
| 80 | // -------------------------------------------------------------------- |
| 81 | |
| 82 | /** |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame] | 83 | * Drop Table |
| 84 | * |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 85 | * @access private |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame] | 86 | * @return bool |
| 87 | */ |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 88 | function _drop_table($table) |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame] | 89 | { |
| 90 | if ($this->db_debug) |
| 91 | { |
| 92 | return $this->display_error('db_unsuported_feature'); |
| 93 | } |
| 94 | return array(); |
| 95 | } |
| 96 | |
| 97 | // -------------------------------------------------------------------- |
| 98 | |
| 99 | /** |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 100 | * Version number query string |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 101 | * |
| 102 | * @access public |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 103 | * @return string |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 104 | */ |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 105 | function _version() |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 106 | { |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 107 | return sqlite_libversion(); |
| 108 | } |
| 109 | |
| 110 | // -------------------------------------------------------------------- |
| 111 | |
| 112 | /** |
| 113 | * Show table query |
| 114 | * |
| 115 | * Generates a platform-specific query string so that the table names can be fetched |
| 116 | * |
| 117 | * @access public |
| 118 | * @return string |
| 119 | */ |
| 120 | function _show_tables() |
| 121 | { |
| 122 | return "SELECT name from sqlite_master WHERE type='table'"; |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | // -------------------------------------------------------------------- |
| 126 | |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 127 | /** |
| 128 | * Show columnn query |
| 129 | * |
| 130 | * Generates a platform-specific query string so that the column names can be fetched |
| 131 | * |
| 132 | * @access public |
| 133 | * @param string the table name |
| 134 | * @return string |
| 135 | */ |
| 136 | function _show_columns($table = '') |
| 137 | { |
| 138 | // Not supported |
| 139 | return FALSE; |
| 140 | } |
| 141 | |
| 142 | // -------------------------------------------------------------------- |
| 143 | |
| 144 | /** |
| 145 | * Field data query |
| 146 | * |
| 147 | * Generates a platform-specific query so that the column data can be retrieved |
| 148 | * |
| 149 | * @access public |
| 150 | * @param string the table name |
| 151 | * @return object |
| 152 | */ |
| 153 | function _field_data($table) |
| 154 | { |
admin | 6cec6a5 | 2006-09-25 06:56:49 +0000 | [diff] [blame] | 155 | return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 156 | } |
| 157 | |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame^] | 158 | // -------------------------------------------------------------------- |
| 159 | |
| 160 | /** |
| 161 | * Optimize table query |
| 162 | * |
| 163 | * Generates a platform-specific query so that a table can be optimized |
| 164 | * |
| 165 | * @access private |
| 166 | * @param string the table name |
| 167 | * @return object |
| 168 | */ |
| 169 | function _optimize_table($table) |
| 170 | { |
| 171 | return FALSE; // Is this supported SQLite? |
| 172 | } |
| 173 | |
| 174 | // -------------------------------------------------------------------- |
| 175 | |
| 176 | /** |
| 177 | * Repair table query |
| 178 | * |
| 179 | * Generates a platform-specific query so that a table can be repaired |
| 180 | * |
| 181 | * @access private |
| 182 | * @param string the table name |
| 183 | * @return object |
| 184 | */ |
| 185 | function _repair_table($table) |
| 186 | { |
| 187 | return return FALSE; // Is this supported in SQLite? |
| 188 | } |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 189 | |
| 190 | |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | ?> |