Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: third_party/sqlite/sqlite-src-3100200/src/pragma.c

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #if !defined(SQLITE_ENABLE_LOCKING_STYLE) 16 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
17 # if defined(__APPLE__) 17 # if defined(__APPLE__)
18 # define SQLITE_ENABLE_LOCKING_STYLE 1 18 # define SQLITE_ENABLE_LOCKING_STYLE 1
19 # else 19 # else
20 # define SQLITE_ENABLE_LOCKING_STYLE 0 20 # define SQLITE_ENABLE_LOCKING_STYLE 0
21 # endif 21 # endif
22 #endif 22 #endif
23 23
24 /*************************************************************************** 24 /***************************************************************************
25 ** The next block of code, including the PragTyp_XXXX macro definitions and 25 ** The "pragma.h" include file is an automatically generated file that
26 ** the aPragmaName[] object is composed of generated code. DO NOT EDIT. 26 ** that includes the PragType_XXXX macro definitions and the aPragmaName[]
27 ** 27 ** object. This ensures that the aPragmaName[] table is arranged in
28 ** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun 28 ** lexicographical order to facility a binary search of the pragma name.
29 ** that script. Then copy/paste the output in place of the following: 29 ** Do not edit pragma.h directly. Edit and rerun the script in at
30 */ 30 ** ../tool/mkpragmatab.tcl. */
31 #define PragTyp_HEADER_VALUE 0 31 #include "pragma.h"
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 ***************************************************************************/
476 32
477 /* 33 /*
478 ** Interpret the given string as a safety level. Return 0 for OFF, 34 ** Interpret the given string as a safety level. Return 0 for OFF,
479 ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or 35 ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
480 ** unrecognized string argument. The FULL option is disallowed 36 ** unrecognized string argument. The FULL option is disallowed
481 ** if the omitFull parameter it 1. 37 ** if the omitFull parameter it 1.
482 ** 38 **
483 ** Note that the values returned are one less that the values that 39 ** Note that the values returned are one less that the values that
484 ** should be passed into sqlite3BtreeSetSafetyLevel(). The is done 40 ** should be passed into sqlite3BtreeSetSafetyLevel(). The is done
485 ** to support legacy SQL code. The safety level used to be boolean 41 ** to support legacy SQL code. The safety level used to be boolean
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 if( db->temp_store==ts ) return SQLITE_OK; 153 if( db->temp_store==ts ) return SQLITE_OK;
598 if( invalidateTempStorage( pParse ) != SQLITE_OK ){ 154 if( invalidateTempStorage( pParse ) != SQLITE_OK ){
599 return SQLITE_ERROR; 155 return SQLITE_ERROR;
600 } 156 }
601 db->temp_store = (u8)ts; 157 db->temp_store = (u8)ts;
602 return SQLITE_OK; 158 return SQLITE_OK;
603 } 159 }
604 #endif /* SQLITE_PAGER_PRAGMAS */ 160 #endif /* SQLITE_PAGER_PRAGMAS */
605 161
606 /* 162 /*
163 ** Set the names of the first N columns to the values in azCol[]
164 */
165 static void setAllColumnNames(
166 Vdbe *v, /* The query under construction */
167 int N, /* Number of columns */
168 const char **azCol /* Names of columns */
169 ){
170 int i;
171 sqlite3VdbeSetNumCols(v, N);
172 for(i=0; i<N; i++){
173 sqlite3VdbeSetColName(v, i, COLNAME_NAME, azCol[i], SQLITE_STATIC);
174 }
175 }
176 static void setOneColumnName(Vdbe *v, const char *z){
177 setAllColumnNames(v, 1, &z);
178 }
179
180 /*
607 ** Generate code to return a single integer value. 181 ** Generate code to return a single integer value.
608 */ 182 */
609 static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){ 183 static void returnSingleInt(Vdbe *v, const char *zLabel, i64 value){
610 Vdbe *v = sqlite3GetVdbe(pParse); 184 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
611 int mem = ++pParse->nMem; 185 setOneColumnName(v, zLabel);
612 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value)); 186 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
613 if( pI64 ){ 187 }
614 memcpy(pI64, &value, sizeof(value)); 188
189 /*
190 ** Generate code to return a single text value.
191 */
192 static void returnSingleText(
193 Vdbe *v, /* Prepared statement under construction */
194 const char *zLabel, /* Name of the result column */
195 const char *zValue /* Value to be returned */
196 ){
197 if( zValue ){
198 sqlite3VdbeLoadString(v, 1, (const char*)zValue);
199 setOneColumnName(v, zLabel);
200 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
615 } 201 }
616 sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
617 sqlite3VdbeSetNumCols(v, 1);
618 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
619 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
620 } 202 }
621 203
622 204
623 /* 205 /*
624 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0 206 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
625 ** set these values for all pagers. 207 ** set these values for all pagers.
626 */ 208 */
627 #ifndef SQLITE_OMIT_PAGER_PRAGMAS 209 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
628 static void setAllPagerFlags(sqlite3 *db){ 210 static void setAllPagerFlags(sqlite3 *db){
629 if( db->autoCommit ){ 211 if( db->autoCommit ){
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 272
691 if( eMode==ArraySize(azModeName) ) return 0; 273 if( eMode==ArraySize(azModeName) ) return 0;
692 return azModeName[eMode]; 274 return azModeName[eMode];
693 } 275 }
694 276
695 /* 277 /*
696 ** Process a pragma statement. 278 ** Process a pragma statement.
697 ** 279 **
698 ** Pragmas are of this form: 280 ** Pragmas are of this form:
699 ** 281 **
700 ** PRAGMA [database.]id [= value] 282 ** PRAGMA [schema.]id [= value]
701 ** 283 **
702 ** The identifier might also be a string. The value is a string, and 284 ** The identifier might also be a string. The value is a string, and
703 ** identifier, or a number. If minusFlag is true, then the value is 285 ** identifier, or a number. If minusFlag is true, then the value is
704 ** a number that was preceded by a minus sign. 286 ** a number that was preceded by a minus sign.
705 ** 287 **
706 ** If the left side is "database.id" then pId1 is the database name 288 ** If the left side is "database.id" then pId1 is the database name
707 ** and pId2 is the id. If the left side is just "id" then pId1 is the 289 ** and pId2 is the id. If the left side is just "id" then pId1 is the
708 ** id and pId2 is any empty string. 290 ** id and pId2 is any empty string.
709 */ 291 */
710 void sqlite3Pragma( 292 void sqlite3Pragma(
711 Parse *pParse, 293 Parse *pParse,
712 Token *pId1, /* First part of [database.]id field */ 294 Token *pId1, /* First part of [schema.]id field */
713 Token *pId2, /* Second part of [database.]id field, or NULL */ 295 Token *pId2, /* Second part of [schema.]id field, or NULL */
714 Token *pValue, /* Token for <value>, or NULL */ 296 Token *pValue, /* Token for <value>, or NULL */
715 int minusFlag /* True if a '-' sign preceded <value> */ 297 int minusFlag /* True if a '-' sign preceded <value> */
716 ){ 298 ){
717 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */ 299 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
718 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */ 300 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
719 const char *zDb = 0; /* The database name */ 301 const char *zDb = 0; /* The database name */
720 Token *pId; /* Pointer to <id> token */ 302 Token *pId; /* Pointer to <id> token */
721 char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */ 303 char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
722 int iDb; /* Database index for <database> */ 304 int iDb; /* Database index for <database> */
723 int lwr, upr, mid; /* Binary search bounds */ 305 int lwr, upr, mid = 0; /* Binary search bounds */
724 int rc; /* return value form SQLITE_FCNTL_PRAGMA */ 306 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
725 sqlite3 *db = pParse->db; /* The database connection */ 307 sqlite3 *db = pParse->db; /* The database connection */
726 Db *pDb; /* The specific database being pragmaed */ 308 Db *pDb; /* The specific database being pragmaed */
727 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */ 309 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
310 const struct sPragmaNames *pPragma;
728 311
729 if( v==0 ) return; 312 if( v==0 ) return;
730 sqlite3VdbeRunOnlyOnce(v); 313 sqlite3VdbeRunOnlyOnce(v);
731 pParse->nMem = 2; 314 pParse->nMem = 2;
732 315
733 /* Interpret the [database.] part of the pragma statement. iDb is the 316 /* Interpret the [schema.] part of the pragma statement. iDb is the
734 ** index of the database this pragma is being applied to in db.aDb[]. */ 317 ** index of the database this pragma is being applied to in db.aDb[]. */
735 iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId); 318 iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId);
736 if( iDb<0 ) return; 319 if( iDb<0 ) return;
737 pDb = &db->aDb[iDb]; 320 pDb = &db->aDb[iDb];
738 321
739 /* If the temp database has been explicitly named as part of the 322 /* If the temp database has been explicitly named as part of the
740 ** pragma, make sure it is open. 323 ** pragma, make sure it is open.
741 */ 324 */
742 if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){ 325 if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){
743 return; 326 return;
744 } 327 }
745 328
746 zLeft = sqlite3NameFromToken(db, pId); 329 zLeft = sqlite3NameFromToken(db, pId);
747 if( !zLeft ) return; 330 if( !zLeft ) return;
748 if( minusFlag ){ 331 if( minusFlag ){
749 zRight = sqlite3MPrintf(db, "-%T", pValue); 332 zRight = sqlite3MPrintf(db, "-%T", pValue);
750 }else{ 333 }else{
751 zRight = sqlite3NameFromToken(db, pValue); 334 zRight = sqlite3NameFromToken(db, pValue);
752 } 335 }
753 336
754 assert( pId2 ); 337 assert( pId2 );
755 zDb = pId2->n>0 ? pDb->zName : 0; 338 zDb = pId2->n>0 ? pDb->zName : 0;
756 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){ 339 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
757 goto pragma_out; 340 goto pragma_out;
758 } 341 }
759 342
760 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS 343 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
761 ** connection. If it returns SQLITE_OK, then assume that the VFS 344 ** connection. If it returns SQLITE_OK, then assume that the VFS
762 ** handled the pragma and generate a no-op prepared statement. 345 ** handled the pragma and generate a no-op prepared statement.
346 **
347 ** IMPLEMENTATION-OF: R-12238-55120 Whenever a PRAGMA statement is parsed,
348 ** an SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file
349 ** object corresponding to the database file to which the pragma
350 ** statement refers.
351 **
352 ** IMPLEMENTATION-OF: R-29875-31678 The argument to the SQLITE_FCNTL_PRAGMA
353 ** file control is an array of pointers to strings (char**) in which the
354 ** second element of the array is the name of the pragma and the third
355 ** element is the argument to the pragma or NULL if the pragma has no
356 ** argument.
763 */ 357 */
764 aFcntl[0] = 0; 358 aFcntl[0] = 0;
765 aFcntl[1] = zLeft; 359 aFcntl[1] = zLeft;
766 aFcntl[2] = zRight; 360 aFcntl[2] = zRight;
767 aFcntl[3] = 0; 361 aFcntl[3] = 0;
768 db->busyHandler.nBusy = 0; 362 db->busyHandler.nBusy = 0;
769 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl); 363 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
770 if( rc==SQLITE_OK ){ 364 if( rc==SQLITE_OK ){
771 if( aFcntl[0] ){ 365 returnSingleText(v, "result", aFcntl[0]);
772 int mem = ++pParse->nMem; 366 sqlite3_free(aFcntl[0]);
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; 367 goto pragma_out;
780 } 368 }
781 if( rc!=SQLITE_NOTFOUND ){ 369 if( rc!=SQLITE_NOTFOUND ){
782 if( aFcntl[0] ){ 370 if( aFcntl[0] ){
783 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]); 371 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
784 sqlite3_free(aFcntl[0]); 372 sqlite3_free(aFcntl[0]);
785 } 373 }
786 pParse->nErr++; 374 pParse->nErr++;
787 pParse->rc = rc; 375 pParse->rc = rc;
788 goto pragma_out; 376 goto pragma_out;
789 } 377 }
790 378
791 /* Locate the pragma in the lookup table */ 379 /* Locate the pragma in the lookup table */
792 lwr = 0; 380 lwr = 0;
793 upr = ArraySize(aPragmaNames)-1; 381 upr = ArraySize(aPragmaNames)-1;
794 while( lwr<=upr ){ 382 while( lwr<=upr ){
795 mid = (lwr+upr)/2; 383 mid = (lwr+upr)/2;
796 rc = sqlite3_stricmp(zLeft, aPragmaNames[mid].zName); 384 rc = sqlite3_stricmp(zLeft, aPragmaNames[mid].zName);
797 if( rc==0 ) break; 385 if( rc==0 ) break;
798 if( rc<0 ){ 386 if( rc<0 ){
799 upr = mid - 1; 387 upr = mid - 1;
800 }else{ 388 }else{
801 lwr = mid + 1; 389 lwr = mid + 1;
802 } 390 }
803 } 391 }
804 if( lwr>upr ) goto pragma_out; 392 if( lwr>upr ) goto pragma_out;
393 pPragma = &aPragmaNames[mid];
805 394
806 /* Make sure the database schema is loaded if the pragma requires that */ 395 /* Make sure the database schema is loaded if the pragma requires that */
807 if( (aPragmaNames[mid].mPragFlag & PragFlag_NeedSchema)!=0 ){ 396 if( (pPragma->mPragFlag & PragFlag_NeedSchema)!=0 ){
808 if( sqlite3ReadSchema(pParse) ) goto pragma_out; 397 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
809 } 398 }
810 399
811 /* Jump to the appropriate pragma handler */ 400 /* Jump to the appropriate pragma handler */
812 switch( aPragmaNames[mid].ePragTyp ){ 401 switch( pPragma->ePragTyp ){
813 402
814 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) 403 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
815 /* 404 /*
816 ** PRAGMA [database.]default_cache_size 405 ** PRAGMA [schema.]default_cache_size
817 ** PRAGMA [database.]default_cache_size=N 406 ** PRAGMA [schema.]default_cache_size=N
818 ** 407 **
819 ** The first form reports the current persistent setting for the 408 ** The first form reports the current persistent setting for the
820 ** page cache size. The value returned is the maximum number of 409 ** page cache size. The value returned is the maximum number of
821 ** pages in the page cache. The second form sets both the current 410 ** pages in the page cache. The second form sets both the current
822 ** page cache size value and the persistent page cache size value 411 ** page cache size value and the persistent page cache size value
823 ** stored in the database file. 412 ** stored in the database file.
824 ** 413 **
825 ** Older versions of SQLite would set the default cache size to a 414 ** Older versions of SQLite would set the default cache size to a
826 ** negative number to indicate synchronous=OFF. These days, synchronous 415 ** negative number to indicate synchronous=OFF. These days, synchronous
827 ** is always on by default regardless of the sign of the default cache 416 ** is always on by default regardless of the sign of the default cache
828 ** size. But continue to take the absolute value of the default cache 417 ** size. But continue to take the absolute value of the default cache
829 ** size of historical compatibility. 418 ** size of historical compatibility.
830 */ 419 */
831 case PragTyp_DEFAULT_CACHE_SIZE: { 420 case PragTyp_DEFAULT_CACHE_SIZE: {
832 static const int iLn = VDBE_OFFSET_LINENO(2); 421 static const int iLn = VDBE_OFFSET_LINENO(2);
833 static const VdbeOpList getCacheSize[] = { 422 static const VdbeOpList getCacheSize[] = {
834 { OP_Transaction, 0, 0, 0}, /* 0 */ 423 { OP_Transaction, 0, 0, 0}, /* 0 */
835 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */ 424 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
836 { OP_IfPos, 1, 8, 0}, 425 { OP_IfPos, 1, 8, 0},
837 { OP_Integer, 0, 2, 0}, 426 { OP_Integer, 0, 2, 0},
838 { OP_Subtract, 1, 2, 1}, 427 { OP_Subtract, 1, 2, 1},
839 { OP_IfPos, 1, 8, 0}, 428 { OP_IfPos, 1, 8, 0},
840 { OP_Integer, 0, 1, 0}, /* 6 */ 429 { OP_Integer, 0, 1, 0}, /* 6 */
841 { OP_Noop, 0, 0, 0}, 430 { OP_Noop, 0, 0, 0},
842 { OP_ResultRow, 1, 1, 0}, 431 { OP_ResultRow, 1, 1, 0},
843 }; 432 };
844 int addr; 433 int addr;
845 sqlite3VdbeUsesBtree(v, iDb); 434 sqlite3VdbeUsesBtree(v, iDb);
846 if( !zRight ){ 435 if( !zRight ){
847 sqlite3VdbeSetNumCols(v, 1); 436 setOneColumnName(v, "cache_size");
848 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
849 pParse->nMem += 2; 437 pParse->nMem += 2;
850 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn); 438 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
851 sqlite3VdbeChangeP1(v, addr, iDb); 439 sqlite3VdbeChangeP1(v, addr, iDb);
852 sqlite3VdbeChangeP1(v, addr+1, iDb); 440 sqlite3VdbeChangeP1(v, addr+1, iDb);
853 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE); 441 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
854 }else{ 442 }else{
855 int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); 443 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
856 sqlite3BeginWriteOperation(pParse, 0, iDb); 444 sqlite3BeginWriteOperation(pParse, 0, iDb);
857 sqlite3VdbeAddOp2(v, OP_Integer, size, 1); 445 sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
858 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1); 446 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
859 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); 447 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
860 pDb->pSchema->cache_size = size; 448 pDb->pSchema->cache_size = size;
861 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); 449 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
862 } 450 }
863 break; 451 break;
864 } 452 }
865 #endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */ 453 #endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */
866 454
867 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) 455 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
868 /* 456 /*
869 ** PRAGMA [database.]page_size 457 ** PRAGMA [schema.]page_size
870 ** PRAGMA [database.]page_size=N 458 ** PRAGMA [schema.]page_size=N
871 ** 459 **
872 ** The first form reports the current setting for the 460 ** The first form reports the current setting for the
873 ** database page size in bytes. The second form sets the 461 ** database page size in bytes. The second form sets the
874 ** database page size value. The value can only be set if 462 ** database page size value. The value can only be set if
875 ** the database has not yet been created. 463 ** the database has not yet been created.
876 */ 464 */
877 case PragTyp_PAGE_SIZE: { 465 case PragTyp_PAGE_SIZE: {
878 Btree *pBt = pDb->pBt; 466 Btree *pBt = pDb->pBt;
879 assert( pBt!=0 ); 467 assert( pBt!=0 );
880 if( !zRight ){ 468 if( !zRight ){
881 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0; 469 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
882 returnSingleInt(pParse, "page_size", size); 470 returnSingleInt(v, "page_size", size);
883 }else{ 471 }else{
884 /* Malloc may fail when setting the page-size, as there is an internal 472 /* Malloc may fail when setting the page-size, as there is an internal
885 ** buffer that the pager module resizes using sqlite3_realloc(). 473 ** buffer that the pager module resizes using sqlite3_realloc().
886 */ 474 */
887 db->nextPagesize = sqlite3Atoi(zRight); 475 db->nextPagesize = sqlite3Atoi(zRight);
888 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){ 476 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
889 db->mallocFailed = 1; 477 db->mallocFailed = 1;
890 } 478 }
891 } 479 }
892 break; 480 break;
893 } 481 }
894 482
895 /* 483 /*
896 ** PRAGMA [database.]secure_delete 484 ** PRAGMA [schema.]secure_delete
897 ** PRAGMA [database.]secure_delete=ON/OFF 485 ** PRAGMA [schema.]secure_delete=ON/OFF
898 ** 486 **
899 ** The first form reports the current setting for the 487 ** The first form reports the current setting for the
900 ** secure_delete flag. The second form changes the secure_delete 488 ** secure_delete flag. The second form changes the secure_delete
901 ** flag setting and reports thenew value. 489 ** flag setting and reports thenew value.
902 */ 490 */
903 case PragTyp_SECURE_DELETE: { 491 case PragTyp_SECURE_DELETE: {
904 Btree *pBt = pDb->pBt; 492 Btree *pBt = pDb->pBt;
905 int b = -1; 493 int b = -1;
906 assert( pBt!=0 ); 494 assert( pBt!=0 );
907 if( zRight ){ 495 if( zRight ){
908 b = sqlite3GetBoolean(zRight, 0); 496 b = sqlite3GetBoolean(zRight, 0);
909 } 497 }
910 if( pId2->n==0 && b>=0 ){ 498 if( pId2->n==0 && b>=0 ){
911 int ii; 499 int ii;
912 for(ii=0; ii<db->nDb; ii++){ 500 for(ii=0; ii<db->nDb; ii++){
913 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b); 501 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
914 } 502 }
915 } 503 }
916 b = sqlite3BtreeSecureDelete(pBt, b); 504 b = sqlite3BtreeSecureDelete(pBt, b);
917 returnSingleInt(pParse, "secure_delete", b); 505 returnSingleInt(v, "secure_delete", b);
918 break; 506 break;
919 } 507 }
920 508
921 /* 509 /*
922 ** PRAGMA [database.]max_page_count 510 ** PRAGMA [schema.]max_page_count
923 ** PRAGMA [database.]max_page_count=N 511 ** PRAGMA [schema.]max_page_count=N
924 ** 512 **
925 ** The first form reports the current setting for the 513 ** The first form reports the current setting for the
926 ** maximum number of pages in the database file. The 514 ** maximum number of pages in the database file. The
927 ** second form attempts to change this setting. Both 515 ** second form attempts to change this setting. Both
928 ** forms return the current setting. 516 ** forms return the current setting.
929 ** 517 **
930 ** The absolute value of N is used. This is undocumented and might 518 ** 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 519 ** change. The only purpose is to provide an easy way to test
932 ** the sqlite3AbsInt32() function. 520 ** the sqlite3AbsInt32() function.
933 ** 521 **
934 ** PRAGMA [database.]page_count 522 ** PRAGMA [schema.]page_count
935 ** 523 **
936 ** Return the number of pages in the specified database. 524 ** Return the number of pages in the specified database.
937 */ 525 */
938 case PragTyp_PAGE_COUNT: { 526 case PragTyp_PAGE_COUNT: {
939 int iReg; 527 int iReg;
940 sqlite3CodeVerifySchema(pParse, iDb); 528 sqlite3CodeVerifySchema(pParse, iDb);
941 iReg = ++pParse->nMem; 529 iReg = ++pParse->nMem;
942 if( sqlite3Tolower(zLeft[0])=='p' ){ 530 if( sqlite3Tolower(zLeft[0])=='p' ){
943 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); 531 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
944 }else{ 532 }else{
945 sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, 533 sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg,
946 sqlite3AbsInt32(sqlite3Atoi(zRight))); 534 sqlite3AbsInt32(sqlite3Atoi(zRight)));
947 } 535 }
948 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1); 536 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
949 sqlite3VdbeSetNumCols(v, 1); 537 sqlite3VdbeSetNumCols(v, 1);
950 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT); 538 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
951 break; 539 break;
952 } 540 }
953 541
954 /* 542 /*
955 ** PRAGMA [database.]locking_mode 543 ** PRAGMA [schema.]locking_mode
956 ** PRAGMA [database.]locking_mode = (normal|exclusive) 544 ** PRAGMA [schema.]locking_mode = (normal|exclusive)
957 */ 545 */
958 case PragTyp_LOCKING_MODE: { 546 case PragTyp_LOCKING_MODE: {
959 const char *zRet = "normal"; 547 const char *zRet = "normal";
960 int eMode = getLockingMode(zRight); 548 int eMode = getLockingMode(zRight);
961 549
962 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){ 550 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
963 /* Simple "PRAGMA locking_mode;" statement. This is a query for 551 /* Simple "PRAGMA locking_mode;" statement. This is a query for
964 ** the current default locking mode (which may be different to 552 ** the current default locking mode (which may be different to
965 ** the locking-mode of the main database). 553 ** the locking-mode of the main database).
966 */ 554 */
(...skipping 19 matching lines...) Expand all
986 } 574 }
987 pPager = sqlite3BtreePager(pDb->pBt); 575 pPager = sqlite3BtreePager(pDb->pBt);
988 eMode = sqlite3PagerLockingMode(pPager, eMode); 576 eMode = sqlite3PagerLockingMode(pPager, eMode);
989 } 577 }
990 578
991 assert( eMode==PAGER_LOCKINGMODE_NORMAL 579 assert( eMode==PAGER_LOCKINGMODE_NORMAL
992 || eMode==PAGER_LOCKINGMODE_EXCLUSIVE ); 580 || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
993 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){ 581 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
994 zRet = "exclusive"; 582 zRet = "exclusive";
995 } 583 }
996 sqlite3VdbeSetNumCols(v, 1); 584 returnSingleText(v, "locking_mode", zRet);
997 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
998 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
999 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
1000 break; 585 break;
1001 } 586 }
1002 587
1003 /* 588 /*
1004 ** PRAGMA [database.]journal_mode 589 ** PRAGMA [schema.]journal_mode
1005 ** PRAGMA [database.]journal_mode = 590 ** PRAGMA [schema.]journal_mode =
1006 ** (delete|persist|off|truncate|memory|wal|off) 591 ** (delete|persist|off|truncate|memory|wal|off)
1007 */ 592 */
1008 case PragTyp_JOURNAL_MODE: { 593 case PragTyp_JOURNAL_MODE: {
1009 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */ 594 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
1010 int ii; /* Loop counter */ 595 int ii; /* Loop counter */
1011 596
1012 sqlite3VdbeSetNumCols(v, 1); 597 setOneColumnName(v, "journal_mode");
1013 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
1014
1015 if( zRight==0 ){ 598 if( zRight==0 ){
1016 /* If there is no "=MODE" part of the pragma, do a query for the 599 /* If there is no "=MODE" part of the pragma, do a query for the
1017 ** current mode */ 600 ** current mode */
1018 eMode = PAGER_JOURNALMODE_QUERY; 601 eMode = PAGER_JOURNALMODE_QUERY;
1019 }else{ 602 }else{
1020 const char *zMode; 603 const char *zMode;
1021 int n = sqlite3Strlen30(zRight); 604 int n = sqlite3Strlen30(zRight);
1022 for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){ 605 for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
1023 if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break; 606 if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
1024 } 607 }
(...skipping 12 matching lines...) Expand all
1037 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){ 620 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
1038 sqlite3VdbeUsesBtree(v, ii); 621 sqlite3VdbeUsesBtree(v, ii);
1039 sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode); 622 sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
1040 } 623 }
1041 } 624 }
1042 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); 625 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
1043 break; 626 break;
1044 } 627 }
1045 628
1046 /* 629 /*
1047 ** PRAGMA [database.]journal_size_limit 630 ** PRAGMA [schema.]journal_size_limit
1048 ** PRAGMA [database.]journal_size_limit=N 631 ** PRAGMA [schema.]journal_size_limit=N
1049 ** 632 **
1050 ** Get or set the size limit on rollback journal files. 633 ** Get or set the size limit on rollback journal files.
1051 */ 634 */
1052 case PragTyp_JOURNAL_SIZE_LIMIT: { 635 case PragTyp_JOURNAL_SIZE_LIMIT: {
1053 Pager *pPager = sqlite3BtreePager(pDb->pBt); 636 Pager *pPager = sqlite3BtreePager(pDb->pBt);
1054 i64 iLimit = -2; 637 i64 iLimit = -2;
1055 if( zRight ){ 638 if( zRight ){
1056 sqlite3DecOrHexToI64(zRight, &iLimit); 639 sqlite3DecOrHexToI64(zRight, &iLimit);
1057 if( iLimit<-1 ) iLimit = -1; 640 if( iLimit<-1 ) iLimit = -1;
1058 } 641 }
1059 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit); 642 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
1060 returnSingleInt(pParse, "journal_size_limit", iLimit); 643 returnSingleInt(v, "journal_size_limit", iLimit);
1061 break; 644 break;
1062 } 645 }
1063 646
1064 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ 647 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
1065 648
1066 /* 649 /*
1067 ** PRAGMA [database.]auto_vacuum 650 ** PRAGMA [schema.]auto_vacuum
1068 ** PRAGMA [database.]auto_vacuum=N 651 ** PRAGMA [schema.]auto_vacuum=N
1069 ** 652 **
1070 ** Get or set the value of the database 'auto-vacuum' parameter. 653 ** Get or set the value of the database 'auto-vacuum' parameter.
1071 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL 654 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
1072 */ 655 */
1073 #ifndef SQLITE_OMIT_AUTOVACUUM 656 #ifndef SQLITE_OMIT_AUTOVACUUM
1074 case PragTyp_AUTO_VACUUM: { 657 case PragTyp_AUTO_VACUUM: {
1075 Btree *pBt = pDb->pBt; 658 Btree *pBt = pDb->pBt;
1076 assert( pBt!=0 ); 659 assert( pBt!=0 );
1077 if( !zRight ){ 660 if( !zRight ){
1078 returnSingleInt(pParse, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt)); 661 returnSingleInt(v, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
1079 }else{ 662 }else{
1080 int eAuto = getAutoVacuum(zRight); 663 int eAuto = getAutoVacuum(zRight);
1081 assert( eAuto>=0 && eAuto<=2 ); 664 assert( eAuto>=0 && eAuto<=2 );
1082 db->nextAutovac = (u8)eAuto; 665 db->nextAutovac = (u8)eAuto;
1083 /* Call SetAutoVacuum() to set initialize the internal auto and 666 /* Call SetAutoVacuum() to set initialize the internal auto and
1084 ** incr-vacuum flags. This is required in case this connection 667 ** incr-vacuum flags. This is required in case this connection
1085 ** creates the database file. It is important that it is created 668 ** creates the database file. It is important that it is created
1086 ** as an auto-vacuum capable db. 669 ** as an auto-vacuum capable db.
1087 */ 670 */
1088 rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); 671 rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
(...skipping 20 matching lines...) Expand all
1109 sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1); 692 sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
1110 sqlite3VdbeChangeP1(v, iAddr+5, iDb); 693 sqlite3VdbeChangeP1(v, iAddr+5, iDb);
1111 sqlite3VdbeUsesBtree(v, iDb); 694 sqlite3VdbeUsesBtree(v, iDb);
1112 } 695 }
1113 } 696 }
1114 break; 697 break;
1115 } 698 }
1116 #endif 699 #endif
1117 700
1118 /* 701 /*
1119 ** PRAGMA [database.]incremental_vacuum(N) 702 ** PRAGMA [schema.]incremental_vacuum(N)
1120 ** 703 **
1121 ** Do N steps of incremental vacuuming on a database. 704 ** Do N steps of incremental vacuuming on a database.
1122 */ 705 */
1123 #ifndef SQLITE_OMIT_AUTOVACUUM 706 #ifndef SQLITE_OMIT_AUTOVACUUM
1124 case PragTyp_INCREMENTAL_VACUUM: { 707 case PragTyp_INCREMENTAL_VACUUM: {
1125 int iLimit, addr; 708 int iLimit, addr;
1126 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ 709 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
1127 iLimit = 0x7fffffff; 710 iLimit = 0x7fffffff;
1128 } 711 }
1129 sqlite3BeginWriteOperation(pParse, 0, iDb); 712 sqlite3BeginWriteOperation(pParse, 0, iDb);
1130 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1); 713 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
1131 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v); 714 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v);
1132 sqlite3VdbeAddOp1(v, OP_ResultRow, 1); 715 sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
1133 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); 716 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
1134 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v); 717 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v);
1135 sqlite3VdbeJumpHere(v, addr); 718 sqlite3VdbeJumpHere(v, addr);
1136 break; 719 break;
1137 } 720 }
1138 #endif 721 #endif
1139 722
1140 #ifndef SQLITE_OMIT_PAGER_PRAGMAS 723 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
1141 /* 724 /*
1142 ** PRAGMA [database.]cache_size 725 ** PRAGMA [schema.]cache_size
1143 ** PRAGMA [database.]cache_size=N 726 ** PRAGMA [schema.]cache_size=N
1144 ** 727 **
1145 ** The first form reports the current local setting for the 728 ** The first form reports the current local setting for the
1146 ** page cache size. The second form sets the local 729 ** page cache size. The second form sets the local
1147 ** page cache size value. If N is positive then that is the 730 ** page cache size value. If N is positive then that is the
1148 ** number of pages in the cache. If N is negative, then the 731 ** number of pages in the cache. If N is negative, then the
1149 ** number of pages is adjusted so that the cache uses -N kibibytes 732 ** number of pages is adjusted so that the cache uses -N kibibytes
1150 ** of memory. 733 ** of memory.
1151 */ 734 */
1152 case PragTyp_CACHE_SIZE: { 735 case PragTyp_CACHE_SIZE: {
1153 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); 736 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
1154 if( !zRight ){ 737 if( !zRight ){
1155 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); 738 returnSingleInt(v, "cache_size", pDb->pSchema->cache_size);
1156 }else{ 739 }else{
1157 int size = sqlite3Atoi(zRight); 740 int size = sqlite3Atoi(zRight);
1158 pDb->pSchema->cache_size = size; 741 pDb->pSchema->cache_size = size;
1159 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); 742 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
1160 } 743 }
1161 break; 744 break;
1162 } 745 }
1163 746
1164 /* 747 /*
1165 ** PRAGMA [database.]mmap_size(N) 748 ** PRAGMA [schema.]cache_spill
749 ** PRAGMA cache_spill=BOOLEAN
750 ** PRAGMA [schema.]cache_spill=N
751 **
752 ** The first form reports the current local setting for the
753 ** page cache spill size. The second form turns cache spill on
754 ** or off. When turnning cache spill on, the size is set to the
755 ** current cache_size. The third form sets a spill size that
756 ** may be different form the cache size.
757 ** If N is positive then that is the
758 ** number of pages in the cache. If N is negative, then the
759 ** number of pages is adjusted so that the cache uses -N kibibytes
760 ** of memory.
761 **
762 ** If the number of cache_spill pages is less then the number of
763 ** cache_size pages, no spilling occurs until the page count exceeds
764 ** the number of cache_size pages.
765 **
766 ** The cache_spill=BOOLEAN setting applies to all attached schemas,
767 ** not just the schema specified.
768 */
769 case PragTyp_CACHE_SPILL: {
770 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
771 if( !zRight ){
772 returnSingleInt(v, "cache_spill",
773 (db->flags & SQLITE_CacheSpill)==0 ? 0 :
774 sqlite3BtreeSetSpillSize(pDb->pBt,0));
775 }else{
776 int size = 1;
777 if( sqlite3GetInt32(zRight, &size) ){
778 sqlite3BtreeSetSpillSize(pDb->pBt, size);
779 }
780 if( sqlite3GetBoolean(zRight, size!=0) ){
781 db->flags |= SQLITE_CacheSpill;
782 }else{
783 db->flags &= ~SQLITE_CacheSpill;
784 }
785 setAllPagerFlags(db);
786 }
787 break;
788 }
789
790 /*
791 ** PRAGMA [schema.]mmap_size(N)
1166 ** 792 **
1167 ** Used to set mapping size limit. The mapping size limit is 793 ** 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 794 ** 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 795 ** 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 796 ** 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. 797 ** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set.
1172 ** The parameter N is measured in bytes. 798 ** The parameter N is measured in bytes.
1173 ** 799 **
1174 ** This value is advisory. The underlying VFS is free to memory map 800 ** 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 801 ** as little or as much as it wants. Except, if N is set to 0 then the
(...skipping 14 matching lines...) Expand all
1190 } 816 }
1191 } 817 }
1192 } 818 }
1193 sz = -1; 819 sz = -1;
1194 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz); 820 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz);
1195 #else 821 #else
1196 sz = 0; 822 sz = 0;
1197 rc = SQLITE_OK; 823 rc = SQLITE_OK;
1198 #endif 824 #endif
1199 if( rc==SQLITE_OK ){ 825 if( rc==SQLITE_OK ){
1200 returnSingleInt(pParse, "mmap_size", sz); 826 returnSingleInt(v, "mmap_size", sz);
1201 }else if( rc!=SQLITE_NOTFOUND ){ 827 }else if( rc!=SQLITE_NOTFOUND ){
1202 pParse->nErr++; 828 pParse->nErr++;
1203 pParse->rc = rc; 829 pParse->rc = rc;
1204 } 830 }
1205 break; 831 break;
1206 } 832 }
1207 833
1208 /* 834 /*
1209 ** PRAGMA temp_store 835 ** PRAGMA temp_store
1210 ** PRAGMA temp_store = "default"|"memory"|"file" 836 ** PRAGMA temp_store = "default"|"memory"|"file"
1211 ** 837 **
1212 ** Return or set the local value of the temp_store flag. Changing 838 ** Return or set the local value of the temp_store flag. Changing
1213 ** the local value does not make changes to the disk file and the default 839 ** the local value does not make changes to the disk file and the default
1214 ** value will be restored the next time the database is opened. 840 ** value will be restored the next time the database is opened.
1215 ** 841 **
1216 ** Note that it is possible for the library compile-time options to 842 ** Note that it is possible for the library compile-time options to
1217 ** override this setting 843 ** override this setting
1218 */ 844 */
1219 case PragTyp_TEMP_STORE: { 845 case PragTyp_TEMP_STORE: {
1220 if( !zRight ){ 846 if( !zRight ){
1221 returnSingleInt(pParse, "temp_store", db->temp_store); 847 returnSingleInt(v, "temp_store", db->temp_store);
1222 }else{ 848 }else{
1223 changeTempStorage(pParse, zRight); 849 changeTempStorage(pParse, zRight);
1224 } 850 }
1225 break; 851 break;
1226 } 852 }
1227 853
1228 /* 854 /*
1229 ** PRAGMA temp_store_directory 855 ** PRAGMA temp_store_directory
1230 ** PRAGMA temp_store_directory = ""|"directory_name" 856 ** PRAGMA temp_store_directory = ""|"directory_name"
1231 ** 857 **
1232 ** Return or set the local value of the temp_store_directory flag. Changing 858 ** Return or set the local value of the temp_store_directory flag. Changing
1233 ** the value sets a specific directory to be used for temporary files. 859 ** the value sets a specific directory to be used for temporary files.
1234 ** Setting to a null string reverts to the default temporary directory search. 860 ** Setting to a null string reverts to the default temporary directory search.
1235 ** If temporary directory is changed, then invalidateTempStorage. 861 ** If temporary directory is changed, then invalidateTempStorage.
1236 ** 862 **
1237 */ 863 */
1238 case PragTyp_TEMP_STORE_DIRECTORY: { 864 case PragTyp_TEMP_STORE_DIRECTORY: {
1239 if( !zRight ){ 865 if( !zRight ){
1240 if( sqlite3_temp_directory ){ 866 returnSingleText(v, "temp_store_directory", sqlite3_temp_directory);
1241 sqlite3VdbeSetNumCols(v, 1);
1242 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
1243 "temp_store_directory", SQLITE_STATIC);
1244 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
1245 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
1246 }
1247 }else{ 867 }else{
1248 #ifndef SQLITE_OMIT_WSD 868 #ifndef SQLITE_OMIT_WSD
1249 if( zRight[0] ){ 869 if( zRight[0] ){
1250 int res; 870 int res;
1251 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); 871 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
1252 if( rc!=SQLITE_OK || res==0 ){ 872 if( rc!=SQLITE_OK || res==0 ){
1253 sqlite3ErrorMsg(pParse, "not a writable directory"); 873 sqlite3ErrorMsg(pParse, "not a writable directory");
1254 goto pragma_out; 874 goto pragma_out;
1255 } 875 }
1256 } 876 }
(...skipping 23 matching lines...) Expand all
1280 ** the value sets a specific directory to be used for database files that 900 ** 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 901 ** were specified with a relative pathname. Setting to a null string reverts
1282 ** to the default database directory, which for database files specified with 902 ** 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 903 ** 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 904 ** process. Database file specified with an absolute path are not impacted
1285 ** by this setting, regardless of its value. 905 ** by this setting, regardless of its value.
1286 ** 906 **
1287 */ 907 */
1288 case PragTyp_DATA_STORE_DIRECTORY: { 908 case PragTyp_DATA_STORE_DIRECTORY: {
1289 if( !zRight ){ 909 if( !zRight ){
1290 if( sqlite3_data_directory ){ 910 returnSingleText(v, "data_store_directory", 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{ 911 }else{
1298 #ifndef SQLITE_OMIT_WSD 912 #ifndef SQLITE_OMIT_WSD
1299 if( zRight[0] ){ 913 if( zRight[0] ){
1300 int res; 914 int res;
1301 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res); 915 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
1302 if( rc!=SQLITE_OK || res==0 ){ 916 if( rc!=SQLITE_OK || res==0 ){
1303 sqlite3ErrorMsg(pParse, "not a writable directory"); 917 sqlite3ErrorMsg(pParse, "not a writable directory");
1304 goto pragma_out; 918 goto pragma_out;
1305 } 919 }
1306 } 920 }
1307 sqlite3_free(sqlite3_data_directory); 921 sqlite3_free(sqlite3_data_directory);
1308 if( zRight[0] ){ 922 if( zRight[0] ){
1309 sqlite3_data_directory = sqlite3_mprintf("%s", zRight); 923 sqlite3_data_directory = sqlite3_mprintf("%s", zRight);
1310 }else{ 924 }else{
1311 sqlite3_data_directory = 0; 925 sqlite3_data_directory = 0;
1312 } 926 }
1313 #endif /* SQLITE_OMIT_WSD */ 927 #endif /* SQLITE_OMIT_WSD */
1314 } 928 }
1315 break; 929 break;
1316 } 930 }
1317 #endif 931 #endif
1318 932
1319 #if SQLITE_ENABLE_LOCKING_STYLE 933 #if SQLITE_ENABLE_LOCKING_STYLE
1320 /* 934 /*
1321 ** PRAGMA [database.]lock_proxy_file 935 ** PRAGMA [schema.]lock_proxy_file
1322 ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path" 936 ** PRAGMA [schema.]lock_proxy_file = ":auto:"|"lock_file_path"
1323 ** 937 **
1324 ** Return or set the value of the lock_proxy_file flag. Changing 938 ** Return or set the value of the lock_proxy_file flag. Changing
1325 ** the value sets a specific file to be used for database access locks. 939 ** the value sets a specific file to be used for database access locks.
1326 ** 940 **
1327 */ 941 */
1328 case PragTyp_LOCK_PROXY_FILE: { 942 case PragTyp_LOCK_PROXY_FILE: {
1329 if( !zRight ){ 943 if( !zRight ){
1330 Pager *pPager = sqlite3BtreePager(pDb->pBt); 944 Pager *pPager = sqlite3BtreePager(pDb->pBt);
1331 char *proxy_file_path = NULL; 945 char *proxy_file_path = NULL;
1332 sqlite3_file *pFile = sqlite3PagerFile(pPager); 946 sqlite3_file *pFile = sqlite3PagerFile(pPager);
1333 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE, 947 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
1334 &proxy_file_path); 948 &proxy_file_path);
1335 949 returnSingleText(v, "lock_proxy_file", proxy_file_path);
1336 if( proxy_file_path ){
1337 sqlite3VdbeSetNumCols(v, 1);
1338 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
1339 "lock_proxy_file", SQLITE_STATIC);
1340 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0);
1341 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
1342 }
1343 }else{ 950 }else{
1344 Pager *pPager = sqlite3BtreePager(pDb->pBt); 951 Pager *pPager = sqlite3BtreePager(pDb->pBt);
1345 sqlite3_file *pFile = sqlite3PagerFile(pPager); 952 sqlite3_file *pFile = sqlite3PagerFile(pPager);
1346 int res; 953 int res;
1347 if( zRight[0] ){ 954 if( zRight[0] ){
1348 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, 955 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
1349 zRight); 956 zRight);
1350 } else { 957 } else {
1351 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, 958 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
1352 NULL); 959 NULL);
1353 } 960 }
1354 if( res!=SQLITE_OK ){ 961 if( res!=SQLITE_OK ){
1355 sqlite3ErrorMsg(pParse, "failed to set lock proxy file"); 962 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
1356 goto pragma_out; 963 goto pragma_out;
1357 } 964 }
1358 } 965 }
1359 break; 966 break;
1360 } 967 }
1361 #endif /* SQLITE_ENABLE_LOCKING_STYLE */ 968 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
1362 969
1363 /* 970 /*
1364 ** PRAGMA [database.]synchronous 971 ** PRAGMA [schema.]synchronous
1365 ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL 972 ** PRAGMA [schema.]synchronous=OFF|ON|NORMAL|FULL
1366 ** 973 **
1367 ** Return or set the local value of the synchronous flag. Changing 974 ** Return or set the local value of the synchronous flag. Changing
1368 ** the local value does not make changes to the disk file and the 975 ** the local value does not make changes to the disk file and the
1369 ** default value will be restored the next time the database is 976 ** default value will be restored the next time the database is
1370 ** opened. 977 ** opened.
1371 */ 978 */
1372 case PragTyp_SYNCHRONOUS: { 979 case PragTyp_SYNCHRONOUS: {
1373 if( !zRight ){ 980 if( !zRight ){
1374 returnSingleInt(pParse, "synchronous", pDb->safety_level-1); 981 returnSingleInt(v, "synchronous", pDb->safety_level-1);
1375 }else{ 982 }else{
1376 if( !db->autoCommit ){ 983 if( !db->autoCommit ){
1377 sqlite3ErrorMsg(pParse, 984 sqlite3ErrorMsg(pParse,
1378 "Safety level may not be changed inside a transaction"); 985 "Safety level may not be changed inside a transaction");
1379 }else{ 986 }else{
1380 pDb->safety_level = getSafetyLevel(zRight,0,1)+1; 987 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
988 if( iLevel==0 ) iLevel = 1;
989 pDb->safety_level = iLevel;
1381 setAllPagerFlags(db); 990 setAllPagerFlags(db);
1382 } 991 }
1383 } 992 }
1384 break; 993 break;
1385 } 994 }
1386 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ 995 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
1387 996
1388 #ifndef SQLITE_OMIT_FLAG_PRAGMAS 997 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
1389 case PragTyp_FLAG: { 998 case PragTyp_FLAG: {
1390 if( zRight==0 ){ 999 if( zRight==0 ){
1391 returnSingleInt(pParse, aPragmaNames[mid].zName, 1000 returnSingleInt(v, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
1392 (db->flags & aPragmaNames[mid].iArg)!=0 );
1393 }else{ 1001 }else{
1394 int mask = aPragmaNames[mid].iArg; /* Mask of bits to set or clear. */ 1002 int mask = pPragma->iArg; /* Mask of bits to set or clear. */
1395 if( db->autoCommit==0 ){ 1003 if( db->autoCommit==0 ){
1396 /* Foreign key support may not be enabled or disabled while not 1004 /* Foreign key support may not be enabled or disabled while not
1397 ** in auto-commit mode. */ 1005 ** in auto-commit mode. */
1398 mask &= ~(SQLITE_ForeignKeys); 1006 mask &= ~(SQLITE_ForeignKeys);
1399 } 1007 }
1400 #if SQLITE_USER_AUTHENTICATION 1008 #if SQLITE_USER_AUTHENTICATION
1401 if( db->auth.authLevel==UAUTH_User ){ 1009 if( db->auth.authLevel==UAUTH_User ){
1402 /* Do not allow non-admin users to modify the schema arbitrarily */ 1010 /* Do not allow non-admin users to modify the schema arbitrarily */
1403 mask &= ~(SQLITE_WriteSchema); 1011 mask &= ~(SQLITE_WriteSchema);
1404 } 1012 }
(...skipping 27 matching lines...) Expand all
1432 ** cid: Column id (numbered from left to right, starting at 0) 1040 ** cid: Column id (numbered from left to right, starting at 0)
1433 ** name: Column name 1041 ** name: Column name
1434 ** type: Column declaration type. 1042 ** type: Column declaration type.
1435 ** notnull: True if 'NOT NULL' is part of column declaration 1043 ** notnull: True if 'NOT NULL' is part of column declaration
1436 ** dflt_value: The default value for the column, if any. 1044 ** dflt_value: The default value for the column, if any.
1437 */ 1045 */
1438 case PragTyp_TABLE_INFO: if( zRight ){ 1046 case PragTyp_TABLE_INFO: if( zRight ){
1439 Table *pTab; 1047 Table *pTab;
1440 pTab = sqlite3FindTable(db, zRight, zDb); 1048 pTab = sqlite3FindTable(db, zRight, zDb);
1441 if( pTab ){ 1049 if( pTab ){
1050 static const char *azCol[] = {
1051 "cid", "name", "type", "notnull", "dflt_value", "pk"
1052 };
1442 int i, k; 1053 int i, k;
1443 int nHidden = 0; 1054 int nHidden = 0;
1444 Column *pCol; 1055 Column *pCol;
1445 Index *pPk = sqlite3PrimaryKeyIndex(pTab); 1056 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
1446 sqlite3VdbeSetNumCols(v, 6);
1447 pParse->nMem = 6; 1057 pParse->nMem = 6;
1448 sqlite3CodeVerifySchema(pParse, iDb); 1058 sqlite3CodeVerifySchema(pParse, iDb);
1449 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC); 1059 setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
1450 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
1451 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
1452 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
1453 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
1454 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
1455 sqlite3ViewGetColumnNames(pParse, pTab); 1060 sqlite3ViewGetColumnNames(pParse, pTab);
1456 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ 1061 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
1457 if( IsHiddenColumn(pCol) ){ 1062 if( IsHiddenColumn(pCol) ){
1458 nHidden++; 1063 nHidden++;
1459 continue; 1064 continue;
1460 } 1065 }
1461 sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
1462 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
1463 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
1464 pCol->zType ? pCol->zType : "", 0);
1465 sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
1466 if( pCol->zDflt ){
1467 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
1468 }else{
1469 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
1470 }
1471 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){ 1066 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
1472 k = 0; 1067 k = 0;
1473 }else if( pPk==0 ){ 1068 }else if( pPk==0 ){
1474 k = 1; 1069 k = 1;
1475 }else{ 1070 }else{
1476 for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){} 1071 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
1477 } 1072 }
1478 sqlite3VdbeAddOp2(v, OP_Integer, k, 6); 1073 sqlite3VdbeMultiLoad(v, 1, "issisi",
1074 i-nHidden,
1075 pCol->zName,
1076 pCol->zType ? pCol->zType : "",
1077 pCol->notNull ? 1 : 0,
1078 pCol->zDflt,
1079 k);
1479 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); 1080 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
1480 } 1081 }
1481 } 1082 }
1482 } 1083 }
1483 break; 1084 break;
1484 1085
1485 case PragTyp_STATS: { 1086 case PragTyp_STATS: {
1087 static const char *azCol[] = { "table", "index", "width", "height" };
1486 Index *pIdx; 1088 Index *pIdx;
1487 HashElem *i; 1089 HashElem *i;
1488 v = sqlite3GetVdbe(pParse); 1090 v = sqlite3GetVdbe(pParse);
1489 sqlite3VdbeSetNumCols(v, 4);
1490 pParse->nMem = 4; 1091 pParse->nMem = 4;
1491 sqlite3CodeVerifySchema(pParse, iDb); 1092 sqlite3CodeVerifySchema(pParse, iDb);
1492 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC); 1093 setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
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)){ 1094 for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
1497 Table *pTab = sqliteHashData(i); 1095 Table *pTab = sqliteHashData(i);
1498 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, pTab->zName, 0); 1096 sqlite3VdbeMultiLoad(v, 1, "ssii",
1499 sqlite3VdbeAddOp2(v, OP_Null, 0, 2); 1097 pTab->zName,
1500 sqlite3VdbeAddOp2(v, OP_Integer, 1098 0,
1501 (int)sqlite3LogEstToInt(pTab->szTabRow), 3); 1099 (int)sqlite3LogEstToInt(pTab->szTabRow),
1502 sqlite3VdbeAddOp2(v, OP_Integer, 1100 (int)sqlite3LogEstToInt(pTab->nRowLogEst));
1503 (int)sqlite3LogEstToInt(pTab->nRowLogEst), 4);
1504 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); 1101 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
1505 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ 1102 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
1506 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); 1103 sqlite3VdbeMultiLoad(v, 2, "sii",
1507 sqlite3VdbeAddOp2(v, OP_Integer, 1104 pIdx->zName,
1508 (int)sqlite3LogEstToInt(pIdx->szIdxRow), 3); 1105 (int)sqlite3LogEstToInt(pIdx->szIdxRow),
1509 sqlite3VdbeAddOp2(v, OP_Integer, 1106 (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]));
1510 (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]), 4);
1511 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); 1107 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
1512 } 1108 }
1513 } 1109 }
1514 } 1110 }
1515 break; 1111 break;
1516 1112
1517 case PragTyp_INDEX_INFO: if( zRight ){ 1113 case PragTyp_INDEX_INFO: if( zRight ){
1518 Index *pIdx; 1114 Index *pIdx;
1519 Table *pTab; 1115 Table *pTab;
1520 pIdx = sqlite3FindIndex(db, zRight, zDb); 1116 pIdx = sqlite3FindIndex(db, zRight, zDb);
1521 if( pIdx ){ 1117 if( pIdx ){
1118 static const char *azCol[] = {
1119 "seqno", "cid", "name", "desc", "coll", "key"
1120 };
1522 int i; 1121 int i;
1122 int mx;
1123 if( pPragma->iArg ){
1124 /* PRAGMA index_xinfo (newer version with more rows and columns) */
1125 mx = pIdx->nColumn;
1126 pParse->nMem = 6;
1127 }else{
1128 /* PRAGMA index_info (legacy version) */
1129 mx = pIdx->nKeyCol;
1130 pParse->nMem = 3;
1131 }
1523 pTab = pIdx->pTable; 1132 pTab = pIdx->pTable;
1524 sqlite3VdbeSetNumCols(v, 3);
1525 pParse->nMem = 3;
1526 sqlite3CodeVerifySchema(pParse, iDb); 1133 sqlite3CodeVerifySchema(pParse, iDb);
1527 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC); 1134 assert( pParse->nMem<=ArraySize(azCol) );
1528 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC); 1135 setAllColumnNames(v, pParse->nMem, azCol);
1529 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC); 1136 for(i=0; i<mx; i++){
1530 for(i=0; i<pIdx->nKeyCol; i++){
1531 i16 cnum = pIdx->aiColumn[i]; 1137 i16 cnum = pIdx->aiColumn[i];
1532 sqlite3VdbeAddOp2(v, OP_Integer, i, 1); 1138 sqlite3VdbeMultiLoad(v, 1, "iis", i, cnum,
1533 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2); 1139 cnum<0 ? 0 : pTab->aCol[cnum].zName);
1534 assert( pTab->nCol>cnum ); 1140 if( pPragma->iArg ){
1535 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0); 1141 sqlite3VdbeMultiLoad(v, 4, "isi",
1536 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); 1142 pIdx->aSortOrder[i],
1143 pIdx->azColl[i],
1144 i<pIdx->nKeyCol);
1145 }
1146 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem);
1537 } 1147 }
1538 } 1148 }
1539 } 1149 }
1540 break; 1150 break;
1541 1151
1542 case PragTyp_INDEX_LIST: if( zRight ){ 1152 case PragTyp_INDEX_LIST: if( zRight ){
1543 Index *pIdx; 1153 Index *pIdx;
1544 Table *pTab; 1154 Table *pTab;
1545 int i; 1155 int i;
1546 pTab = sqlite3FindTable(db, zRight, zDb); 1156 pTab = sqlite3FindTable(db, zRight, zDb);
1547 if( pTab ){ 1157 if( pTab ){
1158 static const char *azCol[] = {
1159 "seq", "name", "unique", "origin", "partial"
1160 };
1548 v = sqlite3GetVdbe(pParse); 1161 v = sqlite3GetVdbe(pParse);
1549 sqlite3VdbeSetNumCols(v, 3); 1162 pParse->nMem = 5;
1550 pParse->nMem = 3;
1551 sqlite3CodeVerifySchema(pParse, iDb); 1163 sqlite3CodeVerifySchema(pParse, iDb);
1552 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); 1164 setAllColumnNames(v, 5, azCol); assert( 5==ArraySize(azCol) );
1553 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
1554 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
1555 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){ 1165 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
1556 sqlite3VdbeAddOp2(v, OP_Integer, i, 1); 1166 const char *azOrigin[] = { "c", "u", "pk" };
1557 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); 1167 sqlite3VdbeMultiLoad(v, 1, "isisi",
1558 sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3); 1168 i,
1559 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); 1169 pIdx->zName,
1170 IsUniqueIndex(pIdx),
1171 azOrigin[pIdx->idxType],
1172 pIdx->pPartIdxWhere!=0);
1173 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
1560 } 1174 }
1561 } 1175 }
1562 } 1176 }
1563 break; 1177 break;
1564 1178
1565 case PragTyp_DATABASE_LIST: { 1179 case PragTyp_DATABASE_LIST: {
1180 static const char *azCol[] = { "seq", "name", "file" };
1566 int i; 1181 int i;
1567 sqlite3VdbeSetNumCols(v, 3);
1568 pParse->nMem = 3; 1182 pParse->nMem = 3;
1569 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); 1183 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
1570 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
1571 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
1572 for(i=0; i<db->nDb; i++){ 1184 for(i=0; i<db->nDb; i++){
1573 if( db->aDb[i].pBt==0 ) continue; 1185 if( db->aDb[i].pBt==0 ) continue;
1574 assert( db->aDb[i].zName!=0 ); 1186 assert( db->aDb[i].zName!=0 );
1575 sqlite3VdbeAddOp2(v, OP_Integer, i, 1); 1187 sqlite3VdbeMultiLoad(v, 1, "iss",
1576 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0); 1188 i,
1577 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, 1189 db->aDb[i].zName,
1578 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0); 1190 sqlite3BtreeGetFilename(db->aDb[i].pBt));
1579 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); 1191 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
1580 } 1192 }
1581 } 1193 }
1582 break; 1194 break;
1583 1195
1584 case PragTyp_COLLATION_LIST: { 1196 case PragTyp_COLLATION_LIST: {
1197 static const char *azCol[] = { "seq", "name" };
1585 int i = 0; 1198 int i = 0;
1586 HashElem *p; 1199 HashElem *p;
1587 sqlite3VdbeSetNumCols(v, 2);
1588 pParse->nMem = 2; 1200 pParse->nMem = 2;
1589 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); 1201 setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
1590 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
1591 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){ 1202 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
1592 CollSeq *pColl = (CollSeq *)sqliteHashData(p); 1203 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
1593 sqlite3VdbeAddOp2(v, OP_Integer, i++, 1); 1204 sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName);
1594 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
1595 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); 1205 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
1596 } 1206 }
1597 } 1207 }
1598 break; 1208 break;
1599 #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */ 1209 #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
1600 1210
1601 #ifndef SQLITE_OMIT_FOREIGN_KEY 1211 #ifndef SQLITE_OMIT_FOREIGN_KEY
1602 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ 1212 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
1603 FKey *pFK; 1213 FKey *pFK;
1604 Table *pTab; 1214 Table *pTab;
1605 pTab = sqlite3FindTable(db, zRight, zDb); 1215 pTab = sqlite3FindTable(db, zRight, zDb);
1606 if( pTab ){ 1216 if( pTab ){
1607 v = sqlite3GetVdbe(pParse); 1217 v = sqlite3GetVdbe(pParse);
1608 pFK = pTab->pFKey; 1218 pFK = pTab->pFKey;
1609 if( pFK ){ 1219 if( pFK ){
1220 static const char *azCol[] = {
1221 "id", "seq", "table", "from", "to", "on_update", "on_delete",
1222 "match"
1223 };
1610 int i = 0; 1224 int i = 0;
1611 sqlite3VdbeSetNumCols(v, 8);
1612 pParse->nMem = 8; 1225 pParse->nMem = 8;
1613 sqlite3CodeVerifySchema(pParse, iDb); 1226 sqlite3CodeVerifySchema(pParse, iDb);
1614 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC); 1227 setAllColumnNames(v, 8, azCol); assert( 8==ArraySize(azCol) );
1615 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
1616 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
1617 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
1618 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
1619 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
1620 sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
1621 sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
1622 while(pFK){ 1228 while(pFK){
1623 int j; 1229 int j;
1624 for(j=0; j<pFK->nCol; j++){ 1230 for(j=0; j<pFK->nCol; j++){
1625 char *zCol = pFK->aCol[j].zCol; 1231 sqlite3VdbeMultiLoad(v, 1, "iissssss",
1626 char *zOnDelete = (char *)actionName(pFK->aAction[0]); 1232 i,
1627 char *zOnUpdate = (char *)actionName(pFK->aAction[1]); 1233 j,
1628 sqlite3VdbeAddOp2(v, OP_Integer, i, 1); 1234 pFK->zTo,
1629 sqlite3VdbeAddOp2(v, OP_Integer, j, 2); 1235 pTab->aCol[pFK->aCol[j].iFrom].zName,
1630 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0); 1236 pFK->aCol[j].zCol,
1631 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, 1237 actionName(pFK->aAction[1]), /* ON UPDATE */
1632 pTab->aCol[pFK->aCol[j].iFrom].zName, 0); 1238 actionName(pFK->aAction[0]), /* ON DELETE */
1633 sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0); 1239 "NONE");
1634 sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0);
1635 sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0);
1636 sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0);
1637 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8); 1240 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
1638 } 1241 }
1639 ++i; 1242 ++i;
1640 pFK = pFK->pNextFrom; 1243 pFK = pFK->pNextFrom;
1641 } 1244 }
1642 } 1245 }
1643 } 1246 }
1644 } 1247 }
1645 break; 1248 break;
1646 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ 1249 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
1647 1250
1648 #ifndef SQLITE_OMIT_FOREIGN_KEY 1251 #ifndef SQLITE_OMIT_FOREIGN_KEY
1649 #ifndef SQLITE_OMIT_TRIGGER 1252 #ifndef SQLITE_OMIT_TRIGGER
1650 case PragTyp_FOREIGN_KEY_CHECK: { 1253 case PragTyp_FOREIGN_KEY_CHECK: {
1651 FKey *pFK; /* A foreign key constraint */ 1254 FKey *pFK; /* A foreign key constraint */
1652 Table *pTab; /* Child table contain "REFERENCES" keyword */ 1255 Table *pTab; /* Child table contain "REFERENCES" keyword */
1653 Table *pParent; /* Parent table that child points to */ 1256 Table *pParent; /* Parent table that child points to */
1654 Index *pIdx; /* Index in the parent table */ 1257 Index *pIdx; /* Index in the parent table */
1655 int i; /* Loop counter: Foreign key number for pTab */ 1258 int i; /* Loop counter: Foreign key number for pTab */
1656 int j; /* Loop counter: Field of the foreign key */ 1259 int j; /* Loop counter: Field of the foreign key */
1657 HashElem *k; /* Loop counter: Next table in schema */ 1260 HashElem *k; /* Loop counter: Next table in schema */
1658 int x; /* result variable */ 1261 int x; /* result variable */
1659 int regResult; /* 3 registers to hold a result row */ 1262 int regResult; /* 3 registers to hold a result row */
1660 int regKey; /* Register to hold key for checking the FK */ 1263 int regKey; /* Register to hold key for checking the FK */
1661 int regRow; /* Registers to hold a row from pTab */ 1264 int regRow; /* Registers to hold a row from pTab */
1662 int addrTop; /* Top of a loop checking foreign keys */ 1265 int addrTop; /* Top of a loop checking foreign keys */
1663 int addrOk; /* Jump here if the key is OK */ 1266 int addrOk; /* Jump here if the key is OK */
1664 int *aiCols; /* child to parent column mapping */ 1267 int *aiCols; /* child to parent column mapping */
1268 static const char *azCol[] = { "table", "rowid", "parent", "fkid" };
1665 1269
1666 regResult = pParse->nMem+1; 1270 regResult = pParse->nMem+1;
1667 pParse->nMem += 4; 1271 pParse->nMem += 4;
1668 regKey = ++pParse->nMem; 1272 regKey = ++pParse->nMem;
1669 regRow = ++pParse->nMem; 1273 regRow = ++pParse->nMem;
1670 v = sqlite3GetVdbe(pParse); 1274 v = sqlite3GetVdbe(pParse);
1671 sqlite3VdbeSetNumCols(v, 4); 1275 setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
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); 1276 sqlite3CodeVerifySchema(pParse, iDb);
1677 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash); 1277 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
1678 while( k ){ 1278 while( k ){
1679 if( zRight ){ 1279 if( zRight ){
1680 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb); 1280 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
1681 k = 0; 1281 k = 0;
1682 }else{ 1282 }else{
1683 pTab = (Table*)sqliteHashData(k); 1283 pTab = (Table*)sqliteHashData(k);
1684 k = sqliteHashNext(k); 1284 k = sqliteHashNext(k);
1685 } 1285 }
1686 if( pTab==0 || pTab->pFKey==0 ) continue; 1286 if( pTab==0 || pTab->pFKey==0 ) continue;
1687 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); 1287 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
1688 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; 1288 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
1689 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); 1289 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
1690 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult, 0, pTab->zName, 1290 sqlite3VdbeLoadString(v, regResult, pTab->zName);
1691 P4_TRANSIENT);
1692 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ 1291 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
1693 pParent = sqlite3FindTable(db, pFK->zTo, zDb); 1292 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
1694 if( pParent==0 ) continue; 1293 if( pParent==0 ) continue;
1695 pIdx = 0; 1294 pIdx = 0;
1696 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); 1295 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
1697 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0); 1296 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
1698 if( x==0 ){ 1297 if( x==0 ){
1699 if( pIdx==0 ){ 1298 if( pIdx==0 ){
1700 sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead); 1299 sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead);
1701 }else{ 1300 }else{
(...skipping 24 matching lines...) Expand all
1726 if( iKey!=pTab->iPKey ){ 1325 if( iKey!=pTab->iPKey ){
1727 sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow); 1326 sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
1728 sqlite3ColumnDefault(v, pTab, iKey, regRow); 1327 sqlite3ColumnDefault(v, pTab, iKey, regRow);
1729 sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v); 1328 sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
1730 sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow, 1329 sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
1731 sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v); 1330 sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
1732 }else{ 1331 }else{
1733 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow); 1332 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
1734 } 1333 }
1735 sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v); 1334 sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
1736 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk); 1335 sqlite3VdbeGoto(v, addrOk);
1737 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); 1336 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
1738 }else{ 1337 }else{
1739 for(j=0; j<pFK->nCol; j++){ 1338 for(j=0; j<pFK->nCol; j++){
1740 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, 1339 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
1741 aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j); 1340 aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
1742 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v); 1341 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
1743 } 1342 }
1744 if( pParent ){ 1343 if( pParent ){
1745 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey, 1344 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
1746 sqlite3IndexAffinityStr(v,pIdx), pFK->nCol); 1345 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
1747 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0); 1346 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
1748 VdbeCoverage(v); 1347 VdbeCoverage(v);
1749 } 1348 }
1750 } 1349 }
1751 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1); 1350 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
1752 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0, 1351 sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
1753 pFK->zTo, P4_TRANSIENT);
1754 sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
1755 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4); 1352 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
1756 sqlite3VdbeResolveLabel(v, addrOk); 1353 sqlite3VdbeResolveLabel(v, addrOk);
1757 sqlite3DbFree(db, aiCols); 1354 sqlite3DbFree(db, aiCols);
1758 } 1355 }
1759 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v); 1356 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
1760 sqlite3VdbeJumpHere(v, addrTop); 1357 sqlite3VdbeJumpHere(v, addrTop);
1761 } 1358 }
1762 } 1359 }
1763 break; 1360 break;
1764 #endif /* !defined(SQLITE_OMIT_TRIGGER) */ 1361 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
1765 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ 1362 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
1766 1363
1767 #ifndef NDEBUG 1364 #ifndef NDEBUG
1768 case PragTyp_PARSER_TRACE: { 1365 case PragTyp_PARSER_TRACE: {
1769 if( zRight ){ 1366 if( zRight ){
1770 if( sqlite3GetBoolean(zRight, 0) ){ 1367 if( sqlite3GetBoolean(zRight, 0) ){
1771 sqlite3ParserTrace(stderr, "parser: "); 1368 sqlite3ParserTrace(stdout, "parser: ");
1772 }else{ 1369 }else{
1773 sqlite3ParserTrace(0, 0); 1370 sqlite3ParserTrace(0, 0);
1774 } 1371 }
1775 } 1372 }
1776 } 1373 }
1777 break; 1374 break;
1778 #endif 1375 #endif
1779 1376
1780 /* Reinstall the LIKE and GLOB functions. The variant of LIKE 1377 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
1781 ** used will be case sensitive or not depending on the RHS. 1378 ** used will be case sensitive or not depending on the RHS.
(...skipping 16 matching lines...) Expand all
1798 */ 1395 */
1799 case PragTyp_INTEGRITY_CHECK: { 1396 case PragTyp_INTEGRITY_CHECK: {
1800 int i, j, addr, mxErr; 1397 int i, j, addr, mxErr;
1801 1398
1802 /* Code that appears at the end of the integrity check. If no error 1399 /* Code that appears at the end of the integrity check. If no error
1803 ** messages have been generated, output OK. Otherwise output the 1400 ** messages have been generated, output OK. Otherwise output the
1804 ** error message 1401 ** error message
1805 */ 1402 */
1806 static const int iLn = VDBE_OFFSET_LINENO(2); 1403 static const int iLn = VDBE_OFFSET_LINENO(2);
1807 static const VdbeOpList endCode[] = { 1404 static const VdbeOpList endCode[] = {
1808 { OP_IfNeg, 1, 0, 0}, /* 0 */ 1405 { OP_AddImm, 1, 0, 0}, /* 0 */
1809 { OP_String8, 0, 3, 0}, /* 1 */ 1406 { OP_If, 1, 0, 0}, /* 1 */
1407 { OP_String8, 0, 3, 0}, /* 2 */
1810 { OP_ResultRow, 3, 1, 0}, 1408 { OP_ResultRow, 3, 1, 0},
1811 }; 1409 };
1812 1410
1813 int isQuick = (sqlite3Tolower(zLeft[0])=='q'); 1411 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
1814 1412
1815 /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check", 1413 /* 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>. 1414 ** 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 1415 ** In this case, the integrity of database iDb only is verified by
1818 ** the VDBE created below. 1416 ** the VDBE created below.
1819 ** 1417 **
1820 ** Otherwise, if the command was simply "PRAGMA integrity_check" (or 1418 ** 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 1419 ** "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 1420 ** to -1 here, to indicate that the VDBE should verify the integrity
1823 ** of all attached databases. */ 1421 ** of all attached databases. */
1824 assert( iDb>=0 ); 1422 assert( iDb>=0 );
1825 assert( iDb==0 || pId2->z ); 1423 assert( iDb==0 || pId2->z );
1826 if( pId2->z==0 ) iDb = -1; 1424 if( pId2->z==0 ) iDb = -1;
1827 1425
1828 /* Initialize the VDBE program */ 1426 /* Initialize the VDBE program */
1829 pParse->nMem = 6; 1427 pParse->nMem = 6;
1830 sqlite3VdbeSetNumCols(v, 1); 1428 setOneColumnName(v, "integrity_check");
1831 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
1832 1429
1833 /* Set the maximum error count */ 1430 /* Set the maximum error count */
1834 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; 1431 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
1835 if( zRight ){ 1432 if( zRight ){
1836 sqlite3GetInt32(zRight, &mxErr); 1433 sqlite3GetInt32(zRight, &mxErr);
1837 if( mxErr<=0 ){ 1434 if( mxErr<=0 ){
1838 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; 1435 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
1839 } 1436 }
1840 } 1437 }
1841 sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */ 1438 sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 int iDataCur, iIdxCur; 1499 int iDataCur, iIdxCur;
1903 int r1 = -1; 1500 int r1 = -1;
1904 1501
1905 if( pTab->pIndex==0 ) continue; 1502 if( pTab->pIndex==0 ) continue;
1906 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); 1503 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
1907 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */ 1504 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
1908 VdbeCoverage(v); 1505 VdbeCoverage(v);
1909 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); 1506 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
1910 sqlite3VdbeJumpHere(v, addr); 1507 sqlite3VdbeJumpHere(v, addr);
1911 sqlite3ExprCacheClear(pParse); 1508 sqlite3ExprCacheClear(pParse);
1912 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 1509 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
1913 1, 0, &iDataCur, &iIdxCur); 1510 1, 0, &iDataCur, &iIdxCur);
1914 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7); 1511 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
1915 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ 1512 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
1916 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */ 1513 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
1917 } 1514 }
1918 pParse->nMem = MAX(pParse->nMem, 8+j); 1515 pParse->nMem = MAX(pParse->nMem, 8+j);
1919 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v); 1516 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
1920 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1); 1517 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
1921 /* Verify that all NOT NULL columns really are NOT NULL */ 1518 /* Verify that all NOT NULL columns really are NOT NULL */
1922 for(j=0; j<pTab->nCol; j++){ 1519 for(j=0; j<pTab->nCol; j++){
(...skipping 20 matching lines...) Expand all
1943 int ckUniq = sqlite3VdbeMakeLabel(v); 1540 int ckUniq = sqlite3VdbeMakeLabel(v);
1944 if( pPk==pIdx ) continue; 1541 if( pPk==pIdx ) continue;
1945 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3, 1542 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
1946 pPrior, r1); 1543 pPrior, r1);
1947 pPrior = pIdx; 1544 pPrior = pIdx;
1948 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */ 1545 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
1949 /* Verify that an index entry exists for the current table row */ 1546 /* Verify that an index entry exists for the current table row */
1950 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1, 1547 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
1951 pIdx->nColumn); VdbeCoverage(v); 1548 pIdx->nColumn); VdbeCoverage(v);
1952 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */ 1549 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
1953 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC); 1550 sqlite3VdbeLoadString(v, 3, "row ");
1954 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3); 1551 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
1955 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, 1552 sqlite3VdbeLoadString(v, 4, " missing from index ");
1956 " missing from index ", P4_STATIC);
1957 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); 1553 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
1958 jmp5 = sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, 1554 jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
1959 pIdx->zName, P4_TRANSIENT);
1960 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); 1555 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
1961 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1); 1556 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
1962 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v); 1557 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
1963 sqlite3VdbeAddOp0(v, OP_Halt); 1558 sqlite3VdbeAddOp0(v, OP_Halt);
1964 sqlite3VdbeJumpHere(v, jmp2); 1559 sqlite3VdbeJumpHere(v, jmp2);
1965 /* For UNIQUE indexes, verify that only one entry exists with the 1560 /* For UNIQUE indexes, verify that only one entry exists with the
1966 ** current key. The entry is unique if (1) any column is NULL 1561 ** current key. The entry is unique if (1) any column is NULL
1967 ** or (2) the next entry has a different key */ 1562 ** or (2) the next entry has a different key */
1968 if( IsUniqueIndex(pIdx) ){ 1563 if( IsUniqueIndex(pIdx) ){
1969 int uniqOk = sqlite3VdbeMakeLabel(v); 1564 int uniqOk = sqlite3VdbeMakeLabel(v);
1970 int jmp6; 1565 int jmp6;
1971 int kk; 1566 int kk;
1972 for(kk=0; kk<pIdx->nKeyCol; kk++){ 1567 for(kk=0; kk<pIdx->nKeyCol; kk++){
1973 int iCol = pIdx->aiColumn[kk]; 1568 int iCol = pIdx->aiColumn[kk];
1974 assert( iCol>=0 && iCol<pTab->nCol ); 1569 assert( iCol!=XN_ROWID && iCol<pTab->nCol );
1975 if( pTab->aCol[iCol].notNull ) continue; 1570 if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
1976 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk); 1571 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
1977 VdbeCoverage(v); 1572 VdbeCoverage(v);
1978 } 1573 }
1979 jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v); 1574 jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
1980 sqlite3VdbeAddOp2(v, OP_Goto, 0, uniqOk); 1575 sqlite3VdbeGoto(v, uniqOk);
1981 sqlite3VdbeJumpHere(v, jmp6); 1576 sqlite3VdbeJumpHere(v, jmp6);
1982 sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1, 1577 sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
1983 pIdx->nKeyCol); VdbeCoverage(v); 1578 pIdx->nKeyCol); VdbeCoverage(v);
1984 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */ 1579 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
1985 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, 1580 sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
1986 "non-unique entry in index ", P4_STATIC); 1581 sqlite3VdbeGoto(v, jmp5);
1987 sqlite3VdbeAddOp2(v, OP_Goto, 0, jmp5);
1988 sqlite3VdbeResolveLabel(v, uniqOk); 1582 sqlite3VdbeResolveLabel(v, uniqOk);
1989 } 1583 }
1990 sqlite3VdbeJumpHere(v, jmp4); 1584 sqlite3VdbeJumpHere(v, jmp4);
1991 sqlite3ResolvePartIdxLabel(pParse, jmp3); 1585 sqlite3ResolvePartIdxLabel(pParse, jmp3);
1992 } 1586 }
1993 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v); 1587 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
1994 sqlite3VdbeJumpHere(v, loopTop-1); 1588 sqlite3VdbeJumpHere(v, loopTop-1);
1995 #ifndef SQLITE_OMIT_BTREECOUNT 1589 #ifndef SQLITE_OMIT_BTREECOUNT
1996 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, 1590 sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
1997 "wrong # of entries in index ", P4_STATIC);
1998 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ 1591 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
1999 if( pPk==pIdx ) continue; 1592 if( pPk==pIdx ) continue;
2000 addr = sqlite3VdbeCurrentAddr(v); 1593 addr = sqlite3VdbeCurrentAddr(v);
2001 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v); 1594 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
2002 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); 1595 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
2003 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); 1596 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
2004 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v); 1597 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
2005 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); 1598 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
2006 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); 1599 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
2007 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT); 1600 sqlite3VdbeLoadString(v, 3, pIdx->zName);
2008 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7); 1601 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
2009 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1); 1602 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
2010 } 1603 }
2011 #endif /* SQLITE_OMIT_BTREECOUNT */ 1604 #endif /* SQLITE_OMIT_BTREECOUNT */
2012 } 1605 }
2013 } 1606 }
2014 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); 1607 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
2015 sqlite3VdbeChangeP3(v, addr, -mxErr); 1608 sqlite3VdbeChangeP2(v, addr, -mxErr);
2016 sqlite3VdbeJumpHere(v, addr); 1609 sqlite3VdbeJumpHere(v, addr+1);
2017 sqlite3VdbeChangeP4(v, addr+1, "ok", P4_STATIC); 1610 sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
2018 } 1611 }
2019 break; 1612 break;
2020 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ 1613 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
2021 1614
2022 #ifndef SQLITE_OMIT_UTF16 1615 #ifndef SQLITE_OMIT_UTF16
2023 /* 1616 /*
2024 ** PRAGMA encoding 1617 ** PRAGMA encoding
2025 ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be" 1618 ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
2026 ** 1619 **
2027 ** In its first form, this pragma returns the encoding of the main 1620 ** In its first form, this pragma returns the encoding of the main
(...skipping 25 matching lines...) Expand all
2053 { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */ 1646 { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */
2054 { "UTF16le", SQLITE_UTF16LE }, 1647 { "UTF16le", SQLITE_UTF16LE },
2055 { "UTF16be", SQLITE_UTF16BE }, 1648 { "UTF16be", SQLITE_UTF16BE },
2056 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */ 1649 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
2057 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */ 1650 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
2058 { 0, 0 } 1651 { 0, 0 }
2059 }; 1652 };
2060 const struct EncName *pEnc; 1653 const struct EncName *pEnc;
2061 if( !zRight ){ /* "PRAGMA encoding" */ 1654 if( !zRight ){ /* "PRAGMA encoding" */
2062 if( sqlite3ReadSchema(pParse) ) goto pragma_out; 1655 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
2063 sqlite3VdbeSetNumCols(v, 1);
2064 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
2065 sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
2066 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 ); 1656 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
2067 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE ); 1657 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
2068 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE ); 1658 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
2069 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC); 1659 returnSingleText(v, "encoding", encnames[ENC(pParse->db)].zName);
2070 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
2071 }else{ /* "PRAGMA encoding = XXX" */ 1660 }else{ /* "PRAGMA encoding = XXX" */
2072 /* Only change the value of sqlite.enc if the database handle is not 1661 /* Only change the value of sqlite.enc if the database handle is not
2073 ** initialized. If the main database exists, the new sqlite.enc value 1662 ** initialized. If the main database exists, the new sqlite.enc value
2074 ** will be overwritten when the schema is next loaded. If it does not 1663 ** will be overwritten when the schema is next loaded. If it does not
2075 ** already exists, it will be created to use the new encoding value. 1664 ** already exists, it will be created to use the new encoding value.
2076 */ 1665 */
2077 if( 1666 if(
2078 !(DbHasProperty(db, 0, DB_SchemaLoaded)) || 1667 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
2079 DbHasProperty(db, 0, DB_Empty) 1668 DbHasProperty(db, 0, DB_Empty)
2080 ){ 1669 ){
2081 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ 1670 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
2082 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ 1671 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
2083 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; 1672 SCHEMA_ENC(db) = ENC(db) =
1673 pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
2084 break; 1674 break;
2085 } 1675 }
2086 } 1676 }
2087 if( !pEnc->zName ){ 1677 if( !pEnc->zName ){
2088 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight); 1678 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
2089 } 1679 }
2090 } 1680 }
2091 } 1681 }
2092 } 1682 }
2093 break; 1683 break;
2094 #endif /* SQLITE_OMIT_UTF16 */ 1684 #endif /* SQLITE_OMIT_UTF16 */
2095 1685
2096 #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS 1686 #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
2097 /* 1687 /*
2098 ** PRAGMA [database.]schema_version 1688 ** PRAGMA [schema.]schema_version
2099 ** PRAGMA [database.]schema_version = <integer> 1689 ** PRAGMA [schema.]schema_version = <integer>
2100 ** 1690 **
2101 ** PRAGMA [database.]user_version 1691 ** PRAGMA [schema.]user_version
2102 ** PRAGMA [database.]user_version = <integer> 1692 ** PRAGMA [schema.]user_version = <integer>
2103 ** 1693 **
2104 ** PRAGMA [database.]freelist_count = <integer> 1694 ** PRAGMA [schema.]freelist_count = <integer>
2105 ** 1695 **
2106 ** PRAGMA [database.]application_id 1696 ** PRAGMA [schema.]application_id
2107 ** PRAGMA [database.]application_id = <integer> 1697 ** PRAGMA [schema.]application_id = <integer>
2108 ** 1698 **
2109 ** The pragma's schema_version and user_version are used to set or get 1699 ** The pragma's schema_version and user_version are used to set or get
2110 ** the value of the schema-version and user-version, respectively. Both 1700 ** the value of the schema-version and user-version, respectively. Both
2111 ** the schema-version and the user-version are 32-bit signed integers 1701 ** the schema-version and the user-version are 32-bit signed integers
2112 ** stored in the database header. 1702 ** stored in the database header.
2113 ** 1703 **
2114 ** The schema-cookie is usually only manipulated internally by SQLite. It 1704 ** The schema-cookie is usually only manipulated internally by SQLite. It
2115 ** is incremented by SQLite whenever the database schema is modified (by 1705 ** is incremented by SQLite whenever the database schema is modified (by
2116 ** creating or dropping a table or index). The schema version is used by 1706 ** creating or dropping a table or index). The schema version is used by
2117 ** SQLite each time a query is executed to ensure that the internal cache 1707 ** SQLite each time a query is executed to ensure that the internal cache
2118 ** of the schema used when compiling the SQL query matches the schema of 1708 ** of the schema used when compiling the SQL query matches the schema of
2119 ** the database against which the compiled query is actually executed. 1709 ** the database against which the compiled query is actually executed.
2120 ** Subverting this mechanism by using "PRAGMA schema_version" to modify 1710 ** Subverting this mechanism by using "PRAGMA schema_version" to modify
2121 ** the schema-version is potentially dangerous and may lead to program 1711 ** the schema-version is potentially dangerous and may lead to program
2122 ** crashes or database corruption. Use with caution! 1712 ** crashes or database corruption. Use with caution!
2123 ** 1713 **
2124 ** The user-version is not used internally by SQLite. It may be used by 1714 ** The user-version is not used internally by SQLite. It may be used by
2125 ** applications for any purpose. 1715 ** applications for any purpose.
2126 */ 1716 */
2127 case PragTyp_HEADER_VALUE: { 1717 case PragTyp_HEADER_VALUE: {
2128 int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */ 1718 int iCookie = pPragma->iArg; /* Which cookie to read or write */
2129 sqlite3VdbeUsesBtree(v, iDb); 1719 sqlite3VdbeUsesBtree(v, iDb);
2130 switch( zLeft[0] ){ 1720 if( zRight && (pPragma->mPragFlag & PragFlag_ReadOnly)==0 ){
2131 case 'a': case 'A':
2132 iCookie = BTREE_APPLICATION_ID;
2133 break;
2134 case 'f': case 'F':
2135 iCookie = BTREE_FREE_PAGE_COUNT;
2136 break;
2137 case 's': case 'S':
2138 iCookie = BTREE_SCHEMA_VERSION;
2139 break;
2140 default:
2141 iCookie = BTREE_USER_VERSION;
2142 break;
2143 }
2144
2145 if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){
2146 /* Write the specified cookie value */ 1721 /* Write the specified cookie value */
2147 static const VdbeOpList setCookie[] = { 1722 static const VdbeOpList setCookie[] = {
2148 { OP_Transaction, 0, 1, 0}, /* 0 */ 1723 { OP_Transaction, 0, 1, 0}, /* 0 */
2149 { OP_Integer, 0, 1, 0}, /* 1 */ 1724 { OP_Integer, 0, 1, 0}, /* 1 */
2150 { OP_SetCookie, 0, 0, 1}, /* 2 */ 1725 { OP_SetCookie, 0, 0, 1}, /* 2 */
2151 }; 1726 };
2152 int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0); 1727 int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
2153 sqlite3VdbeChangeP1(v, addr, iDb); 1728 sqlite3VdbeChangeP1(v, addr, iDb);
2154 sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight)); 1729 sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight));
2155 sqlite3VdbeChangeP1(v, addr+2, iDb); 1730 sqlite3VdbeChangeP1(v, addr+2, iDb);
(...skipping 19 matching lines...) Expand all
2175 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS 1750 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
2176 /* 1751 /*
2177 ** PRAGMA compile_options 1752 ** PRAGMA compile_options
2178 ** 1753 **
2179 ** Return the names of all compile-time options used in this build, 1754 ** Return the names of all compile-time options used in this build,
2180 ** one option per row. 1755 ** one option per row.
2181 */ 1756 */
2182 case PragTyp_COMPILE_OPTIONS: { 1757 case PragTyp_COMPILE_OPTIONS: {
2183 int i = 0; 1758 int i = 0;
2184 const char *zOpt; 1759 const char *zOpt;
2185 sqlite3VdbeSetNumCols(v, 1);
2186 pParse->nMem = 1; 1760 pParse->nMem = 1;
2187 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC); 1761 setOneColumnName(v, "compile_option");
2188 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){ 1762 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
2189 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0); 1763 sqlite3VdbeLoadString(v, 1, zOpt);
2190 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1); 1764 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
2191 } 1765 }
2192 } 1766 }
2193 break; 1767 break;
2194 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ 1768 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
2195 1769
2196 #ifndef SQLITE_OMIT_WAL 1770 #ifndef SQLITE_OMIT_WAL
2197 /* 1771 /*
2198 ** PRAGMA [database.]wal_checkpoint = passive|full|restart 1772 ** PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate
2199 ** 1773 **
2200 ** Checkpoint the database. 1774 ** Checkpoint the database.
2201 */ 1775 */
2202 case PragTyp_WAL_CHECKPOINT: { 1776 case PragTyp_WAL_CHECKPOINT: {
1777 static const char *azCol[] = { "busy", "log", "checkpointed" };
2203 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED); 1778 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
2204 int eMode = SQLITE_CHECKPOINT_PASSIVE; 1779 int eMode = SQLITE_CHECKPOINT_PASSIVE;
2205 if( zRight ){ 1780 if( zRight ){
2206 if( sqlite3StrICmp(zRight, "full")==0 ){ 1781 if( sqlite3StrICmp(zRight, "full")==0 ){
2207 eMode = SQLITE_CHECKPOINT_FULL; 1782 eMode = SQLITE_CHECKPOINT_FULL;
2208 }else if( sqlite3StrICmp(zRight, "restart")==0 ){ 1783 }else if( sqlite3StrICmp(zRight, "restart")==0 ){
2209 eMode = SQLITE_CHECKPOINT_RESTART; 1784 eMode = SQLITE_CHECKPOINT_RESTART;
1785 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
1786 eMode = SQLITE_CHECKPOINT_TRUNCATE;
2210 } 1787 }
2211 } 1788 }
2212 sqlite3VdbeSetNumCols(v, 3); 1789 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
2213 pParse->nMem = 3; 1790 pParse->nMem = 3;
2214 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
2215 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC);
2216 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC);
2217
2218 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1); 1791 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
2219 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); 1792 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
2220 } 1793 }
2221 break; 1794 break;
2222 1795
2223 /* 1796 /*
2224 ** PRAGMA wal_autocheckpoint 1797 ** PRAGMA wal_autocheckpoint
2225 ** PRAGMA wal_autocheckpoint = N 1798 ** PRAGMA wal_autocheckpoint = N
2226 ** 1799 **
2227 ** Configure a database connection to automatically checkpoint a database 1800 ** Configure a database connection to automatically checkpoint a database
2228 ** after accumulating N frames in the log. Or query for the current value 1801 ** after accumulating N frames in the log. Or query for the current value
2229 ** of N. 1802 ** of N.
2230 */ 1803 */
2231 case PragTyp_WAL_AUTOCHECKPOINT: { 1804 case PragTyp_WAL_AUTOCHECKPOINT: {
2232 if( zRight ){ 1805 if( zRight ){
2233 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight)); 1806 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
2234 } 1807 }
2235 returnSingleInt(pParse, "wal_autocheckpoint", 1808 returnSingleInt(v, "wal_autocheckpoint",
2236 db->xWalCallback==sqlite3WalDefaultHook ? 1809 db->xWalCallback==sqlite3WalDefaultHook ?
2237 SQLITE_PTR_TO_INT(db->pWalArg) : 0); 1810 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
2238 } 1811 }
2239 break; 1812 break;
2240 #endif 1813 #endif
2241 1814
2242 /* 1815 /*
2243 ** PRAGMA shrink_memory 1816 ** PRAGMA shrink_memory
2244 ** 1817 **
2245 ** This pragma attempts to free as much memory as possible from the 1818 ** IMPLEMENTATION-OF: R-23445-46109 This pragma causes the database
2246 ** current database connection. 1819 ** connection on which it is invoked to free up as much memory as it
1820 ** can, by calling sqlite3_db_release_memory().
2247 */ 1821 */
2248 case PragTyp_SHRINK_MEMORY: { 1822 case PragTyp_SHRINK_MEMORY: {
2249 sqlite3_db_release_memory(db); 1823 sqlite3_db_release_memory(db);
2250 break; 1824 break;
2251 } 1825 }
2252 1826
2253 /* 1827 /*
2254 ** PRAGMA busy_timeout 1828 ** PRAGMA busy_timeout
2255 ** PRAGMA busy_timeout = N 1829 ** PRAGMA busy_timeout = N
2256 ** 1830 **
2257 ** Call sqlite3_busy_timeout(db, N). Return the current timeout value 1831 ** 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 1832 ** 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 1833 ** then 0 is returned. Setting the busy_timeout to 0 or negative
2260 ** disables the timeout. 1834 ** disables the timeout.
2261 */ 1835 */
2262 /*case PragTyp_BUSY_TIMEOUT*/ default: { 1836 /*case PragTyp_BUSY_TIMEOUT*/ default: {
2263 assert( aPragmaNames[mid].ePragTyp==PragTyp_BUSY_TIMEOUT ); 1837 assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
2264 if( zRight ){ 1838 if( zRight ){
2265 sqlite3_busy_timeout(db, sqlite3Atoi(zRight)); 1839 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
2266 } 1840 }
2267 returnSingleInt(pParse, "timeout", db->busyTimeout); 1841 returnSingleInt(v, "timeout", db->busyTimeout);
2268 break; 1842 break;
2269 } 1843 }
2270 1844
2271 /* 1845 /*
2272 ** PRAGMA soft_heap_limit 1846 ** PRAGMA soft_heap_limit
2273 ** PRAGMA soft_heap_limit = N 1847 ** PRAGMA soft_heap_limit = N
2274 ** 1848 **
2275 ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted, 1849 ** IMPLEMENTATION-OF: R-26343-45930 This pragma invokes the
2276 ** use -1. 1850 ** sqlite3_soft_heap_limit64() interface with the argument N, if N is
1851 ** specified and is a non-negative integer.
1852 ** IMPLEMENTATION-OF: R-64451-07163 The soft_heap_limit pragma always
1853 ** returns the same integer that would be returned by the
1854 ** sqlite3_soft_heap_limit64(-1) C-language function.
2277 */ 1855 */
2278 case PragTyp_SOFT_HEAP_LIMIT: { 1856 case PragTyp_SOFT_HEAP_LIMIT: {
2279 sqlite3_int64 N; 1857 sqlite3_int64 N;
2280 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){ 1858 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
2281 sqlite3_soft_heap_limit64(N); 1859 sqlite3_soft_heap_limit64(N);
2282 } 1860 }
2283 returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1)); 1861 returnSingleInt(v, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
2284 break; 1862 break;
2285 } 1863 }
2286 1864
2287 /* 1865 /*
2288 ** PRAGMA threads 1866 ** PRAGMA threads
2289 ** PRAGMA threads = N 1867 ** PRAGMA threads = N
2290 ** 1868 **
2291 ** Configure the maximum number of worker threads. Return the new 1869 ** Configure the maximum number of worker threads. Return the new
2292 ** maximum, which might be less than requested. 1870 ** maximum, which might be less than requested.
2293 */ 1871 */
2294 case PragTyp_THREADS: { 1872 case PragTyp_THREADS: {
2295 sqlite3_int64 N; 1873 sqlite3_int64 N;
2296 if( zRight 1874 if( zRight
2297 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK 1875 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
2298 && N>=0 1876 && N>=0
2299 ){ 1877 ){
2300 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff)); 1878 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
2301 } 1879 }
2302 returnSingleInt(pParse, "threads", 1880 returnSingleInt(v, "threads",
2303 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1)); 1881 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
2304 break; 1882 break;
2305 } 1883 }
2306 1884
2307 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) 1885 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
2308 /* 1886 /*
2309 ** Report the current state of file logs for all databases 1887 ** Report the current state of file logs for all databases
2310 */ 1888 */
2311 case PragTyp_LOCK_STATUS: { 1889 case PragTyp_LOCK_STATUS: {
2312 static const char *const azLockName[] = { 1890 static const char *const azLockName[] = {
2313 "unlocked", "shared", "reserved", "pending", "exclusive" 1891 "unlocked", "shared", "reserved", "pending", "exclusive"
2314 }; 1892 };
1893 static const char *azCol[] = { "database", "status" };
2315 int i; 1894 int i;
2316 sqlite3VdbeSetNumCols(v, 2); 1895 setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
2317 pParse->nMem = 2; 1896 pParse->nMem = 2;
2318 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
2319 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
2320 for(i=0; i<db->nDb; i++){ 1897 for(i=0; i<db->nDb; i++){
2321 Btree *pBt; 1898 Btree *pBt;
2322 const char *zState = "unknown"; 1899 const char *zState = "unknown";
2323 int j; 1900 int j;
2324 if( db->aDb[i].zName==0 ) continue; 1901 if( db->aDb[i].zName==0 ) continue;
2325 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
2326 pBt = db->aDb[i].pBt; 1902 pBt = db->aDb[i].pBt;
2327 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){ 1903 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
2328 zState = "closed"; 1904 zState = "closed";
2329 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0, 1905 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
2330 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){ 1906 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
2331 zState = azLockName[j]; 1907 zState = azLockName[j];
2332 } 1908 }
2333 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC); 1909 sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
2334 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2); 1910 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
2335 } 1911 }
2336 break; 1912 break;
2337 } 1913 }
2338 #endif 1914 #endif
2339 1915
2340 #ifdef SQLITE_HAS_CODEC 1916 #ifdef SQLITE_HAS_CODEC
2341 case PragTyp_KEY: { 1917 case PragTyp_KEY: {
2342 if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight)); 1918 if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
2343 break; 1919 break;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2381 #endif 1957 #endif
2382 1958
2383 } /* End of the PRAGMA switch */ 1959 } /* End of the PRAGMA switch */
2384 1960
2385 pragma_out: 1961 pragma_out:
2386 sqlite3DbFree(db, zLeft); 1962 sqlite3DbFree(db, zLeft);
2387 sqlite3DbFree(db, zRight); 1963 sqlite3DbFree(db, zRight);
2388 } 1964 }
2389 1965
2390 #endif /* SQLITE_OMIT_PRAGMA */ 1966 #endif /* SQLITE_OMIT_PRAGMA */
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3100200/src/pragma.h ('k') | third_party/sqlite/sqlite-src-3100200/src/prepare.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698