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