blob: 1312beef04b4c269dfd642a05900ccf4399a0288 [file] [log] [blame]
drhc11d4f92003-04-06 21:08:24 +00001/*
2** 2003 April 6
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12** This file contains code used to implement the PRAGMA command.
drhc11d4f92003-04-06 21:08:24 +000013*/
14#include "sqliteInt.h"
15
drh9ccd8652013-09-13 16:36:46 +000016#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
17# if defined(__APPLE__)
18# define SQLITE_ENABLE_LOCKING_STYLE 1
19# else
20# define SQLITE_ENABLE_LOCKING_STYLE 0
21# endif
22#endif
23
24/***************************************************************************
25** The next block of code, including the PragTyp_XXXX macro definitions and
26** the aPragmaName[] object is composed of generated code. DO NOT EDIT.
27**
28** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun
29** that script. Then copy/paste the output in place of the following:
30*/
31#define PragTyp_HEADER_VALUE 0
32#define PragTyp_AUTO_VACUUM 1
33#define PragTyp_FLAG 2
34#define PragTyp_BUSY_TIMEOUT 3
35#define PragTyp_CACHE_SIZE 4
36#define PragTyp_CASE_SENSITIVE_LIKE 5
37#define PragTyp_COLLATION_LIST 6
38#define PragTyp_COMPILE_OPTIONS 7
39#define PragTyp_DATA_STORE_DIRECTORY 8
40#define PragTyp_DATABASE_LIST 9
41#define PragTyp_DEFAULT_CACHE_SIZE 10
42#define PragTyp_ENCODING 11
43#define PragTyp_FOREIGN_KEY_CHECK 12
44#define PragTyp_FOREIGN_KEY_LIST 13
45#define PragTyp_INCREMENTAL_VACUUM 14
46#define PragTyp_INDEX_INFO 15
47#define PragTyp_INDEX_LIST 16
48#define PragTyp_INTEGRITY_CHECK 17
49#define PragTyp_JOURNAL_MODE 18
50#define PragTyp_JOURNAL_SIZE_LIMIT 19
51#define PragTyp_LOCK_PROXY_FILE 20
52#define PragTyp_LOCKING_MODE 21
53#define PragTyp_PAGE_COUNT 22
54#define PragTyp_MMAP_SIZE 23
55#define PragTyp_PAGE_SIZE 24
56#define PragTyp_SECURE_DELETE 25
57#define PragTyp_SHRINK_MEMORY 26
drh55e85ca2013-09-13 21:01:56 +000058#define PragTyp_SOFT_HEAP_LIMIT 27
drh3ef26152013-10-12 20:22:00 +000059#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
drh03459612014-08-25 15:13:22 +000064#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
drhf63936e2013-10-03 14:08:07 +000073#define PragFlag_NeedSchema 0x01
drh8e755e72014-12-19 18:49:55 +000074#define PragFlag_ReadOnly 0x02
drh9ccd8652013-09-13 16:36:46 +000075static const struct sPragmaNames {
drh77ff23f2013-09-13 21:03:45 +000076 const char *const zName; /* Name of pragma */
drhd49c3582013-09-13 19:00:06 +000077 u8 ePragTyp; /* PragTyp_XXX value */
drhf63936e2013-10-03 14:08:07 +000078 u8 mPragFlag; /* Zero or more PragFlag_XXX values */
drh9ccd8652013-09-13 16:36:46 +000079 u32 iArg; /* Extra argument */
80} aPragmaNames[] = {
81#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
drhf63936e2013-10-03 14:08:07 +000082 { /* zName: */ "activate_extensions",
83 /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS,
84 /* ePragFlag: */ 0,
85 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +000086#endif
87#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +000088 { /* zName: */ "application_id",
89 /* ePragTyp: */ PragTyp_HEADER_VALUE,
90 /* ePragFlag: */ 0,
drh8e755e72014-12-19 18:49:55 +000091 /* iArg: */ BTREE_APPLICATION_ID },
drh9ccd8652013-09-13 16:36:46 +000092#endif
93#if !defined(SQLITE_OMIT_AUTOVACUUM)
drhf63936e2013-10-03 14:08:07 +000094 { /* zName: */ "auto_vacuum",
95 /* ePragTyp: */ PragTyp_AUTO_VACUUM,
96 /* ePragFlag: */ PragFlag_NeedSchema,
97 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +000098#endif
mistachkindd197832013-10-21 23:17:23 +000099#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drh9ccd8652013-09-13 16:36:46 +0000100#if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
drhf63936e2013-10-03 14:08:07 +0000101 { /* zName: */ "automatic_index",
102 /* ePragTyp: */ PragTyp_FLAG,
103 /* ePragFlag: */ 0,
104 /* iArg: */ SQLITE_AutoIndex },
drh9ccd8652013-09-13 16:36:46 +0000105#endif
mistachkindd197832013-10-21 23:17:23 +0000106#endif
drhf63936e2013-10-03 14:08:07 +0000107 { /* zName: */ "busy_timeout",
108 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
109 /* ePragFlag: */ 0,
110 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000111#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000112 { /* zName: */ "cache_size",
113 /* ePragTyp: */ PragTyp_CACHE_SIZE,
114 /* ePragFlag: */ PragFlag_NeedSchema,
115 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000116#endif
mistachkindd197832013-10-21 23:17:23 +0000117#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000118 { /* zName: */ "cache_spill",
119 /* ePragTyp: */ PragTyp_FLAG,
120 /* ePragFlag: */ 0,
121 /* iArg: */ SQLITE_CacheSpill },
mistachkindd197832013-10-21 23:17:23 +0000122#endif
drhf63936e2013-10-03 14:08:07 +0000123 { /* zName: */ "case_sensitive_like",
124 /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE,
125 /* ePragFlag: */ 0,
126 /* iArg: */ 0 },
mistachkindd197832013-10-21 23:17:23 +0000127#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000128 { /* zName: */ "checkpoint_fullfsync",
129 /* ePragTyp: */ PragTyp_FLAG,
130 /* ePragFlag: */ 0,
131 /* iArg: */ SQLITE_CkptFullFSync },
mistachkindd197832013-10-21 23:17:23 +0000132#endif
drh9ccd8652013-09-13 16:36:46 +0000133#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000134 { /* zName: */ "collation_list",
135 /* ePragTyp: */ PragTyp_COLLATION_LIST,
136 /* ePragFlag: */ 0,
137 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000138#endif
139#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
drhf63936e2013-10-03 14:08:07 +0000140 { /* zName: */ "compile_options",
141 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
142 /* ePragFlag: */ 0,
143 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000144#endif
mistachkindd197832013-10-21 23:17:23 +0000145#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000146 { /* zName: */ "count_changes",
147 /* ePragTyp: */ PragTyp_FLAG,
148 /* ePragFlag: */ 0,
149 /* iArg: */ SQLITE_CountRows },
mistachkindd197832013-10-21 23:17:23 +0000150#endif
drh9ccd8652013-09-13 16:36:46 +0000151#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
drhf63936e2013-10-03 14:08:07 +0000152 { /* zName: */ "data_store_directory",
153 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
154 /* ePragFlag: */ 0,
155 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000156#endif
drh91618562014-12-19 19:28:02 +0000157#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
158 { /* zName: */ "data_version",
159 /* ePragTyp: */ PragTyp_HEADER_VALUE,
160 /* ePragFlag: */ PragFlag_ReadOnly,
161 /* iArg: */ BTREE_DATA_VERSION },
162#endif
drh9ccd8652013-09-13 16:36:46 +0000163#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000164 { /* zName: */ "database_list",
165 /* ePragTyp: */ PragTyp_DATABASE_LIST,
166 /* ePragFlag: */ PragFlag_NeedSchema,
167 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000168#endif
169#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
drhf63936e2013-10-03 14:08:07 +0000170 { /* zName: */ "default_cache_size",
171 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
172 /* ePragFlag: */ PragFlag_NeedSchema,
173 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000174#endif
mistachkindd197832013-10-21 23:17:23 +0000175#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drh9ccd8652013-09-13 16:36:46 +0000176#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
drhf63936e2013-10-03 14:08:07 +0000177 { /* zName: */ "defer_foreign_keys",
178 /* ePragTyp: */ PragTyp_FLAG,
179 /* ePragFlag: */ 0,
180 /* iArg: */ SQLITE_DeferFKs },
drh9ccd8652013-09-13 16:36:46 +0000181#endif
mistachkindd197832013-10-21 23:17:23 +0000182#endif
183#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000184 { /* zName: */ "empty_result_callbacks",
185 /* ePragTyp: */ PragTyp_FLAG,
186 /* ePragFlag: */ 0,
187 /* iArg: */ SQLITE_NullCallback },
mistachkindd197832013-10-21 23:17:23 +0000188#endif
drh9ccd8652013-09-13 16:36:46 +0000189#if !defined(SQLITE_OMIT_UTF16)
drhf63936e2013-10-03 14:08:07 +0000190 { /* zName: */ "encoding",
191 /* ePragTyp: */ PragTyp_ENCODING,
192 /* ePragFlag: */ 0,
193 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000194#endif
195#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
drhf63936e2013-10-03 14:08:07 +0000196 { /* zName: */ "foreign_key_check",
197 /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
198 /* ePragFlag: */ PragFlag_NeedSchema,
199 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000200#endif
201#if !defined(SQLITE_OMIT_FOREIGN_KEY)
drhf63936e2013-10-03 14:08:07 +0000202 { /* zName: */ "foreign_key_list",
203 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
204 /* ePragFlag: */ PragFlag_NeedSchema,
205 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000206#endif
mistachkindd197832013-10-21 23:17:23 +0000207#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drh9ccd8652013-09-13 16:36:46 +0000208#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
drhf63936e2013-10-03 14:08:07 +0000209 { /* zName: */ "foreign_keys",
210 /* ePragTyp: */ PragTyp_FLAG,
211 /* ePragFlag: */ 0,
212 /* iArg: */ SQLITE_ForeignKeys },
drh9ccd8652013-09-13 16:36:46 +0000213#endif
mistachkindd197832013-10-21 23:17:23 +0000214#endif
drh9ccd8652013-09-13 16:36:46 +0000215#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000216 { /* zName: */ "freelist_count",
217 /* ePragTyp: */ PragTyp_HEADER_VALUE,
drh8e755e72014-12-19 18:49:55 +0000218 /* ePragFlag: */ PragFlag_ReadOnly,
219 /* iArg: */ BTREE_FREE_PAGE_COUNT },
drh9ccd8652013-09-13 16:36:46 +0000220#endif
mistachkindd197832013-10-21 23:17:23 +0000221#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000222 { /* zName: */ "full_column_names",
223 /* ePragTyp: */ PragTyp_FLAG,
224 /* ePragFlag: */ 0,
225 /* iArg: */ SQLITE_FullColNames },
226 { /* zName: */ "fullfsync",
227 /* ePragTyp: */ PragTyp_FLAG,
228 /* ePragFlag: */ 0,
229 /* iArg: */ SQLITE_FullFSync },
mistachkindd197832013-10-21 23:17:23 +0000230#endif
drh9ccd8652013-09-13 16:36:46 +0000231#if defined(SQLITE_HAS_CODEC)
drhf63936e2013-10-03 14:08:07 +0000232 { /* zName: */ "hexkey",
233 /* ePragTyp: */ PragTyp_HEXKEY,
234 /* ePragFlag: */ 0,
235 /* iArg: */ 0 },
drh8ab88322013-10-07 00:36:01 +0000236 { /* zName: */ "hexrekey",
237 /* ePragTyp: */ PragTyp_HEXKEY,
238 /* ePragFlag: */ 0,
239 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000240#endif
mistachkindd197832013-10-21 23:17:23 +0000241#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drh9ccd8652013-09-13 16:36:46 +0000242#if !defined(SQLITE_OMIT_CHECK)
drhf63936e2013-10-03 14:08:07 +0000243 { /* zName: */ "ignore_check_constraints",
244 /* ePragTyp: */ PragTyp_FLAG,
245 /* ePragFlag: */ 0,
246 /* iArg: */ SQLITE_IgnoreChecks },
drh9ccd8652013-09-13 16:36:46 +0000247#endif
mistachkindd197832013-10-21 23:17:23 +0000248#endif
drh9ccd8652013-09-13 16:36:46 +0000249#if !defined(SQLITE_OMIT_AUTOVACUUM)
drhf63936e2013-10-03 14:08:07 +0000250 { /* zName: */ "incremental_vacuum",
251 /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM,
252 /* ePragFlag: */ PragFlag_NeedSchema,
253 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000254#endif
255#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000256 { /* zName: */ "index_info",
257 /* ePragTyp: */ PragTyp_INDEX_INFO,
258 /* ePragFlag: */ PragFlag_NeedSchema,
259 /* iArg: */ 0 },
260 { /* zName: */ "index_list",
261 /* ePragTyp: */ PragTyp_INDEX_LIST,
262 /* ePragFlag: */ PragFlag_NeedSchema,
263 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000264#endif
265#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
drhf63936e2013-10-03 14:08:07 +0000266 { /* zName: */ "integrity_check",
267 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
268 /* ePragFlag: */ PragFlag_NeedSchema,
269 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000270#endif
271#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000272 { /* zName: */ "journal_mode",
273 /* ePragTyp: */ PragTyp_JOURNAL_MODE,
274 /* ePragFlag: */ PragFlag_NeedSchema,
275 /* iArg: */ 0 },
276 { /* zName: */ "journal_size_limit",
277 /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT,
278 /* ePragFlag: */ 0,
279 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000280#endif
281#if defined(SQLITE_HAS_CODEC)
drhf63936e2013-10-03 14:08:07 +0000282 { /* zName: */ "key",
283 /* ePragTyp: */ PragTyp_KEY,
284 /* ePragFlag: */ 0,
285 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000286#endif
mistachkindd197832013-10-21 23:17:23 +0000287#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000288 { /* zName: */ "legacy_file_format",
289 /* ePragTyp: */ PragTyp_FLAG,
290 /* ePragFlag: */ 0,
291 /* iArg: */ SQLITE_LegacyFileFmt },
mistachkindd197832013-10-21 23:17:23 +0000292#endif
drh9ccd8652013-09-13 16:36:46 +0000293#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
drhf63936e2013-10-03 14:08:07 +0000294 { /* zName: */ "lock_proxy_file",
295 /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE,
296 /* ePragFlag: */ 0,
297 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000298#endif
299#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
drhf63936e2013-10-03 14:08:07 +0000300 { /* zName: */ "lock_status",
301 /* ePragTyp: */ PragTyp_LOCK_STATUS,
302 /* ePragFlag: */ 0,
303 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000304#endif
305#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000306 { /* zName: */ "locking_mode",
307 /* ePragTyp: */ PragTyp_LOCKING_MODE,
308 /* ePragFlag: */ 0,
309 /* iArg: */ 0 },
310 { /* zName: */ "max_page_count",
311 /* ePragTyp: */ PragTyp_PAGE_COUNT,
312 /* ePragFlag: */ PragFlag_NeedSchema,
313 /* iArg: */ 0 },
314 { /* zName: */ "mmap_size",
315 /* ePragTyp: */ PragTyp_MMAP_SIZE,
316 /* ePragFlag: */ 0,
317 /* iArg: */ 0 },
318 { /* zName: */ "page_count",
319 /* ePragTyp: */ PragTyp_PAGE_COUNT,
320 /* ePragFlag: */ PragFlag_NeedSchema,
321 /* iArg: */ 0 },
322 { /* zName: */ "page_size",
323 /* ePragTyp: */ PragTyp_PAGE_SIZE,
324 /* ePragFlag: */ 0,
325 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000326#endif
327#if defined(SQLITE_DEBUG)
drhf63936e2013-10-03 14:08:07 +0000328 { /* zName: */ "parser_trace",
329 /* ePragTyp: */ PragTyp_PARSER_TRACE,
330 /* ePragFlag: */ 0,
331 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000332#endif
mistachkindd197832013-10-21 23:17:23 +0000333#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000334 { /* zName: */ "query_only",
335 /* ePragTyp: */ PragTyp_FLAG,
336 /* ePragFlag: */ 0,
337 /* iArg: */ SQLITE_QueryOnly },
mistachkindd197832013-10-21 23:17:23 +0000338#endif
drh9ccd8652013-09-13 16:36:46 +0000339#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
drhf63936e2013-10-03 14:08:07 +0000340 { /* zName: */ "quick_check",
341 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
342 /* ePragFlag: */ PragFlag_NeedSchema,
343 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000344#endif
mistachkindd197832013-10-21 23:17:23 +0000345#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000346 { /* zName: */ "read_uncommitted",
347 /* ePragTyp: */ PragTyp_FLAG,
348 /* ePragFlag: */ 0,
349 /* iArg: */ SQLITE_ReadUncommitted },
350 { /* zName: */ "recursive_triggers",
351 /* ePragTyp: */ PragTyp_FLAG,
352 /* ePragFlag: */ 0,
353 /* iArg: */ SQLITE_RecTriggers },
mistachkindd197832013-10-21 23:17:23 +0000354#endif
drh9ccd8652013-09-13 16:36:46 +0000355#if defined(SQLITE_HAS_CODEC)
drhf63936e2013-10-03 14:08:07 +0000356 { /* zName: */ "rekey",
357 /* ePragTyp: */ PragTyp_REKEY,
358 /* ePragFlag: */ 0,
359 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000360#endif
mistachkindd197832013-10-21 23:17:23 +0000361#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000362 { /* zName: */ "reverse_unordered_selects",
363 /* ePragTyp: */ PragTyp_FLAG,
364 /* ePragFlag: */ 0,
365 /* iArg: */ SQLITE_ReverseOrder },
mistachkindd197832013-10-21 23:17:23 +0000366#endif
drh9ccd8652013-09-13 16:36:46 +0000367#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000368 { /* zName: */ "schema_version",
369 /* ePragTyp: */ PragTyp_HEADER_VALUE,
370 /* ePragFlag: */ 0,
drh8e755e72014-12-19 18:49:55 +0000371 /* iArg: */ BTREE_SCHEMA_VERSION },
drh9ccd8652013-09-13 16:36:46 +0000372#endif
373#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000374 { /* zName: */ "secure_delete",
375 /* ePragTyp: */ PragTyp_SECURE_DELETE,
376 /* ePragFlag: */ 0,
377 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000378#endif
mistachkindd197832013-10-21 23:17:23 +0000379#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000380 { /* zName: */ "short_column_names",
381 /* ePragTyp: */ PragTyp_FLAG,
382 /* ePragFlag: */ 0,
383 /* iArg: */ SQLITE_ShortColNames },
mistachkindd197832013-10-21 23:17:23 +0000384#endif
drhf63936e2013-10-03 14:08:07 +0000385 { /* zName: */ "shrink_memory",
386 /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
387 /* ePragFlag: */ 0,
388 /* iArg: */ 0 },
389 { /* zName: */ "soft_heap_limit",
390 /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT,
391 /* ePragFlag: */ 0,
392 /* iArg: */ 0 },
mistachkindd197832013-10-21 23:17:23 +0000393#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drh9ccd8652013-09-13 16:36:46 +0000394#if defined(SQLITE_DEBUG)
drhf63936e2013-10-03 14:08:07 +0000395 { /* zName: */ "sql_trace",
396 /* ePragTyp: */ PragTyp_FLAG,
397 /* ePragFlag: */ 0,
398 /* iArg: */ SQLITE_SqlTrace },
drh9ccd8652013-09-13 16:36:46 +0000399#endif
mistachkindd197832013-10-21 23:17:23 +0000400#endif
drh3ef26152013-10-12 20:22:00 +0000401#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
402 { /* zName: */ "stats",
403 /* ePragTyp: */ PragTyp_STATS,
404 /* ePragFlag: */ PragFlag_NeedSchema,
405 /* iArg: */ 0 },
406#endif
drh9ccd8652013-09-13 16:36:46 +0000407#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000408 { /* zName: */ "synchronous",
409 /* ePragTyp: */ PragTyp_SYNCHRONOUS,
410 /* ePragFlag: */ PragFlag_NeedSchema,
411 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000412#endif
413#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000414 { /* zName: */ "table_info",
415 /* ePragTyp: */ PragTyp_TABLE_INFO,
416 /* ePragFlag: */ PragFlag_NeedSchema,
417 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000418#endif
419#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000420 { /* zName: */ "temp_store",
421 /* ePragTyp: */ PragTyp_TEMP_STORE,
422 /* ePragFlag: */ 0,
423 /* iArg: */ 0 },
424 { /* zName: */ "temp_store_directory",
425 /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
426 /* ePragFlag: */ 0,
427 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000428#endif
drh03459612014-08-25 15:13:22 +0000429 { /* zName: */ "threads",
430 /* ePragTyp: */ PragTyp_THREADS,
431 /* ePragFlag: */ 0,
432 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000433#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000434 { /* zName: */ "user_version",
435 /* ePragTyp: */ PragTyp_HEADER_VALUE,
436 /* ePragFlag: */ 0,
drh8e755e72014-12-19 18:49:55 +0000437 /* iArg: */ BTREE_USER_VERSION },
drh9ccd8652013-09-13 16:36:46 +0000438#endif
mistachkindd197832013-10-21 23:17:23 +0000439#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drh9ccd8652013-09-13 16:36:46 +0000440#if defined(SQLITE_DEBUG)
drhf63936e2013-10-03 14:08:07 +0000441 { /* zName: */ "vdbe_addoptrace",
442 /* ePragTyp: */ PragTyp_FLAG,
443 /* ePragFlag: */ 0,
444 /* iArg: */ SQLITE_VdbeAddopTrace },
445 { /* zName: */ "vdbe_debug",
446 /* ePragTyp: */ PragTyp_FLAG,
447 /* ePragFlag: */ 0,
448 /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
drh84e55a82013-11-13 17:58:23 +0000449 { /* zName: */ "vdbe_eqp",
450 /* ePragTyp: */ PragTyp_FLAG,
451 /* ePragFlag: */ 0,
452 /* iArg: */ SQLITE_VdbeEQP },
drhf63936e2013-10-03 14:08:07 +0000453 { /* zName: */ "vdbe_listing",
454 /* ePragTyp: */ PragTyp_FLAG,
455 /* ePragFlag: */ 0,
456 /* iArg: */ SQLITE_VdbeListing },
457 { /* zName: */ "vdbe_trace",
458 /* ePragTyp: */ PragTyp_FLAG,
459 /* ePragFlag: */ 0,
460 /* iArg: */ SQLITE_VdbeTrace },
drh9ccd8652013-09-13 16:36:46 +0000461#endif
mistachkindd197832013-10-21 23:17:23 +0000462#endif
drh9ccd8652013-09-13 16:36:46 +0000463#if !defined(SQLITE_OMIT_WAL)
drhf63936e2013-10-03 14:08:07 +0000464 { /* zName: */ "wal_autocheckpoint",
465 /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT,
466 /* ePragFlag: */ 0,
467 /* iArg: */ 0 },
468 { /* zName: */ "wal_checkpoint",
469 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
470 /* ePragFlag: */ PragFlag_NeedSchema,
471 /* iArg: */ 0 },
drh9ccd8652013-09-13 16:36:46 +0000472#endif
mistachkindd197832013-10-21 23:17:23 +0000473#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
drhf63936e2013-10-03 14:08:07 +0000474 { /* zName: */ "writable_schema",
475 /* ePragTyp: */ PragTyp_FLAG,
476 /* ePragFlag: */ 0,
477 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
mistachkindd197832013-10-21 23:17:23 +0000478#endif
drh9ccd8652013-09-13 16:36:46 +0000479};
drh91618562014-12-19 19:28:02 +0000480/* Number of pragmas: 58 on by default, 71 total. */
drh9ccd8652013-09-13 16:36:46 +0000481/* End of the automatically generated pragma table.
482***************************************************************************/
483
drhc11d4f92003-04-06 21:08:24 +0000484/*
drhc11d4f92003-04-06 21:08:24 +0000485** Interpret the given string as a safety level. Return 0 for OFF,
jplyonb1639ff2004-01-19 04:52:29 +0000486** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
drh908c0052012-01-30 18:40:55 +0000487** unrecognized string argument. The FULL option is disallowed
488** if the omitFull parameter it 1.
drhc11d4f92003-04-06 21:08:24 +0000489**
490** Note that the values returned are one less that the values that
danielk19774adee202004-05-08 08:23:19 +0000491** should be passed into sqlite3BtreeSetSafetyLevel(). The is done
drhc11d4f92003-04-06 21:08:24 +0000492** to support legacy SQL code. The safety level used to be boolean
493** and older scripts may have used numbers 0 for OFF and 1 for ON.
494*/
drheac5bd72014-07-25 21:35:39 +0000495static u8 getSafetyLevel(const char *z, int omitFull, u8 dflt){
drh722e95a2004-10-25 20:33:44 +0000496 /* 123456789 123456789 */
497 static const char zText[] = "onoffalseyestruefull";
498 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
499 static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
500 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2};
501 int i, n;
danielk197778ca0e72009-01-20 16:53:39 +0000502 if( sqlite3Isdigit(*z) ){
drh60ac3f42010-11-23 18:59:27 +0000503 return (u8)sqlite3Atoi(z);
drhc11d4f92003-04-06 21:08:24 +0000504 }
drhea678832008-12-10 19:26:22 +0000505 n = sqlite3Strlen30(z);
drh908c0052012-01-30 18:40:55 +0000506 for(i=0; i<ArraySize(iLength)-omitFull; i++){
drh722e95a2004-10-25 20:33:44 +0000507 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
508 return iValue[i];
509 }
drhc11d4f92003-04-06 21:08:24 +0000510 }
drh908c0052012-01-30 18:40:55 +0000511 return dflt;
drhc11d4f92003-04-06 21:08:24 +0000512}
513
514/*
drh722e95a2004-10-25 20:33:44 +0000515** Interpret the given string as a boolean value.
516*/
drheac5bd72014-07-25 21:35:39 +0000517u8 sqlite3GetBoolean(const char *z, u8 dflt){
drh38d9c612012-01-31 14:24:47 +0000518 return getSafetyLevel(z,1,dflt)!=0;
drh722e95a2004-10-25 20:33:44 +0000519}
520
drhc7dc9bf2011-06-03 13:02:57 +0000521/* The sqlite3GetBoolean() function is used by other modules but the
522** remainder of this file is specific to PRAGMA processing. So omit
523** the rest of the file if PRAGMAs are omitted from the build.
524*/
525#if !defined(SQLITE_OMIT_PRAGMA)
526
danielk197741483462007-03-24 16:45:04 +0000527/*
528** Interpret the given string as a locking mode value.
529*/
530static int getLockingMode(const char *z){
531 if( z ){
532 if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE;
533 if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL;
534 }
535 return PAGER_LOCKINGMODE_QUERY;
536}
537
danielk1977dddbcdc2007-04-26 14:42:34 +0000538#ifndef SQLITE_OMIT_AUTOVACUUM
539/*
540** Interpret the given string as an auto-vacuum mode value.
541**
542** The following strings, "none", "full" and "incremental" are
543** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
544*/
545static int getAutoVacuum(const char *z){
546 int i;
547 if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE;
548 if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL;
549 if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR;
drh60ac3f42010-11-23 18:59:27 +0000550 i = sqlite3Atoi(z);
drh4f21c4a2008-12-10 22:15:00 +0000551 return (u8)((i>=0&&i<=2)?i:0);
danielk1977dddbcdc2007-04-26 14:42:34 +0000552}
553#endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
554
danielk1977b84f96f2005-01-20 11:32:23 +0000555#ifndef SQLITE_OMIT_PAGER_PRAGMAS
drh722e95a2004-10-25 20:33:44 +0000556/*
drh90f5ecb2004-07-22 01:19:35 +0000557** Interpret the given string as a temp db location. Return 1 for file
558** backed temporary databases, 2 for the Red-Black tree in memory database
559** and 0 to use the compile-time default.
560*/
561static int getTempStore(const char *z){
562 if( z[0]>='0' && z[0]<='2' ){
563 return z[0] - '0';
564 }else if( sqlite3StrICmp(z, "file")==0 ){
565 return 1;
566 }else if( sqlite3StrICmp(z, "memory")==0 ){
567 return 2;
568 }else{
569 return 0;
570 }
571}
drhbf216272005-02-26 18:10:44 +0000572#endif /* SQLITE_PAGER_PRAGMAS */
drh90f5ecb2004-07-22 01:19:35 +0000573
drhbf216272005-02-26 18:10:44 +0000574#ifndef SQLITE_OMIT_PAGER_PRAGMAS
drh90f5ecb2004-07-22 01:19:35 +0000575/*
tpoindex9a09a3c2004-12-20 19:01:32 +0000576** Invalidate temp storage, either when the temp storage is changed
577** from default, or when 'file' and the temp_store_directory has changed
drh90f5ecb2004-07-22 01:19:35 +0000578*/
tpoindex9a09a3c2004-12-20 19:01:32 +0000579static int invalidateTempStorage(Parse *pParse){
drh9bb575f2004-09-06 17:24:11 +0000580 sqlite3 *db = pParse->db;
drh90f5ecb2004-07-22 01:19:35 +0000581 if( db->aDb[1].pBt!=0 ){
danielk1977983e2302008-07-08 07:35:51 +0000582 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
drh90f5ecb2004-07-22 01:19:35 +0000583 sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
584 "from within a transaction");
585 return SQLITE_ERROR;
586 }
587 sqlite3BtreeClose(db->aDb[1].pBt);
588 db->aDb[1].pBt = 0;
drh81028a42012-05-15 18:28:27 +0000589 sqlite3ResetAllSchemasOfConnection(db);
drh90f5ecb2004-07-22 01:19:35 +0000590 }
tpoindex9a09a3c2004-12-20 19:01:32 +0000591 return SQLITE_OK;
592}
drhbf216272005-02-26 18:10:44 +0000593#endif /* SQLITE_PAGER_PRAGMAS */
tpoindex9a09a3c2004-12-20 19:01:32 +0000594
drhbf216272005-02-26 18:10:44 +0000595#ifndef SQLITE_OMIT_PAGER_PRAGMAS
tpoindex9a09a3c2004-12-20 19:01:32 +0000596/*
597** If the TEMP database is open, close it and mark the database schema
danielk1977b06a0b62008-06-26 10:54:12 +0000598** as needing reloading. This must be done when using the SQLITE_TEMP_STORE
tpoindex9a09a3c2004-12-20 19:01:32 +0000599** or DEFAULT_TEMP_STORE pragmas.
600*/
601static int changeTempStorage(Parse *pParse, const char *zStorageType){
602 int ts = getTempStore(zStorageType);
603 sqlite3 *db = pParse->db;
604 if( db->temp_store==ts ) return SQLITE_OK;
605 if( invalidateTempStorage( pParse ) != SQLITE_OK ){
606 return SQLITE_ERROR;
607 }
drh4f21c4a2008-12-10 22:15:00 +0000608 db->temp_store = (u8)ts;
drh90f5ecb2004-07-22 01:19:35 +0000609 return SQLITE_OK;
610}
drhbf216272005-02-26 18:10:44 +0000611#endif /* SQLITE_PAGER_PRAGMAS */
drh90f5ecb2004-07-22 01:19:35 +0000612
613/*
614** Generate code to return a single integer value.
615*/
drh3c713642009-04-04 16:02:32 +0000616static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
drh5bb7ffe2004-09-02 15:14:00 +0000617 Vdbe *v = sqlite3GetVdbe(pParse);
drh0a07c102008-01-03 18:03:08 +0000618 int mem = ++pParse->nMem;
drh3c713642009-04-04 16:02:32 +0000619 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
620 if( pI64 ){
621 memcpy(pI64, &value, sizeof(value));
622 }
623 sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
drh10861722009-04-07 00:49:16 +0000624 sqlite3VdbeSetNumCols(v, 1);
625 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
drh66a51672008-01-03 00:01:23 +0000626 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
drh90f5ecb2004-07-22 01:19:35 +0000627}
628
drhd3605a42013-08-17 15:42:29 +0000629
630/*
631** Set the safety_level and pager flags for pager iDb. Or if iDb<0
632** set these values for all pagers.
633*/
634#ifndef SQLITE_OMIT_PAGER_PRAGMAS
635static void setAllPagerFlags(sqlite3 *db){
636 if( db->autoCommit ){
637 Db *pDb = db->aDb;
638 int n = db->nDb;
639 assert( SQLITE_FullFSync==PAGER_FULLFSYNC );
640 assert( SQLITE_CkptFullFSync==PAGER_CKPT_FULLFSYNC );
641 assert( SQLITE_CacheSpill==PAGER_CACHESPILL );
642 assert( (PAGER_FULLFSYNC | PAGER_CKPT_FULLFSYNC | PAGER_CACHESPILL)
643 == PAGER_FLAGS_MASK );
644 assert( (pDb->safety_level & PAGER_SYNCHRONOUS_MASK)==pDb->safety_level );
645 while( (n--) > 0 ){
646 if( pDb->pBt ){
647 sqlite3BtreeSetPagerFlags(pDb->pBt,
648 pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) );
649 }
650 pDb++;
651 }
652 }
653}
drhfeb56e02013-08-23 17:33:46 +0000654#else
655# define setAllPagerFlags(X) /* no-op */
drhd3605a42013-08-17 15:42:29 +0000656#endif
657
658
drhd2cb50b2009-01-09 21:41:17 +0000659/*
660** Return a human-readable name for a constraint resolution action.
661*/
danba9108b2009-09-22 07:13:42 +0000662#ifndef SQLITE_OMIT_FOREIGN_KEY
danielk197750af3e12008-10-10 17:47:21 +0000663static const char *actionName(u8 action){
drhd2cb50b2009-01-09 21:41:17 +0000664 const char *zName;
danielk197750af3e12008-10-10 17:47:21 +0000665 switch( action ){
dan1da40a32009-09-19 17:00:31 +0000666 case OE_SetNull: zName = "SET NULL"; break;
667 case OE_SetDflt: zName = "SET DEFAULT"; break;
668 case OE_Cascade: zName = "CASCADE"; break;
669 case OE_Restrict: zName = "RESTRICT"; break;
670 default: zName = "NO ACTION";
671 assert( action==OE_None ); break;
danielk197750af3e12008-10-10 17:47:21 +0000672 }
drhd2cb50b2009-01-09 21:41:17 +0000673 return zName;
danielk197750af3e12008-10-10 17:47:21 +0000674}
danba9108b2009-09-22 07:13:42 +0000675#endif
danielk197750af3e12008-10-10 17:47:21 +0000676
dane04dc882010-04-20 18:53:15 +0000677
678/*
679** Parameter eMode must be one of the PAGER_JOURNALMODE_XXX constants
680** defined in pager.h. This function returns the associated lowercase
681** journal-mode name.
682*/
683const char *sqlite3JournalModename(int eMode){
684 static char * const azModeName[] = {
dan5cf53532010-05-01 16:40:20 +0000685 "delete", "persist", "off", "truncate", "memory"
686#ifndef SQLITE_OMIT_WAL
687 , "wal"
688#endif
dane04dc882010-04-20 18:53:15 +0000689 };
690 assert( PAGER_JOURNALMODE_DELETE==0 );
691 assert( PAGER_JOURNALMODE_PERSIST==1 );
692 assert( PAGER_JOURNALMODE_OFF==2 );
693 assert( PAGER_JOURNALMODE_TRUNCATE==3 );
694 assert( PAGER_JOURNALMODE_MEMORY==4 );
695 assert( PAGER_JOURNALMODE_WAL==5 );
696 assert( eMode>=0 && eMode<=ArraySize(azModeName) );
697
698 if( eMode==ArraySize(azModeName) ) return 0;
699 return azModeName[eMode];
700}
701
drh87223182004-02-21 14:00:29 +0000702/*
drhc11d4f92003-04-06 21:08:24 +0000703** Process a pragma statement.
704**
705** Pragmas are of this form:
706**
danielk197791cf71b2004-06-26 06:37:06 +0000707** PRAGMA [database.]id [= value]
drhc11d4f92003-04-06 21:08:24 +0000708**
709** The identifier might also be a string. The value is a string, and
710** identifier, or a number. If minusFlag is true, then the value is
711** a number that was preceded by a minus sign.
drh90f5ecb2004-07-22 01:19:35 +0000712**
713** If the left side is "database.id" then pId1 is the database name
714** and pId2 is the id. If the left side is just "id" then pId1 is the
715** id and pId2 is any empty string.
drhc11d4f92003-04-06 21:08:24 +0000716*/
danielk197791cf71b2004-06-26 06:37:06 +0000717void sqlite3Pragma(
718 Parse *pParse,
719 Token *pId1, /* First part of [database.]id field */
720 Token *pId2, /* Second part of [database.]id field, or NULL */
721 Token *pValue, /* Token for <value>, or NULL */
722 int minusFlag /* True if a '-' sign preceded <value> */
723){
724 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
725 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
726 const char *zDb = 0; /* The database name */
727 Token *pId; /* Pointer to <id> token */
drh3fa97302012-02-22 16:58:36 +0000728 char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
drh9ccd8652013-09-13 16:36:46 +0000729 int iDb; /* Database index for <database> */
730 int lwr, upr, mid; /* Binary search bounds */
drh06fd5d62012-02-22 14:45:19 +0000731 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
732 sqlite3 *db = pParse->db; /* The database connection */
733 Db *pDb; /* The specific database being pragmaed */
drhef8e9862013-04-11 13:26:18 +0000734 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
drh06fd5d62012-02-22 14:45:19 +0000735
drhc11d4f92003-04-06 21:08:24 +0000736 if( v==0 ) return;
drh4611d922010-02-25 14:47:01 +0000737 sqlite3VdbeRunOnlyOnce(v);
drh9cbf3422008-01-17 16:22:13 +0000738 pParse->nMem = 2;
drhc11d4f92003-04-06 21:08:24 +0000739
danielk197791cf71b2004-06-26 06:37:06 +0000740 /* Interpret the [database.] part of the pragma statement. iDb is the
741 ** index of the database this pragma is being applied to in db.aDb[]. */
742 iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId);
743 if( iDb<0 ) return;
drh90f5ecb2004-07-22 01:19:35 +0000744 pDb = &db->aDb[iDb];
danielk197791cf71b2004-06-26 06:37:06 +0000745
danielk1977ddfb2f02006-02-17 12:25:14 +0000746 /* If the temp database has been explicitly named as part of the
747 ** pragma, make sure it is open.
748 */
749 if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){
750 return;
751 }
752
drh17435752007-08-16 04:30:38 +0000753 zLeft = sqlite3NameFromToken(db, pId);
danielk197796fb0dd2004-06-30 09:49:22 +0000754 if( !zLeft ) return;
drhc11d4f92003-04-06 21:08:24 +0000755 if( minusFlag ){
drh17435752007-08-16 04:30:38 +0000756 zRight = sqlite3MPrintf(db, "-%T", pValue);
drhc11d4f92003-04-06 21:08:24 +0000757 }else{
drh17435752007-08-16 04:30:38 +0000758 zRight = sqlite3NameFromToken(db, pValue);
drhc11d4f92003-04-06 21:08:24 +0000759 }
danielk197791cf71b2004-06-26 06:37:06 +0000760
drhd2cb50b2009-01-09 21:41:17 +0000761 assert( pId2 );
762 zDb = pId2->n>0 ? pDb->zName : 0;
danielk197791cf71b2004-06-26 06:37:06 +0000763 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
danielk1977e0048402004-06-15 16:51:01 +0000764 goto pragma_out;
drhc11d4f92003-04-06 21:08:24 +0000765 }
drh06fd5d62012-02-22 14:45:19 +0000766
767 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
768 ** connection. If it returns SQLITE_OK, then assume that the VFS
769 ** handled the pragma and generate a no-op prepared statement.
770 */
drh3fa97302012-02-22 16:58:36 +0000771 aFcntl[0] = 0;
772 aFcntl[1] = zLeft;
773 aFcntl[2] = zRight;
774 aFcntl[3] = 0;
dan80bb6f82012-10-01 18:44:33 +0000775 db->busyHandler.nBusy = 0;
drh06fd5d62012-02-22 14:45:19 +0000776 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
777 if( rc==SQLITE_OK ){
drh3fa97302012-02-22 16:58:36 +0000778 if( aFcntl[0] ){
779 int mem = ++pParse->nMem;
780 sqlite3VdbeAddOp4(v, OP_String8, 0, mem, 0, aFcntl[0], 0);
781 sqlite3VdbeSetNumCols(v, 1);
782 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
783 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
784 sqlite3_free(aFcntl[0]);
785 }
drh9ccd8652013-09-13 16:36:46 +0000786 goto pragma_out;
787 }
788 if( rc!=SQLITE_NOTFOUND ){
drh92c700d2012-02-22 19:56:17 +0000789 if( aFcntl[0] ){
790 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
791 sqlite3_free(aFcntl[0]);
792 }
793 pParse->nErr++;
794 pParse->rc = rc;
drh9ccd8652013-09-13 16:36:46 +0000795 goto pragma_out;
796 }
797
798 /* Locate the pragma in the lookup table */
799 lwr = 0;
800 upr = ArraySize(aPragmaNames)-1;
801 while( lwr<=upr ){
802 mid = (lwr+upr)/2;
803 rc = sqlite3_stricmp(zLeft, aPragmaNames[mid].zName);
804 if( rc==0 ) break;
805 if( rc<0 ){
806 upr = mid - 1;
807 }else{
808 lwr = mid + 1;
809 }
810 }
811 if( lwr>upr ) goto pragma_out;
812
drhf63936e2013-10-03 14:08:07 +0000813 /* Make sure the database schema is loaded if the pragma requires that */
814 if( (aPragmaNames[mid].mPragFlag & PragFlag_NeedSchema)!=0 ){
815 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
816 }
817
drh9ccd8652013-09-13 16:36:46 +0000818 /* Jump to the appropriate pragma handler */
819 switch( aPragmaNames[mid].ePragTyp ){
820
drhe73c9142011-11-09 16:12:24 +0000821#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
drhc11d4f92003-04-06 21:08:24 +0000822 /*
drh90f5ecb2004-07-22 01:19:35 +0000823 ** PRAGMA [database.]default_cache_size
824 ** PRAGMA [database.]default_cache_size=N
drhc11d4f92003-04-06 21:08:24 +0000825 **
826 ** The first form reports the current persistent setting for the
827 ** page cache size. The value returned is the maximum number of
828 ** pages in the page cache. The second form sets both the current
829 ** page cache size value and the persistent page cache size value
830 ** stored in the database file.
831 **
drh93791ea2010-04-26 17:36:35 +0000832 ** Older versions of SQLite would set the default cache size to a
833 ** negative number to indicate synchronous=OFF. These days, synchronous
834 ** is always on by default regardless of the sign of the default cache
835 ** size. But continue to take the absolute value of the default cache
836 ** size of historical compatibility.
drhc11d4f92003-04-06 21:08:24 +0000837 */
drh9ccd8652013-09-13 16:36:46 +0000838 case PragTyp_DEFAULT_CACHE_SIZE: {
drhb06a4ec2014-03-10 18:03:09 +0000839 static const int iLn = VDBE_OFFSET_LINENO(2);
drh57196282004-10-06 15:41:16 +0000840 static const VdbeOpList getCacheSize[] = {
danielk1977602b4662009-07-02 07:47:33 +0000841 { OP_Transaction, 0, 0, 0}, /* 0 */
842 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
drhef8e9862013-04-11 13:26:18 +0000843 { OP_IfPos, 1, 8, 0},
drh3c84ddf2008-01-09 02:15:38 +0000844 { OP_Integer, 0, 2, 0},
845 { OP_Subtract, 1, 2, 1},
drhef8e9862013-04-11 13:26:18 +0000846 { OP_IfPos, 1, 8, 0},
danielk1977602b4662009-07-02 07:47:33 +0000847 { OP_Integer, 0, 1, 0}, /* 6 */
drhef8e9862013-04-11 13:26:18 +0000848 { OP_Noop, 0, 0, 0},
drh3c84ddf2008-01-09 02:15:38 +0000849 { OP_ResultRow, 1, 1, 0},
drhc11d4f92003-04-06 21:08:24 +0000850 };
drh905793e2004-02-21 13:31:09 +0000851 int addr;
drhfb982642007-08-30 01:19:59 +0000852 sqlite3VdbeUsesBtree(v, iDb);
danielk197791cf71b2004-06-26 06:37:06 +0000853 if( !zRight ){
danielk197722322fd2004-05-25 23:35:17 +0000854 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +0000855 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
drh3c84ddf2008-01-09 02:15:38 +0000856 pParse->nMem += 2;
drh688852a2014-02-17 22:40:43 +0000857 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
danielk197791cf71b2004-06-26 06:37:06 +0000858 sqlite3VdbeChangeP1(v, addr, iDb);
danielk1977602b4662009-07-02 07:47:33 +0000859 sqlite3VdbeChangeP1(v, addr+1, iDb);
860 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
drhc11d4f92003-04-06 21:08:24 +0000861 }else{
drhd50ffc42011-03-08 02:38:28 +0000862 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
danielk197791cf71b2004-06-26 06:37:06 +0000863 sqlite3BeginWriteOperation(pParse, 0, iDb);
drh9cbf3422008-01-17 16:22:13 +0000864 sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
danielk19770d19f7a2009-06-03 11:25:07 +0000865 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
drh21206082011-04-04 18:22:02 +0000866 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
danielk197714db2662006-01-09 16:12:04 +0000867 pDb->pSchema->cache_size = size;
868 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
drhc11d4f92003-04-06 21:08:24 +0000869 }
drh9ccd8652013-09-13 16:36:46 +0000870 break;
871 }
drhe73c9142011-11-09 16:12:24 +0000872#endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */
drhc11d4f92003-04-06 21:08:24 +0000873
drhe73c9142011-11-09 16:12:24 +0000874#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
drhc11d4f92003-04-06 21:08:24 +0000875 /*
drh90f5ecb2004-07-22 01:19:35 +0000876 ** PRAGMA [database.]page_size
877 ** PRAGMA [database.]page_size=N
878 **
879 ** The first form reports the current setting for the
880 ** database page size in bytes. The second form sets the
881 ** database page size value. The value can only be set if
882 ** the database has not yet been created.
883 */
drh9ccd8652013-09-13 16:36:46 +0000884 case PragTyp_PAGE_SIZE: {
drh90f5ecb2004-07-22 01:19:35 +0000885 Btree *pBt = pDb->pBt;
drhd2cb50b2009-01-09 21:41:17 +0000886 assert( pBt!=0 );
drh90f5ecb2004-07-22 01:19:35 +0000887 if( !zRight ){
drhd2cb50b2009-01-09 21:41:17 +0000888 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
drh5bb7ffe2004-09-02 15:14:00 +0000889 returnSingleInt(pParse, "page_size", size);
drh90f5ecb2004-07-22 01:19:35 +0000890 }else{
danielk1977992772c2007-08-30 10:07:38 +0000891 /* Malloc may fail when setting the page-size, as there is an internal
892 ** buffer that the pager module resizes using sqlite3_realloc().
893 */
drh60ac3f42010-11-23 18:59:27 +0000894 db->nextPagesize = sqlite3Atoi(zRight);
drhe73c9142011-11-09 16:12:24 +0000895 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
danielk1977992772c2007-08-30 10:07:38 +0000896 db->mallocFailed = 1;
897 }
drh90f5ecb2004-07-22 01:19:35 +0000898 }
drh9ccd8652013-09-13 16:36:46 +0000899 break;
900 }
danielk197741483462007-03-24 16:45:04 +0000901
902 /*
drh5b47efa2010-02-12 18:18:39 +0000903 ** PRAGMA [database.]secure_delete
904 ** PRAGMA [database.]secure_delete=ON/OFF
905 **
906 ** The first form reports the current setting for the
907 ** secure_delete flag. The second form changes the secure_delete
908 ** flag setting and reports thenew value.
909 */
drh9ccd8652013-09-13 16:36:46 +0000910 case PragTyp_SECURE_DELETE: {
drh5b47efa2010-02-12 18:18:39 +0000911 Btree *pBt = pDb->pBt;
912 int b = -1;
913 assert( pBt!=0 );
914 if( zRight ){
drh38d9c612012-01-31 14:24:47 +0000915 b = sqlite3GetBoolean(zRight, 0);
drh5b47efa2010-02-12 18:18:39 +0000916 }
drhaf034ed2010-02-12 19:46:26 +0000917 if( pId2->n==0 && b>=0 ){
918 int ii;
919 for(ii=0; ii<db->nDb; ii++){
920 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
921 }
922 }
drh5b47efa2010-02-12 18:18:39 +0000923 b = sqlite3BtreeSecureDelete(pBt, b);
924 returnSingleInt(pParse, "secure_delete", b);
drh9ccd8652013-09-13 16:36:46 +0000925 break;
926 }
drh5b47efa2010-02-12 18:18:39 +0000927
928 /*
drh60ac3f42010-11-23 18:59:27 +0000929 ** PRAGMA [database.]max_page_count
930 ** PRAGMA [database.]max_page_count=N
931 **
932 ** The first form reports the current setting for the
933 ** maximum number of pages in the database file. The
934 ** second form attempts to change this setting. Both
935 ** forms return the current setting.
936 **
drhe73c9142011-11-09 16:12:24 +0000937 ** The absolute value of N is used. This is undocumented and might
938 ** change. The only purpose is to provide an easy way to test
939 ** the sqlite3AbsInt32() function.
940 **
danielk197759a93792008-05-15 17:48:20 +0000941 ** PRAGMA [database.]page_count
942 **
943 ** Return the number of pages in the specified database.
944 */
drh9ccd8652013-09-13 16:36:46 +0000945 case PragTyp_PAGE_COUNT: {
danielk197759a93792008-05-15 17:48:20 +0000946 int iReg;
danielk197759a93792008-05-15 17:48:20 +0000947 sqlite3CodeVerifySchema(pParse, iDb);
948 iReg = ++pParse->nMem;
drhc5227312011-10-13 17:09:01 +0000949 if( sqlite3Tolower(zLeft[0])=='p' ){
drh60ac3f42010-11-23 18:59:27 +0000950 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
951 }else{
drhe73c9142011-11-09 16:12:24 +0000952 sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg,
953 sqlite3AbsInt32(sqlite3Atoi(zRight)));
drh60ac3f42010-11-23 18:59:27 +0000954 }
danielk197759a93792008-05-15 17:48:20 +0000955 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
956 sqlite3VdbeSetNumCols(v, 1);
drh60ac3f42010-11-23 18:59:27 +0000957 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
drh9ccd8652013-09-13 16:36:46 +0000958 break;
959 }
danielk197759a93792008-05-15 17:48:20 +0000960
961 /*
danielk197741483462007-03-24 16:45:04 +0000962 ** PRAGMA [database.]locking_mode
963 ** PRAGMA [database.]locking_mode = (normal|exclusive)
964 */
drh9ccd8652013-09-13 16:36:46 +0000965 case PragTyp_LOCKING_MODE: {
danielk197741483462007-03-24 16:45:04 +0000966 const char *zRet = "normal";
967 int eMode = getLockingMode(zRight);
968
969 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
970 /* Simple "PRAGMA locking_mode;" statement. This is a query for
971 ** the current default locking mode (which may be different to
972 ** the locking-mode of the main database).
973 */
974 eMode = db->dfltLockMode;
975 }else{
976 Pager *pPager;
977 if( pId2->n==0 ){
978 /* This indicates that no database name was specified as part
979 ** of the PRAGMA command. In this case the locking-mode must be
980 ** set on all attached databases, as well as the main db file.
981 **
982 ** Also, the sqlite3.dfltLockMode variable is set so that
983 ** any subsequently attached databases also use the specified
984 ** locking mode.
985 */
986 int ii;
987 assert(pDb==&db->aDb[0]);
988 for(ii=2; ii<db->nDb; ii++){
989 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
990 sqlite3PagerLockingMode(pPager, eMode);
991 }
drh4f21c4a2008-12-10 22:15:00 +0000992 db->dfltLockMode = (u8)eMode;
danielk197741483462007-03-24 16:45:04 +0000993 }
994 pPager = sqlite3BtreePager(pDb->pBt);
995 eMode = sqlite3PagerLockingMode(pPager, eMode);
996 }
997
drh9ccd8652013-09-13 16:36:46 +0000998 assert( eMode==PAGER_LOCKINGMODE_NORMAL
999 || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
danielk197741483462007-03-24 16:45:04 +00001000 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
1001 zRet = "exclusive";
1002 }
1003 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +00001004 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
drh2d401ab2008-01-10 23:50:11 +00001005 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
1006 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
drh9ccd8652013-09-13 16:36:46 +00001007 break;
1008 }
drh3b020132008-04-17 17:02:01 +00001009
1010 /*
1011 ** PRAGMA [database.]journal_mode
drh3ebaee92010-05-06 21:37:22 +00001012 ** PRAGMA [database.]journal_mode =
1013 ** (delete|persist|off|truncate|memory|wal|off)
drh3b020132008-04-17 17:02:01 +00001014 */
drh9ccd8652013-09-13 16:36:46 +00001015 case PragTyp_JOURNAL_MODE: {
drhc6b2a0f2010-07-08 17:40:37 +00001016 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
1017 int ii; /* Loop counter */
dane04dc882010-04-20 18:53:15 +00001018
1019 sqlite3VdbeSetNumCols(v, 1);
1020 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
drh3b020132008-04-17 17:02:01 +00001021
1022 if( zRight==0 ){
drhc6b2a0f2010-07-08 17:40:37 +00001023 /* If there is no "=MODE" part of the pragma, do a query for the
1024 ** current mode */
drh3b020132008-04-17 17:02:01 +00001025 eMode = PAGER_JOURNALMODE_QUERY;
1026 }else{
dane04dc882010-04-20 18:53:15 +00001027 const char *zMode;
drhea678832008-12-10 19:26:22 +00001028 int n = sqlite3Strlen30(zRight);
drhf77e2ac2010-07-07 14:33:09 +00001029 for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
dane04dc882010-04-20 18:53:15 +00001030 if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
1031 }
1032 if( !zMode ){
drhc6b2a0f2010-07-08 17:40:37 +00001033 /* If the "=MODE" part does not match any known journal mode,
1034 ** then do a query */
dane04dc882010-04-20 18:53:15 +00001035 eMode = PAGER_JOURNALMODE_QUERY;
drh3b020132008-04-17 17:02:01 +00001036 }
1037 }
drhc6b2a0f2010-07-08 17:40:37 +00001038 if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){
1039 /* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */
1040 iDb = 0;
1041 pId2->n = 1;
1042 }
1043 for(ii=db->nDb-1; ii>=0; ii--){
1044 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
1045 sqlite3VdbeUsesBtree(v, ii);
1046 sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
dane04dc882010-04-20 18:53:15 +00001047 }
drh3b020132008-04-17 17:02:01 +00001048 }
drh3b020132008-04-17 17:02:01 +00001049 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
drh9ccd8652013-09-13 16:36:46 +00001050 break;
1051 }
danielk1977b53e4962008-06-04 06:45:59 +00001052
1053 /*
1054 ** PRAGMA [database.]journal_size_limit
1055 ** PRAGMA [database.]journal_size_limit=N
1056 **
drha9e364f2009-01-13 20:14:15 +00001057 ** Get or set the size limit on rollback journal files.
danielk1977b53e4962008-06-04 06:45:59 +00001058 */
drh9ccd8652013-09-13 16:36:46 +00001059 case PragTyp_JOURNAL_SIZE_LIMIT: {
danielk1977b53e4962008-06-04 06:45:59 +00001060 Pager *pPager = sqlite3BtreePager(pDb->pBt);
1061 i64 iLimit = -2;
1062 if( zRight ){
drh9296c182014-07-23 13:40:49 +00001063 sqlite3DecOrHexToI64(zRight, &iLimit);
drh3c713642009-04-04 16:02:32 +00001064 if( iLimit<-1 ) iLimit = -1;
danielk1977b53e4962008-06-04 06:45:59 +00001065 }
1066 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
drh3c713642009-04-04 16:02:32 +00001067 returnSingleInt(pParse, "journal_size_limit", iLimit);
drh9ccd8652013-09-13 16:36:46 +00001068 break;
1069 }
danielk1977b53e4962008-06-04 06:45:59 +00001070
drh13d70422004-11-13 15:59:14 +00001071#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
drh90f5ecb2004-07-22 01:19:35 +00001072
1073 /*
danielk1977951af802004-11-05 15:45:09 +00001074 ** PRAGMA [database.]auto_vacuum
1075 ** PRAGMA [database.]auto_vacuum=N
1076 **
drha9e364f2009-01-13 20:14:15 +00001077 ** Get or set the value of the database 'auto-vacuum' parameter.
1078 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
danielk1977951af802004-11-05 15:45:09 +00001079 */
1080#ifndef SQLITE_OMIT_AUTOVACUUM
drh9ccd8652013-09-13 16:36:46 +00001081 case PragTyp_AUTO_VACUUM: {
danielk1977951af802004-11-05 15:45:09 +00001082 Btree *pBt = pDb->pBt;
drhd2cb50b2009-01-09 21:41:17 +00001083 assert( pBt!=0 );
danielk1977951af802004-11-05 15:45:09 +00001084 if( !zRight ){
drhf63936e2013-10-03 14:08:07 +00001085 returnSingleInt(pParse, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
danielk1977951af802004-11-05 15:45:09 +00001086 }else{
danielk1977dddbcdc2007-04-26 14:42:34 +00001087 int eAuto = getAutoVacuum(zRight);
drhd2cb50b2009-01-09 21:41:17 +00001088 assert( eAuto>=0 && eAuto<=2 );
drh4f21c4a2008-12-10 22:15:00 +00001089 db->nextAutovac = (u8)eAuto;
drhf63936e2013-10-03 14:08:07 +00001090 /* Call SetAutoVacuum() to set initialize the internal auto and
1091 ** incr-vacuum flags. This is required in case this connection
1092 ** creates the database file. It is important that it is created
1093 ** as an auto-vacuum capable db.
1094 */
1095 rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
1096 if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){
1097 /* When setting the auto_vacuum mode to either "full" or
1098 ** "incremental", write the value of meta[6] in the database
1099 ** file. Before writing to meta[6], check that meta[3] indicates
1100 ** that this really is an auto-vacuum capable database.
danielk197727b1f952007-06-25 08:16:58 +00001101 */
drhb06a4ec2014-03-10 18:03:09 +00001102 static const int iLn = VDBE_OFFSET_LINENO(2);
drhf63936e2013-10-03 14:08:07 +00001103 static const VdbeOpList setMeta6[] = {
1104 { OP_Transaction, 0, 1, 0}, /* 0 */
1105 { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
1106 { OP_If, 1, 0, 0}, /* 2 */
1107 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
1108 { OP_Integer, 0, 1, 0}, /* 4 */
1109 { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */
1110 };
1111 int iAddr;
drh688852a2014-02-17 22:40:43 +00001112 iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn);
drhf63936e2013-10-03 14:08:07 +00001113 sqlite3VdbeChangeP1(v, iAddr, iDb);
1114 sqlite3VdbeChangeP1(v, iAddr+1, iDb);
1115 sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
1116 sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
1117 sqlite3VdbeChangeP1(v, iAddr+5, iDb);
1118 sqlite3VdbeUsesBtree(v, iDb);
danielk1977dddbcdc2007-04-26 14:42:34 +00001119 }
danielk1977951af802004-11-05 15:45:09 +00001120 }
drh9ccd8652013-09-13 16:36:46 +00001121 break;
1122 }
danielk1977951af802004-11-05 15:45:09 +00001123#endif
1124
drhca5557f2007-05-04 18:30:40 +00001125 /*
1126 ** PRAGMA [database.]incremental_vacuum(N)
1127 **
1128 ** Do N steps of incremental vacuuming on a database.
1129 */
1130#ifndef SQLITE_OMIT_AUTOVACUUM
drh9ccd8652013-09-13 16:36:46 +00001131 case PragTyp_INCREMENTAL_VACUUM: {
drhca5557f2007-05-04 18:30:40 +00001132 int iLimit, addr;
1133 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
1134 iLimit = 0x7fffffff;
1135 }
1136 sqlite3BeginWriteOperation(pParse, 0, iDb);
drh4c583122008-01-04 22:01:03 +00001137 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
drh688852a2014-02-17 22:40:43 +00001138 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v);
drh2d401ab2008-01-10 23:50:11 +00001139 sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
drh8558cde2008-01-05 05:20:10 +00001140 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
drh688852a2014-02-17 22:40:43 +00001141 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v);
drhca5557f2007-05-04 18:30:40 +00001142 sqlite3VdbeJumpHere(v, addr);
drh9ccd8652013-09-13 16:36:46 +00001143 break;
1144 }
drhca5557f2007-05-04 18:30:40 +00001145#endif
1146
drh13d70422004-11-13 15:59:14 +00001147#ifndef SQLITE_OMIT_PAGER_PRAGMAS
danielk1977951af802004-11-05 15:45:09 +00001148 /*
drh90f5ecb2004-07-22 01:19:35 +00001149 ** PRAGMA [database.]cache_size
1150 ** PRAGMA [database.]cache_size=N
drhc11d4f92003-04-06 21:08:24 +00001151 **
1152 ** The first form reports the current local setting for the
drh3b42abb2011-11-09 14:23:04 +00001153 ** page cache size. The second form sets the local
1154 ** page cache size value. If N is positive then that is the
1155 ** number of pages in the cache. If N is negative, then the
1156 ** number of pages is adjusted so that the cache uses -N kibibytes
1157 ** of memory.
drhc11d4f92003-04-06 21:08:24 +00001158 */
drh9ccd8652013-09-13 16:36:46 +00001159 case PragTyp_CACHE_SIZE: {
drh21206082011-04-04 18:22:02 +00001160 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
danielk197791cf71b2004-06-26 06:37:06 +00001161 if( !zRight ){
danielk197714db2662006-01-09 16:12:04 +00001162 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
drhc11d4f92003-04-06 21:08:24 +00001163 }else{
drh3b42abb2011-11-09 14:23:04 +00001164 int size = sqlite3Atoi(zRight);
danielk197714db2662006-01-09 16:12:04 +00001165 pDb->pSchema->cache_size = size;
1166 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
drhc11d4f92003-04-06 21:08:24 +00001167 }
drh9ccd8652013-09-13 16:36:46 +00001168 break;
1169 }
drhc11d4f92003-04-06 21:08:24 +00001170
1171 /*
drh9b4c59f2013-04-15 17:03:42 +00001172 ** PRAGMA [database.]mmap_size(N)
dan5d8a1372013-03-19 19:28:06 +00001173 **
drh0d0614b2013-03-25 23:09:28 +00001174 ** Used to set mapping size limit. The mapping size limit is
dan5d8a1372013-03-19 19:28:06 +00001175 ** used to limit the aggregate size of all memory mapped regions of the
1176 ** database file. If this parameter is set to zero, then memory mapping
drha1f42c72013-04-01 22:38:06 +00001177 ** is not used at all. If N is negative, then the default memory map
drh9b4c59f2013-04-15 17:03:42 +00001178 ** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set.
drha1f42c72013-04-01 22:38:06 +00001179 ** The parameter N is measured in bytes.
dan5d8a1372013-03-19 19:28:06 +00001180 **
drh0d0614b2013-03-25 23:09:28 +00001181 ** This value is advisory. The underlying VFS is free to memory map
1182 ** as little or as much as it wants. Except, if N is set to 0 then the
1183 ** upper layers will never invoke the xFetch interfaces to the VFS.
dan5d8a1372013-03-19 19:28:06 +00001184 */
drh9ccd8652013-09-13 16:36:46 +00001185 case PragTyp_MMAP_SIZE: {
drh9b4c59f2013-04-15 17:03:42 +00001186 sqlite3_int64 sz;
mistachkine98844f2013-08-24 00:59:24 +00001187#if SQLITE_MAX_MMAP_SIZE>0
dan5d8a1372013-03-19 19:28:06 +00001188 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
drh0d0614b2013-03-25 23:09:28 +00001189 if( zRight ){
drha1f42c72013-04-01 22:38:06 +00001190 int ii;
drh9296c182014-07-23 13:40:49 +00001191 sqlite3DecOrHexToI64(zRight, &sz);
drh9b4c59f2013-04-15 17:03:42 +00001192 if( sz<0 ) sz = sqlite3GlobalConfig.szMmap;
1193 if( pId2->n==0 ) db->szMmap = sz;
drha1f42c72013-04-01 22:38:06 +00001194 for(ii=db->nDb-1; ii>=0; ii--){
1195 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
drh9b4c59f2013-04-15 17:03:42 +00001196 sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
drha1f42c72013-04-01 22:38:06 +00001197 }
1198 }
dan5d8a1372013-03-19 19:28:06 +00001199 }
drh9b4c59f2013-04-15 17:03:42 +00001200 sz = -1;
dan3719f5f2013-05-23 10:13:18 +00001201 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz);
mistachkine98844f2013-08-24 00:59:24 +00001202#else
dan3719f5f2013-05-23 10:13:18 +00001203 sz = 0;
mistachkine98844f2013-08-24 00:59:24 +00001204 rc = SQLITE_OK;
drh188d4882013-04-08 20:47:49 +00001205#endif
dan3719f5f2013-05-23 10:13:18 +00001206 if( rc==SQLITE_OK ){
drh9b4c59f2013-04-15 17:03:42 +00001207 returnSingleInt(pParse, "mmap_size", sz);
dan3719f5f2013-05-23 10:13:18 +00001208 }else if( rc!=SQLITE_NOTFOUND ){
1209 pParse->nErr++;
1210 pParse->rc = rc;
drh34f74902013-04-03 13:09:18 +00001211 }
drh9ccd8652013-09-13 16:36:46 +00001212 break;
1213 }
dan5d8a1372013-03-19 19:28:06 +00001214
1215 /*
drh90f5ecb2004-07-22 01:19:35 +00001216 ** PRAGMA temp_store
1217 ** PRAGMA temp_store = "default"|"memory"|"file"
1218 **
1219 ** Return or set the local value of the temp_store flag. Changing
1220 ** the local value does not make changes to the disk file and the default
1221 ** value will be restored the next time the database is opened.
1222 **
1223 ** Note that it is possible for the library compile-time options to
1224 ** override this setting
1225 */
drh9ccd8652013-09-13 16:36:46 +00001226 case PragTyp_TEMP_STORE: {
drh90f5ecb2004-07-22 01:19:35 +00001227 if( !zRight ){
drh5bb7ffe2004-09-02 15:14:00 +00001228 returnSingleInt(pParse, "temp_store", db->temp_store);
drh90f5ecb2004-07-22 01:19:35 +00001229 }else{
1230 changeTempStorage(pParse, zRight);
1231 }
drh9ccd8652013-09-13 16:36:46 +00001232 break;
1233 }
drh90f5ecb2004-07-22 01:19:35 +00001234
1235 /*
tpoindex9a09a3c2004-12-20 19:01:32 +00001236 ** PRAGMA temp_store_directory
1237 ** PRAGMA temp_store_directory = ""|"directory_name"
1238 **
1239 ** Return or set the local value of the temp_store_directory flag. Changing
1240 ** the value sets a specific directory to be used for temporary files.
1241 ** Setting to a null string reverts to the default temporary directory search.
1242 ** If temporary directory is changed, then invalidateTempStorage.
1243 **
1244 */
drh9ccd8652013-09-13 16:36:46 +00001245 case PragTyp_TEMP_STORE_DIRECTORY: {
tpoindex9a09a3c2004-12-20 19:01:32 +00001246 if( !zRight ){
1247 if( sqlite3_temp_directory ){
1248 sqlite3VdbeSetNumCols(v, 1);
danielk1977955de522006-02-10 02:27:42 +00001249 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
danielk197710fb7492008-10-31 10:53:22 +00001250 "temp_store_directory", SQLITE_STATIC);
drh2d401ab2008-01-10 23:50:11 +00001251 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
1252 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
tpoindex9a09a3c2004-12-20 19:01:32 +00001253 }
1254 }else{
drh78f82d12008-09-02 00:52:52 +00001255#ifndef SQLITE_OMIT_WSD
danielk1977861f7452008-06-05 11:39:11 +00001256 if( zRight[0] ){
1257 int res;
danielk1977fab11272008-09-16 14:38:02 +00001258 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
1259 if( rc!=SQLITE_OK || res==0 ){
danielk1977861f7452008-06-05 11:39:11 +00001260 sqlite3ErrorMsg(pParse, "not a writable directory");
1261 goto pragma_out;
1262 }
drh268283b2005-01-08 15:44:25 +00001263 }
danielk1977b06a0b62008-06-26 10:54:12 +00001264 if( SQLITE_TEMP_STORE==0
1265 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
1266 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
drh268283b2005-01-08 15:44:25 +00001267 ){
1268 invalidateTempStorage(pParse);
1269 }
drh17435752007-08-16 04:30:38 +00001270 sqlite3_free(sqlite3_temp_directory);
drh268283b2005-01-08 15:44:25 +00001271 if( zRight[0] ){
drhb9755982010-07-24 16:34:37 +00001272 sqlite3_temp_directory = sqlite3_mprintf("%s", zRight);
tpoindex9a09a3c2004-12-20 19:01:32 +00001273 }else{
drh268283b2005-01-08 15:44:25 +00001274 sqlite3_temp_directory = 0;
tpoindex9a09a3c2004-12-20 19:01:32 +00001275 }
drh78f82d12008-09-02 00:52:52 +00001276#endif /* SQLITE_OMIT_WSD */
tpoindex9a09a3c2004-12-20 19:01:32 +00001277 }
drh9ccd8652013-09-13 16:36:46 +00001278 break;
1279 }
tpoindex9a09a3c2004-12-20 19:01:32 +00001280
drhcc716452012-06-06 23:23:23 +00001281#if SQLITE_OS_WIN
mistachkina112d142012-03-14 00:44:01 +00001282 /*
1283 ** PRAGMA data_store_directory
1284 ** PRAGMA data_store_directory = ""|"directory_name"
1285 **
1286 ** Return or set the local value of the data_store_directory flag. Changing
1287 ** the value sets a specific directory to be used for database files that
1288 ** were specified with a relative pathname. Setting to a null string reverts
1289 ** to the default database directory, which for database files specified with
1290 ** a relative path will probably be based on the current directory for the
1291 ** process. Database file specified with an absolute path are not impacted
1292 ** by this setting, regardless of its value.
1293 **
1294 */
drh9ccd8652013-09-13 16:36:46 +00001295 case PragTyp_DATA_STORE_DIRECTORY: {
mistachkina112d142012-03-14 00:44:01 +00001296 if( !zRight ){
1297 if( sqlite3_data_directory ){
1298 sqlite3VdbeSetNumCols(v, 1);
1299 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
1300 "data_store_directory", SQLITE_STATIC);
1301 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_data_directory, 0);
1302 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
1303 }
1304 }else{
1305#ifndef SQLITE_OMIT_WSD
1306 if( zRight[0] ){
1307 int res;
1308 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
1309 if( rc!=SQLITE_OK || res==0 ){
1310 sqlite3ErrorMsg(pParse, "not a writable directory");
1311 goto pragma_out;
1312 }
1313 }
1314 sqlite3_free(sqlite3_data_directory);
1315 if( zRight[0] ){
1316 sqlite3_data_directory = sqlite3_mprintf("%s", zRight);
1317 }else{
1318 sqlite3_data_directory = 0;
1319 }
1320#endif /* SQLITE_OMIT_WSD */
1321 }
drh9ccd8652013-09-13 16:36:46 +00001322 break;
1323 }
drhcc716452012-06-06 23:23:23 +00001324#endif
mistachkina112d142012-03-14 00:44:01 +00001325
drhd2cb50b2009-01-09 21:41:17 +00001326#if SQLITE_ENABLE_LOCKING_STYLE
tpoindex9a09a3c2004-12-20 19:01:32 +00001327 /*
drh9ccd8652013-09-13 16:36:46 +00001328 ** PRAGMA [database.]lock_proxy_file
1329 ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
1330 **
1331 ** Return or set the value of the lock_proxy_file flag. Changing
1332 ** the value sets a specific file to be used for database access locks.
1333 **
1334 */
1335 case PragTyp_LOCK_PROXY_FILE: {
aswiftaebf4132008-11-21 00:10:35 +00001336 if( !zRight ){
1337 Pager *pPager = sqlite3BtreePager(pDb->pBt);
1338 char *proxy_file_path = NULL;
1339 sqlite3_file *pFile = sqlite3PagerFile(pPager);
drhc02372c2012-01-10 17:59:59 +00001340 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
aswiftaebf4132008-11-21 00:10:35 +00001341 &proxy_file_path);
1342
1343 if( proxy_file_path ){
1344 sqlite3VdbeSetNumCols(v, 1);
1345 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
1346 "lock_proxy_file", SQLITE_STATIC);
1347 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0);
1348 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
1349 }
1350 }else{
1351 Pager *pPager = sqlite3BtreePager(pDb->pBt);
1352 sqlite3_file *pFile = sqlite3PagerFile(pPager);
1353 int res;
1354 if( zRight[0] ){
1355 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
1356 zRight);
1357 } else {
1358 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
1359 NULL);
1360 }
1361 if( res!=SQLITE_OK ){
1362 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
1363 goto pragma_out;
1364 }
1365 }
drh9ccd8652013-09-13 16:36:46 +00001366 break;
1367 }
drhd2cb50b2009-01-09 21:41:17 +00001368#endif /* SQLITE_ENABLE_LOCKING_STYLE */
aswiftaebf4132008-11-21 00:10:35 +00001369
1370 /*
drh90f5ecb2004-07-22 01:19:35 +00001371 ** PRAGMA [database.]synchronous
1372 ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
drhc11d4f92003-04-06 21:08:24 +00001373 **
1374 ** Return or set the local value of the synchronous flag. Changing
1375 ** the local value does not make changes to the disk file and the
1376 ** default value will be restored the next time the database is
1377 ** opened.
1378 */
drh9ccd8652013-09-13 16:36:46 +00001379 case PragTyp_SYNCHRONOUS: {
danielk197791cf71b2004-06-26 06:37:06 +00001380 if( !zRight ){
drh5bb7ffe2004-09-02 15:14:00 +00001381 returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
drhc11d4f92003-04-06 21:08:24 +00001382 }else{
danielk197791cf71b2004-06-26 06:37:06 +00001383 if( !db->autoCommit ){
1384 sqlite3ErrorMsg(pParse,
1385 "Safety level may not be changed inside a transaction");
1386 }else{
drh908c0052012-01-30 18:40:55 +00001387 pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
drhd3605a42013-08-17 15:42:29 +00001388 setAllPagerFlags(db);
danielk197791cf71b2004-06-26 06:37:06 +00001389 }
drhc11d4f92003-04-06 21:08:24 +00001390 }
drh9ccd8652013-09-13 16:36:46 +00001391 break;
1392 }
drh13d70422004-11-13 15:59:14 +00001393#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
drhc11d4f92003-04-06 21:08:24 +00001394
drhbf216272005-02-26 18:10:44 +00001395#ifndef SQLITE_OMIT_FLAG_PRAGMAS
drh9ccd8652013-09-13 16:36:46 +00001396 case PragTyp_FLAG: {
1397 if( zRight==0 ){
1398 returnSingleInt(pParse, aPragmaNames[mid].zName,
1399 (db->flags & aPragmaNames[mid].iArg)!=0 );
1400 }else{
1401 int mask = aPragmaNames[mid].iArg; /* Mask of bits to set or clear. */
1402 if( db->autoCommit==0 ){
1403 /* Foreign key support may not be enabled or disabled while not
1404 ** in auto-commit mode. */
1405 mask &= ~(SQLITE_ForeignKeys);
1406 }
drhd4530972014-09-09 14:47:53 +00001407#if SQLITE_USER_AUTHENTICATION
drhb2445d52014-09-11 14:01:41 +00001408 if( db->auth.authLevel==UAUTH_User ){
drhd4530972014-09-09 14:47:53 +00001409 /* Do not allow non-admin users to modify the schema arbitrarily */
1410 mask &= ~(SQLITE_WriteSchema);
1411 }
1412#endif
drh9ccd8652013-09-13 16:36:46 +00001413
1414 if( sqlite3GetBoolean(zRight, 0) ){
1415 db->flags |= mask;
1416 }else{
1417 db->flags &= ~mask;
1418 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
1419 }
1420
1421 /* Many of the flag-pragmas modify the code generated by the SQL
1422 ** compiler (eg. count_changes). So add an opcode to expire all
1423 ** compiled SQL statements after modifying a pragma value.
1424 */
1425 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
1426 setAllPagerFlags(db);
1427 }
1428 break;
1429 }
drhbf216272005-02-26 18:10:44 +00001430#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
drhc11d4f92003-04-06 21:08:24 +00001431
drh13d70422004-11-13 15:59:14 +00001432#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
danielk197791cf71b2004-06-26 06:37:06 +00001433 /*
1434 ** PRAGMA table_info(<table>)
1435 **
1436 ** Return a single row for each column of the named table. The columns of
1437 ** the returned data set are:
1438 **
1439 ** cid: Column id (numbered from left to right, starting at 0)
1440 ** name: Column name
1441 ** type: Column declaration type.
1442 ** notnull: True if 'NOT NULL' is part of column declaration
1443 ** dflt_value: The default value for the column, if any.
1444 */
drh9ccd8652013-09-13 16:36:46 +00001445 case PragTyp_TABLE_INFO: if( zRight ){
drhc11d4f92003-04-06 21:08:24 +00001446 Table *pTab;
drh2783e4b2004-10-05 15:42:53 +00001447 pTab = sqlite3FindTable(db, zRight, zDb);
drhc11d4f92003-04-06 21:08:24 +00001448 if( pTab ){
drh384b7fe2013-01-01 13:55:31 +00001449 int i, k;
danielk1977034ca142007-06-26 10:38:54 +00001450 int nHidden = 0;
drhf7eece62006-02-06 21:34:27 +00001451 Column *pCol;
drh44156282013-10-23 22:23:03 +00001452 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
drh9f6696a2006-02-09 16:52:23 +00001453 sqlite3VdbeSetNumCols(v, 6);
drh2d401ab2008-01-10 23:50:11 +00001454 pParse->nMem = 6;
drhc95e01d2013-02-14 16:16:05 +00001455 sqlite3CodeVerifySchema(pParse, iDb);
danielk197710fb7492008-10-31 10:53:22 +00001456 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
1457 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
1458 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
1459 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
1460 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
1461 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
danielk19774adee202004-05-08 08:23:19 +00001462 sqlite3ViewGetColumnNames(pParse, pTab);
drhf7eece62006-02-06 21:34:27 +00001463 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
danielk1977034ca142007-06-26 10:38:54 +00001464 if( IsHiddenColumn(pCol) ){
1465 nHidden++;
1466 continue;
1467 }
drh2d401ab2008-01-10 23:50:11 +00001468 sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
1469 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
1470 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
drhbfa8b102006-03-03 21:20:16 +00001471 pCol->zType ? pCol->zType : "", 0);
danielk1977f96a3772008-10-23 05:45:07 +00001472 sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
drhb7916a72009-05-27 10:31:29 +00001473 if( pCol->zDflt ){
1474 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
drh6f835982006-09-25 13:48:30 +00001475 }else{
drh2d401ab2008-01-10 23:50:11 +00001476 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
drh6f835982006-09-25 13:48:30 +00001477 }
drh384b7fe2013-01-01 13:55:31 +00001478 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
1479 k = 0;
1480 }else if( pPk==0 ){
1481 k = 1;
1482 }else{
1483 for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
1484 }
1485 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
drh2d401ab2008-01-10 23:50:11 +00001486 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
drhc11d4f92003-04-06 21:08:24 +00001487 }
1488 }
drh9ccd8652013-09-13 16:36:46 +00001489 }
1490 break;
drhc11d4f92003-04-06 21:08:24 +00001491
drh3ef26152013-10-12 20:22:00 +00001492 case PragTyp_STATS: {
1493 Index *pIdx;
1494 HashElem *i;
1495 v = sqlite3GetVdbe(pParse);
1496 sqlite3VdbeSetNumCols(v, 4);
1497 pParse->nMem = 4;
1498 sqlite3CodeVerifySchema(pParse, iDb);
1499 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
1500 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "index", SQLITE_STATIC);
1501 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "width", SQLITE_STATIC);
1502 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "height", SQLITE_STATIC);
1503 for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
1504 Table *pTab = sqliteHashData(i);
1505 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, pTab->zName, 0);
1506 sqlite3VdbeAddOp2(v, OP_Null, 0, 2);
1507 sqlite3VdbeAddOp2(v, OP_Integer,
1508 (int)sqlite3LogEstToInt(pTab->szTabRow), 3);
dancfc9df72014-04-25 15:01:01 +00001509 sqlite3VdbeAddOp2(v, OP_Integer,
1510 (int)sqlite3LogEstToInt(pTab->nRowLogEst), 4);
drh3ef26152013-10-12 20:22:00 +00001511 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
1512 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
1513 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
1514 sqlite3VdbeAddOp2(v, OP_Integer,
1515 (int)sqlite3LogEstToInt(pIdx->szIdxRow), 3);
dancfc9df72014-04-25 15:01:01 +00001516 sqlite3VdbeAddOp2(v, OP_Integer,
1517 (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]), 4);
drh3ef26152013-10-12 20:22:00 +00001518 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
1519 }
1520 }
1521 }
1522 break;
1523
drh9ccd8652013-09-13 16:36:46 +00001524 case PragTyp_INDEX_INFO: if( zRight ){
drhc11d4f92003-04-06 21:08:24 +00001525 Index *pIdx;
1526 Table *pTab;
drh2783e4b2004-10-05 15:42:53 +00001527 pIdx = sqlite3FindIndex(db, zRight, zDb);
drhc11d4f92003-04-06 21:08:24 +00001528 if( pIdx ){
drhc11d4f92003-04-06 21:08:24 +00001529 int i;
1530 pTab = pIdx->pTable;
danielk197722322fd2004-05-25 23:35:17 +00001531 sqlite3VdbeSetNumCols(v, 3);
drh2d401ab2008-01-10 23:50:11 +00001532 pParse->nMem = 3;
drhc95e01d2013-02-14 16:16:05 +00001533 sqlite3CodeVerifySchema(pParse, iDb);
danielk197710fb7492008-10-31 10:53:22 +00001534 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
1535 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
1536 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
drhbbbdc832013-10-22 18:01:40 +00001537 for(i=0; i<pIdx->nKeyCol; i++){
1538 i16 cnum = pIdx->aiColumn[i];
drh2d401ab2008-01-10 23:50:11 +00001539 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
1540 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
drhc11d4f92003-04-06 21:08:24 +00001541 assert( pTab->nCol>cnum );
drh2d401ab2008-01-10 23:50:11 +00001542 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
1543 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
drhc11d4f92003-04-06 21:08:24 +00001544 }
1545 }
drh9ccd8652013-09-13 16:36:46 +00001546 }
1547 break;
drhc11d4f92003-04-06 21:08:24 +00001548
drh9ccd8652013-09-13 16:36:46 +00001549 case PragTyp_INDEX_LIST: if( zRight ){
drhc11d4f92003-04-06 21:08:24 +00001550 Index *pIdx;
1551 Table *pTab;
drhe13e9f52013-10-05 19:18:00 +00001552 int i;
drh2783e4b2004-10-05 15:42:53 +00001553 pTab = sqlite3FindTable(db, zRight, zDb);
drhc11d4f92003-04-06 21:08:24 +00001554 if( pTab ){
danielk19774adee202004-05-08 08:23:19 +00001555 v = sqlite3GetVdbe(pParse);
drh3ef26152013-10-12 20:22:00 +00001556 sqlite3VdbeSetNumCols(v, 3);
1557 pParse->nMem = 3;
drhe13e9f52013-10-05 19:18:00 +00001558 sqlite3CodeVerifySchema(pParse, iDb);
1559 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
1560 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
1561 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
drh3ef26152013-10-12 20:22:00 +00001562 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
drhe13e9f52013-10-05 19:18:00 +00001563 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
1564 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
drh5f1d1d92014-07-31 22:59:04 +00001565 sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3);
drh3ef26152013-10-12 20:22:00 +00001566 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
drhc11d4f92003-04-06 21:08:24 +00001567 }
1568 }
drh9ccd8652013-09-13 16:36:46 +00001569 }
1570 break;
drhc11d4f92003-04-06 21:08:24 +00001571
drh9ccd8652013-09-13 16:36:46 +00001572 case PragTyp_DATABASE_LIST: {
drh13d70422004-11-13 15:59:14 +00001573 int i;
drh13d70422004-11-13 15:59:14 +00001574 sqlite3VdbeSetNumCols(v, 3);
drh2d401ab2008-01-10 23:50:11 +00001575 pParse->nMem = 3;
danielk197710fb7492008-10-31 10:53:22 +00001576 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
1577 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
1578 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
drh13d70422004-11-13 15:59:14 +00001579 for(i=0; i<db->nDb; i++){
1580 if( db->aDb[i].pBt==0 ) continue;
1581 assert( db->aDb[i].zName!=0 );
drh2d401ab2008-01-10 23:50:11 +00001582 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
1583 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
1584 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
drh13d70422004-11-13 15:59:14 +00001585 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
drh2d401ab2008-01-10 23:50:11 +00001586 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
drh13d70422004-11-13 15:59:14 +00001587 }
drh9ccd8652013-09-13 16:36:46 +00001588 }
1589 break;
danielk197748af65a2005-02-09 03:20:37 +00001590
drh9ccd8652013-09-13 16:36:46 +00001591 case PragTyp_COLLATION_LIST: {
danielk197748af65a2005-02-09 03:20:37 +00001592 int i = 0;
1593 HashElem *p;
1594 sqlite3VdbeSetNumCols(v, 2);
drh2d401ab2008-01-10 23:50:11 +00001595 pParse->nMem = 2;
danielk197710fb7492008-10-31 10:53:22 +00001596 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
1597 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
danielk197748af65a2005-02-09 03:20:37 +00001598 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
1599 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
drh2d401ab2008-01-10 23:50:11 +00001600 sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
1601 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
1602 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
danielk197748af65a2005-02-09 03:20:37 +00001603 }
drh9ccd8652013-09-13 16:36:46 +00001604 }
1605 break;
drh13d70422004-11-13 15:59:14 +00001606#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
1607
drhb7f91642004-10-31 02:22:47 +00001608#ifndef SQLITE_OMIT_FOREIGN_KEY
drh9ccd8652013-09-13 16:36:46 +00001609 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
drh78100cc2003-08-23 22:40:53 +00001610 FKey *pFK;
1611 Table *pTab;
drh2783e4b2004-10-05 15:42:53 +00001612 pTab = sqlite3FindTable(db, zRight, zDb);
drh78100cc2003-08-23 22:40:53 +00001613 if( pTab ){
danielk19774adee202004-05-08 08:23:19 +00001614 v = sqlite3GetVdbe(pParse);
drh78100cc2003-08-23 22:40:53 +00001615 pFK = pTab->pFKey;
danielk1977742f9472004-06-16 12:02:43 +00001616 if( pFK ){
1617 int i = 0;
danielk197750af3e12008-10-10 17:47:21 +00001618 sqlite3VdbeSetNumCols(v, 8);
1619 pParse->nMem = 8;
drhc95e01d2013-02-14 16:16:05 +00001620 sqlite3CodeVerifySchema(pParse, iDb);
danielk197710fb7492008-10-31 10:53:22 +00001621 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC);
1622 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
1623 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
1624 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
1625 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
1626 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
1627 sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
1628 sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
danielk1977742f9472004-06-16 12:02:43 +00001629 while(pFK){
1630 int j;
1631 for(j=0; j<pFK->nCol; j++){
drh2f471492005-06-23 03:15:07 +00001632 char *zCol = pFK->aCol[j].zCol;
dan8099ce62009-09-23 08:43:35 +00001633 char *zOnDelete = (char *)actionName(pFK->aAction[0]);
1634 char *zOnUpdate = (char *)actionName(pFK->aAction[1]);
drh2d401ab2008-01-10 23:50:11 +00001635 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
1636 sqlite3VdbeAddOp2(v, OP_Integer, j, 2);
1637 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0);
1638 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
drh66a51672008-01-03 00:01:23 +00001639 pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
drh2d401ab2008-01-10 23:50:11 +00001640 sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0);
danielk197750af3e12008-10-10 17:47:21 +00001641 sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0);
1642 sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0);
1643 sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0);
1644 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
danielk1977742f9472004-06-16 12:02:43 +00001645 }
1646 ++i;
1647 pFK = pFK->pNextFrom;
drh78100cc2003-08-23 22:40:53 +00001648 }
drh78100cc2003-08-23 22:40:53 +00001649 }
1650 }
drh9ccd8652013-09-13 16:36:46 +00001651 }
1652 break;
drhb7f91642004-10-31 02:22:47 +00001653#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
drh78100cc2003-08-23 22:40:53 +00001654
drh6c5b9152012-12-17 16:46:37 +00001655#ifndef SQLITE_OMIT_FOREIGN_KEY
dan09ff9e12013-03-11 11:49:03 +00001656#ifndef SQLITE_OMIT_TRIGGER
drh9ccd8652013-09-13 16:36:46 +00001657 case PragTyp_FOREIGN_KEY_CHECK: {
drh613028b2012-12-17 18:43:02 +00001658 FKey *pFK; /* A foreign key constraint */
1659 Table *pTab; /* Child table contain "REFERENCES" keyword */
1660 Table *pParent; /* Parent table that child points to */
1661 Index *pIdx; /* Index in the parent table */
1662 int i; /* Loop counter: Foreign key number for pTab */
1663 int j; /* Loop counter: Field of the foreign key */
1664 HashElem *k; /* Loop counter: Next table in schema */
1665 int x; /* result variable */
1666 int regResult; /* 3 registers to hold a result row */
1667 int regKey; /* Register to hold key for checking the FK */
1668 int regRow; /* Registers to hold a row from pTab */
1669 int addrTop; /* Top of a loop checking foreign keys */
1670 int addrOk; /* Jump here if the key is OK */
drh7d22a4d2012-12-17 22:32:14 +00001671 int *aiCols; /* child to parent column mapping */
drh6c5b9152012-12-17 16:46:37 +00001672
drh613028b2012-12-17 18:43:02 +00001673 regResult = pParse->nMem+1;
drh4b4b4732012-12-17 20:57:15 +00001674 pParse->nMem += 4;
drh613028b2012-12-17 18:43:02 +00001675 regKey = ++pParse->nMem;
1676 regRow = ++pParse->nMem;
1677 v = sqlite3GetVdbe(pParse);
drh4b4b4732012-12-17 20:57:15 +00001678 sqlite3VdbeSetNumCols(v, 4);
drh613028b2012-12-17 18:43:02 +00001679 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
1680 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "rowid", SQLITE_STATIC);
drh4b4b4732012-12-17 20:57:15 +00001681 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "parent", SQLITE_STATIC);
1682 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "fkid", SQLITE_STATIC);
drh613028b2012-12-17 18:43:02 +00001683 sqlite3CodeVerifySchema(pParse, iDb);
1684 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
1685 while( k ){
1686 if( zRight ){
1687 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
1688 k = 0;
1689 }else{
1690 pTab = (Table*)sqliteHashData(k);
1691 k = sqliteHashNext(k);
1692 }
drh9148def2012-12-17 20:40:39 +00001693 if( pTab==0 || pTab->pFKey==0 ) continue;
1694 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
drh613028b2012-12-17 18:43:02 +00001695 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
drh6c5b9152012-12-17 16:46:37 +00001696 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
drh613028b2012-12-17 18:43:02 +00001697 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult, 0, pTab->zName,
1698 P4_TRANSIENT);
drh6c5b9152012-12-17 16:46:37 +00001699 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
dan5e878302013-10-12 19:06:48 +00001700 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
1701 if( pParent==0 ) continue;
drh6c5b9152012-12-17 16:46:37 +00001702 pIdx = 0;
drh9148def2012-12-17 20:40:39 +00001703 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
drh613028b2012-12-17 18:43:02 +00001704 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
drh6c5b9152012-12-17 16:46:37 +00001705 if( x==0 ){
1706 if( pIdx==0 ){
1707 sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead);
1708 }else{
drh6c5b9152012-12-17 16:46:37 +00001709 sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iDb);
drh2ec2fb22013-11-06 19:59:23 +00001710 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
drh6c5b9152012-12-17 16:46:37 +00001711 }
1712 }else{
drh613028b2012-12-17 18:43:02 +00001713 k = 0;
drh6c5b9152012-12-17 16:46:37 +00001714 break;
1715 }
drh6c5b9152012-12-17 16:46:37 +00001716 }
dan5e878302013-10-12 19:06:48 +00001717 assert( pParse->nErr>0 || pFK==0 );
drh613028b2012-12-17 18:43:02 +00001718 if( pFK ) break;
1719 if( pParse->nTab<i ) pParse->nTab = i;
drh688852a2014-02-17 22:40:43 +00001720 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
drh613028b2012-12-17 18:43:02 +00001721 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
dan5e878302013-10-12 19:06:48 +00001722 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
drh613028b2012-12-17 18:43:02 +00001723 pIdx = 0;
drh7d22a4d2012-12-17 22:32:14 +00001724 aiCols = 0;
dan5e878302013-10-12 19:06:48 +00001725 if( pParent ){
1726 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
1727 assert( x==0 );
1728 }
drh613028b2012-12-17 18:43:02 +00001729 addrOk = sqlite3VdbeMakeLabel(v);
dan5e878302013-10-12 19:06:48 +00001730 if( pParent && pIdx==0 ){
drh613028b2012-12-17 18:43:02 +00001731 int iKey = pFK->aCol[0].iFrom;
drh83e0dba2012-12-20 00:32:49 +00001732 assert( iKey>=0 && iKey<pTab->nCol );
1733 if( iKey!=pTab->iPKey ){
drh613028b2012-12-17 18:43:02 +00001734 sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
1735 sqlite3ColumnDefault(v, pTab, iKey, regRow);
drh688852a2014-02-17 22:40:43 +00001736 sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
1737 sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
1738 sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
drh6c5b9152012-12-17 16:46:37 +00001739 }else{
drh613028b2012-12-17 18:43:02 +00001740 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
drh6c5b9152012-12-17 16:46:37 +00001741 }
drh688852a2014-02-17 22:40:43 +00001742 sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
drh613028b2012-12-17 18:43:02 +00001743 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
1744 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
1745 }else{
1746 for(j=0; j<pFK->nCol; j++){
drh7d22a4d2012-12-17 22:32:14 +00001747 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
dan5e878302013-10-12 19:06:48 +00001748 aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
drh688852a2014-02-17 22:40:43 +00001749 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
drh613028b2012-12-17 18:43:02 +00001750 }
dan5e878302013-10-12 19:06:48 +00001751 if( pParent ){
drh57bf4a82014-02-17 14:59:22 +00001752 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
1753 sqlite3IndexAffinityStr(v,pIdx), pFK->nCol);
dan5e878302013-10-12 19:06:48 +00001754 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
drh688852a2014-02-17 22:40:43 +00001755 VdbeCoverage(v);
dan5e878302013-10-12 19:06:48 +00001756 }
drh6c5b9152012-12-17 16:46:37 +00001757 }
drh613028b2012-12-17 18:43:02 +00001758 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
drh4b4b4732012-12-17 20:57:15 +00001759 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0,
1760 pFK->zTo, P4_TRANSIENT);
1761 sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
1762 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
drh613028b2012-12-17 18:43:02 +00001763 sqlite3VdbeResolveLabel(v, addrOk);
drh7d22a4d2012-12-17 22:32:14 +00001764 sqlite3DbFree(db, aiCols);
drh6c5b9152012-12-17 16:46:37 +00001765 }
drh688852a2014-02-17 22:40:43 +00001766 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
drh613028b2012-12-17 18:43:02 +00001767 sqlite3VdbeJumpHere(v, addrTop);
drh6c5b9152012-12-17 16:46:37 +00001768 }
drh9ccd8652013-09-13 16:36:46 +00001769 }
1770 break;
dan09ff9e12013-03-11 11:49:03 +00001771#endif /* !defined(SQLITE_OMIT_TRIGGER) */
drh6c5b9152012-12-17 16:46:37 +00001772#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
1773
drhc11d4f92003-04-06 21:08:24 +00001774#ifndef NDEBUG
drh9ccd8652013-09-13 16:36:46 +00001775 case PragTyp_PARSER_TRACE: {
drh55ef4d92005-08-14 01:20:37 +00001776 if( zRight ){
drh38d9c612012-01-31 14:24:47 +00001777 if( sqlite3GetBoolean(zRight, 0) ){
drh55ef4d92005-08-14 01:20:37 +00001778 sqlite3ParserTrace(stderr, "parser: ");
1779 }else{
1780 sqlite3ParserTrace(0, 0);
1781 }
drhc11d4f92003-04-06 21:08:24 +00001782 }
drh9ccd8652013-09-13 16:36:46 +00001783 }
1784 break;
drhc11d4f92003-04-06 21:08:24 +00001785#endif
1786
drh55ef4d92005-08-14 01:20:37 +00001787 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
1788 ** used will be case sensitive or not depending on the RHS.
1789 */
drh9ccd8652013-09-13 16:36:46 +00001790 case PragTyp_CASE_SENSITIVE_LIKE: {
drh55ef4d92005-08-14 01:20:37 +00001791 if( zRight ){
drh38d9c612012-01-31 14:24:47 +00001792 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
drh55ef4d92005-08-14 01:20:37 +00001793 }
drh9ccd8652013-09-13 16:36:46 +00001794 }
1795 break;
drh55ef4d92005-08-14 01:20:37 +00001796
drh1dcdbc02007-01-27 02:24:54 +00001797#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
1798# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
1799#endif
1800
drhb7f91642004-10-31 02:22:47 +00001801#ifndef SQLITE_OMIT_INTEGRITY_CHECK
drhf7b54962013-05-28 12:11:54 +00001802 /* Pragma "quick_check" is reduced version of
danielk197741c58b72007-12-29 13:39:19 +00001803 ** integrity_check designed to detect most database corruption
1804 ** without most of the overhead of a full integrity-check.
1805 */
drh9ccd8652013-09-13 16:36:46 +00001806 case PragTyp_INTEGRITY_CHECK: {
drh1dcdbc02007-01-27 02:24:54 +00001807 int i, j, addr, mxErr;
drhed717fe2003-06-15 23:42:24 +00001808
drhed717fe2003-06-15 23:42:24 +00001809 /* Code that appears at the end of the integrity check. If no error
1810 ** messages have been generated, output OK. Otherwise output the
1811 ** error message
1812 */
drhb06a4ec2014-03-10 18:03:09 +00001813 static const int iLn = VDBE_OFFSET_LINENO(2);
drh57196282004-10-06 15:41:16 +00001814 static const VdbeOpList endCode[] = {
drh4336b0e2014-08-05 00:53:51 +00001815 { OP_IfNeg, 1, 0, 0}, /* 0 */
1816 { OP_String8, 0, 3, 0}, /* 1 */
drh2d401ab2008-01-10 23:50:11 +00001817 { OP_ResultRow, 3, 1, 0},
drhc11d4f92003-04-06 21:08:24 +00001818 };
drhed717fe2003-06-15 23:42:24 +00001819
drhc5227312011-10-13 17:09:01 +00001820 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
danielk197741c58b72007-12-29 13:39:19 +00001821
dan5885e762012-07-16 10:06:12 +00001822 /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
1823 ** then iDb is set to the index of the database identified by <db>.
1824 ** In this case, the integrity of database iDb only is verified by
1825 ** the VDBE created below.
1826 **
1827 ** Otherwise, if the command was simply "PRAGMA integrity_check" (or
1828 ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
1829 ** to -1 here, to indicate that the VDBE should verify the integrity
1830 ** of all attached databases. */
1831 assert( iDb>=0 );
1832 assert( iDb==0 || pId2->z );
1833 if( pId2->z==0 ) iDb = -1;
1834
drhed717fe2003-06-15 23:42:24 +00001835 /* Initialize the VDBE program */
drh2d401ab2008-01-10 23:50:11 +00001836 pParse->nMem = 6;
danielk197722322fd2004-05-25 23:35:17 +00001837 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +00001838 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
drh1dcdbc02007-01-27 02:24:54 +00001839
1840 /* Set the maximum error count */
1841 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
1842 if( zRight ){
drh60ac3f42010-11-23 18:59:27 +00001843 sqlite3GetInt32(zRight, &mxErr);
drh1dcdbc02007-01-27 02:24:54 +00001844 if( mxErr<=0 ){
1845 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
1846 }
1847 }
drh2d401ab2008-01-10 23:50:11 +00001848 sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */
drhed717fe2003-06-15 23:42:24 +00001849
1850 /* Do an integrity check on each database file */
1851 for(i=0; i<db->nDb; i++){
1852 HashElem *x;
danielk1977da184232006-01-05 11:34:32 +00001853 Hash *pTbls;
drh79069752004-05-22 21:30:40 +00001854 int cnt = 0;
drhed717fe2003-06-15 23:42:24 +00001855
danielk197753c0f742005-03-29 03:10:59 +00001856 if( OMIT_TEMPDB && i==1 ) continue;
dan5885e762012-07-16 10:06:12 +00001857 if( iDb>=0 && i!=iDb ) continue;
danielk197753c0f742005-03-29 03:10:59 +00001858
drh80242052004-06-09 00:48:12 +00001859 sqlite3CodeVerifySchema(pParse, i);
drh2d401ab2008-01-10 23:50:11 +00001860 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
drh688852a2014-02-17 22:40:43 +00001861 VdbeCoverage(v);
drh66a51672008-01-03 00:01:23 +00001862 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
drh1dcdbc02007-01-27 02:24:54 +00001863 sqlite3VdbeJumpHere(v, addr);
drh80242052004-06-09 00:48:12 +00001864
drhed717fe2003-06-15 23:42:24 +00001865 /* Do an integrity check of the B-Tree
drh2d401ab2008-01-10 23:50:11 +00001866 **
1867 ** Begin by filling registers 2, 3, ... with the root pages numbers
1868 ** for all tables and indices in the database.
drhed717fe2003-06-15 23:42:24 +00001869 */
dan5885e762012-07-16 10:06:12 +00001870 assert( sqlite3SchemaMutexHeld(db, i, 0) );
danielk1977da184232006-01-05 11:34:32 +00001871 pTbls = &db->aDb[i].pSchema->tblHash;
1872 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
drh79069752004-05-22 21:30:40 +00001873 Table *pTab = sqliteHashData(x);
1874 Index *pIdx;
drh6fbe41a2013-10-30 20:22:55 +00001875 if( HasRowid(pTab) ){
1876 sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
drh58383402013-11-04 17:00:50 +00001877 VdbeComment((v, "%s", pTab->zName));
drh6fbe41a2013-10-30 20:22:55 +00001878 cnt++;
1879 }
drh79069752004-05-22 21:30:40 +00001880 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
drh98757152008-01-09 23:04:12 +00001881 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt);
drh58383402013-11-04 17:00:50 +00001882 VdbeComment((v, "%s", pIdx->zName));
drh79069752004-05-22 21:30:40 +00001883 cnt++;
1884 }
1885 }
drh2d401ab2008-01-10 23:50:11 +00001886
1887 /* Make sure sufficient number of registers have been allocated */
drh6fbe41a2013-10-30 20:22:55 +00001888 pParse->nMem = MAX( pParse->nMem, cnt+8 );
drh2d401ab2008-01-10 23:50:11 +00001889
1890 /* Do the b-tree integrity checks */
drh98757152008-01-09 23:04:12 +00001891 sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
drh4f21c4a2008-12-10 22:15:00 +00001892 sqlite3VdbeChangeP5(v, (u8)i);
drh688852a2014-02-17 22:40:43 +00001893 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
drh98757152008-01-09 23:04:12 +00001894 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
danielk19771e536952007-08-16 10:09:01 +00001895 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
drh66a51672008-01-03 00:01:23 +00001896 P4_DYNAMIC);
drh079a3072014-03-19 14:10:55 +00001897 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
danielk1977a7a8e142008-02-13 18:25:27 +00001898 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
drh98757152008-01-09 23:04:12 +00001899 sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
drh1dcdbc02007-01-27 02:24:54 +00001900 sqlite3VdbeJumpHere(v, addr);
drhed717fe2003-06-15 23:42:24 +00001901
1902 /* Make sure all the indices are constructed correctly.
1903 */
danielk197741c58b72007-12-29 13:39:19 +00001904 for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){
drhed717fe2003-06-15 23:42:24 +00001905 Table *pTab = sqliteHashData(x);
drh6fbe41a2013-10-30 20:22:55 +00001906 Index *pIdx, *pPk;
drh1c2c0b72014-01-04 19:27:05 +00001907 Index *pPrior = 0;
drhed717fe2003-06-15 23:42:24 +00001908 int loopTop;
drh26198bb2013-10-31 11:15:09 +00001909 int iDataCur, iIdxCur;
drh1c2c0b72014-01-04 19:27:05 +00001910 int r1 = -1;
drhed717fe2003-06-15 23:42:24 +00001911
1912 if( pTab->pIndex==0 ) continue;
drh26198bb2013-10-31 11:15:09 +00001913 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
drh2d401ab2008-01-10 23:50:11 +00001914 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
drh688852a2014-02-17 22:40:43 +00001915 VdbeCoverage(v);
drh66a51672008-01-03 00:01:23 +00001916 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
drh1dcdbc02007-01-27 02:24:54 +00001917 sqlite3VdbeJumpHere(v, addr);
drh66518ca2013-08-01 15:09:57 +00001918 sqlite3ExprCacheClear(pParse);
drh26198bb2013-10-31 11:15:09 +00001919 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
drh6a534992013-11-16 20:13:39 +00001920 1, 0, &iDataCur, &iIdxCur);
drh6fbe41a2013-10-30 20:22:55 +00001921 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
drh8a9789b2013-08-01 03:36:59 +00001922 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
drh6fbe41a2013-10-30 20:22:55 +00001923 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
drh8a9789b2013-08-01 03:36:59 +00001924 }
drh6fbe41a2013-10-30 20:22:55 +00001925 pParse->nMem = MAX(pParse->nMem, 8+j);
drh688852a2014-02-17 22:40:43 +00001926 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
drh6fbe41a2013-10-30 20:22:55 +00001927 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
drhcefc87f2014-08-01 01:40:33 +00001928 /* Verify that all NOT NULL columns really are NOT NULL */
1929 for(j=0; j<pTab->nCol; j++){
1930 char *zErr;
1931 int jmp2, jmp3;
1932 if( j==pTab->iPKey ) continue;
1933 if( pTab->aCol[j].notNull==0 ) continue;
1934 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
1935 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
1936 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
1937 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
1938 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
1939 pTab->aCol[j].zName);
1940 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
1941 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
1942 jmp3 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
1943 sqlite3VdbeAddOp0(v, OP_Halt);
1944 sqlite3VdbeJumpHere(v, jmp2);
1945 sqlite3VdbeJumpHere(v, jmp3);
1946 }
1947 /* Validate index entries for the current row */
drhed717fe2003-06-15 23:42:24 +00001948 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
drhcefc87f2014-08-01 01:40:33 +00001949 int jmp2, jmp3, jmp4, jmp5;
1950 int ckUniq = sqlite3VdbeMakeLabel(v);
drh6fbe41a2013-10-30 20:22:55 +00001951 if( pPk==pIdx ) continue;
drh1c2c0b72014-01-04 19:27:05 +00001952 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
1953 pPrior, r1);
1954 pPrior = pIdx;
drh6fbe41a2013-10-30 20:22:55 +00001955 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
drhcefc87f2014-08-01 01:40:33 +00001956 /* Verify that an index entry exists for the current table row */
1957 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
drh688852a2014-02-17 22:40:43 +00001958 pIdx->nColumn); VdbeCoverage(v);
drh6fbe41a2013-10-30 20:22:55 +00001959 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
1960 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
1961 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
drhcefc87f2014-08-01 01:40:33 +00001962 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
1963 " missing from index ", P4_STATIC);
drh6fbe41a2013-10-30 20:22:55 +00001964 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
drhcefc87f2014-08-01 01:40:33 +00001965 jmp5 = sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
1966 pIdx->zName, P4_TRANSIENT);
drh6fbe41a2013-10-30 20:22:55 +00001967 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
1968 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
drh688852a2014-02-17 22:40:43 +00001969 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
drh6fbe41a2013-10-30 20:22:55 +00001970 sqlite3VdbeAddOp0(v, OP_Halt);
drhd654be82005-09-20 17:42:23 +00001971 sqlite3VdbeJumpHere(v, jmp2);
drhcefc87f2014-08-01 01:40:33 +00001972 /* For UNIQUE indexes, verify that only one entry exists with the
1973 ** current key. The entry is unique if (1) any column is NULL
1974 ** or (2) the next entry has a different key */
1975 if( IsUniqueIndex(pIdx) ){
1976 int uniqOk = sqlite3VdbeMakeLabel(v);
1977 int jmp6;
1978 int kk;
1979 for(kk=0; kk<pIdx->nKeyCol; kk++){
1980 int iCol = pIdx->aiColumn[kk];
1981 assert( iCol>=0 && iCol<pTab->nCol );
1982 if( pTab->aCol[iCol].notNull ) continue;
1983 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
1984 VdbeCoverage(v);
1985 }
1986 jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
1987 sqlite3VdbeAddOp2(v, OP_Goto, 0, uniqOk);
1988 sqlite3VdbeJumpHere(v, jmp6);
1989 sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
1990 pIdx->nKeyCol); VdbeCoverage(v);
1991 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
1992 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
1993 "non-unique entry in index ", P4_STATIC);
1994 sqlite3VdbeAddOp2(v, OP_Goto, 0, jmp5);
1995 sqlite3VdbeResolveLabel(v, uniqOk);
1996 }
1997 sqlite3VdbeJumpHere(v, jmp4);
drh87744512014-04-13 19:15:49 +00001998 sqlite3ResolvePartIdxLabel(pParse, jmp3);
drhed717fe2003-06-15 23:42:24 +00001999 }
drh688852a2014-02-17 22:40:43 +00002000 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
drh8a9789b2013-08-01 03:36:59 +00002001 sqlite3VdbeJumpHere(v, loopTop-1);
2002#ifndef SQLITE_OMIT_BTREECOUNT
2003 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
drh24003452008-01-03 01:28:59 +00002004 "wrong # of entries in index ", P4_STATIC);
drh8a9789b2013-08-01 03:36:59 +00002005 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
drh6fbe41a2013-10-30 20:22:55 +00002006 if( pPk==pIdx ) continue;
drh8a9789b2013-08-01 03:36:59 +00002007 addr = sqlite3VdbeCurrentAddr(v);
drh688852a2014-02-17 22:40:43 +00002008 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
drh8a9789b2013-08-01 03:36:59 +00002009 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
drh26198bb2013-10-31 11:15:09 +00002010 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
drh688852a2014-02-17 22:40:43 +00002011 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
drh5655c542014-02-19 19:14:34 +00002012 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
drh8a9789b2013-08-01 03:36:59 +00002013 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
2014 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
2015 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
2016 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
drhed717fe2003-06-15 23:42:24 +00002017 }
drh8a9789b2013-08-01 03:36:59 +00002018#endif /* SQLITE_OMIT_BTREECOUNT */
drhed717fe2003-06-15 23:42:24 +00002019 }
2020 }
drh688852a2014-02-17 22:40:43 +00002021 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
drh4336b0e2014-08-05 00:53:51 +00002022 sqlite3VdbeChangeP3(v, addr, -mxErr);
2023 sqlite3VdbeJumpHere(v, addr);
2024 sqlite3VdbeChangeP4(v, addr+1, "ok", P4_STATIC);
drh9ccd8652013-09-13 16:36:46 +00002025 }
2026 break;
drhb7f91642004-10-31 02:22:47 +00002027#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
2028
drh13d70422004-11-13 15:59:14 +00002029#ifndef SQLITE_OMIT_UTF16
danielk19778e227872004-06-07 07:52:17 +00002030 /*
2031 ** PRAGMA encoding
2032 ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
2033 **
drh85b623f2007-12-13 21:54:09 +00002034 ** In its first form, this pragma returns the encoding of the main
danielk19778e227872004-06-07 07:52:17 +00002035 ** database. If the database is not initialized, it is initialized now.
2036 **
2037 ** The second form of this pragma is a no-op if the main database file
2038 ** has not already been initialized. In this case it sets the default
2039 ** encoding that will be used for the main database file if a new file
2040 ** is created. If an existing main database file is opened, then the
2041 ** default text encoding for the existing database is used.
2042 **
2043 ** In all cases new databases created using the ATTACH command are
2044 ** created to use the same default text encoding as the main database. If
2045 ** the main database has not been initialized and/or created when ATTACH
2046 ** is executed, this is done before the ATTACH operation.
2047 **
2048 ** In the second form this pragma sets the text encoding to be used in
2049 ** new database files created using this database handle. It is only
2050 ** useful if invoked immediately after the main database i
2051 */
drh9ccd8652013-09-13 16:36:46 +00002052 case PragTyp_ENCODING: {
drh0f7eb612006-08-08 13:51:43 +00002053 static const struct EncName {
danielk19778e227872004-06-07 07:52:17 +00002054 char *zName;
2055 u8 enc;
2056 } encnames[] = {
drh998da3a2004-06-19 15:22:56 +00002057 { "UTF8", SQLITE_UTF8 },
drhd2cb50b2009-01-09 21:41:17 +00002058 { "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */
2059 { "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */
2060 { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */
drh998da3a2004-06-19 15:22:56 +00002061 { "UTF16le", SQLITE_UTF16LE },
drh998da3a2004-06-19 15:22:56 +00002062 { "UTF16be", SQLITE_UTF16BE },
drh0f7eb612006-08-08 13:51:43 +00002063 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
2064 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
danielk19778e227872004-06-07 07:52:17 +00002065 { 0, 0 }
2066 };
drh0f7eb612006-08-08 13:51:43 +00002067 const struct EncName *pEnc;
danielk197791cf71b2004-06-26 06:37:06 +00002068 if( !zRight ){ /* "PRAGMA encoding" */
danielk19778a414492004-06-29 08:59:35 +00002069 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
danielk19778e227872004-06-07 07:52:17 +00002070 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +00002071 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
drh2d401ab2008-01-10 23:50:11 +00002072 sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
drhd2cb50b2009-01-09 21:41:17 +00002073 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
2074 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
2075 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
2076 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
drh2d401ab2008-01-10 23:50:11 +00002077 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
danielk19778e227872004-06-07 07:52:17 +00002078 }else{ /* "PRAGMA encoding = XXX" */
2079 /* Only change the value of sqlite.enc if the database handle is not
2080 ** initialized. If the main database exists, the new sqlite.enc value
2081 ** will be overwritten when the schema is next loaded. If it does not
2082 ** already exists, it will be created to use the new encoding value.
2083 */
danielk1977b82e7ed2006-01-11 14:09:31 +00002084 if(
2085 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
2086 DbHasProperty(db, 0, DB_Empty)
2087 ){
danielk19778e227872004-06-07 07:52:17 +00002088 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
2089 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
drh9bd3cc42014-12-12 23:17:54 +00002090 SCHEMA_ENC(db) = ENC(db) =
2091 pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
danielk19778e227872004-06-07 07:52:17 +00002092 break;
2093 }
2094 }
2095 if( !pEnc->zName ){
drh5260f7e2004-06-26 19:35:29 +00002096 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
danielk19778e227872004-06-07 07:52:17 +00002097 }
2098 }
2099 }
drh9ccd8652013-09-13 16:36:46 +00002100 }
2101 break;
drh13d70422004-11-13 15:59:14 +00002102#endif /* SQLITE_OMIT_UTF16 */
2103
2104#ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
danielk1977dae24952004-11-11 05:10:43 +00002105 /*
danielk1977b92b70b2004-11-12 16:11:59 +00002106 ** PRAGMA [database.]schema_version
2107 ** PRAGMA [database.]schema_version = <integer>
danielk1977dae24952004-11-11 05:10:43 +00002108 **
danielk1977b92b70b2004-11-12 16:11:59 +00002109 ** PRAGMA [database.]user_version
2110 ** PRAGMA [database.]user_version = <integer>
danielk1977dae24952004-11-11 05:10:43 +00002111 **
drh4ee09b42013-05-01 19:49:27 +00002112 ** PRAGMA [database.]freelist_count = <integer>
2113 **
2114 ** PRAGMA [database.]application_id
2115 ** PRAGMA [database.]application_id = <integer>
2116 **
danielk1977b92b70b2004-11-12 16:11:59 +00002117 ** The pragma's schema_version and user_version are used to set or get
2118 ** the value of the schema-version and user-version, respectively. Both
2119 ** the schema-version and the user-version are 32-bit signed integers
danielk1977dae24952004-11-11 05:10:43 +00002120 ** stored in the database header.
2121 **
2122 ** The schema-cookie is usually only manipulated internally by SQLite. It
2123 ** is incremented by SQLite whenever the database schema is modified (by
danielk1977b92b70b2004-11-12 16:11:59 +00002124 ** creating or dropping a table or index). The schema version is used by
danielk1977dae24952004-11-11 05:10:43 +00002125 ** SQLite each time a query is executed to ensure that the internal cache
2126 ** of the schema used when compiling the SQL query matches the schema of
2127 ** the database against which the compiled query is actually executed.
danielk1977b92b70b2004-11-12 16:11:59 +00002128 ** Subverting this mechanism by using "PRAGMA schema_version" to modify
2129 ** the schema-version is potentially dangerous and may lead to program
danielk1977dae24952004-11-11 05:10:43 +00002130 ** crashes or database corruption. Use with caution!
2131 **
danielk1977b92b70b2004-11-12 16:11:59 +00002132 ** The user-version is not used internally by SQLite. It may be used by
danielk1977dae24952004-11-11 05:10:43 +00002133 ** applications for any purpose.
2134 */
drh9ccd8652013-09-13 16:36:46 +00002135 case PragTyp_HEADER_VALUE: {
drh8e755e72014-12-19 18:49:55 +00002136 int iCookie = aPragmaNames[mid].iArg; /* Which cookie to read or write */
drhfb982642007-08-30 01:19:59 +00002137 sqlite3VdbeUsesBtree(v, iDb);
drh8e755e72014-12-19 18:49:55 +00002138 if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){
danielk1977dae24952004-11-11 05:10:43 +00002139 /* Write the specified cookie value */
2140 static const VdbeOpList setCookie[] = {
2141 { OP_Transaction, 0, 1, 0}, /* 0 */
drh9cbf3422008-01-17 16:22:13 +00002142 { OP_Integer, 0, 1, 0}, /* 1 */
2143 { OP_SetCookie, 0, 0, 1}, /* 2 */
danielk1977dae24952004-11-11 05:10:43 +00002144 };
drh688852a2014-02-17 22:40:43 +00002145 int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
danielk1977dae24952004-11-11 05:10:43 +00002146 sqlite3VdbeChangeP1(v, addr, iDb);
drh60ac3f42010-11-23 18:59:27 +00002147 sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight));
danielk1977dae24952004-11-11 05:10:43 +00002148 sqlite3VdbeChangeP1(v, addr+2, iDb);
2149 sqlite3VdbeChangeP2(v, addr+2, iCookie);
2150 }else{
2151 /* Read the specified cookie value */
2152 static const VdbeOpList readCookie[] = {
danielk1977602b4662009-07-02 07:47:33 +00002153 { OP_Transaction, 0, 0, 0}, /* 0 */
2154 { OP_ReadCookie, 0, 1, 0}, /* 1 */
drh2d401ab2008-01-10 23:50:11 +00002155 { OP_ResultRow, 1, 1, 0}
danielk1977dae24952004-11-11 05:10:43 +00002156 };
drh688852a2014-02-17 22:40:43 +00002157 int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie, 0);
danielk1977dae24952004-11-11 05:10:43 +00002158 sqlite3VdbeChangeP1(v, addr, iDb);
danielk1977602b4662009-07-02 07:47:33 +00002159 sqlite3VdbeChangeP1(v, addr+1, iDb);
2160 sqlite3VdbeChangeP3(v, addr+1, iCookie);
danielk1977dae24952004-11-11 05:10:43 +00002161 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +00002162 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
danielk1977dae24952004-11-11 05:10:43 +00002163 }
drh9ccd8652013-09-13 16:36:46 +00002164 }
2165 break;
drh13d70422004-11-13 15:59:14 +00002166#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
drhc11d4f92003-04-06 21:08:24 +00002167
shanehdc97a8c2010-02-23 20:08:35 +00002168#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
2169 /*
2170 ** PRAGMA compile_options
shanehdc97a8c2010-02-23 20:08:35 +00002171 **
drh71caabf2010-02-26 15:39:24 +00002172 ** Return the names of all compile-time options used in this build,
2173 ** one option per row.
shanehdc97a8c2010-02-23 20:08:35 +00002174 */
drh9ccd8652013-09-13 16:36:46 +00002175 case PragTyp_COMPILE_OPTIONS: {
shanehdc97a8c2010-02-23 20:08:35 +00002176 int i = 0;
2177 const char *zOpt;
2178 sqlite3VdbeSetNumCols(v, 1);
2179 pParse->nMem = 1;
2180 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC);
2181 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
2182 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0);
2183 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
2184 }
drh9ccd8652013-09-13 16:36:46 +00002185 }
2186 break;
shanehdc97a8c2010-02-23 20:08:35 +00002187#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
2188
dan5cf53532010-05-01 16:40:20 +00002189#ifndef SQLITE_OMIT_WAL
2190 /*
danf26a1542014-12-02 19:04:54 +00002191 ** PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate
dan5cf53532010-05-01 16:40:20 +00002192 **
2193 ** Checkpoint the database.
2194 */
drh9ccd8652013-09-13 16:36:46 +00002195 case PragTyp_WAL_CHECKPOINT: {
dana58f26f2010-11-16 18:56:51 +00002196 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
dancdc1f042010-11-18 12:11:05 +00002197 int eMode = SQLITE_CHECKPOINT_PASSIVE;
2198 if( zRight ){
2199 if( sqlite3StrICmp(zRight, "full")==0 ){
2200 eMode = SQLITE_CHECKPOINT_FULL;
2201 }else if( sqlite3StrICmp(zRight, "restart")==0 ){
2202 eMode = SQLITE_CHECKPOINT_RESTART;
danf26a1542014-12-02 19:04:54 +00002203 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
2204 eMode = SQLITE_CHECKPOINT_TRUNCATE;
dancdc1f042010-11-18 12:11:05 +00002205 }
2206 }
dancdc1f042010-11-18 12:11:05 +00002207 sqlite3VdbeSetNumCols(v, 3);
2208 pParse->nMem = 3;
2209 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
2210 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC);
2211 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC);
2212
drh30aa3b92011-02-07 23:56:01 +00002213 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
dancdc1f042010-11-18 12:11:05 +00002214 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
drh9ccd8652013-09-13 16:36:46 +00002215 }
2216 break;
dan5a299f92010-05-03 11:05:08 +00002217
2218 /*
2219 ** PRAGMA wal_autocheckpoint
2220 ** PRAGMA wal_autocheckpoint = N
2221 **
2222 ** Configure a database connection to automatically checkpoint a database
2223 ** after accumulating N frames in the log. Or query for the current value
2224 ** of N.
2225 */
drh9ccd8652013-09-13 16:36:46 +00002226 case PragTyp_WAL_AUTOCHECKPOINT: {
dan5a299f92010-05-03 11:05:08 +00002227 if( zRight ){
drh60ac3f42010-11-23 18:59:27 +00002228 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
dan5a299f92010-05-03 11:05:08 +00002229 }
drhb033d8b2010-05-03 13:37:30 +00002230 returnSingleInt(pParse, "wal_autocheckpoint",
2231 db->xWalCallback==sqlite3WalDefaultHook ?
2232 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
drh9ccd8652013-09-13 16:36:46 +00002233 }
2234 break;
dan5cf53532010-05-01 16:40:20 +00002235#endif
dan7c246102010-04-12 19:00:29 +00002236
drh09419b42011-11-16 19:29:17 +00002237 /*
2238 ** PRAGMA shrink_memory
2239 **
2240 ** This pragma attempts to free as much memory as possible from the
2241 ** current database connection.
2242 */
drh9ccd8652013-09-13 16:36:46 +00002243 case PragTyp_SHRINK_MEMORY: {
drh09419b42011-11-16 19:29:17 +00002244 sqlite3_db_release_memory(db);
drh9ccd8652013-09-13 16:36:46 +00002245 break;
2246 }
drh09419b42011-11-16 19:29:17 +00002247
drhf3603962012-09-07 16:46:59 +00002248 /*
2249 ** PRAGMA busy_timeout
2250 ** PRAGMA busy_timeout = N
2251 **
2252 ** Call sqlite3_busy_timeout(db, N). Return the current timeout value
drhc0c7b5e2012-09-07 18:49:57 +00002253 ** if one is set. If no busy handler or a different busy handler is set
2254 ** then 0 is returned. Setting the busy_timeout to 0 or negative
2255 ** disables the timeout.
drhf3603962012-09-07 16:46:59 +00002256 */
drhd49c3582013-09-13 19:00:06 +00002257 /*case PragTyp_BUSY_TIMEOUT*/ default: {
2258 assert( aPragmaNames[mid].ePragTyp==PragTyp_BUSY_TIMEOUT );
drhf3603962012-09-07 16:46:59 +00002259 if( zRight ){
2260 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
2261 }
2262 returnSingleInt(pParse, "timeout", db->busyTimeout);
drh9ccd8652013-09-13 16:36:46 +00002263 break;
2264 }
drhf3603962012-09-07 16:46:59 +00002265
drh55e85ca2013-09-13 21:01:56 +00002266 /*
2267 ** PRAGMA soft_heap_limit
2268 ** PRAGMA soft_heap_limit = N
2269 **
2270 ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted,
2271 ** use -1.
2272 */
2273 case PragTyp_SOFT_HEAP_LIMIT: {
2274 sqlite3_int64 N;
drh9296c182014-07-23 13:40:49 +00002275 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
drh55e85ca2013-09-13 21:01:56 +00002276 sqlite3_soft_heap_limit64(N);
2277 }
2278 returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
2279 break;
2280 }
2281
drh03459612014-08-25 15:13:22 +00002282 /*
2283 ** PRAGMA threads
2284 ** PRAGMA threads = N
2285 **
2286 ** Configure the maximum number of worker threads. Return the new
2287 ** maximum, which might be less than requested.
2288 */
2289 case PragTyp_THREADS: {
2290 sqlite3_int64 N;
drh111544c2014-08-29 16:20:47 +00002291 if( zRight
drh03459612014-08-25 15:13:22 +00002292 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
2293 && N>=0
2294 ){
drh111544c2014-08-29 16:20:47 +00002295 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
drh03459612014-08-25 15:13:22 +00002296 }
drh111544c2014-08-29 16:20:47 +00002297 returnSingleInt(pParse, "threads",
2298 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
drh03459612014-08-25 15:13:22 +00002299 break;
2300 }
2301
dougcurrie81c95ef2004-06-18 23:21:47 +00002302#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
drh89ac8c12004-06-09 14:17:20 +00002303 /*
2304 ** Report the current state of file logs for all databases
2305 */
drh9ccd8652013-09-13 16:36:46 +00002306 case PragTyp_LOCK_STATUS: {
drh57196282004-10-06 15:41:16 +00002307 static const char *const azLockName[] = {
drh89ac8c12004-06-09 14:17:20 +00002308 "unlocked", "shared", "reserved", "pending", "exclusive"
2309 };
2310 int i;
drh89ac8c12004-06-09 14:17:20 +00002311 sqlite3VdbeSetNumCols(v, 2);
drh2d401ab2008-01-10 23:50:11 +00002312 pParse->nMem = 2;
danielk197710fb7492008-10-31 10:53:22 +00002313 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
2314 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
drh89ac8c12004-06-09 14:17:20 +00002315 for(i=0; i<db->nDb; i++){
2316 Btree *pBt;
drh9e33c2c2007-08-31 18:34:59 +00002317 const char *zState = "unknown";
2318 int j;
drh89ac8c12004-06-09 14:17:20 +00002319 if( db->aDb[i].zName==0 ) continue;
drh2d401ab2008-01-10 23:50:11 +00002320 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
drh89ac8c12004-06-09 14:17:20 +00002321 pBt = db->aDb[i].pBt;
drh5a05be12012-10-09 18:51:44 +00002322 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
drh9e33c2c2007-08-31 18:34:59 +00002323 zState = "closed";
drhc4dd3fd2008-01-22 01:48:05 +00002324 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
drh9e33c2c2007-08-31 18:34:59 +00002325 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
2326 zState = azLockName[j];
drh89ac8c12004-06-09 14:17:20 +00002327 }
drh2d401ab2008-01-10 23:50:11 +00002328 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
2329 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
drh89ac8c12004-06-09 14:17:20 +00002330 }
drh9ccd8652013-09-13 16:36:46 +00002331 break;
2332 }
drh89ac8c12004-06-09 14:17:20 +00002333#endif
2334
shanehad9f9f62010-02-17 17:48:46 +00002335#ifdef SQLITE_HAS_CODEC
drh9ccd8652013-09-13 16:36:46 +00002336 case PragTyp_KEY: {
2337 if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
2338 break;
2339 }
2340 case PragTyp_REKEY: {
2341 if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
2342 break;
2343 }
2344 case PragTyp_HEXKEY: {
2345 if( zRight ){
drh8ab88322013-10-07 00:36:01 +00002346 u8 iByte;
2347 int i;
drh9ccd8652013-09-13 16:36:46 +00002348 char zKey[40];
drh8ab88322013-10-07 00:36:01 +00002349 for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zRight[i]); i++){
2350 iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]);
2351 if( (i&1)!=0 ) zKey[i/2] = iByte;
drh9ccd8652013-09-13 16:36:46 +00002352 }
2353 if( (zLeft[3] & 0xf)==0xb ){
2354 sqlite3_key_v2(db, zDb, zKey, i/2);
2355 }else{
2356 sqlite3_rekey_v2(db, zDb, zKey, i/2);
2357 }
drhd2cb50b2009-01-09 21:41:17 +00002358 }
drh9ccd8652013-09-13 16:36:46 +00002359 break;
2360 }
drh3c4f2a42005-12-08 18:12:56 +00002361#endif
shanehad9f9f62010-02-17 17:48:46 +00002362#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
drh9ccd8652013-09-13 16:36:46 +00002363 case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){
shanehad9f9f62010-02-17 17:48:46 +00002364#ifdef SQLITE_HAS_CODEC
drh21e2cab2006-09-25 18:01:57 +00002365 if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){
drh21e2cab2006-09-25 18:01:57 +00002366 sqlite3_activate_see(&zRight[4]);
2367 }
2368#endif
2369#ifdef SQLITE_ENABLE_CEROD
2370 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
drh21e2cab2006-09-25 18:01:57 +00002371 sqlite3_activate_cerod(&zRight[6]);
2372 }
2373#endif
drh9ccd8652013-09-13 16:36:46 +00002374 }
2375 break;
drh21e2cab2006-09-25 18:01:57 +00002376#endif
drh3c4f2a42005-12-08 18:12:56 +00002377
drh9ccd8652013-09-13 16:36:46 +00002378 } /* End of the PRAGMA switch */
danielk1977a21c6b62005-01-24 10:25:59 +00002379
danielk1977e0048402004-06-15 16:51:01 +00002380pragma_out:
drh633e6d52008-07-28 19:34:53 +00002381 sqlite3DbFree(db, zLeft);
2382 sqlite3DbFree(db, zRight);
drhc11d4f92003-04-06 21:08:24 +00002383}
drh13d70422004-11-13 15:59:14 +00002384
drh8bfdf722009-06-19 14:06:03 +00002385#endif /* SQLITE_OMIT_PRAGMA */