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 | { |
admin | 4a2ed69 | 2006-09-29 01:14:52 +0000 | [diff] [blame^] | 37 | // In SQLite, a database is created when you connect to the database. |
| 38 | // We'll return TRUE so that an error isn't generated |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 39 | return TRUE; |
| 40 | } |
| 41 | |
| 42 | // -------------------------------------------------------------------- |
| 43 | |
| 44 | /** |
| 45 | * Drop database |
| 46 | * |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 47 | * @access private |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 48 | * @param string the database name |
| 49 | * @return bool |
| 50 | */ |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 51 | function _drop_database($name) |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 52 | { |
| 53 | if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) |
| 54 | { |
| 55 | if ($this->db_debug) |
| 56 | { |
| 57 | return $this->display_error('db_unable_to_drop'); |
| 58 | } |
| 59 | return FALSE; |
| 60 | } |
| 61 | return TRUE; |
| 62 | } |
| 63 | |
| 64 | // -------------------------------------------------------------------- |
| 65 | |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 66 | /** |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 67 | * List databases |
| 68 | * |
admin | 4a2ed69 | 2006-09-29 01:14:52 +0000 | [diff] [blame^] | 69 | * I don't believe you can do a database listing with SQLite |
| 70 | * since each database is its own file. I suppose we could |
| 71 | * try reading a directory looking for SQLite files, but |
| 72 | * that doesn't seem like a terribly good idea |
| 73 | * |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 74 | * @access private |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 75 | * @return bool |
| 76 | */ |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 77 | function _list_databases() |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 78 | { |
admin | 4a2ed69 | 2006-09-29 01:14:52 +0000 | [diff] [blame^] | 79 | |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 80 | if ($this->db_debug) |
| 81 | { |
| 82 | return $this->display_error('db_unsuported_feature'); |
| 83 | } |
| 84 | return array(); |
| 85 | } |
| 86 | |
| 87 | // -------------------------------------------------------------------- |
| 88 | |
| 89 | /** |
admin | 9cd4e8e | 2006-09-25 23:26:25 +0000 | [diff] [blame] | 90 | * Show table query |
| 91 | * |
| 92 | * Generates a platform-specific query string so that the table names can be fetched |
| 93 | * |
| 94 | * @access private |
| 95 | * @return string |
| 96 | */ |
| 97 | function _list_tables() |
| 98 | { |
| 99 | return "SELECT name from sqlite_master WHERE type='table'"; |
| 100 | } |
| 101 | |
| 102 | // -------------------------------------------------------------------- |
| 103 | |
| 104 | /** |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame] | 105 | * Drop Table |
| 106 | * |
admin | 4a2ed69 | 2006-09-29 01:14:52 +0000 | [diff] [blame^] | 107 | * Unsupported feature in SQLite |
| 108 | * |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 109 | * @access private |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame] | 110 | * @return bool |
| 111 | */ |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 112 | function _drop_table($table) |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame] | 113 | { |
| 114 | if ($this->db_debug) |
| 115 | { |
| 116 | return $this->display_error('db_unsuported_feature'); |
| 117 | } |
| 118 | return array(); |
| 119 | } |
| 120 | |
| 121 | // -------------------------------------------------------------------- |
| 122 | |
| 123 | /** |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 124 | * Optimize table query |
| 125 | * |
admin | 4a2ed69 | 2006-09-29 01:14:52 +0000 | [diff] [blame^] | 126 | * Is optimization even supported in SQLite? |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 127 | * |
| 128 | * @access private |
| 129 | * @param string the table name |
| 130 | * @return object |
| 131 | */ |
| 132 | function _optimize_table($table) |
| 133 | { |
admin | 4a2ed69 | 2006-09-29 01:14:52 +0000 | [diff] [blame^] | 134 | return FALSE; |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // -------------------------------------------------------------------- |
| 138 | |
| 139 | /** |
| 140 | * Repair table query |
| 141 | * |
admin | 4a2ed69 | 2006-09-29 01:14:52 +0000 | [diff] [blame^] | 142 | * Are table repairs even supported in SQLite? |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 143 | * |
| 144 | * @access private |
| 145 | * @param string the table name |
| 146 | * @return object |
| 147 | */ |
| 148 | function _repair_table($table) |
| 149 | { |
admin | 4a2ed69 | 2006-09-29 01:14:52 +0000 | [diff] [blame^] | 150 | return return FALSE; |
admin | ab4f61b | 2006-09-25 22:12:32 +0000 | [diff] [blame] | 151 | } |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 152 | |
| 153 | |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | ?> |