drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** 2003 April 6 |
| 3 | ** |
| 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
| 6 | ** |
| 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
| 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** This file contains code used to implement the PRAGMA command. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 13 | */ |
| 14 | #include "sqliteInt.h" |
| 15 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 16 | #if !defined(SQLITE_ENABLE_LOCKING_STYLE) |
| 17 | # if defined(__APPLE__) |
| 18 | # define SQLITE_ENABLE_LOCKING_STYLE 1 |
| 19 | # else |
| 20 | # define SQLITE_ENABLE_LOCKING_STYLE 0 |
| 21 | # endif |
| 22 | #endif |
| 23 | |
| 24 | /*************************************************************************** |
| 25 | ** The next block of code, including the PragTyp_XXXX macro definitions and |
| 26 | ** the aPragmaName[] object is composed of generated code. DO NOT EDIT. |
| 27 | ** |
| 28 | ** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun |
| 29 | ** that script. Then copy/paste the output in place of the following: |
| 30 | */ |
| 31 | #define PragTyp_HEADER_VALUE 0 |
| 32 | #define PragTyp_AUTO_VACUUM 1 |
| 33 | #define PragTyp_FLAG 2 |
| 34 | #define PragTyp_BUSY_TIMEOUT 3 |
| 35 | #define PragTyp_CACHE_SIZE 4 |
| 36 | #define PragTyp_CASE_SENSITIVE_LIKE 5 |
| 37 | #define PragTyp_COLLATION_LIST 6 |
| 38 | #define PragTyp_COMPILE_OPTIONS 7 |
| 39 | #define PragTyp_DATA_STORE_DIRECTORY 8 |
| 40 | #define PragTyp_DATABASE_LIST 9 |
| 41 | #define PragTyp_DEFAULT_CACHE_SIZE 10 |
| 42 | #define PragTyp_ENCODING 11 |
| 43 | #define PragTyp_FOREIGN_KEY_CHECK 12 |
| 44 | #define PragTyp_FOREIGN_KEY_LIST 13 |
| 45 | #define PragTyp_INCREMENTAL_VACUUM 14 |
| 46 | #define PragTyp_INDEX_INFO 15 |
| 47 | #define PragTyp_INDEX_LIST 16 |
| 48 | #define PragTyp_INTEGRITY_CHECK 17 |
| 49 | #define PragTyp_JOURNAL_MODE 18 |
| 50 | #define PragTyp_JOURNAL_SIZE_LIMIT 19 |
| 51 | #define PragTyp_LOCK_PROXY_FILE 20 |
| 52 | #define PragTyp_LOCKING_MODE 21 |
| 53 | #define PragTyp_PAGE_COUNT 22 |
| 54 | #define PragTyp_MMAP_SIZE 23 |
| 55 | #define PragTyp_PAGE_SIZE 24 |
| 56 | #define PragTyp_SECURE_DELETE 25 |
| 57 | #define PragTyp_SHRINK_MEMORY 26 |
drh | 55e85ca | 2013-09-13 21:01:56 +0000 | [diff] [blame] | 58 | #define PragTyp_SOFT_HEAP_LIMIT 27 |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 59 | #define PragTyp_STATS 28 |
| 60 | #define PragTyp_SYNCHRONOUS 29 |
| 61 | #define PragTyp_TABLE_INFO 30 |
| 62 | #define PragTyp_TEMP_STORE 31 |
| 63 | #define PragTyp_TEMP_STORE_DIRECTORY 32 |
| 64 | #define PragTyp_WAL_AUTOCHECKPOINT 33 |
| 65 | #define PragTyp_WAL_CHECKPOINT 34 |
| 66 | #define PragTyp_ACTIVATE_EXTENSIONS 35 |
| 67 | #define PragTyp_HEXKEY 36 |
| 68 | #define PragTyp_KEY 37 |
| 69 | #define PragTyp_REKEY 38 |
| 70 | #define PragTyp_LOCK_STATUS 39 |
| 71 | #define PragTyp_PARSER_TRACE 40 |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 72 | #define PragFlag_NeedSchema 0x01 |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 73 | static const struct sPragmaNames { |
drh | 77ff23f | 2013-09-13 21:03:45 +0000 | [diff] [blame] | 74 | const char *const zName; /* Name of pragma */ |
drh | d49c358 | 2013-09-13 19:00:06 +0000 | [diff] [blame] | 75 | u8 ePragTyp; /* PragTyp_XXX value */ |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 76 | u8 mPragFlag; /* Zero or more PragFlag_XXX values */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 77 | u32 iArg; /* Extra argument */ |
| 78 | } aPragmaNames[] = { |
| 79 | #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 80 | { /* zName: */ "activate_extensions", |
| 81 | /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS, |
| 82 | /* ePragFlag: */ 0, |
| 83 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 84 | #endif |
| 85 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 86 | { /* zName: */ "application_id", |
| 87 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 88 | /* ePragFlag: */ 0, |
| 89 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 90 | #endif |
| 91 | #if !defined(SQLITE_OMIT_AUTOVACUUM) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 92 | { /* zName: */ "auto_vacuum", |
| 93 | /* ePragTyp: */ PragTyp_AUTO_VACUUM, |
| 94 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 95 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 96 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 97 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 98 | #if !defined(SQLITE_OMIT_AUTOMATIC_INDEX) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 99 | { /* zName: */ "automatic_index", |
| 100 | /* ePragTyp: */ PragTyp_FLAG, |
| 101 | /* ePragFlag: */ 0, |
| 102 | /* iArg: */ SQLITE_AutoIndex }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 103 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 104 | #endif |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 105 | { /* zName: */ "busy_timeout", |
| 106 | /* ePragTyp: */ PragTyp_BUSY_TIMEOUT, |
| 107 | /* ePragFlag: */ 0, |
| 108 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 109 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 110 | { /* zName: */ "cache_size", |
| 111 | /* ePragTyp: */ PragTyp_CACHE_SIZE, |
| 112 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 113 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 114 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 115 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 116 | { /* zName: */ "cache_spill", |
| 117 | /* ePragTyp: */ PragTyp_FLAG, |
| 118 | /* ePragFlag: */ 0, |
| 119 | /* iArg: */ SQLITE_CacheSpill }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 120 | #endif |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 121 | { /* zName: */ "case_sensitive_like", |
| 122 | /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE, |
| 123 | /* ePragFlag: */ 0, |
| 124 | /* iArg: */ 0 }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 125 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 126 | { /* zName: */ "checkpoint_fullfsync", |
| 127 | /* ePragTyp: */ PragTyp_FLAG, |
| 128 | /* ePragFlag: */ 0, |
| 129 | /* iArg: */ SQLITE_CkptFullFSync }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 130 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 131 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 132 | { /* zName: */ "collation_list", |
| 133 | /* ePragTyp: */ PragTyp_COLLATION_LIST, |
| 134 | /* ePragFlag: */ 0, |
| 135 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 136 | #endif |
| 137 | #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 138 | { /* zName: */ "compile_options", |
| 139 | /* ePragTyp: */ PragTyp_COMPILE_OPTIONS, |
| 140 | /* ePragFlag: */ 0, |
| 141 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 142 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 143 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 144 | { /* zName: */ "count_changes", |
| 145 | /* ePragTyp: */ PragTyp_FLAG, |
| 146 | /* ePragFlag: */ 0, |
| 147 | /* iArg: */ SQLITE_CountRows }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 148 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 149 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 150 | { /* zName: */ "data_store_directory", |
| 151 | /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY, |
| 152 | /* ePragFlag: */ 0, |
| 153 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 154 | #endif |
| 155 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 156 | { /* zName: */ "database_list", |
| 157 | /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 158 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 159 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 160 | #endif |
| 161 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 162 | { /* zName: */ "default_cache_size", |
| 163 | /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE, |
| 164 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 165 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 166 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 167 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 168 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 169 | { /* zName: */ "defer_foreign_keys", |
| 170 | /* ePragTyp: */ PragTyp_FLAG, |
| 171 | /* ePragFlag: */ 0, |
| 172 | /* iArg: */ SQLITE_DeferFKs }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 173 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 174 | #endif |
| 175 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 176 | { /* zName: */ "empty_result_callbacks", |
| 177 | /* ePragTyp: */ PragTyp_FLAG, |
| 178 | /* ePragFlag: */ 0, |
| 179 | /* iArg: */ SQLITE_NullCallback }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 180 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 181 | #if !defined(SQLITE_OMIT_UTF16) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 182 | { /* zName: */ "encoding", |
| 183 | /* ePragTyp: */ PragTyp_ENCODING, |
| 184 | /* ePragFlag: */ 0, |
| 185 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 186 | #endif |
| 187 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 188 | { /* zName: */ "foreign_key_check", |
| 189 | /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK, |
| 190 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 191 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 192 | #endif |
| 193 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 194 | { /* zName: */ "foreign_key_list", |
| 195 | /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST, |
| 196 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 197 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 198 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 199 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 200 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 201 | { /* zName: */ "foreign_keys", |
| 202 | /* ePragTyp: */ PragTyp_FLAG, |
| 203 | /* ePragFlag: */ 0, |
| 204 | /* iArg: */ SQLITE_ForeignKeys }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 205 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 206 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 207 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 208 | { /* zName: */ "freelist_count", |
| 209 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 210 | /* ePragFlag: */ 0, |
| 211 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 212 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 213 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 214 | { /* zName: */ "full_column_names", |
| 215 | /* ePragTyp: */ PragTyp_FLAG, |
| 216 | /* ePragFlag: */ 0, |
| 217 | /* iArg: */ SQLITE_FullColNames }, |
| 218 | { /* zName: */ "fullfsync", |
| 219 | /* ePragTyp: */ PragTyp_FLAG, |
| 220 | /* ePragFlag: */ 0, |
| 221 | /* iArg: */ SQLITE_FullFSync }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 222 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 223 | #if defined(SQLITE_HAS_CODEC) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 224 | { /* zName: */ "hexkey", |
| 225 | /* ePragTyp: */ PragTyp_HEXKEY, |
| 226 | /* ePragFlag: */ 0, |
| 227 | /* iArg: */ 0 }, |
drh | 8ab8832 | 2013-10-07 00:36:01 +0000 | [diff] [blame] | 228 | { /* zName: */ "hexrekey", |
| 229 | /* ePragTyp: */ PragTyp_HEXKEY, |
| 230 | /* ePragFlag: */ 0, |
| 231 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 232 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 233 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 234 | #if !defined(SQLITE_OMIT_CHECK) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 235 | { /* zName: */ "ignore_check_constraints", |
| 236 | /* ePragTyp: */ PragTyp_FLAG, |
| 237 | /* ePragFlag: */ 0, |
| 238 | /* iArg: */ SQLITE_IgnoreChecks }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 239 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 240 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 241 | #if !defined(SQLITE_OMIT_AUTOVACUUM) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 242 | { /* zName: */ "incremental_vacuum", |
| 243 | /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM, |
| 244 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 245 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 246 | #endif |
| 247 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 248 | { /* zName: */ "index_info", |
| 249 | /* ePragTyp: */ PragTyp_INDEX_INFO, |
| 250 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 251 | /* iArg: */ 0 }, |
| 252 | { /* zName: */ "index_list", |
| 253 | /* ePragTyp: */ PragTyp_INDEX_LIST, |
| 254 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 255 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 256 | #endif |
| 257 | #if !defined(SQLITE_OMIT_INTEGRITY_CHECK) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 258 | { /* zName: */ "integrity_check", |
| 259 | /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, |
| 260 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 261 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 262 | #endif |
| 263 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 264 | { /* zName: */ "journal_mode", |
| 265 | /* ePragTyp: */ PragTyp_JOURNAL_MODE, |
| 266 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 267 | /* iArg: */ 0 }, |
| 268 | { /* zName: */ "journal_size_limit", |
| 269 | /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT, |
| 270 | /* ePragFlag: */ 0, |
| 271 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 272 | #endif |
| 273 | #if defined(SQLITE_HAS_CODEC) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 274 | { /* zName: */ "key", |
| 275 | /* ePragTyp: */ PragTyp_KEY, |
| 276 | /* ePragFlag: */ 0, |
| 277 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 278 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 279 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 280 | { /* zName: */ "legacy_file_format", |
| 281 | /* ePragTyp: */ PragTyp_FLAG, |
| 282 | /* ePragFlag: */ 0, |
| 283 | /* iArg: */ SQLITE_LegacyFileFmt }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 284 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 285 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 286 | { /* zName: */ "lock_proxy_file", |
| 287 | /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE, |
| 288 | /* ePragFlag: */ 0, |
| 289 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 290 | #endif |
| 291 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 292 | { /* zName: */ "lock_status", |
| 293 | /* ePragTyp: */ PragTyp_LOCK_STATUS, |
| 294 | /* ePragFlag: */ 0, |
| 295 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 296 | #endif |
| 297 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 298 | { /* zName: */ "locking_mode", |
| 299 | /* ePragTyp: */ PragTyp_LOCKING_MODE, |
| 300 | /* ePragFlag: */ 0, |
| 301 | /* iArg: */ 0 }, |
| 302 | { /* zName: */ "max_page_count", |
| 303 | /* ePragTyp: */ PragTyp_PAGE_COUNT, |
| 304 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 305 | /* iArg: */ 0 }, |
| 306 | { /* zName: */ "mmap_size", |
| 307 | /* ePragTyp: */ PragTyp_MMAP_SIZE, |
| 308 | /* ePragFlag: */ 0, |
| 309 | /* iArg: */ 0 }, |
| 310 | { /* zName: */ "page_count", |
| 311 | /* ePragTyp: */ PragTyp_PAGE_COUNT, |
| 312 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 313 | /* iArg: */ 0 }, |
| 314 | { /* zName: */ "page_size", |
| 315 | /* ePragTyp: */ PragTyp_PAGE_SIZE, |
| 316 | /* ePragFlag: */ 0, |
| 317 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 318 | #endif |
| 319 | #if defined(SQLITE_DEBUG) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 320 | { /* zName: */ "parser_trace", |
| 321 | /* ePragTyp: */ PragTyp_PARSER_TRACE, |
| 322 | /* ePragFlag: */ 0, |
| 323 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 324 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 325 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 326 | { /* zName: */ "query_only", |
| 327 | /* ePragTyp: */ PragTyp_FLAG, |
| 328 | /* ePragFlag: */ 0, |
| 329 | /* iArg: */ SQLITE_QueryOnly }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 330 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 331 | #if !defined(SQLITE_OMIT_INTEGRITY_CHECK) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 332 | { /* zName: */ "quick_check", |
| 333 | /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, |
| 334 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 335 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 336 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 337 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 338 | { /* zName: */ "read_uncommitted", |
| 339 | /* ePragTyp: */ PragTyp_FLAG, |
| 340 | /* ePragFlag: */ 0, |
| 341 | /* iArg: */ SQLITE_ReadUncommitted }, |
| 342 | { /* zName: */ "recursive_triggers", |
| 343 | /* ePragTyp: */ PragTyp_FLAG, |
| 344 | /* ePragFlag: */ 0, |
| 345 | /* iArg: */ SQLITE_RecTriggers }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 346 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 347 | #if defined(SQLITE_HAS_CODEC) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 348 | { /* zName: */ "rekey", |
| 349 | /* ePragTyp: */ PragTyp_REKEY, |
| 350 | /* ePragFlag: */ 0, |
| 351 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 352 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 353 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 354 | { /* zName: */ "reverse_unordered_selects", |
| 355 | /* ePragTyp: */ PragTyp_FLAG, |
| 356 | /* ePragFlag: */ 0, |
| 357 | /* iArg: */ SQLITE_ReverseOrder }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 358 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 359 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 360 | { /* zName: */ "schema_version", |
| 361 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 362 | /* ePragFlag: */ 0, |
| 363 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 364 | #endif |
| 365 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 366 | { /* zName: */ "secure_delete", |
| 367 | /* ePragTyp: */ PragTyp_SECURE_DELETE, |
| 368 | /* ePragFlag: */ 0, |
| 369 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 370 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 371 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 372 | { /* zName: */ "short_column_names", |
| 373 | /* ePragTyp: */ PragTyp_FLAG, |
| 374 | /* ePragFlag: */ 0, |
| 375 | /* iArg: */ SQLITE_ShortColNames }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 376 | #endif |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 377 | { /* zName: */ "shrink_memory", |
| 378 | /* ePragTyp: */ PragTyp_SHRINK_MEMORY, |
| 379 | /* ePragFlag: */ 0, |
| 380 | /* iArg: */ 0 }, |
| 381 | { /* zName: */ "soft_heap_limit", |
| 382 | /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT, |
| 383 | /* ePragFlag: */ 0, |
| 384 | /* iArg: */ 0 }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 385 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 386 | #if defined(SQLITE_DEBUG) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 387 | { /* zName: */ "sql_trace", |
| 388 | /* ePragTyp: */ PragTyp_FLAG, |
| 389 | /* ePragFlag: */ 0, |
| 390 | /* iArg: */ SQLITE_SqlTrace }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 391 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 392 | #endif |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 393 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 394 | { /* zName: */ "stats", |
| 395 | /* ePragTyp: */ PragTyp_STATS, |
| 396 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 397 | /* iArg: */ 0 }, |
| 398 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 399 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 400 | { /* zName: */ "synchronous", |
| 401 | /* ePragTyp: */ PragTyp_SYNCHRONOUS, |
| 402 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 403 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 404 | #endif |
| 405 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 406 | { /* zName: */ "table_info", |
| 407 | /* ePragTyp: */ PragTyp_TABLE_INFO, |
| 408 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 409 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 410 | #endif |
| 411 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 412 | { /* zName: */ "temp_store", |
| 413 | /* ePragTyp: */ PragTyp_TEMP_STORE, |
| 414 | /* ePragFlag: */ 0, |
| 415 | /* iArg: */ 0 }, |
| 416 | { /* zName: */ "temp_store_directory", |
| 417 | /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY, |
| 418 | /* ePragFlag: */ 0, |
| 419 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 420 | #endif |
| 421 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 422 | { /* zName: */ "user_version", |
| 423 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 424 | /* ePragFlag: */ 0, |
| 425 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 426 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 427 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 428 | #if defined(SQLITE_DEBUG) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 429 | { /* zName: */ "vdbe_addoptrace", |
| 430 | /* ePragTyp: */ PragTyp_FLAG, |
| 431 | /* ePragFlag: */ 0, |
| 432 | /* iArg: */ SQLITE_VdbeAddopTrace }, |
| 433 | { /* zName: */ "vdbe_debug", |
| 434 | /* ePragTyp: */ PragTyp_FLAG, |
| 435 | /* ePragFlag: */ 0, |
| 436 | /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace }, |
drh | 84e55a8 | 2013-11-13 17:58:23 +0000 | [diff] [blame] | 437 | { /* zName: */ "vdbe_eqp", |
| 438 | /* ePragTyp: */ PragTyp_FLAG, |
| 439 | /* ePragFlag: */ 0, |
| 440 | /* iArg: */ SQLITE_VdbeEQP }, |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 441 | { /* zName: */ "vdbe_listing", |
| 442 | /* ePragTyp: */ PragTyp_FLAG, |
| 443 | /* ePragFlag: */ 0, |
| 444 | /* iArg: */ SQLITE_VdbeListing }, |
| 445 | { /* zName: */ "vdbe_trace", |
| 446 | /* ePragTyp: */ PragTyp_FLAG, |
| 447 | /* ePragFlag: */ 0, |
| 448 | /* iArg: */ SQLITE_VdbeTrace }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 449 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 450 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 451 | #if !defined(SQLITE_OMIT_WAL) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 452 | { /* zName: */ "wal_autocheckpoint", |
| 453 | /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT, |
| 454 | /* ePragFlag: */ 0, |
| 455 | /* iArg: */ 0 }, |
| 456 | { /* zName: */ "wal_checkpoint", |
| 457 | /* ePragTyp: */ PragTyp_WAL_CHECKPOINT, |
| 458 | /* ePragFlag: */ PragFlag_NeedSchema, |
| 459 | /* iArg: */ 0 }, |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 460 | #endif |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 461 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 462 | { /* zName: */ "writable_schema", |
| 463 | /* ePragTyp: */ PragTyp_FLAG, |
| 464 | /* ePragFlag: */ 0, |
| 465 | /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
mistachkin | dd19783 | 2013-10-21 23:17:23 +0000 | [diff] [blame] | 466 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 467 | }; |
drh | 84e55a8 | 2013-11-13 17:58:23 +0000 | [diff] [blame] | 468 | /* Number of pragmas: 56 on by default, 69 total. */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 469 | /* End of the automatically generated pragma table. |
| 470 | ***************************************************************************/ |
| 471 | |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 472 | /* |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 473 | ** Interpret the given string as a safety level. Return 0 for OFF, |
jplyon | b1639ff | 2004-01-19 04:52:29 +0000 | [diff] [blame] | 474 | ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or |
drh | 908c005 | 2012-01-30 18:40:55 +0000 | [diff] [blame] | 475 | ** unrecognized string argument. The FULL option is disallowed |
| 476 | ** if the omitFull parameter it 1. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 477 | ** |
| 478 | ** Note that the values returned are one less that the values that |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 479 | ** should be passed into sqlite3BtreeSetSafetyLevel(). The is done |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 480 | ** to support legacy SQL code. The safety level used to be boolean |
| 481 | ** and older scripts may have used numbers 0 for OFF and 1 for ON. |
| 482 | */ |
drh | 908c005 | 2012-01-30 18:40:55 +0000 | [diff] [blame] | 483 | static u8 getSafetyLevel(const char *z, int omitFull, int dflt){ |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 484 | /* 123456789 123456789 */ |
| 485 | static const char zText[] = "onoffalseyestruefull"; |
| 486 | static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16}; |
| 487 | static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4}; |
| 488 | static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2}; |
| 489 | int i, n; |
danielk1977 | 78ca0e7 | 2009-01-20 16:53:39 +0000 | [diff] [blame] | 490 | if( sqlite3Isdigit(*z) ){ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 491 | return (u8)sqlite3Atoi(z); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 492 | } |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 493 | n = sqlite3Strlen30(z); |
drh | 908c005 | 2012-01-30 18:40:55 +0000 | [diff] [blame] | 494 | for(i=0; i<ArraySize(iLength)-omitFull; i++){ |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 495 | if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){ |
| 496 | return iValue[i]; |
| 497 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 498 | } |
drh | 908c005 | 2012-01-30 18:40:55 +0000 | [diff] [blame] | 499 | return dflt; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /* |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 503 | ** Interpret the given string as a boolean value. |
| 504 | */ |
drh | 38d9c61 | 2012-01-31 14:24:47 +0000 | [diff] [blame] | 505 | u8 sqlite3GetBoolean(const char *z, int dflt){ |
| 506 | return getSafetyLevel(z,1,dflt)!=0; |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 507 | } |
| 508 | |
drh | c7dc9bf | 2011-06-03 13:02:57 +0000 | [diff] [blame] | 509 | /* The sqlite3GetBoolean() function is used by other modules but the |
| 510 | ** remainder of this file is specific to PRAGMA processing. So omit |
| 511 | ** the rest of the file if PRAGMAs are omitted from the build. |
| 512 | */ |
| 513 | #if !defined(SQLITE_OMIT_PRAGMA) |
| 514 | |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 515 | /* |
| 516 | ** Interpret the given string as a locking mode value. |
| 517 | */ |
| 518 | static int getLockingMode(const char *z){ |
| 519 | if( z ){ |
| 520 | if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE; |
| 521 | if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL; |
| 522 | } |
| 523 | return PAGER_LOCKINGMODE_QUERY; |
| 524 | } |
| 525 | |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 526 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 527 | /* |
| 528 | ** Interpret the given string as an auto-vacuum mode value. |
| 529 | ** |
| 530 | ** The following strings, "none", "full" and "incremental" are |
| 531 | ** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively. |
| 532 | */ |
| 533 | static int getAutoVacuum(const char *z){ |
| 534 | int i; |
| 535 | if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE; |
| 536 | if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL; |
| 537 | if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR; |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 538 | i = sqlite3Atoi(z); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 539 | return (u8)((i>=0&&i<=2)?i:0); |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 540 | } |
| 541 | #endif /* ifndef SQLITE_OMIT_AUTOVACUUM */ |
| 542 | |
danielk1977 | b84f96f | 2005-01-20 11:32:23 +0000 | [diff] [blame] | 543 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
drh | 722e95a | 2004-10-25 20:33:44 +0000 | [diff] [blame] | 544 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 545 | ** Interpret the given string as a temp db location. Return 1 for file |
| 546 | ** backed temporary databases, 2 for the Red-Black tree in memory database |
| 547 | ** and 0 to use the compile-time default. |
| 548 | */ |
| 549 | static int getTempStore(const char *z){ |
| 550 | if( z[0]>='0' && z[0]<='2' ){ |
| 551 | return z[0] - '0'; |
| 552 | }else if( sqlite3StrICmp(z, "file")==0 ){ |
| 553 | return 1; |
| 554 | }else if( sqlite3StrICmp(z, "memory")==0 ){ |
| 555 | return 2; |
| 556 | }else{ |
| 557 | return 0; |
| 558 | } |
| 559 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 560 | #endif /* SQLITE_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 561 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 562 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 563 | /* |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 564 | ** Invalidate temp storage, either when the temp storage is changed |
| 565 | ** from default, or when 'file' and the temp_store_directory has changed |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 566 | */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 567 | static int invalidateTempStorage(Parse *pParse){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 568 | sqlite3 *db = pParse->db; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 569 | if( db->aDb[1].pBt!=0 ){ |
danielk1977 | 983e230 | 2008-07-08 07:35:51 +0000 | [diff] [blame] | 570 | if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 571 | sqlite3ErrorMsg(pParse, "temporary storage cannot be changed " |
| 572 | "from within a transaction"); |
| 573 | return SQLITE_ERROR; |
| 574 | } |
| 575 | sqlite3BtreeClose(db->aDb[1].pBt); |
| 576 | db->aDb[1].pBt = 0; |
drh | 81028a4 | 2012-05-15 18:28:27 +0000 | [diff] [blame] | 577 | sqlite3ResetAllSchemasOfConnection(db); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 578 | } |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 579 | return SQLITE_OK; |
| 580 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 581 | #endif /* SQLITE_PAGER_PRAGMAS */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 582 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 583 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 584 | /* |
| 585 | ** If the TEMP database is open, close it and mark the database schema |
danielk1977 | b06a0b6 | 2008-06-26 10:54:12 +0000 | [diff] [blame] | 586 | ** as needing reloading. This must be done when using the SQLITE_TEMP_STORE |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 587 | ** or DEFAULT_TEMP_STORE pragmas. |
| 588 | */ |
| 589 | static int changeTempStorage(Parse *pParse, const char *zStorageType){ |
| 590 | int ts = getTempStore(zStorageType); |
| 591 | sqlite3 *db = pParse->db; |
| 592 | if( db->temp_store==ts ) return SQLITE_OK; |
| 593 | if( invalidateTempStorage( pParse ) != SQLITE_OK ){ |
| 594 | return SQLITE_ERROR; |
| 595 | } |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 596 | db->temp_store = (u8)ts; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 597 | return SQLITE_OK; |
| 598 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 599 | #endif /* SQLITE_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 600 | |
| 601 | /* |
| 602 | ** Generate code to return a single integer value. |
| 603 | */ |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 604 | static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){ |
drh | 5bb7ffe | 2004-09-02 15:14:00 +0000 | [diff] [blame] | 605 | Vdbe *v = sqlite3GetVdbe(pParse); |
drh | 0a07c10 | 2008-01-03 18:03:08 +0000 | [diff] [blame] | 606 | int mem = ++pParse->nMem; |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 607 | i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value)); |
| 608 | if( pI64 ){ |
| 609 | memcpy(pI64, &value, sizeof(value)); |
| 610 | } |
| 611 | sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64); |
drh | 1086172 | 2009-04-07 00:49:16 +0000 | [diff] [blame] | 612 | sqlite3VdbeSetNumCols(v, 1); |
| 613 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC); |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 614 | sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 615 | } |
| 616 | |
drh | d3605a4 | 2013-08-17 15:42:29 +0000 | [diff] [blame] | 617 | |
| 618 | /* |
| 619 | ** Set the safety_level and pager flags for pager iDb. Or if iDb<0 |
| 620 | ** set these values for all pagers. |
| 621 | */ |
| 622 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 623 | static void setAllPagerFlags(sqlite3 *db){ |
| 624 | if( db->autoCommit ){ |
| 625 | Db *pDb = db->aDb; |
| 626 | int n = db->nDb; |
| 627 | assert( SQLITE_FullFSync==PAGER_FULLFSYNC ); |
| 628 | assert( SQLITE_CkptFullFSync==PAGER_CKPT_FULLFSYNC ); |
| 629 | assert( SQLITE_CacheSpill==PAGER_CACHESPILL ); |
| 630 | assert( (PAGER_FULLFSYNC | PAGER_CKPT_FULLFSYNC | PAGER_CACHESPILL) |
| 631 | == PAGER_FLAGS_MASK ); |
| 632 | assert( (pDb->safety_level & PAGER_SYNCHRONOUS_MASK)==pDb->safety_level ); |
| 633 | while( (n--) > 0 ){ |
| 634 | if( pDb->pBt ){ |
| 635 | sqlite3BtreeSetPagerFlags(pDb->pBt, |
| 636 | pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) ); |
| 637 | } |
| 638 | pDb++; |
| 639 | } |
| 640 | } |
| 641 | } |
drh | feb56e0 | 2013-08-23 17:33:46 +0000 | [diff] [blame] | 642 | #else |
| 643 | # define setAllPagerFlags(X) /* no-op */ |
drh | d3605a4 | 2013-08-17 15:42:29 +0000 | [diff] [blame] | 644 | #endif |
| 645 | |
| 646 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 647 | /* |
| 648 | ** Return a human-readable name for a constraint resolution action. |
| 649 | */ |
dan | ba9108b | 2009-09-22 07:13:42 +0000 | [diff] [blame] | 650 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 651 | static const char *actionName(u8 action){ |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 652 | const char *zName; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 653 | switch( action ){ |
dan | 1da40a3 | 2009-09-19 17:00:31 +0000 | [diff] [blame] | 654 | case OE_SetNull: zName = "SET NULL"; break; |
| 655 | case OE_SetDflt: zName = "SET DEFAULT"; break; |
| 656 | case OE_Cascade: zName = "CASCADE"; break; |
| 657 | case OE_Restrict: zName = "RESTRICT"; break; |
| 658 | default: zName = "NO ACTION"; |
| 659 | assert( action==OE_None ); break; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 660 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 661 | return zName; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 662 | } |
dan | ba9108b | 2009-09-22 07:13:42 +0000 | [diff] [blame] | 663 | #endif |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 664 | |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 665 | |
| 666 | /* |
| 667 | ** Parameter eMode must be one of the PAGER_JOURNALMODE_XXX constants |
| 668 | ** defined in pager.h. This function returns the associated lowercase |
| 669 | ** journal-mode name. |
| 670 | */ |
| 671 | const char *sqlite3JournalModename(int eMode){ |
| 672 | static char * const azModeName[] = { |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 673 | "delete", "persist", "off", "truncate", "memory" |
| 674 | #ifndef SQLITE_OMIT_WAL |
| 675 | , "wal" |
| 676 | #endif |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 677 | }; |
| 678 | assert( PAGER_JOURNALMODE_DELETE==0 ); |
| 679 | assert( PAGER_JOURNALMODE_PERSIST==1 ); |
| 680 | assert( PAGER_JOURNALMODE_OFF==2 ); |
| 681 | assert( PAGER_JOURNALMODE_TRUNCATE==3 ); |
| 682 | assert( PAGER_JOURNALMODE_MEMORY==4 ); |
| 683 | assert( PAGER_JOURNALMODE_WAL==5 ); |
| 684 | assert( eMode>=0 && eMode<=ArraySize(azModeName) ); |
| 685 | |
| 686 | if( eMode==ArraySize(azModeName) ) return 0; |
| 687 | return azModeName[eMode]; |
| 688 | } |
| 689 | |
drh | 8722318 | 2004-02-21 14:00:29 +0000 | [diff] [blame] | 690 | /* |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 691 | ** Process a pragma statement. |
| 692 | ** |
| 693 | ** Pragmas are of this form: |
| 694 | ** |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 695 | ** PRAGMA [database.]id [= value] |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 696 | ** |
| 697 | ** The identifier might also be a string. The value is a string, and |
| 698 | ** identifier, or a number. If minusFlag is true, then the value is |
| 699 | ** a number that was preceded by a minus sign. |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 700 | ** |
| 701 | ** If the left side is "database.id" then pId1 is the database name |
| 702 | ** and pId2 is the id. If the left side is just "id" then pId1 is the |
| 703 | ** id and pId2 is any empty string. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 704 | */ |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 705 | void sqlite3Pragma( |
| 706 | Parse *pParse, |
| 707 | Token *pId1, /* First part of [database.]id field */ |
| 708 | Token *pId2, /* Second part of [database.]id field, or NULL */ |
| 709 | Token *pValue, /* Token for <value>, or NULL */ |
| 710 | int minusFlag /* True if a '-' sign preceded <value> */ |
| 711 | ){ |
| 712 | char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */ |
| 713 | char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */ |
| 714 | const char *zDb = 0; /* The database name */ |
| 715 | Token *pId; /* Pointer to <id> token */ |
drh | 3fa9730 | 2012-02-22 16:58:36 +0000 | [diff] [blame] | 716 | char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 717 | int iDb; /* Database index for <database> */ |
| 718 | int lwr, upr, mid; /* Binary search bounds */ |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 719 | int rc; /* return value form SQLITE_FCNTL_PRAGMA */ |
| 720 | sqlite3 *db = pParse->db; /* The database connection */ |
| 721 | Db *pDb; /* The specific database being pragmaed */ |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 722 | Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */ |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 723 | |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 724 | if( v==0 ) return; |
drh | 4611d92 | 2010-02-25 14:47:01 +0000 | [diff] [blame] | 725 | sqlite3VdbeRunOnlyOnce(v); |
drh | 9cbf342 | 2008-01-17 16:22:13 +0000 | [diff] [blame] | 726 | pParse->nMem = 2; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 727 | |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 728 | /* Interpret the [database.] part of the pragma statement. iDb is the |
| 729 | ** index of the database this pragma is being applied to in db.aDb[]. */ |
| 730 | iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId); |
| 731 | if( iDb<0 ) return; |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 732 | pDb = &db->aDb[iDb]; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 733 | |
danielk1977 | ddfb2f0 | 2006-02-17 12:25:14 +0000 | [diff] [blame] | 734 | /* If the temp database has been explicitly named as part of the |
| 735 | ** pragma, make sure it is open. |
| 736 | */ |
| 737 | if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){ |
| 738 | return; |
| 739 | } |
| 740 | |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 741 | zLeft = sqlite3NameFromToken(db, pId); |
danielk1977 | 96fb0dd | 2004-06-30 09:49:22 +0000 | [diff] [blame] | 742 | if( !zLeft ) return; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 743 | if( minusFlag ){ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 744 | zRight = sqlite3MPrintf(db, "-%T", pValue); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 745 | }else{ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 746 | zRight = sqlite3NameFromToken(db, pValue); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 747 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 748 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 749 | assert( pId2 ); |
| 750 | zDb = pId2->n>0 ? pDb->zName : 0; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 751 | if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){ |
danielk1977 | e004840 | 2004-06-15 16:51:01 +0000 | [diff] [blame] | 752 | goto pragma_out; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 753 | } |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 754 | |
| 755 | /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS |
| 756 | ** connection. If it returns SQLITE_OK, then assume that the VFS |
| 757 | ** handled the pragma and generate a no-op prepared statement. |
| 758 | */ |
drh | 3fa9730 | 2012-02-22 16:58:36 +0000 | [diff] [blame] | 759 | aFcntl[0] = 0; |
| 760 | aFcntl[1] = zLeft; |
| 761 | aFcntl[2] = zRight; |
| 762 | aFcntl[3] = 0; |
dan | 80bb6f8 | 2012-10-01 18:44:33 +0000 | [diff] [blame] | 763 | db->busyHandler.nBusy = 0; |
drh | 06fd5d6 | 2012-02-22 14:45:19 +0000 | [diff] [blame] | 764 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl); |
| 765 | if( rc==SQLITE_OK ){ |
drh | 3fa9730 | 2012-02-22 16:58:36 +0000 | [diff] [blame] | 766 | if( aFcntl[0] ){ |
| 767 | int mem = ++pParse->nMem; |
| 768 | sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0); |
| 769 | sqlite3VdbeSetNumCols(v, 1); |
| 770 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC); |
| 771 | sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); |
| 772 | sqlite3_free(aFcntl[0]); |
| 773 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 774 | goto pragma_out; |
| 775 | } |
| 776 | if( rc!=SQLITE_NOTFOUND ){ |
drh | 92c700d | 2012-02-22 19:56:17 +0000 | [diff] [blame] | 777 | if( aFcntl[0] ){ |
| 778 | sqlite3ErrorMsg(pParse, "%s", aFcntl[0]); |
| 779 | sqlite3_free(aFcntl[0]); |
| 780 | } |
| 781 | pParse->nErr++; |
| 782 | pParse->rc = rc; |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 783 | goto pragma_out; |
| 784 | } |
| 785 | |
| 786 | /* Locate the pragma in the lookup table */ |
| 787 | lwr = 0; |
| 788 | upr = ArraySize(aPragmaNames)-1; |
| 789 | while( lwr<=upr ){ |
| 790 | mid = (lwr+upr)/2; |
| 791 | rc = sqlite3_stricmp(zLeft, aPragmaNames[mid].zName); |
| 792 | if( rc==0 ) break; |
| 793 | if( rc<0 ){ |
| 794 | upr = mid - 1; |
| 795 | }else{ |
| 796 | lwr = mid + 1; |
| 797 | } |
| 798 | } |
| 799 | if( lwr>upr ) goto pragma_out; |
| 800 | |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 801 | /* Make sure the database schema is loaded if the pragma requires that */ |
| 802 | if( (aPragmaNames[mid].mPragFlag & PragFlag_NeedSchema)!=0 ){ |
| 803 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 804 | } |
| 805 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 806 | /* Jump to the appropriate pragma handler */ |
| 807 | switch( aPragmaNames[mid].ePragTyp ){ |
| 808 | |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 809 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 810 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 811 | ** PRAGMA [database.]default_cache_size |
| 812 | ** PRAGMA [database.]default_cache_size=N |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 813 | ** |
| 814 | ** The first form reports the current persistent setting for the |
| 815 | ** page cache size. The value returned is the maximum number of |
| 816 | ** pages in the page cache. The second form sets both the current |
| 817 | ** page cache size value and the persistent page cache size value |
| 818 | ** stored in the database file. |
| 819 | ** |
drh | 93791ea | 2010-04-26 17:36:35 +0000 | [diff] [blame] | 820 | ** Older versions of SQLite would set the default cache size to a |
| 821 | ** negative number to indicate synchronous=OFF. These days, synchronous |
| 822 | ** is always on by default regardless of the sign of the default cache |
| 823 | ** size. But continue to take the absolute value of the default cache |
| 824 | ** size of historical compatibility. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 825 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 826 | case PragTyp_DEFAULT_CACHE_SIZE: { |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 827 | static const int iLn = __LINE__+2; |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 828 | static const VdbeOpList getCacheSize[] = { |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 829 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 830 | { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */ |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 831 | { OP_IfPos, 1, 8, 0}, |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 832 | { OP_Integer, 0, 2, 0}, |
| 833 | { OP_Subtract, 1, 2, 1}, |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 834 | { OP_IfPos, 1, 8, 0}, |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 835 | { OP_Integer, 0, 1, 0}, /* 6 */ |
drh | ef8e986 | 2013-04-11 13:26:18 +0000 | [diff] [blame] | 836 | { OP_Noop, 0, 0, 0}, |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 837 | { OP_ResultRow, 1, 1, 0}, |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 838 | }; |
drh | 905793e | 2004-02-21 13:31:09 +0000 | [diff] [blame] | 839 | int addr; |
drh | fb98264 | 2007-08-30 01:19:59 +0000 | [diff] [blame] | 840 | sqlite3VdbeUsesBtree(v, iDb); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 841 | if( !zRight ){ |
danielk1977 | 22322fd | 2004-05-25 23:35:17 +0000 | [diff] [blame] | 842 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 843 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC); |
drh | 3c84ddf | 2008-01-09 02:15:38 +0000 | [diff] [blame] | 844 | pParse->nMem += 2; |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 845 | addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 846 | sqlite3VdbeChangeP1(v, addr, iDb); |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 847 | sqlite3VdbeChangeP1(v, addr+1, iDb); |
| 848 | sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 849 | }else{ |
drh | d50ffc4 | 2011-03-08 02:38:28 +0000 | [diff] [blame] | 850 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 851 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
drh | 9cbf342 | 2008-01-17 16:22:13 +0000 | [diff] [blame] | 852 | sqlite3VdbeAddOp2(v, OP_Integer, size, 1); |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 853 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1); |
drh | 2120608 | 2011-04-04 18:22:02 +0000 | [diff] [blame] | 854 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 855 | pDb->pSchema->cache_size = size; |
| 856 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 857 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 858 | break; |
| 859 | } |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 860 | #endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 861 | |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 862 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 863 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 864 | ** PRAGMA [database.]page_size |
| 865 | ** PRAGMA [database.]page_size=N |
| 866 | ** |
| 867 | ** The first form reports the current setting for the |
| 868 | ** database page size in bytes. The second form sets the |
| 869 | ** database page size value. The value can only be set if |
| 870 | ** the database has not yet been created. |
| 871 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 872 | case PragTyp_PAGE_SIZE: { |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 873 | Btree *pBt = pDb->pBt; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 874 | assert( pBt!=0 ); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 875 | if( !zRight ){ |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 876 | int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0; |
drh | 5bb7ffe | 2004-09-02 15:14:00 +0000 | [diff] [blame] | 877 | returnSingleInt(pParse, "page_size", size); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 878 | }else{ |
danielk1977 | 992772c | 2007-08-30 10:07:38 +0000 | [diff] [blame] | 879 | /* Malloc may fail when setting the page-size, as there is an internal |
| 880 | ** buffer that the pager module resizes using sqlite3_realloc(). |
| 881 | */ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 882 | db->nextPagesize = sqlite3Atoi(zRight); |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 883 | if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){ |
danielk1977 | 992772c | 2007-08-30 10:07:38 +0000 | [diff] [blame] | 884 | db->mallocFailed = 1; |
| 885 | } |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 886 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 887 | break; |
| 888 | } |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 889 | |
| 890 | /* |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 891 | ** PRAGMA [database.]secure_delete |
| 892 | ** PRAGMA [database.]secure_delete=ON/OFF |
| 893 | ** |
| 894 | ** The first form reports the current setting for the |
| 895 | ** secure_delete flag. The second form changes the secure_delete |
| 896 | ** flag setting and reports thenew value. |
| 897 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 898 | case PragTyp_SECURE_DELETE: { |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 899 | Btree *pBt = pDb->pBt; |
| 900 | int b = -1; |
| 901 | assert( pBt!=0 ); |
| 902 | if( zRight ){ |
drh | 38d9c61 | 2012-01-31 14:24:47 +0000 | [diff] [blame] | 903 | b = sqlite3GetBoolean(zRight, 0); |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 904 | } |
drh | af034ed | 2010-02-12 19:46:26 +0000 | [diff] [blame] | 905 | if( pId2->n==0 && b>=0 ){ |
| 906 | int ii; |
| 907 | for(ii=0; ii<db->nDb; ii++){ |
| 908 | sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b); |
| 909 | } |
| 910 | } |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 911 | b = sqlite3BtreeSecureDelete(pBt, b); |
| 912 | returnSingleInt(pParse, "secure_delete", b); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 913 | break; |
| 914 | } |
drh | 5b47efa | 2010-02-12 18:18:39 +0000 | [diff] [blame] | 915 | |
| 916 | /* |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 917 | ** PRAGMA [database.]max_page_count |
| 918 | ** PRAGMA [database.]max_page_count=N |
| 919 | ** |
| 920 | ** The first form reports the current setting for the |
| 921 | ** maximum number of pages in the database file. The |
| 922 | ** second form attempts to change this setting. Both |
| 923 | ** forms return the current setting. |
| 924 | ** |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 925 | ** The absolute value of N is used. This is undocumented and might |
| 926 | ** change. The only purpose is to provide an easy way to test |
| 927 | ** the sqlite3AbsInt32() function. |
| 928 | ** |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 929 | ** PRAGMA [database.]page_count |
| 930 | ** |
| 931 | ** Return the number of pages in the specified database. |
| 932 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 933 | case PragTyp_PAGE_COUNT: { |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 934 | int iReg; |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 935 | sqlite3CodeVerifySchema(pParse, iDb); |
| 936 | iReg = ++pParse->nMem; |
drh | c522731 | 2011-10-13 17:09:01 +0000 | [diff] [blame] | 937 | if( sqlite3Tolower(zLeft[0])=='p' ){ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 938 | sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); |
| 939 | }else{ |
drh | e73c914 | 2011-11-09 16:12:24 +0000 | [diff] [blame] | 940 | sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, |
| 941 | sqlite3AbsInt32(sqlite3Atoi(zRight))); |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 942 | } |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 943 | sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1); |
| 944 | sqlite3VdbeSetNumCols(v, 1); |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 945 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 946 | break; |
| 947 | } |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 948 | |
| 949 | /* |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 950 | ** PRAGMA [database.]locking_mode |
| 951 | ** PRAGMA [database.]locking_mode = (normal|exclusive) |
| 952 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 953 | case PragTyp_LOCKING_MODE: { |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 954 | const char *zRet = "normal"; |
| 955 | int eMode = getLockingMode(zRight); |
| 956 | |
| 957 | if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){ |
| 958 | /* Simple "PRAGMA locking_mode;" statement. This is a query for |
| 959 | ** the current default locking mode (which may be different to |
| 960 | ** the locking-mode of the main database). |
| 961 | */ |
| 962 | eMode = db->dfltLockMode; |
| 963 | }else{ |
| 964 | Pager *pPager; |
| 965 | if( pId2->n==0 ){ |
| 966 | /* This indicates that no database name was specified as part |
| 967 | ** of the PRAGMA command. In this case the locking-mode must be |
| 968 | ** set on all attached databases, as well as the main db file. |
| 969 | ** |
| 970 | ** Also, the sqlite3.dfltLockMode variable is set so that |
| 971 | ** any subsequently attached databases also use the specified |
| 972 | ** locking mode. |
| 973 | */ |
| 974 | int ii; |
| 975 | assert(pDb==&db->aDb[0]); |
| 976 | for(ii=2; ii<db->nDb; ii++){ |
| 977 | pPager = sqlite3BtreePager(db->aDb[ii].pBt); |
| 978 | sqlite3PagerLockingMode(pPager, eMode); |
| 979 | } |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 980 | db->dfltLockMode = (u8)eMode; |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 981 | } |
| 982 | pPager = sqlite3BtreePager(pDb->pBt); |
| 983 | eMode = sqlite3PagerLockingMode(pPager, eMode); |
| 984 | } |
| 985 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 986 | assert( eMode==PAGER_LOCKINGMODE_NORMAL |
| 987 | || eMode==PAGER_LOCKINGMODE_EXCLUSIVE ); |
danielk1977 | 4148346 | 2007-03-24 16:45:04 +0000 | [diff] [blame] | 988 | if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){ |
| 989 | zRet = "exclusive"; |
| 990 | } |
| 991 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 992 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 993 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0); |
| 994 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 995 | break; |
| 996 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 997 | |
| 998 | /* |
| 999 | ** PRAGMA [database.]journal_mode |
drh | 3ebaee9 | 2010-05-06 21:37:22 +0000 | [diff] [blame] | 1000 | ** PRAGMA [database.]journal_mode = |
| 1001 | ** (delete|persist|off|truncate|memory|wal|off) |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 1002 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1003 | case PragTyp_JOURNAL_MODE: { |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 1004 | int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */ |
| 1005 | int ii; /* Loop counter */ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 1006 | |
| 1007 | sqlite3VdbeSetNumCols(v, 1); |
| 1008 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC); |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 1009 | |
| 1010 | if( zRight==0 ){ |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 1011 | /* If there is no "=MODE" part of the pragma, do a query for the |
| 1012 | ** current mode */ |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 1013 | eMode = PAGER_JOURNALMODE_QUERY; |
| 1014 | }else{ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 1015 | const char *zMode; |
drh | ea67883 | 2008-12-10 19:26:22 +0000 | [diff] [blame] | 1016 | int n = sqlite3Strlen30(zRight); |
drh | f77e2ac | 2010-07-07 14:33:09 +0000 | [diff] [blame] | 1017 | for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 1018 | if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break; |
| 1019 | } |
| 1020 | if( !zMode ){ |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 1021 | /* If the "=MODE" part does not match any known journal mode, |
| 1022 | ** then do a query */ |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 1023 | eMode = PAGER_JOURNALMODE_QUERY; |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 1024 | } |
| 1025 | } |
drh | c6b2a0f | 2010-07-08 17:40:37 +0000 | [diff] [blame] | 1026 | if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){ |
| 1027 | /* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */ |
| 1028 | iDb = 0; |
| 1029 | pId2->n = 1; |
| 1030 | } |
| 1031 | for(ii=db->nDb-1; ii>=0; ii--){ |
| 1032 | if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){ |
| 1033 | sqlite3VdbeUsesBtree(v, ii); |
| 1034 | sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode); |
dan | e04dc88 | 2010-04-20 18:53:15 +0000 | [diff] [blame] | 1035 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 1036 | } |
drh | 3b02013 | 2008-04-17 17:02:01 +0000 | [diff] [blame] | 1037 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1038 | break; |
| 1039 | } |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 1040 | |
| 1041 | /* |
| 1042 | ** PRAGMA [database.]journal_size_limit |
| 1043 | ** PRAGMA [database.]journal_size_limit=N |
| 1044 | ** |
drh | a9e364f | 2009-01-13 20:14:15 +0000 | [diff] [blame] | 1045 | ** Get or set the size limit on rollback journal files. |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 1046 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1047 | case PragTyp_JOURNAL_SIZE_LIMIT: { |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 1048 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 1049 | i64 iLimit = -2; |
| 1050 | if( zRight ){ |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 1051 | sqlite3Atoi64(zRight, &iLimit, sqlite3Strlen30(zRight), SQLITE_UTF8); |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 1052 | if( iLimit<-1 ) iLimit = -1; |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 1053 | } |
| 1054 | iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit); |
drh | 3c71364 | 2009-04-04 16:02:32 +0000 | [diff] [blame] | 1055 | returnSingleInt(pParse, "journal_size_limit", iLimit); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1056 | break; |
| 1057 | } |
danielk1977 | b53e496 | 2008-06-04 06:45:59 +0000 | [diff] [blame] | 1058 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1059 | #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 1060 | |
| 1061 | /* |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 1062 | ** PRAGMA [database.]auto_vacuum |
| 1063 | ** PRAGMA [database.]auto_vacuum=N |
| 1064 | ** |
drh | a9e364f | 2009-01-13 20:14:15 +0000 | [diff] [blame] | 1065 | ** Get or set the value of the database 'auto-vacuum' parameter. |
| 1066 | ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 1067 | */ |
| 1068 | #ifndef SQLITE_OMIT_AUTOVACUUM |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1069 | case PragTyp_AUTO_VACUUM: { |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 1070 | Btree *pBt = pDb->pBt; |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1071 | assert( pBt!=0 ); |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 1072 | if( !zRight ){ |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 1073 | returnSingleInt(pParse, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt)); |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 1074 | }else{ |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 1075 | int eAuto = getAutoVacuum(zRight); |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1076 | assert( eAuto>=0 && eAuto<=2 ); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 1077 | db->nextAutovac = (u8)eAuto; |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 1078 | /* Call SetAutoVacuum() to set initialize the internal auto and |
| 1079 | ** incr-vacuum flags. This is required in case this connection |
| 1080 | ** creates the database file. It is important that it is created |
| 1081 | ** as an auto-vacuum capable db. |
| 1082 | */ |
| 1083 | rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); |
| 1084 | if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){ |
| 1085 | /* When setting the auto_vacuum mode to either "full" or |
| 1086 | ** "incremental", write the value of meta[6] in the database |
| 1087 | ** file. Before writing to meta[6], check that meta[3] indicates |
| 1088 | ** that this really is an auto-vacuum capable database. |
danielk1977 | 27b1f95 | 2007-06-25 08:16:58 +0000 | [diff] [blame] | 1089 | */ |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1090 | static const int iLn = __LINE__+2; |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 1091 | static const VdbeOpList setMeta6[] = { |
| 1092 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 1093 | { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE}, |
| 1094 | { OP_If, 1, 0, 0}, /* 2 */ |
| 1095 | { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
| 1096 | { OP_Integer, 0, 1, 0}, /* 4 */ |
| 1097 | { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */ |
| 1098 | }; |
| 1099 | int iAddr; |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1100 | iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn); |
drh | f63936e | 2013-10-03 14:08:07 +0000 | [diff] [blame] | 1101 | sqlite3VdbeChangeP1(v, iAddr, iDb); |
| 1102 | sqlite3VdbeChangeP1(v, iAddr+1, iDb); |
| 1103 | sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4); |
| 1104 | sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1); |
| 1105 | sqlite3VdbeChangeP1(v, iAddr+5, iDb); |
| 1106 | sqlite3VdbeUsesBtree(v, iDb); |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 1107 | } |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 1108 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1109 | break; |
| 1110 | } |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 1111 | #endif |
| 1112 | |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 1113 | /* |
| 1114 | ** PRAGMA [database.]incremental_vacuum(N) |
| 1115 | ** |
| 1116 | ** Do N steps of incremental vacuuming on a database. |
| 1117 | */ |
| 1118 | #ifndef SQLITE_OMIT_AUTOVACUUM |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1119 | case PragTyp_INCREMENTAL_VACUUM: { |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 1120 | int iLimit, addr; |
| 1121 | if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ |
| 1122 | iLimit = 0x7fffffff; |
| 1123 | } |
| 1124 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
drh | 4c58312 | 2008-01-04 22:01:03 +0000 | [diff] [blame] | 1125 | sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1126 | addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1127 | sqlite3VdbeAddOp1(v, OP_ResultRow, 1); |
drh | 8558cde | 2008-01-05 05:20:10 +0000 | [diff] [blame] | 1128 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1129 | sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v); |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 1130 | sqlite3VdbeJumpHere(v, addr); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1131 | break; |
| 1132 | } |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 1133 | #endif |
| 1134 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1135 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 1136 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 1137 | ** PRAGMA [database.]cache_size |
| 1138 | ** PRAGMA [database.]cache_size=N |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1139 | ** |
| 1140 | ** The first form reports the current local setting for the |
drh | 3b42abb | 2011-11-09 14:23:04 +0000 | [diff] [blame] | 1141 | ** page cache size. The second form sets the local |
| 1142 | ** page cache size value. If N is positive then that is the |
| 1143 | ** number of pages in the cache. If N is negative, then the |
| 1144 | ** number of pages is adjusted so that the cache uses -N kibibytes |
| 1145 | ** of memory. |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1146 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1147 | case PragTyp_CACHE_SIZE: { |
drh | 2120608 | 2011-04-04 18:22:02 +0000 | [diff] [blame] | 1148 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1149 | if( !zRight ){ |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 1150 | returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1151 | }else{ |
drh | 3b42abb | 2011-11-09 14:23:04 +0000 | [diff] [blame] | 1152 | int size = sqlite3Atoi(zRight); |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 1153 | pDb->pSchema->cache_size = size; |
| 1154 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1155 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1156 | break; |
| 1157 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1158 | |
| 1159 | /* |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 1160 | ** PRAGMA [database.]mmap_size(N) |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 1161 | ** |
drh | 0d0614b | 2013-03-25 23:09:28 +0000 | [diff] [blame] | 1162 | ** Used to set mapping size limit. The mapping size limit is |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 1163 | ** used to limit the aggregate size of all memory mapped regions of the |
| 1164 | ** database file. If this parameter is set to zero, then memory mapping |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 1165 | ** is not used at all. If N is negative, then the default memory map |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 1166 | ** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set. |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 1167 | ** The parameter N is measured in bytes. |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 1168 | ** |
drh | 0d0614b | 2013-03-25 23:09:28 +0000 | [diff] [blame] | 1169 | ** This value is advisory. The underlying VFS is free to memory map |
| 1170 | ** as little or as much as it wants. Except, if N is set to 0 then the |
| 1171 | ** upper layers will never invoke the xFetch interfaces to the VFS. |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 1172 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1173 | case PragTyp_MMAP_SIZE: { |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 1174 | sqlite3_int64 sz; |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 1175 | #if SQLITE_MAX_MMAP_SIZE>0 |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 1176 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
drh | 0d0614b | 2013-03-25 23:09:28 +0000 | [diff] [blame] | 1177 | if( zRight ){ |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 1178 | int ii; |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 1179 | sqlite3Atoi64(zRight, &sz, sqlite3Strlen30(zRight), SQLITE_UTF8); |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 1180 | if( sz<0 ) sz = sqlite3GlobalConfig.szMmap; |
| 1181 | if( pId2->n==0 ) db->szMmap = sz; |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 1182 | for(ii=db->nDb-1; ii>=0; ii--){ |
| 1183 | if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){ |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 1184 | sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz); |
drh | a1f42c7 | 2013-04-01 22:38:06 +0000 | [diff] [blame] | 1185 | } |
| 1186 | } |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 1187 | } |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 1188 | sz = -1; |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 1189 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz); |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 1190 | #else |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 1191 | sz = 0; |
mistachkin | e98844f | 2013-08-24 00:59:24 +0000 | [diff] [blame] | 1192 | rc = SQLITE_OK; |
drh | 188d488 | 2013-04-08 20:47:49 +0000 | [diff] [blame] | 1193 | #endif |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 1194 | if( rc==SQLITE_OK ){ |
drh | 9b4c59f | 2013-04-15 17:03:42 +0000 | [diff] [blame] | 1195 | returnSingleInt(pParse, "mmap_size", sz); |
dan | 3719f5f | 2013-05-23 10:13:18 +0000 | [diff] [blame] | 1196 | }else if( rc!=SQLITE_NOTFOUND ){ |
| 1197 | pParse->nErr++; |
| 1198 | pParse->rc = rc; |
drh | 34f7490 | 2013-04-03 13:09:18 +0000 | [diff] [blame] | 1199 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1200 | break; |
| 1201 | } |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 1202 | |
| 1203 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 1204 | ** PRAGMA temp_store |
| 1205 | ** PRAGMA temp_store = "default"|"memory"|"file" |
| 1206 | ** |
| 1207 | ** Return or set the local value of the temp_store flag. Changing |
| 1208 | ** the local value does not make changes to the disk file and the default |
| 1209 | ** value will be restored the next time the database is opened. |
| 1210 | ** |
| 1211 | ** Note that it is possible for the library compile-time options to |
| 1212 | ** override this setting |
| 1213 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1214 | case PragTyp_TEMP_STORE: { |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 1215 | if( !zRight ){ |
drh | 5bb7ffe | 2004-09-02 15:14:00 +0000 | [diff] [blame] | 1216 | returnSingleInt(pParse, "temp_store", db->temp_store); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 1217 | }else{ |
| 1218 | changeTempStorage(pParse, zRight); |
| 1219 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1220 | break; |
| 1221 | } |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 1222 | |
| 1223 | /* |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1224 | ** PRAGMA temp_store_directory |
| 1225 | ** PRAGMA temp_store_directory = ""|"directory_name" |
| 1226 | ** |
| 1227 | ** Return or set the local value of the temp_store_directory flag. Changing |
| 1228 | ** the value sets a specific directory to be used for temporary files. |
| 1229 | ** Setting to a null string reverts to the default temporary directory search. |
| 1230 | ** If temporary directory is changed, then invalidateTempStorage. |
| 1231 | ** |
| 1232 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1233 | case PragTyp_TEMP_STORE_DIRECTORY: { |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1234 | if( !zRight ){ |
| 1235 | if( sqlite3_temp_directory ){ |
| 1236 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 955de52 | 2006-02-10 02:27:42 +0000 | [diff] [blame] | 1237 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1238 | "temp_store_directory", SQLITE_STATIC); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1239 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0); |
| 1240 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1241 | } |
| 1242 | }else{ |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 1243 | #ifndef SQLITE_OMIT_WSD |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 1244 | if( zRight[0] ){ |
| 1245 | int res; |
danielk1977 | fab1127 | 2008-09-16 14:38:02 +0000 | [diff] [blame] | 1246 | rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); |
| 1247 | if( rc!=SQLITE_OK || res==0 ){ |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 1248 | sqlite3ErrorMsg(pParse, "not a writable directory"); |
| 1249 | goto pragma_out; |
| 1250 | } |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 1251 | } |
danielk1977 | b06a0b6 | 2008-06-26 10:54:12 +0000 | [diff] [blame] | 1252 | if( SQLITE_TEMP_STORE==0 |
| 1253 | || (SQLITE_TEMP_STORE==1 && db->temp_store<=1) |
| 1254 | || (SQLITE_TEMP_STORE==2 && db->temp_store==1) |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 1255 | ){ |
| 1256 | invalidateTempStorage(pParse); |
| 1257 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1258 | sqlite3_free(sqlite3_temp_directory); |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 1259 | if( zRight[0] ){ |
drh | b975598 | 2010-07-24 16:34:37 +0000 | [diff] [blame] | 1260 | sqlite3_temp_directory = sqlite3_mprintf("%s", zRight); |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1261 | }else{ |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 1262 | sqlite3_temp_directory = 0; |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1263 | } |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 1264 | #endif /* SQLITE_OMIT_WSD */ |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1265 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1266 | break; |
| 1267 | } |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1268 | |
drh | cc71645 | 2012-06-06 23:23:23 +0000 | [diff] [blame] | 1269 | #if SQLITE_OS_WIN |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1270 | /* |
| 1271 | ** PRAGMA data_store_directory |
| 1272 | ** PRAGMA data_store_directory = ""|"directory_name" |
| 1273 | ** |
| 1274 | ** Return or set the local value of the data_store_directory flag. Changing |
| 1275 | ** the value sets a specific directory to be used for database files that |
| 1276 | ** were specified with a relative pathname. Setting to a null string reverts |
| 1277 | ** to the default database directory, which for database files specified with |
| 1278 | ** a relative path will probably be based on the current directory for the |
| 1279 | ** process. Database file specified with an absolute path are not impacted |
| 1280 | ** by this setting, regardless of its value. |
| 1281 | ** |
| 1282 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1283 | case PragTyp_DATA_STORE_DIRECTORY: { |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1284 | if( !zRight ){ |
| 1285 | if( sqlite3_data_directory ){ |
| 1286 | sqlite3VdbeSetNumCols(v, 1); |
| 1287 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, |
| 1288 | "data_store_directory", SQLITE_STATIC); |
| 1289 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_data_directory, 0); |
| 1290 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 1291 | } |
| 1292 | }else{ |
| 1293 | #ifndef SQLITE_OMIT_WSD |
| 1294 | if( zRight[0] ){ |
| 1295 | int res; |
| 1296 | rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); |
| 1297 | if( rc!=SQLITE_OK || res==0 ){ |
| 1298 | sqlite3ErrorMsg(pParse, "not a writable directory"); |
| 1299 | goto pragma_out; |
| 1300 | } |
| 1301 | } |
| 1302 | sqlite3_free(sqlite3_data_directory); |
| 1303 | if( zRight[0] ){ |
| 1304 | sqlite3_data_directory = sqlite3_mprintf("%s", zRight); |
| 1305 | }else{ |
| 1306 | sqlite3_data_directory = 0; |
| 1307 | } |
| 1308 | #endif /* SQLITE_OMIT_WSD */ |
| 1309 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1310 | break; |
| 1311 | } |
drh | cc71645 | 2012-06-06 23:23:23 +0000 | [diff] [blame] | 1312 | #endif |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1313 | |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1314 | #if SQLITE_ENABLE_LOCKING_STYLE |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1315 | /* |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1316 | ** PRAGMA [database.]lock_proxy_file |
| 1317 | ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path" |
| 1318 | ** |
| 1319 | ** Return or set the value of the lock_proxy_file flag. Changing |
| 1320 | ** the value sets a specific file to be used for database access locks. |
| 1321 | ** |
| 1322 | */ |
| 1323 | case PragTyp_LOCK_PROXY_FILE: { |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1324 | if( !zRight ){ |
| 1325 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 1326 | char *proxy_file_path = NULL; |
| 1327 | sqlite3_file *pFile = sqlite3PagerFile(pPager); |
drh | c02372c | 2012-01-10 17:59:59 +0000 | [diff] [blame] | 1328 | sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE, |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1329 | &proxy_file_path); |
| 1330 | |
| 1331 | if( proxy_file_path ){ |
| 1332 | sqlite3VdbeSetNumCols(v, 1); |
| 1333 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, |
| 1334 | "lock_proxy_file", SQLITE_STATIC); |
| 1335 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0); |
| 1336 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 1337 | } |
| 1338 | }else{ |
| 1339 | Pager *pPager = sqlite3BtreePager(pDb->pBt); |
| 1340 | sqlite3_file *pFile = sqlite3PagerFile(pPager); |
| 1341 | int res; |
| 1342 | if( zRight[0] ){ |
| 1343 | res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, |
| 1344 | zRight); |
| 1345 | } else { |
| 1346 | res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, |
| 1347 | NULL); |
| 1348 | } |
| 1349 | if( res!=SQLITE_OK ){ |
| 1350 | sqlite3ErrorMsg(pParse, "failed to set lock proxy file"); |
| 1351 | goto pragma_out; |
| 1352 | } |
| 1353 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1354 | break; |
| 1355 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1356 | #endif /* SQLITE_ENABLE_LOCKING_STYLE */ |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1357 | |
| 1358 | /* |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 1359 | ** PRAGMA [database.]synchronous |
| 1360 | ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1361 | ** |
| 1362 | ** Return or set the local value of the synchronous flag. Changing |
| 1363 | ** the local value does not make changes to the disk file and the |
| 1364 | ** default value will be restored the next time the database is |
| 1365 | ** opened. |
| 1366 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1367 | case PragTyp_SYNCHRONOUS: { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1368 | if( !zRight ){ |
drh | 5bb7ffe | 2004-09-02 15:14:00 +0000 | [diff] [blame] | 1369 | returnSingleInt(pParse, "synchronous", pDb->safety_level-1); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1370 | }else{ |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1371 | if( !db->autoCommit ){ |
| 1372 | sqlite3ErrorMsg(pParse, |
| 1373 | "Safety level may not be changed inside a transaction"); |
| 1374 | }else{ |
drh | 908c005 | 2012-01-30 18:40:55 +0000 | [diff] [blame] | 1375 | pDb->safety_level = getSafetyLevel(zRight,0,1)+1; |
drh | d3605a4 | 2013-08-17 15:42:29 +0000 | [diff] [blame] | 1376 | setAllPagerFlags(db); |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1377 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1378 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1379 | break; |
| 1380 | } |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1381 | #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1382 | |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 1383 | #ifndef SQLITE_OMIT_FLAG_PRAGMAS |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1384 | case PragTyp_FLAG: { |
| 1385 | if( zRight==0 ){ |
| 1386 | returnSingleInt(pParse, aPragmaNames[mid].zName, |
| 1387 | (db->flags & aPragmaNames[mid].iArg)!=0 ); |
| 1388 | }else{ |
| 1389 | int mask = aPragmaNames[mid].iArg; /* Mask of bits to set or clear. */ |
| 1390 | if( db->autoCommit==0 ){ |
| 1391 | /* Foreign key support may not be enabled or disabled while not |
| 1392 | ** in auto-commit mode. */ |
| 1393 | mask &= ~(SQLITE_ForeignKeys); |
| 1394 | } |
| 1395 | |
| 1396 | if( sqlite3GetBoolean(zRight, 0) ){ |
| 1397 | db->flags |= mask; |
| 1398 | }else{ |
| 1399 | db->flags &= ~mask; |
| 1400 | if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0; |
| 1401 | } |
| 1402 | |
| 1403 | /* Many of the flag-pragmas modify the code generated by the SQL |
| 1404 | ** compiler (eg. count_changes). So add an opcode to expire all |
| 1405 | ** compiled SQL statements after modifying a pragma value. |
| 1406 | */ |
| 1407 | sqlite3VdbeAddOp2(v, OP_Expire, 0, 0); |
| 1408 | setAllPagerFlags(db); |
| 1409 | } |
| 1410 | break; |
| 1411 | } |
drh | bf21627 | 2005-02-26 18:10:44 +0000 | [diff] [blame] | 1412 | #endif /* SQLITE_OMIT_FLAG_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1413 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1414 | #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 1415 | /* |
| 1416 | ** PRAGMA table_info(<table>) |
| 1417 | ** |
| 1418 | ** Return a single row for each column of the named table. The columns of |
| 1419 | ** the returned data set are: |
| 1420 | ** |
| 1421 | ** cid: Column id (numbered from left to right, starting at 0) |
| 1422 | ** name: Column name |
| 1423 | ** type: Column declaration type. |
| 1424 | ** notnull: True if 'NOT NULL' is part of column declaration |
| 1425 | ** dflt_value: The default value for the column, if any. |
| 1426 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1427 | case PragTyp_TABLE_INFO: if( zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1428 | Table *pTab; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1429 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1430 | if( pTab ){ |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 1431 | int i, k; |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 1432 | int nHidden = 0; |
drh | f7eece6 | 2006-02-06 21:34:27 +0000 | [diff] [blame] | 1433 | Column *pCol; |
drh | 4415628 | 2013-10-23 22:23:03 +0000 | [diff] [blame] | 1434 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
drh | 9f6696a | 2006-02-09 16:52:23 +0000 | [diff] [blame] | 1435 | sqlite3VdbeSetNumCols(v, 6); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1436 | pParse->nMem = 6; |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1437 | sqlite3CodeVerifySchema(pParse, iDb); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1438 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC); |
| 1439 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 1440 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC); |
| 1441 | sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC); |
| 1442 | sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC); |
| 1443 | sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1444 | sqlite3ViewGetColumnNames(pParse, pTab); |
drh | f7eece6 | 2006-02-06 21:34:27 +0000 | [diff] [blame] | 1445 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
danielk1977 | 034ca14 | 2007-06-26 10:38:54 +0000 | [diff] [blame] | 1446 | if( IsHiddenColumn(pCol) ){ |
| 1447 | nHidden++; |
| 1448 | continue; |
| 1449 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1450 | sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1); |
| 1451 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0); |
| 1452 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
drh | bfa8b10 | 2006-03-03 21:20:16 +0000 | [diff] [blame] | 1453 | pCol->zType ? pCol->zType : "", 0); |
danielk1977 | f96a377 | 2008-10-23 05:45:07 +0000 | [diff] [blame] | 1454 | sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4); |
drh | b7916a7 | 2009-05-27 10:31:29 +0000 | [diff] [blame] | 1455 | if( pCol->zDflt ){ |
| 1456 | sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0); |
drh | 6f83598 | 2006-09-25 13:48:30 +0000 | [diff] [blame] | 1457 | }else{ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1458 | sqlite3VdbeAddOp2(v, OP_Null, 0, 5); |
drh | 6f83598 | 2006-09-25 13:48:30 +0000 | [diff] [blame] | 1459 | } |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 1460 | if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){ |
| 1461 | k = 0; |
| 1462 | }else if( pPk==0 ){ |
| 1463 | k = 1; |
| 1464 | }else{ |
| 1465 | for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){} |
| 1466 | } |
| 1467 | sqlite3VdbeAddOp2(v, OP_Integer, k, 6); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1468 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1469 | } |
| 1470 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1471 | } |
| 1472 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1473 | |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1474 | case PragTyp_STATS: { |
| 1475 | Index *pIdx; |
| 1476 | HashElem *i; |
| 1477 | v = sqlite3GetVdbe(pParse); |
| 1478 | sqlite3VdbeSetNumCols(v, 4); |
| 1479 | pParse->nMem = 4; |
| 1480 | sqlite3CodeVerifySchema(pParse, iDb); |
| 1481 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC); |
| 1482 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "index", SQLITE_STATIC); |
| 1483 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "width", SQLITE_STATIC); |
| 1484 | sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "height", SQLITE_STATIC); |
| 1485 | for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){ |
| 1486 | Table *pTab = sqliteHashData(i); |
| 1487 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, pTab->zName, 0); |
| 1488 | sqlite3VdbeAddOp2(v, OP_Null, 0, 2); |
| 1489 | sqlite3VdbeAddOp2(v, OP_Integer, |
| 1490 | (int)sqlite3LogEstToInt(pTab->szTabRow), 3); |
| 1491 | sqlite3VdbeAddOp2(v, OP_Integer, (int)pTab->nRowEst, 4); |
| 1492 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 1493 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 1494 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); |
| 1495 | sqlite3VdbeAddOp2(v, OP_Integer, |
| 1496 | (int)sqlite3LogEstToInt(pIdx->szIdxRow), 3); |
| 1497 | sqlite3VdbeAddOp2(v, OP_Integer, (int)pIdx->aiRowEst[0], 4); |
| 1498 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 1499 | } |
| 1500 | } |
| 1501 | } |
| 1502 | break; |
| 1503 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1504 | case PragTyp_INDEX_INFO: if( zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1505 | Index *pIdx; |
| 1506 | Table *pTab; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1507 | pIdx = sqlite3FindIndex(db, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1508 | if( pIdx ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1509 | int i; |
| 1510 | pTab = pIdx->pTable; |
danielk1977 | 22322fd | 2004-05-25 23:35:17 +0000 | [diff] [blame] | 1511 | sqlite3VdbeSetNumCols(v, 3); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1512 | pParse->nMem = 3; |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1513 | sqlite3CodeVerifySchema(pParse, iDb); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1514 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC); |
| 1515 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC); |
| 1516 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC); |
drh | bbbdc83 | 2013-10-22 18:01:40 +0000 | [diff] [blame] | 1517 | for(i=0; i<pIdx->nKeyCol; i++){ |
| 1518 | i16 cnum = pIdx->aiColumn[i]; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1519 | sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 1520 | sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1521 | assert( pTab->nCol>cnum ); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1522 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0); |
| 1523 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1524 | } |
| 1525 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1526 | } |
| 1527 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1528 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1529 | case PragTyp_INDEX_LIST: if( zRight ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1530 | Index *pIdx; |
| 1531 | Table *pTab; |
drh | e13e9f5 | 2013-10-05 19:18:00 +0000 | [diff] [blame] | 1532 | int i; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1533 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1534 | if( pTab ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1535 | v = sqlite3GetVdbe(pParse); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1536 | sqlite3VdbeSetNumCols(v, 3); |
| 1537 | pParse->nMem = 3; |
drh | e13e9f5 | 2013-10-05 19:18:00 +0000 | [diff] [blame] | 1538 | sqlite3CodeVerifySchema(pParse, iDb); |
| 1539 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 1540 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 1541 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1542 | for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){ |
drh | e13e9f5 | 2013-10-05 19:18:00 +0000 | [diff] [blame] | 1543 | sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 1544 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); |
| 1545 | sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3); |
drh | 3ef2615 | 2013-10-12 20:22:00 +0000 | [diff] [blame] | 1546 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1549 | } |
| 1550 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1551 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1552 | case PragTyp_DATABASE_LIST: { |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1553 | int i; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1554 | sqlite3VdbeSetNumCols(v, 3); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1555 | pParse->nMem = 3; |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1556 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 1557 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 1558 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC); |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1559 | for(i=0; i<db->nDb; i++){ |
| 1560 | if( db->aDb[i].pBt==0 ) continue; |
| 1561 | assert( db->aDb[i].zName!=0 ); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1562 | sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 1563 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0); |
| 1564 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1565 | sqlite3BtreeGetFilename(db->aDb[i].pBt), 0); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1566 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1567 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1568 | } |
| 1569 | break; |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1570 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1571 | case PragTyp_COLLATION_LIST: { |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1572 | int i = 0; |
| 1573 | HashElem *p; |
| 1574 | sqlite3VdbeSetNumCols(v, 2); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1575 | pParse->nMem = 2; |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1576 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 1577 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1578 | for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){ |
| 1579 | CollSeq *pColl = (CollSeq *)sqliteHashData(p); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1580 | sqlite3VdbeAddOp2(v, OP_Integer, i++, 1); |
| 1581 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0); |
| 1582 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1583 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1584 | } |
| 1585 | break; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1586 | #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */ |
| 1587 | |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1588 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1589 | case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1590 | FKey *pFK; |
| 1591 | Table *pTab; |
drh | 2783e4b | 2004-10-05 15:42:53 +0000 | [diff] [blame] | 1592 | pTab = sqlite3FindTable(db, zRight, zDb); |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1593 | if( pTab ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1594 | v = sqlite3GetVdbe(pParse); |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1595 | pFK = pTab->pFKey; |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1596 | if( pFK ){ |
| 1597 | int i = 0; |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 1598 | sqlite3VdbeSetNumCols(v, 8); |
| 1599 | pParse->nMem = 8; |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1600 | sqlite3CodeVerifySchema(pParse, iDb); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1601 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC); |
| 1602 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 1603 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC); |
| 1604 | sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC); |
| 1605 | sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC); |
| 1606 | sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC); |
| 1607 | sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC); |
| 1608 | sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1609 | while(pFK){ |
| 1610 | int j; |
| 1611 | for(j=0; j<pFK->nCol; j++){ |
drh | 2f47149 | 2005-06-23 03:15:07 +0000 | [diff] [blame] | 1612 | char *zCol = pFK->aCol[j].zCol; |
dan | 8099ce6 | 2009-09-23 08:43:35 +0000 | [diff] [blame] | 1613 | char *zOnDelete = (char *)actionName(pFK->aAction[0]); |
| 1614 | char *zOnUpdate = (char *)actionName(pFK->aAction[1]); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1615 | sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 1616 | sqlite3VdbeAddOp2(v, OP_Integer, j, 2); |
| 1617 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0); |
| 1618 | sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1619 | pTab->aCol[pFK->aCol[j].iFrom].zName, 0); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1620 | sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0); |
danielk1977 | 50af3e1 | 2008-10-10 17:47:21 +0000 | [diff] [blame] | 1621 | sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0); |
| 1622 | sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0); |
| 1623 | sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0); |
| 1624 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8); |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 1625 | } |
| 1626 | ++i; |
| 1627 | pFK = pFK->pNextFrom; |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1628 | } |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1629 | } |
| 1630 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1631 | } |
| 1632 | break; |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1633 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 1634 | |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1635 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
dan | 09ff9e1 | 2013-03-11 11:49:03 +0000 | [diff] [blame] | 1636 | #ifndef SQLITE_OMIT_TRIGGER |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1637 | case PragTyp_FOREIGN_KEY_CHECK: { |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1638 | FKey *pFK; /* A foreign key constraint */ |
| 1639 | Table *pTab; /* Child table contain "REFERENCES" keyword */ |
| 1640 | Table *pParent; /* Parent table that child points to */ |
| 1641 | Index *pIdx; /* Index in the parent table */ |
| 1642 | int i; /* Loop counter: Foreign key number for pTab */ |
| 1643 | int j; /* Loop counter: Field of the foreign key */ |
| 1644 | HashElem *k; /* Loop counter: Next table in schema */ |
| 1645 | int x; /* result variable */ |
| 1646 | int regResult; /* 3 registers to hold a result row */ |
| 1647 | int regKey; /* Register to hold key for checking the FK */ |
| 1648 | int regRow; /* Registers to hold a row from pTab */ |
| 1649 | int addrTop; /* Top of a loop checking foreign keys */ |
| 1650 | int addrOk; /* Jump here if the key is OK */ |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1651 | int *aiCols; /* child to parent column mapping */ |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1652 | |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1653 | regResult = pParse->nMem+1; |
drh | 4b4b473 | 2012-12-17 20:57:15 +0000 | [diff] [blame] | 1654 | pParse->nMem += 4; |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1655 | regKey = ++pParse->nMem; |
| 1656 | regRow = ++pParse->nMem; |
| 1657 | v = sqlite3GetVdbe(pParse); |
drh | 4b4b473 | 2012-12-17 20:57:15 +0000 | [diff] [blame] | 1658 | sqlite3VdbeSetNumCols(v, 4); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1659 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC); |
| 1660 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "rowid", SQLITE_STATIC); |
drh | 4b4b473 | 2012-12-17 20:57:15 +0000 | [diff] [blame] | 1661 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "parent", SQLITE_STATIC); |
| 1662 | sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "fkid", SQLITE_STATIC); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1663 | sqlite3CodeVerifySchema(pParse, iDb); |
| 1664 | k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash); |
| 1665 | while( k ){ |
| 1666 | if( zRight ){ |
| 1667 | pTab = sqlite3LocateTable(pParse, 0, zRight, zDb); |
| 1668 | k = 0; |
| 1669 | }else{ |
| 1670 | pTab = (Table*)sqliteHashData(k); |
| 1671 | k = sqliteHashNext(k); |
| 1672 | } |
drh | 9148def | 2012-12-17 20:40:39 +0000 | [diff] [blame] | 1673 | if( pTab==0 || pTab->pFKey==0 ) continue; |
| 1674 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1675 | if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1676 | sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1677 | sqlite3VdbeAddOp4(v, OP_String8, 0, regResult, 0, pTab->zName, |
| 1678 | P4_TRANSIENT); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1679 | for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1680 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 1681 | if( pParent==0 ) continue; |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1682 | pIdx = 0; |
drh | 9148def | 2012-12-17 20:40:39 +0000 | [diff] [blame] | 1683 | sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1684 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1685 | if( x==0 ){ |
| 1686 | if( pIdx==0 ){ |
| 1687 | sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead); |
| 1688 | }else{ |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1689 | sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iDb); |
drh | 2ec2fb2 | 2013-11-06 19:59:23 +0000 | [diff] [blame] | 1690 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1691 | } |
| 1692 | }else{ |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1693 | k = 0; |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1694 | break; |
| 1695 | } |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1696 | } |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1697 | assert( pParse->nErr>0 || pFK==0 ); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1698 | if( pFK ) break; |
| 1699 | if( pParse->nTab<i ) pParse->nTab = i; |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1700 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1701 | for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1702 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1703 | pIdx = 0; |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1704 | aiCols = 0; |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1705 | if( pParent ){ |
| 1706 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols); |
| 1707 | assert( x==0 ); |
| 1708 | } |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1709 | addrOk = sqlite3VdbeMakeLabel(v); |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1710 | if( pParent && pIdx==0 ){ |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1711 | int iKey = pFK->aCol[0].iFrom; |
drh | 83e0dba | 2012-12-20 00:32:49 +0000 | [diff] [blame] | 1712 | assert( iKey>=0 && iKey<pTab->nCol ); |
| 1713 | if( iKey!=pTab->iPKey ){ |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1714 | sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow); |
| 1715 | sqlite3ColumnDefault(v, pTab, iKey, regRow); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1716 | sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v); |
| 1717 | sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow, |
| 1718 | sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1719 | }else{ |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1720 | sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1721 | } |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1722 | sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1723 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk); |
| 1724 | sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); |
| 1725 | }else{ |
| 1726 | for(j=0; j<pFK->nCol; j++){ |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1727 | sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1728 | aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1729 | sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1730 | } |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1731 | if( pParent ){ |
drh | 57bf4a8 | 2014-02-17 14:59:22 +0000 | [diff] [blame] | 1732 | sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey, |
| 1733 | sqlite3IndexAffinityStr(v,pIdx), pFK->nCol); |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1734 | sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1735 | VdbeCoverage(v); |
dan | 5e87830 | 2013-10-12 19:06:48 +0000 | [diff] [blame] | 1736 | } |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1737 | } |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1738 | sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1); |
drh | 4b4b473 | 2012-12-17 20:57:15 +0000 | [diff] [blame] | 1739 | sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0, |
| 1740 | pFK->zTo, P4_TRANSIENT); |
| 1741 | sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3); |
| 1742 | sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1743 | sqlite3VdbeResolveLabel(v, addrOk); |
drh | 7d22a4d | 2012-12-17 22:32:14 +0000 | [diff] [blame] | 1744 | sqlite3DbFree(db, aiCols); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1745 | } |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1746 | sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v); |
drh | 613028b | 2012-12-17 18:43:02 +0000 | [diff] [blame] | 1747 | sqlite3VdbeJumpHere(v, addrTop); |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1748 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1749 | } |
| 1750 | break; |
dan | 09ff9e1 | 2013-03-11 11:49:03 +0000 | [diff] [blame] | 1751 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
drh | 6c5b915 | 2012-12-17 16:46:37 +0000 | [diff] [blame] | 1752 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| 1753 | |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1754 | #ifndef NDEBUG |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1755 | case PragTyp_PARSER_TRACE: { |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1756 | if( zRight ){ |
drh | 38d9c61 | 2012-01-31 14:24:47 +0000 | [diff] [blame] | 1757 | if( sqlite3GetBoolean(zRight, 0) ){ |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1758 | sqlite3ParserTrace(stderr, "parser: "); |
| 1759 | }else{ |
| 1760 | sqlite3ParserTrace(0, 0); |
| 1761 | } |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1762 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1763 | } |
| 1764 | break; |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1765 | #endif |
| 1766 | |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1767 | /* Reinstall the LIKE and GLOB functions. The variant of LIKE |
| 1768 | ** used will be case sensitive or not depending on the RHS. |
| 1769 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1770 | case PragTyp_CASE_SENSITIVE_LIKE: { |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1771 | if( zRight ){ |
drh | 38d9c61 | 2012-01-31 14:24:47 +0000 | [diff] [blame] | 1772 | sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0)); |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1773 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1774 | } |
| 1775 | break; |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 1776 | |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1777 | #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
| 1778 | # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100 |
| 1779 | #endif |
| 1780 | |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1781 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
drh | f7b5496 | 2013-05-28 12:11:54 +0000 | [diff] [blame] | 1782 | /* Pragma "quick_check" is reduced version of |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1783 | ** integrity_check designed to detect most database corruption |
| 1784 | ** without most of the overhead of a full integrity-check. |
| 1785 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1786 | case PragTyp_INTEGRITY_CHECK: { |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1787 | int i, j, addr, mxErr; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1788 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1789 | /* Code that appears at the end of the integrity check. If no error |
| 1790 | ** messages have been generated, output OK. Otherwise output the |
| 1791 | ** error message |
| 1792 | */ |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1793 | static const int iLn = __LINE__+2; |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 1794 | static const VdbeOpList endCode[] = { |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1795 | { OP_AddImm, 1, 0, 0}, /* 0 */ |
| 1796 | { OP_IfNeg, 1, 0, 0}, /* 1 */ |
| 1797 | { OP_String8, 0, 3, 0}, /* 2 */ |
| 1798 | { OP_ResultRow, 3, 1, 0}, |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1799 | }; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1800 | |
drh | c522731 | 2011-10-13 17:09:01 +0000 | [diff] [blame] | 1801 | int isQuick = (sqlite3Tolower(zLeft[0])=='q'); |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1802 | |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1803 | /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check", |
| 1804 | ** then iDb is set to the index of the database identified by <db>. |
| 1805 | ** In this case, the integrity of database iDb only is verified by |
| 1806 | ** the VDBE created below. |
| 1807 | ** |
| 1808 | ** Otherwise, if the command was simply "PRAGMA integrity_check" (or |
| 1809 | ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb |
| 1810 | ** to -1 here, to indicate that the VDBE should verify the integrity |
| 1811 | ** of all attached databases. */ |
| 1812 | assert( iDb>=0 ); |
| 1813 | assert( iDb==0 || pId2->z ); |
| 1814 | if( pId2->z==0 ) iDb = -1; |
| 1815 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1816 | /* Initialize the VDBE program */ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1817 | pParse->nMem = 6; |
danielk1977 | 22322fd | 2004-05-25 23:35:17 +0000 | [diff] [blame] | 1818 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 1819 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1820 | |
| 1821 | /* Set the maximum error count */ |
| 1822 | mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
| 1823 | if( zRight ){ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 1824 | sqlite3GetInt32(zRight, &mxErr); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1825 | if( mxErr<=0 ){ |
| 1826 | mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
| 1827 | } |
| 1828 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1829 | sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1830 | |
| 1831 | /* Do an integrity check on each database file */ |
| 1832 | for(i=0; i<db->nDb; i++){ |
| 1833 | HashElem *x; |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 1834 | Hash *pTbls; |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1835 | int cnt = 0; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1836 | |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 1837 | if( OMIT_TEMPDB && i==1 ) continue; |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1838 | if( iDb>=0 && i!=iDb ) continue; |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 1839 | |
drh | 8024205 | 2004-06-09 00:48:12 +0000 | [diff] [blame] | 1840 | sqlite3CodeVerifySchema(pParse, i); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1841 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */ |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1842 | VdbeCoverage(v); |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1843 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1844 | sqlite3VdbeJumpHere(v, addr); |
drh | 8024205 | 2004-06-09 00:48:12 +0000 | [diff] [blame] | 1845 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1846 | /* Do an integrity check of the B-Tree |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1847 | ** |
| 1848 | ** Begin by filling registers 2, 3, ... with the root pages numbers |
| 1849 | ** for all tables and indices in the database. |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1850 | */ |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1851 | assert( sqlite3SchemaMutexHeld(db, i, 0) ); |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 1852 | pTbls = &db->aDb[i].pSchema->tblHash; |
| 1853 | for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1854 | Table *pTab = sqliteHashData(x); |
| 1855 | Index *pIdx; |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1856 | if( HasRowid(pTab) ){ |
| 1857 | sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt); |
drh | 5838340 | 2013-11-04 17:00:50 +0000 | [diff] [blame] | 1858 | VdbeComment((v, "%s", pTab->zName)); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1859 | cnt++; |
| 1860 | } |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1861 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1862 | sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt); |
drh | 5838340 | 2013-11-04 17:00:50 +0000 | [diff] [blame] | 1863 | VdbeComment((v, "%s", pIdx->zName)); |
drh | 7906975 | 2004-05-22 21:30:40 +0000 | [diff] [blame] | 1864 | cnt++; |
| 1865 | } |
| 1866 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1867 | |
| 1868 | /* Make sure sufficient number of registers have been allocated */ |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1869 | pParse->nMem = MAX( pParse->nMem, cnt+8 ); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1870 | |
| 1871 | /* Do the b-tree integrity checks */ |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1872 | sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1); |
drh | 4f21c4a | 2008-12-10 22:15:00 +0000 | [diff] [blame] | 1873 | sqlite3VdbeChangeP5(v, (u8)i); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1874 | addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v); |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1875 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 1876 | sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName), |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1877 | P4_DYNAMIC); |
drh | e8e4af7 | 2012-09-21 00:04:28 +0000 | [diff] [blame] | 1878 | sqlite3VdbeAddOp2(v, OP_Move, 2, 4); |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 1879 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2); |
drh | 9875715 | 2008-01-09 23:04:12 +0000 | [diff] [blame] | 1880 | sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1881 | sqlite3VdbeJumpHere(v, addr); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1882 | |
| 1883 | /* Make sure all the indices are constructed correctly. |
| 1884 | */ |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 1885 | for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1886 | Table *pTab = sqliteHashData(x); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1887 | Index *pIdx, *pPk; |
drh | 1c2c0b7 | 2014-01-04 19:27:05 +0000 | [diff] [blame] | 1888 | Index *pPrior = 0; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1889 | int loopTop; |
drh | 26198bb | 2013-10-31 11:15:09 +0000 | [diff] [blame] | 1890 | int iDataCur, iIdxCur; |
drh | 1c2c0b7 | 2014-01-04 19:27:05 +0000 | [diff] [blame] | 1891 | int r1 = -1; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1892 | |
| 1893 | if( pTab->pIndex==0 ) continue; |
drh | 26198bb | 2013-10-31 11:15:09 +0000 | [diff] [blame] | 1894 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1895 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */ |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1896 | VdbeCoverage(v); |
drh | 66a5167 | 2008-01-03 00:01:23 +0000 | [diff] [blame] | 1897 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 1898 | sqlite3VdbeJumpHere(v, addr); |
drh | 66518ca | 2013-08-01 15:09:57 +0000 | [diff] [blame] | 1899 | sqlite3ExprCacheClear(pParse); |
drh | 26198bb | 2013-10-31 11:15:09 +0000 | [diff] [blame] | 1900 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, |
drh | 6a53499 | 2013-11-16 20:13:39 +0000 | [diff] [blame] | 1901 | 1, 0, &iDataCur, &iIdxCur); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1902 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 7); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1903 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1904 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */ |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1905 | } |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1906 | pParse->nMem = MAX(pParse->nMem, 8+j); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1907 | sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1908 | loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1909 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1910 | int jmp2, jmp3, jmp4; |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1911 | if( pPk==pIdx ) continue; |
drh | 1c2c0b7 | 2014-01-04 19:27:05 +0000 | [diff] [blame] | 1912 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3, |
| 1913 | pPrior, r1); |
| 1914 | pPrior = pIdx; |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1915 | sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */ |
drh | 26198bb | 2013-10-31 11:15:09 +0000 | [diff] [blame] | 1916 | jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1, |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1917 | pIdx->nColumn); VdbeCoverage(v); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1918 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */ |
| 1919 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC); |
| 1920 | sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3); |
| 1921 | sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ", |
| 1922 | P4_STATIC); |
| 1923 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 1924 | sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT); |
| 1925 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 1926 | sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1927 | jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v); |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1928 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 1929 | sqlite3VdbeJumpHere(v, jmp4); |
drh | d654be8 | 2005-09-20 17:42:23 +0000 | [diff] [blame] | 1930 | sqlite3VdbeJumpHere(v, jmp2); |
drh | b2b9d3d | 2013-08-01 01:14:43 +0000 | [diff] [blame] | 1931 | sqlite3VdbeResolveLabel(v, jmp3); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1932 | } |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1933 | sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1934 | sqlite3VdbeJumpHere(v, loopTop-1); |
| 1935 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 1936 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, |
drh | 2400345 | 2008-01-03 01:28:59 +0000 | [diff] [blame] | 1937 | "wrong # of entries in index ", P4_STATIC); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1938 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
drh | 6fbe41a | 2013-10-30 20:22:55 +0000 | [diff] [blame] | 1939 | if( pPk==pIdx ) continue; |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1940 | addr = sqlite3VdbeCurrentAddr(v); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1941 | sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1942 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
drh | 26198bb | 2013-10-31 11:15:09 +0000 | [diff] [blame] | 1943 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1944 | sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v); |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1945 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); |
| 1946 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT); |
| 1947 | sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7); |
| 1948 | sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1); |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1949 | } |
drh | 8a9789b | 2013-08-01 03:36:59 +0000 | [diff] [blame] | 1950 | #endif /* SQLITE_OMIT_BTREECOUNT */ |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 1951 | } |
| 1952 | } |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 1953 | addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 1954 | sqlite3VdbeChangeP2(v, addr, -mxErr); |
| 1955 | sqlite3VdbeJumpHere(v, addr+1); |
| 1956 | sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1957 | } |
| 1958 | break; |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1959 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 1960 | |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 1961 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1962 | /* |
| 1963 | ** PRAGMA encoding |
| 1964 | ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be" |
| 1965 | ** |
drh | 85b623f | 2007-12-13 21:54:09 +0000 | [diff] [blame] | 1966 | ** In its first form, this pragma returns the encoding of the main |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1967 | ** database. If the database is not initialized, it is initialized now. |
| 1968 | ** |
| 1969 | ** The second form of this pragma is a no-op if the main database file |
| 1970 | ** has not already been initialized. In this case it sets the default |
| 1971 | ** encoding that will be used for the main database file if a new file |
| 1972 | ** is created. If an existing main database file is opened, then the |
| 1973 | ** default text encoding for the existing database is used. |
| 1974 | ** |
| 1975 | ** In all cases new databases created using the ATTACH command are |
| 1976 | ** created to use the same default text encoding as the main database. If |
| 1977 | ** the main database has not been initialized and/or created when ATTACH |
| 1978 | ** is executed, this is done before the ATTACH operation. |
| 1979 | ** |
| 1980 | ** In the second form this pragma sets the text encoding to be used in |
| 1981 | ** new database files created using this database handle. It is only |
| 1982 | ** useful if invoked immediately after the main database i |
| 1983 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 1984 | case PragTyp_ENCODING: { |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 1985 | static const struct EncName { |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1986 | char *zName; |
| 1987 | u8 enc; |
| 1988 | } encnames[] = { |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 1989 | { "UTF8", SQLITE_UTF8 }, |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1990 | { "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */ |
| 1991 | { "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */ |
| 1992 | { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */ |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 1993 | { "UTF16le", SQLITE_UTF16LE }, |
drh | 998da3a | 2004-06-19 15:22:56 +0000 | [diff] [blame] | 1994 | { "UTF16be", SQLITE_UTF16BE }, |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 1995 | { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */ |
| 1996 | { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */ |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 1997 | { 0, 0 } |
| 1998 | }; |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 1999 | const struct EncName *pEnc; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 2000 | if( !zRight ){ /* "PRAGMA encoding" */ |
danielk1977 | 8a41449 | 2004-06-29 08:59:35 +0000 | [diff] [blame] | 2001 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2002 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 2003 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 2004 | sqlite3VdbeAddOp2(v, OP_String8, 0, 1); |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 2005 | assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 ); |
| 2006 | assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE ); |
| 2007 | assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE ); |
| 2008 | sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 2009 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2010 | }else{ /* "PRAGMA encoding = XXX" */ |
| 2011 | /* Only change the value of sqlite.enc if the database handle is not |
| 2012 | ** initialized. If the main database exists, the new sqlite.enc value |
| 2013 | ** will be overwritten when the schema is next loaded. If it does not |
| 2014 | ** already exists, it will be created to use the new encoding value. |
| 2015 | */ |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 2016 | if( |
| 2017 | !(DbHasProperty(db, 0, DB_SchemaLoaded)) || |
| 2018 | DbHasProperty(db, 0, DB_Empty) |
| 2019 | ){ |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2020 | for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ |
| 2021 | if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ |
drh | 0f7eb61 | 2006-08-08 13:51:43 +0000 | [diff] [blame] | 2022 | ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2023 | break; |
| 2024 | } |
| 2025 | } |
| 2026 | if( !pEnc->zName ){ |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 2027 | sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight); |
danielk1977 | 8e22787 | 2004-06-07 07:52:17 +0000 | [diff] [blame] | 2028 | } |
| 2029 | } |
| 2030 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2031 | } |
| 2032 | break; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 2033 | #endif /* SQLITE_OMIT_UTF16 */ |
| 2034 | |
| 2035 | #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2036 | /* |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 2037 | ** PRAGMA [database.]schema_version |
| 2038 | ** PRAGMA [database.]schema_version = <integer> |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2039 | ** |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 2040 | ** PRAGMA [database.]user_version |
| 2041 | ** PRAGMA [database.]user_version = <integer> |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2042 | ** |
drh | 4ee09b4 | 2013-05-01 19:49:27 +0000 | [diff] [blame] | 2043 | ** PRAGMA [database.]freelist_count = <integer> |
| 2044 | ** |
| 2045 | ** PRAGMA [database.]application_id |
| 2046 | ** PRAGMA [database.]application_id = <integer> |
| 2047 | ** |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 2048 | ** The pragma's schema_version and user_version are used to set or get |
| 2049 | ** the value of the schema-version and user-version, respectively. Both |
| 2050 | ** the schema-version and the user-version are 32-bit signed integers |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2051 | ** stored in the database header. |
| 2052 | ** |
| 2053 | ** The schema-cookie is usually only manipulated internally by SQLite. It |
| 2054 | ** is incremented by SQLite whenever the database schema is modified (by |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 2055 | ** creating or dropping a table or index). The schema version is used by |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2056 | ** SQLite each time a query is executed to ensure that the internal cache |
| 2057 | ** of the schema used when compiling the SQL query matches the schema of |
| 2058 | ** the database against which the compiled query is actually executed. |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 2059 | ** Subverting this mechanism by using "PRAGMA schema_version" to modify |
| 2060 | ** the schema-version is potentially dangerous and may lead to program |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2061 | ** crashes or database corruption. Use with caution! |
| 2062 | ** |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 2063 | ** The user-version is not used internally by SQLite. It may be used by |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2064 | ** applications for any purpose. |
| 2065 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2066 | case PragTyp_HEADER_VALUE: { |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 2067 | int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */ |
drh | fb98264 | 2007-08-30 01:19:59 +0000 | [diff] [blame] | 2068 | sqlite3VdbeUsesBtree(v, iDb); |
danielk1977 | 180b56a | 2007-06-24 08:00:42 +0000 | [diff] [blame] | 2069 | switch( zLeft[0] ){ |
drh | 4ee09b4 | 2013-05-01 19:49:27 +0000 | [diff] [blame] | 2070 | case 'a': case 'A': |
| 2071 | iCookie = BTREE_APPLICATION_ID; |
| 2072 | break; |
danielk1977 | 180b56a | 2007-06-24 08:00:42 +0000 | [diff] [blame] | 2073 | case 'f': case 'F': |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 2074 | iCookie = BTREE_FREE_PAGE_COUNT; |
| 2075 | break; |
| 2076 | case 's': case 'S': |
| 2077 | iCookie = BTREE_SCHEMA_VERSION; |
danielk1977 | 180b56a | 2007-06-24 08:00:42 +0000 | [diff] [blame] | 2078 | break; |
| 2079 | default: |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 2080 | iCookie = BTREE_USER_VERSION; |
danielk1977 | 180b56a | 2007-06-24 08:00:42 +0000 | [diff] [blame] | 2081 | break; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
danielk1977 | 0d19f7a | 2009-06-03 11:25:07 +0000 | [diff] [blame] | 2084 | if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){ |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2085 | /* Write the specified cookie value */ |
| 2086 | static const VdbeOpList setCookie[] = { |
| 2087 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
drh | 9cbf342 | 2008-01-17 16:22:13 +0000 | [diff] [blame] | 2088 | { OP_Integer, 0, 1, 0}, /* 1 */ |
| 2089 | { OP_SetCookie, 0, 0, 1}, /* 2 */ |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2090 | }; |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 2091 | int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0); |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2092 | sqlite3VdbeChangeP1(v, addr, iDb); |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 2093 | sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight)); |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2094 | sqlite3VdbeChangeP1(v, addr+2, iDb); |
| 2095 | sqlite3VdbeChangeP2(v, addr+2, iCookie); |
| 2096 | }else{ |
| 2097 | /* Read the specified cookie value */ |
| 2098 | static const VdbeOpList readCookie[] = { |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 2099 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 2100 | { OP_ReadCookie, 0, 1, 0}, /* 1 */ |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 2101 | { OP_ResultRow, 1, 1, 0} |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2102 | }; |
drh | 688852a | 2014-02-17 22:40:43 +0000 | [diff] [blame] | 2103 | int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie, 0); |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2104 | sqlite3VdbeChangeP1(v, addr, iDb); |
danielk1977 | 602b466 | 2009-07-02 07:47:33 +0000 | [diff] [blame] | 2105 | sqlite3VdbeChangeP1(v, addr+1, iDb); |
| 2106 | sqlite3VdbeChangeP3(v, addr+1, iCookie); |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2107 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 2108 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT); |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 2109 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2110 | } |
| 2111 | break; |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 2112 | #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 2113 | |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2114 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 2115 | /* |
| 2116 | ** PRAGMA compile_options |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2117 | ** |
drh | 71caabf | 2010-02-26 15:39:24 +0000 | [diff] [blame] | 2118 | ** Return the names of all compile-time options used in this build, |
| 2119 | ** one option per row. |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2120 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2121 | case PragTyp_COMPILE_OPTIONS: { |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2122 | int i = 0; |
| 2123 | const char *zOpt; |
| 2124 | sqlite3VdbeSetNumCols(v, 1); |
| 2125 | pParse->nMem = 1; |
| 2126 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC); |
| 2127 | while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){ |
| 2128 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0); |
| 2129 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); |
| 2130 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2131 | } |
| 2132 | break; |
shaneh | dc97a8c | 2010-02-23 20:08:35 +0000 | [diff] [blame] | 2133 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 2134 | |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 2135 | #ifndef SQLITE_OMIT_WAL |
| 2136 | /* |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 2137 | ** PRAGMA [database.]wal_checkpoint = passive|full|restart |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 2138 | ** |
| 2139 | ** Checkpoint the database. |
| 2140 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2141 | case PragTyp_WAL_CHECKPOINT: { |
dan | a58f26f | 2010-11-16 18:56:51 +0000 | [diff] [blame] | 2142 | int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED); |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 2143 | int eMode = SQLITE_CHECKPOINT_PASSIVE; |
| 2144 | if( zRight ){ |
| 2145 | if( sqlite3StrICmp(zRight, "full")==0 ){ |
| 2146 | eMode = SQLITE_CHECKPOINT_FULL; |
| 2147 | }else if( sqlite3StrICmp(zRight, "restart")==0 ){ |
| 2148 | eMode = SQLITE_CHECKPOINT_RESTART; |
| 2149 | } |
| 2150 | } |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 2151 | sqlite3VdbeSetNumCols(v, 3); |
| 2152 | pParse->nMem = 3; |
| 2153 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC); |
| 2154 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC); |
| 2155 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC); |
| 2156 | |
drh | 30aa3b9 | 2011-02-07 23:56:01 +0000 | [diff] [blame] | 2157 | sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1); |
dan | cdc1f04 | 2010-11-18 12:11:05 +0000 | [diff] [blame] | 2158 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2159 | } |
| 2160 | break; |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 2161 | |
| 2162 | /* |
| 2163 | ** PRAGMA wal_autocheckpoint |
| 2164 | ** PRAGMA wal_autocheckpoint = N |
| 2165 | ** |
| 2166 | ** Configure a database connection to automatically checkpoint a database |
| 2167 | ** after accumulating N frames in the log. Or query for the current value |
| 2168 | ** of N. |
| 2169 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2170 | case PragTyp_WAL_AUTOCHECKPOINT: { |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 2171 | if( zRight ){ |
drh | 60ac3f4 | 2010-11-23 18:59:27 +0000 | [diff] [blame] | 2172 | sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight)); |
dan | 5a299f9 | 2010-05-03 11:05:08 +0000 | [diff] [blame] | 2173 | } |
drh | b033d8b | 2010-05-03 13:37:30 +0000 | [diff] [blame] | 2174 | returnSingleInt(pParse, "wal_autocheckpoint", |
| 2175 | db->xWalCallback==sqlite3WalDefaultHook ? |
| 2176 | SQLITE_PTR_TO_INT(db->pWalArg) : 0); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2177 | } |
| 2178 | break; |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame] | 2179 | #endif |
dan | 7c24610 | 2010-04-12 19:00:29 +0000 | [diff] [blame] | 2180 | |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 2181 | /* |
| 2182 | ** PRAGMA shrink_memory |
| 2183 | ** |
| 2184 | ** This pragma attempts to free as much memory as possible from the |
| 2185 | ** current database connection. |
| 2186 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2187 | case PragTyp_SHRINK_MEMORY: { |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 2188 | sqlite3_db_release_memory(db); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2189 | break; |
| 2190 | } |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 2191 | |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 2192 | /* |
| 2193 | ** PRAGMA busy_timeout |
| 2194 | ** PRAGMA busy_timeout = N |
| 2195 | ** |
| 2196 | ** Call sqlite3_busy_timeout(db, N). Return the current timeout value |
drh | c0c7b5e | 2012-09-07 18:49:57 +0000 | [diff] [blame] | 2197 | ** if one is set. If no busy handler or a different busy handler is set |
| 2198 | ** then 0 is returned. Setting the busy_timeout to 0 or negative |
| 2199 | ** disables the timeout. |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 2200 | */ |
drh | d49c358 | 2013-09-13 19:00:06 +0000 | [diff] [blame] | 2201 | /*case PragTyp_BUSY_TIMEOUT*/ default: { |
| 2202 | assert( aPragmaNames[mid].ePragTyp==PragTyp_BUSY_TIMEOUT ); |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 2203 | if( zRight ){ |
| 2204 | sqlite3_busy_timeout(db, sqlite3Atoi(zRight)); |
| 2205 | } |
| 2206 | returnSingleInt(pParse, "timeout", db->busyTimeout); |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2207 | break; |
| 2208 | } |
drh | f360396 | 2012-09-07 16:46:59 +0000 | [diff] [blame] | 2209 | |
drh | 55e85ca | 2013-09-13 21:01:56 +0000 | [diff] [blame] | 2210 | /* |
| 2211 | ** PRAGMA soft_heap_limit |
| 2212 | ** PRAGMA soft_heap_limit = N |
| 2213 | ** |
| 2214 | ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted, |
| 2215 | ** use -1. |
| 2216 | */ |
| 2217 | case PragTyp_SOFT_HEAP_LIMIT: { |
| 2218 | sqlite3_int64 N; |
| 2219 | if( zRight && sqlite3Atoi64(zRight, &N, 1000000, SQLITE_UTF8)==SQLITE_OK ){ |
| 2220 | sqlite3_soft_heap_limit64(N); |
| 2221 | } |
| 2222 | returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1)); |
| 2223 | break; |
| 2224 | } |
| 2225 | |
dougcurrie | 81c95ef | 2004-06-18 23:21:47 +0000 | [diff] [blame] | 2226 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2227 | /* |
| 2228 | ** Report the current state of file logs for all databases |
| 2229 | */ |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2230 | case PragTyp_LOCK_STATUS: { |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 2231 | static const char *const azLockName[] = { |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2232 | "unlocked", "shared", "reserved", "pending", "exclusive" |
| 2233 | }; |
| 2234 | int i; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2235 | sqlite3VdbeSetNumCols(v, 2); |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 2236 | pParse->nMem = 2; |
danielk1977 | 10fb749 | 2008-10-31 10:53:22 +0000 | [diff] [blame] | 2237 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC); |
| 2238 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC); |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2239 | for(i=0; i<db->nDb; i++){ |
| 2240 | Btree *pBt; |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 2241 | const char *zState = "unknown"; |
| 2242 | int j; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2243 | if( db->aDb[i].zName==0 ) continue; |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 2244 | sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC); |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2245 | pBt = db->aDb[i].pBt; |
drh | 5a05be1 | 2012-10-09 18:51:44 +0000 | [diff] [blame] | 2246 | if( pBt==0 || sqlite3BtreePager(pBt)==0 ){ |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 2247 | zState = "closed"; |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 2248 | }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0, |
drh | 9e33c2c | 2007-08-31 18:34:59 +0000 | [diff] [blame] | 2249 | SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){ |
| 2250 | zState = azLockName[j]; |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2251 | } |
drh | 2d401ab | 2008-01-10 23:50:11 +0000 | [diff] [blame] | 2252 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC); |
| 2253 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2254 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2255 | break; |
| 2256 | } |
drh | 89ac8c1 | 2004-06-09 14:17:20 +0000 | [diff] [blame] | 2257 | #endif |
| 2258 | |
shaneh | ad9f9f6 | 2010-02-17 17:48:46 +0000 | [diff] [blame] | 2259 | #ifdef SQLITE_HAS_CODEC |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2260 | case PragTyp_KEY: { |
| 2261 | if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight)); |
| 2262 | break; |
| 2263 | } |
| 2264 | case PragTyp_REKEY: { |
| 2265 | if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight)); |
| 2266 | break; |
| 2267 | } |
| 2268 | case PragTyp_HEXKEY: { |
| 2269 | if( zRight ){ |
drh | 8ab8832 | 2013-10-07 00:36:01 +0000 | [diff] [blame] | 2270 | u8 iByte; |
| 2271 | int i; |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2272 | char zKey[40]; |
drh | 8ab8832 | 2013-10-07 00:36:01 +0000 | [diff] [blame] | 2273 | for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zRight[i]); i++){ |
| 2274 | iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]); |
| 2275 | if( (i&1)!=0 ) zKey[i/2] = iByte; |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2276 | } |
| 2277 | if( (zLeft[3] & 0xf)==0xb ){ |
| 2278 | sqlite3_key_v2(db, zDb, zKey, i/2); |
| 2279 | }else{ |
| 2280 | sqlite3_rekey_v2(db, zDb, zKey, i/2); |
| 2281 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 2282 | } |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2283 | break; |
| 2284 | } |
drh | 3c4f2a4 | 2005-12-08 18:12:56 +0000 | [diff] [blame] | 2285 | #endif |
shaneh | ad9f9f6 | 2010-02-17 17:48:46 +0000 | [diff] [blame] | 2286 | #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2287 | case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){ |
shaneh | ad9f9f6 | 2010-02-17 17:48:46 +0000 | [diff] [blame] | 2288 | #ifdef SQLITE_HAS_CODEC |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 2289 | if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){ |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 2290 | sqlite3_activate_see(&zRight[4]); |
| 2291 | } |
| 2292 | #endif |
| 2293 | #ifdef SQLITE_ENABLE_CEROD |
| 2294 | if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){ |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 2295 | sqlite3_activate_cerod(&zRight[6]); |
| 2296 | } |
| 2297 | #endif |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2298 | } |
| 2299 | break; |
drh | 21e2cab | 2006-09-25 18:01:57 +0000 | [diff] [blame] | 2300 | #endif |
drh | 3c4f2a4 | 2005-12-08 18:12:56 +0000 | [diff] [blame] | 2301 | |
drh | 9ccd865 | 2013-09-13 16:36:46 +0000 | [diff] [blame] | 2302 | } /* End of the PRAGMA switch */ |
danielk1977 | a21c6b6 | 2005-01-24 10:25:59 +0000 | [diff] [blame] | 2303 | |
danielk1977 | e004840 | 2004-06-15 16:51:01 +0000 | [diff] [blame] | 2304 | pragma_out: |
drh | 633e6d5 | 2008-07-28 19:34:53 +0000 | [diff] [blame] | 2305 | sqlite3DbFree(db, zLeft); |
| 2306 | sqlite3DbFree(db, zRight); |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 2307 | } |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 2308 | |
drh | 8bfdf72 | 2009-06-19 14:06:03 +0000 | [diff] [blame] | 2309 | #endif /* SQLITE_OMIT_PRAGMA */ |