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