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