monotone

monotone Mtn Source Tree

Root/sqlite/pragma.c

1/*
2** 2003 April 6
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12** This file contains code used to implement the PRAGMA command.
13**
14** $Id: pragma.c,v 1.139 2007/05/23 13:50:24 danielk1977 Exp $
15*/
16#include "sqliteInt.h"
17#include "os.h"
18#include <ctype.h>
19
20/* Ignore this whole file if pragmas are disabled
21*/
22#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
23
24#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
25# include "pager.h"
26# include "btree.h"
27#endif
28
29/*
30** Interpret the given string as a safety level. Return 0 for OFF,
31** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
32** unrecognized string argument.
33**
34** Note that the values returned are one less that the values that
35** should be passed into sqlite3BtreeSetSafetyLevel(). The is done
36** to support legacy SQL code. The safety level used to be boolean
37** and older scripts may have used numbers 0 for OFF and 1 for ON.
38*/
39static int getSafetyLevel(const char *z){
40 /* 123456789 123456789 */
41 static const char zText[] = "onoffalseyestruefull";
42 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
43 static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
44 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2};
45 int i, n;
46 if( isdigit(*z) ){
47 return atoi(z);
48 }
49 n = strlen(z);
50 for(i=0; i<sizeof(iLength); i++){
51 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
52 return iValue[i];
53 }
54 }
55 return 1;
56}
57
58/*
59** Interpret the given string as a boolean value.
60*/
61static int getBoolean(const char *z){
62 return getSafetyLevel(z)&1;
63}
64
65/*
66** Interpret the given string as a locking mode value.
67*/
68static int getLockingMode(const char *z){
69 if( z ){
70 if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE;
71 if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL;
72 }
73 return PAGER_LOCKINGMODE_QUERY;
74}
75
76#ifndef SQLITE_OMIT_AUTOVACUUM
77/*
78** Interpret the given string as an auto-vacuum mode value.
79**
80** The following strings, "none", "full" and "incremental" are
81** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
82*/
83static int getAutoVacuum(const char *z){
84 int i;
85 if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE;
86 if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL;
87 if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR;
88 i = atoi(z);
89 return ((i>=0&&i<=2)?i:0);
90}
91#endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
92
93#ifndef SQLITE_OMIT_PAGER_PRAGMAS
94/*
95** Interpret the given string as a temp db location. Return 1 for file
96** backed temporary databases, 2 for the Red-Black tree in memory database
97** and 0 to use the compile-time default.
98*/
99static int getTempStore(const char *z){
100 if( z[0]>='0' && z[0]<='2' ){
101 return z[0] - '0';
102 }else if( sqlite3StrICmp(z, "file")==0 ){
103 return 1;
104 }else if( sqlite3StrICmp(z, "memory")==0 ){
105 return 2;
106 }else{
107 return 0;
108 }
109}
110#endif /* SQLITE_PAGER_PRAGMAS */
111
112#ifndef SQLITE_OMIT_PAGER_PRAGMAS
113/*
114** Invalidate temp storage, either when the temp storage is changed
115** from default, or when 'file' and the temp_store_directory has changed
116*/
117static int invalidateTempStorage(Parse *pParse){
118 sqlite3 *db = pParse->db;
119 if( db->aDb[1].pBt!=0 ){
120 if( !db->autoCommit ){
121 sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
122 "from within a transaction");
123 return SQLITE_ERROR;
124 }
125 sqlite3BtreeClose(db->aDb[1].pBt);
126 db->aDb[1].pBt = 0;
127 sqlite3ResetInternalSchema(db, 0);
128 }
129 return SQLITE_OK;
130}
131#endif /* SQLITE_PAGER_PRAGMAS */
132
133#ifndef SQLITE_OMIT_PAGER_PRAGMAS
134/*
135** If the TEMP database is open, close it and mark the database schema
136** as needing reloading. This must be done when using the TEMP_STORE
137** or DEFAULT_TEMP_STORE pragmas.
138*/
139static int changeTempStorage(Parse *pParse, const char *zStorageType){
140 int ts = getTempStore(zStorageType);
141 sqlite3 *db = pParse->db;
142 if( db->temp_store==ts ) return SQLITE_OK;
143 if( invalidateTempStorage( pParse ) != SQLITE_OK ){
144 return SQLITE_ERROR;
145 }
146 db->temp_store = ts;
147 return SQLITE_OK;
148}
149#endif /* SQLITE_PAGER_PRAGMAS */
150
151/*
152** Generate code to return a single integer value.
153*/
154static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
155 Vdbe *v = sqlite3GetVdbe(pParse);
156 sqlite3VdbeAddOp(v, OP_Integer, value, 0);
157 if( pParse->explain==0 ){
158 sqlite3VdbeSetNumCols(v, 1);
159 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P3_STATIC);
160 }
161 sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
162}
163
164#ifndef SQLITE_OMIT_FLAG_PRAGMAS
165/*
166** Check to see if zRight and zLeft refer to a pragma that queries
167** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
168** Also, implement the pragma.
169*/
170static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
171 static const struct sPragmaType {
172 const char *zName; /* Name of the pragma */
173 int mask; /* Mask for the db->flags value */
174 } aPragma[] = {
175 { "full_column_names", SQLITE_FullColNames },
176 { "short_column_names", SQLITE_ShortColNames },
177 { "count_changes", SQLITE_CountRows },
178 { "empty_result_callbacks", SQLITE_NullCallback },
179 { "legacy_file_format", SQLITE_LegacyFileFmt },
180 { "fullfsync", SQLITE_FullFSync },
181#ifdef SQLITE_DEBUG
182 { "sql_trace", SQLITE_SqlTrace },
183 { "vdbe_listing", SQLITE_VdbeListing },
184 { "vdbe_trace", SQLITE_VdbeTrace },
185#endif
186#ifndef SQLITE_OMIT_CHECK
187 { "ignore_check_constraints", SQLITE_IgnoreChecks },
188#endif
189 /* The following is VERY experimental */
190 { "writable_schema", SQLITE_WriteSchema|SQLITE_RecoveryMode },
191 { "omit_readlock", SQLITE_NoReadlock },
192
193 /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
194 ** flag if there are any active statements. */
195 { "read_uncommitted", SQLITE_ReadUncommitted },
196 };
197 int i;
198 const struct sPragmaType *p;
199 for(i=0, p=aPragma; i<sizeof(aPragma)/sizeof(aPragma[0]); i++, p++){
200 if( sqlite3StrICmp(zLeft, p->zName)==0 ){
201 sqlite3 *db = pParse->db;
202 Vdbe *v;
203 v = sqlite3GetVdbe(pParse);
204 if( v ){
205 if( zRight==0 ){
206 returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
207 }else{
208 if( getBoolean(zRight) ){
209 db->flags |= p->mask;
210 }else{
211 db->flags &= ~p->mask;
212 }
213 }
214 }
215 return 1;
216 }
217 }
218 return 0;
219}
220#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
221
222/*
223** Process a pragma statement.
224**
225** Pragmas are of this form:
226**
227** PRAGMA [database.]id [= value]
228**
229** The identifier might also be a string. The value is a string, and
230** identifier, or a number. If minusFlag is true, then the value is
231** a number that was preceded by a minus sign.
232**
233** If the left side is "database.id" then pId1 is the database name
234** and pId2 is the id. If the left side is just "id" then pId1 is the
235** id and pId2 is any empty string.
236*/
237void sqlite3Pragma(
238 Parse *pParse,
239 Token *pId1, /* First part of [database.]id field */
240 Token *pId2, /* Second part of [database.]id field, or NULL */
241 Token *pValue, /* Token for <value>, or NULL */
242 int minusFlag /* True if a '-' sign preceded <value> */
243){
244 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
245 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
246 const char *zDb = 0; /* The database name */
247 Token *pId; /* Pointer to <id> token */
248 int iDb; /* Database index for <database> */
249 sqlite3 *db = pParse->db;
250 Db *pDb;
251 Vdbe *v = sqlite3GetVdbe(pParse);
252 if( v==0 ) return;
253
254 /* Interpret the [database.] part of the pragma statement. iDb is the
255 ** index of the database this pragma is being applied to in db.aDb[]. */
256 iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId);
257 if( iDb<0 ) return;
258 pDb = &db->aDb[iDb];
259
260 /* If the temp database has been explicitly named as part of the
261 ** pragma, make sure it is open.
262 */
263 if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){
264 return;
265 }
266
267 zLeft = sqlite3NameFromToken(pId);
268 if( !zLeft ) return;
269 if( minusFlag ){
270 zRight = sqlite3MPrintf("-%T", pValue);
271 }else{
272 zRight = sqlite3NameFromToken(pValue);
273 }
274
275 zDb = ((iDb>0)?pDb->zName:0);
276 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
277 goto pragma_out;
278 }
279
280#ifndef SQLITE_OMIT_PAGER_PRAGMAS
281 /*
282 ** PRAGMA [database.]default_cache_size
283 ** PRAGMA [database.]default_cache_size=N
284 **
285 ** The first form reports the current persistent setting for the
286 ** page cache size. The value returned is the maximum number of
287 ** pages in the page cache. The second form sets both the current
288 ** page cache size value and the persistent page cache size value
289 ** stored in the database file.
290 **
291 ** The default cache size is stored in meta-value 2 of page 1 of the
292 ** database file. The cache size is actually the absolute value of
293 ** this memory location. The sign of meta-value 2 determines the
294 ** synchronous setting. A negative value means synchronous is off
295 ** and a positive value means synchronous is on.
296 */
297 if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
298 static const VdbeOpList getCacheSize[] = {
299 { OP_ReadCookie, 0, 2, 0}, /* 0 */
300 { OP_AbsValue, 0, 0, 0},
301 { OP_Dup, 0, 0, 0},
302 { OP_Integer, 0, 0, 0},
303 { OP_Ne, 0, 6, 0},
304 { OP_Integer, 0, 0, 0}, /* 5 */
305 { OP_Callback, 1, 0, 0},
306 };
307 int addr;
308 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
309 if( !zRight ){
310 sqlite3VdbeSetNumCols(v, 1);
311 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", P3_STATIC);
312 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
313 sqlite3VdbeChangeP1(v, addr, iDb);
314 sqlite3VdbeChangeP1(v, addr+5, SQLITE_DEFAULT_CACHE_SIZE);
315 }else{
316 int size = atoi(zRight);
317 if( size<0 ) size = -size;
318 sqlite3BeginWriteOperation(pParse, 0, iDb);
319 sqlite3VdbeAddOp(v, OP_Integer, size, 0);
320 sqlite3VdbeAddOp(v, OP_ReadCookie, iDb, 2);
321 addr = sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
322 sqlite3VdbeAddOp(v, OP_Ge, 0, addr+3);
323 sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
324 sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 2);
325 pDb->pSchema->cache_size = size;
326 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
327 }
328 }else
329
330 /*
331 ** PRAGMA [database.]page_size
332 ** PRAGMA [database.]page_size=N
333 **
334 ** The first form reports the current setting for the
335 ** database page size in bytes. The second form sets the
336 ** database page size value. The value can only be set if
337 ** the database has not yet been created.
338 */
339 if( sqlite3StrICmp(zLeft,"page_size")==0 ){
340 Btree *pBt = pDb->pBt;
341 if( !zRight ){
342 int size = pBt ? sqlite3BtreeGetPageSize(pBt) : 0;
343 returnSingleInt(pParse, "page_size", size);
344 }else{
345 sqlite3BtreeSetPageSize(pBt, atoi(zRight), -1);
346 }
347 }else
348
349 /*
350 ** PRAGMA [database.]max_page_count
351 ** PRAGMA [database.]max_page_count=N
352 **
353 ** The first form reports the current setting for the
354 ** maximum number of pages in the database file. The
355 ** second form attempts to change this setting. Both
356 ** forms return the current setting.
357 */
358 if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
359 Btree *pBt = pDb->pBt;
360 int newMax = 0;
361 if( zRight ){
362 newMax = atoi(zRight);
363 }
364 if( pBt ){
365 newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
366 }
367 returnSingleInt(pParse, "max_page_count", newMax);
368 }else
369
370 /*
371 ** PRAGMA [database.]locking_mode
372 ** PRAGMA [database.]locking_mode = (normal|exclusive)
373 */
374 if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){
375 const char *zRet = "normal";
376 int eMode = getLockingMode(zRight);
377
378 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
379 /* Simple "PRAGMA locking_mode;" statement. This is a query for
380 ** the current default locking mode (which may be different to
381 ** the locking-mode of the main database).
382 */
383 eMode = db->dfltLockMode;
384 }else{
385 Pager *pPager;
386 if( pId2->n==0 ){
387 /* This indicates that no database name was specified as part
388 ** of the PRAGMA command. In this case the locking-mode must be
389 ** set on all attached databases, as well as the main db file.
390 **
391 ** Also, the sqlite3.dfltLockMode variable is set so that
392 ** any subsequently attached databases also use the specified
393 ** locking mode.
394 */
395 int ii;
396 assert(pDb==&db->aDb[0]);
397 for(ii=2; ii<db->nDb; ii++){
398 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
399 sqlite3PagerLockingMode(pPager, eMode);
400 }
401 db->dfltLockMode = eMode;
402 }
403 pPager = sqlite3BtreePager(pDb->pBt);
404 eMode = sqlite3PagerLockingMode(pPager, eMode);
405 }
406
407 assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE);
408 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
409 zRet = "exclusive";
410 }
411 sqlite3VdbeSetNumCols(v, 1);
412 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", P3_STATIC);
413 sqlite3VdbeOp3(v, OP_String8, 0, 0, zRet, 0);
414 sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
415 }else
416#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
417
418 /*
419 ** PRAGMA [database.]auto_vacuum
420 ** PRAGMA [database.]auto_vacuum=N
421 **
422 ** Get or set the (boolean) value of the database 'auto-vacuum' parameter.
423 */
424#ifndef SQLITE_OMIT_AUTOVACUUM
425 if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
426 Btree *pBt = pDb->pBt;
427 if( !zRight ){
428 int auto_vacuum =
429 pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM;
430 returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
431 }else{
432 int eAuto = getAutoVacuum(zRight);
433 if( eAuto>=0 ){
434 sqlite3BtreeSetAutoVacuum(pBt, eAuto);
435 }
436 }
437 }else
438#endif
439
440 /*
441 ** PRAGMA [database.]incremental_vacuum(N)
442 **
443 ** Do N steps of incremental vacuuming on a database.
444 */
445#ifndef SQLITE_OMIT_AUTOVACUUM
446 if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){
447 int iLimit, addr;
448 if( sqlite3ReadSchema(pParse) ){
449 goto pragma_out;
450 }
451 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
452 iLimit = 0x7fffffff;
453 }
454 sqlite3BeginWriteOperation(pParse, 0, iDb);
455 sqlite3VdbeAddOp(v, OP_MemInt, iLimit, 0);
456 addr = sqlite3VdbeAddOp(v, OP_IncrVacuum, iDb, 0);
457 sqlite3VdbeAddOp(v, OP_Callback, 0, 0);
458 sqlite3VdbeAddOp(v, OP_MemIncr, -1, 0);
459 sqlite3VdbeAddOp(v, OP_IfMemPos, 0, addr);
460 sqlite3VdbeJumpHere(v, addr);
461 }else
462#endif
463
464#ifndef SQLITE_OMIT_PAGER_PRAGMAS
465 /*
466 ** PRAGMA [database.]cache_size
467 ** PRAGMA [database.]cache_size=N
468 **
469 ** The first form reports the current local setting for the
470 ** page cache size. The local setting can be different from
471 ** the persistent cache size value that is stored in the database
472 ** file itself. The value returned is the maximum number of
473 ** pages in the page cache. The second form sets the local
474 ** page cache size value. It does not change the persistent
475 ** cache size stored on the disk so the cache size will revert
476 ** to its default value when the database is closed and reopened.
477 ** N should be a positive integer.
478 */
479 if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
480 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
481 if( !zRight ){
482 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
483 }else{
484 int size = atoi(zRight);
485 if( size<0 ) size = -size;
486 pDb->pSchema->cache_size = size;
487 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
488 }
489 }else
490
491 /*
492 ** PRAGMA temp_store
493 ** PRAGMA temp_store = "default"|"memory"|"file"
494 **
495 ** Return or set the local value of the temp_store flag. Changing
496 ** the local value does not make changes to the disk file and the default
497 ** value will be restored the next time the database is opened.
498 **
499 ** Note that it is possible for the library compile-time options to
500 ** override this setting
501 */
502 if( sqlite3StrICmp(zLeft, "temp_store")==0 ){
503 if( !zRight ){
504 returnSingleInt(pParse, "temp_store", db->temp_store);
505 }else{
506 changeTempStorage(pParse, zRight);
507 }
508 }else
509
510 /*
511 ** PRAGMA temp_store_directory
512 ** PRAGMA temp_store_directory = ""|"directory_name"
513 **
514 ** Return or set the local value of the temp_store_directory flag. Changing
515 ** the value sets a specific directory to be used for temporary files.
516 ** Setting to a null string reverts to the default temporary directory search.
517 ** If temporary directory is changed, then invalidateTempStorage.
518 **
519 */
520 if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
521 if( !zRight ){
522 if( sqlite3_temp_directory ){
523 sqlite3VdbeSetNumCols(v, 1);
524 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
525 "temp_store_directory", P3_STATIC);
526 sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);
527 sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
528 }
529 }else{
530 if( zRight[0] && !sqlite3OsIsDirWritable(zRight) ){
531 sqlite3ErrorMsg(pParse, "not a writable directory");
532 goto pragma_out;
533 }
534 if( TEMP_STORE==0
535 || (TEMP_STORE==1 && db->temp_store<=1)
536 || (TEMP_STORE==2 && db->temp_store==1)
537 ){
538 invalidateTempStorage(pParse);
539 }
540 sqliteFree(sqlite3_temp_directory);
541 if( zRight[0] ){
542 sqlite3_temp_directory = zRight;
543 zRight = 0;
544 }else{
545 sqlite3_temp_directory = 0;
546 }
547 }
548 }else
549
550 /*
551 ** PRAGMA [database.]synchronous
552 ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
553 **
554 ** Return or set the local value of the synchronous flag. Changing
555 ** the local value does not make changes to the disk file and the
556 ** default value will be restored the next time the database is
557 ** opened.
558 */
559 if( sqlite3StrICmp(zLeft,"synchronous")==0 ){
560 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
561 if( !zRight ){
562 returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
563 }else{
564 if( !db->autoCommit ){
565 sqlite3ErrorMsg(pParse,
566 "Safety level may not be changed inside a transaction");
567 }else{
568 pDb->safety_level = getSafetyLevel(zRight)+1;
569 }
570 }
571 }else
572#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
573
574#ifndef SQLITE_OMIT_FLAG_PRAGMAS
575 if( flagPragma(pParse, zLeft, zRight) ){
576 /* The flagPragma() subroutine also generates any necessary code
577 ** there is nothing more to do here */
578 }else
579#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
580
581#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
582 /*
583 ** PRAGMA table_info(<table>)
584 **
585 ** Return a single row for each column of the named table. The columns of
586 ** the returned data set are:
587 **
588 ** cid: Column id (numbered from left to right, starting at 0)
589 ** name: Column name
590 ** type: Column declaration type.
591 ** notnull: True if 'NOT NULL' is part of column declaration
592 ** dflt_value: The default value for the column, if any.
593 */
594 if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
595 Table *pTab;
596 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
597 pTab = sqlite3FindTable(db, zRight, zDb);
598 if( pTab ){
599 int i;
600 Column *pCol;
601 sqlite3VdbeSetNumCols(v, 6);
602 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P3_STATIC);
603 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
604 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P3_STATIC);
605 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P3_STATIC);
606 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P3_STATIC);
607 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P3_STATIC);
608 sqlite3ViewGetColumnNames(pParse, pTab);
609 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
610 const Token *pDflt;
611 sqlite3VdbeAddOp(v, OP_Integer, i, 0);
612 sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zName, 0);
613 sqlite3VdbeOp3(v, OP_String8, 0, 0,
614 pCol->zType ? pCol->zType : "", 0);
615 sqlite3VdbeAddOp(v, OP_Integer, pCol->notNull, 0);
616 if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){
617 sqlite3VdbeOp3(v, OP_String8, 0, 0, (char*)pDflt->z, pDflt->n);
618 }else{
619 sqlite3VdbeAddOp(v, OP_Null, 0, 0);
620 }
621 sqlite3VdbeAddOp(v, OP_Integer, pCol->isPrimKey, 0);
622 sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
623 }
624 }
625 }else
626
627 if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
628 Index *pIdx;
629 Table *pTab;
630 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
631 pIdx = sqlite3FindIndex(db, zRight, zDb);
632 if( pIdx ){
633 int i;
634 pTab = pIdx->pTable;
635 sqlite3VdbeSetNumCols(v, 3);
636 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P3_STATIC);
637 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P3_STATIC);
638 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P3_STATIC);
639 for(i=0; i<pIdx->nColumn; i++){
640 int cnum = pIdx->aiColumn[i];
641 sqlite3VdbeAddOp(v, OP_Integer, i, 0);
642 sqlite3VdbeAddOp(v, OP_Integer, cnum, 0);
643 assert( pTab->nCol>cnum );
644 sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[cnum].zName, 0);
645 sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
646 }
647 }
648 }else
649
650 if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){
651 Index *pIdx;
652 Table *pTab;
653 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
654 pTab = sqlite3FindTable(db, zRight, zDb);
655 if( pTab ){
656 v = sqlite3GetVdbe(pParse);
657 pIdx = pTab->pIndex;
658 if( pIdx ){
659 int i = 0;
660 sqlite3VdbeSetNumCols(v, 3);
661 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
662 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
663 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P3_STATIC);
664 while(pIdx){
665 sqlite3VdbeAddOp(v, OP_Integer, i, 0);
666 sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
667 sqlite3VdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
668 sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
669 ++i;
670 pIdx = pIdx->pNext;
671 }
672 }
673 }
674 }else
675
676 if( sqlite3StrICmp(zLeft, "database_list")==0 ){
677 int i;
678 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
679 sqlite3VdbeSetNumCols(v, 3);
680 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
681 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
682 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P3_STATIC);
683 for(i=0; i<db->nDb; i++){
684 if( db->aDb[i].pBt==0 ) continue;
685 assert( db->aDb[i].zName!=0 );
686 sqlite3VdbeAddOp(v, OP_Integer, i, 0);
687 sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, 0);
688 sqlite3VdbeOp3(v, OP_String8, 0, 0,
689 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
690 sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
691 }
692 }else
693
694 if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
695 int i = 0;
696 HashElem *p;
697 sqlite3VdbeSetNumCols(v, 2);
698 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
699 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
700 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
701 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
702 sqlite3VdbeAddOp(v, OP_Integer, i++, 0);
703 sqlite3VdbeOp3(v, OP_String8, 0, 0, pColl->zName, 0);
704 sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
705 }
706 }else
707#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
708
709#ifndef SQLITE_OMIT_FOREIGN_KEY
710 if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
711 FKey *pFK;
712 Table *pTab;
713 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
714 pTab = sqlite3FindTable(db, zRight, zDb);
715 if( pTab ){
716 v = sqlite3GetVdbe(pParse);
717 pFK = pTab->pFKey;
718 if( pFK ){
719 int i = 0;
720 sqlite3VdbeSetNumCols(v, 5);
721 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P3_STATIC);
722 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P3_STATIC);
723 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P3_STATIC);
724 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P3_STATIC);
725 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P3_STATIC);
726 while(pFK){
727 int j;
728 for(j=0; j<pFK->nCol; j++){
729 char *zCol = pFK->aCol[j].zCol;
730 sqlite3VdbeAddOp(v, OP_Integer, i, 0);
731 sqlite3VdbeAddOp(v, OP_Integer, j, 0);
732 sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);
733 sqlite3VdbeOp3(v, OP_String8, 0, 0,
734 pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
735 sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0);
736 sqlite3VdbeAddOp(v, OP_Callback, 5, 0);
737 }
738 ++i;
739 pFK = pFK->pNextFrom;
740 }
741 }
742 }
743 }else
744#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
745
746#ifndef NDEBUG
747 if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
748 if( zRight ){
749 if( getBoolean(zRight) ){
750 sqlite3ParserTrace(stderr, "parser: ");
751 }else{
752 sqlite3ParserTrace(0, 0);
753 }
754 }
755 }else
756#endif
757
758 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
759 ** used will be case sensitive or not depending on the RHS.
760 */
761 if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
762 if( zRight ){
763 sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
764 }
765 }else
766
767#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
768# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
769#endif
770
771#ifndef SQLITE_OMIT_INTEGRITY_CHECK
772 if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){
773 int i, j, addr, mxErr;
774
775 /* Code that appears at the end of the integrity check. If no error
776 ** messages have been generated, output OK. Otherwise output the
777 ** error message
778 */
779 static const VdbeOpList endCode[] = {
780 { OP_MemLoad, 0, 0, 0},
781 { OP_Integer, 0, 0, 0},
782 { OP_Ne, 0, 0, 0}, /* 2 */
783 { OP_String8, 0, 0, "ok"},
784 { OP_Callback, 1, 0, 0},
785 };
786
787 /* Initialize the VDBE program */
788 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
789 sqlite3VdbeSetNumCols(v, 1);
790 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", P3_STATIC);
791
792 /* Set the maximum error count */
793 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
794 if( zRight ){
795 mxErr = atoi(zRight);
796 if( mxErr<=0 ){
797 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
798 }
799 }
800 sqlite3VdbeAddOp(v, OP_MemInt, mxErr, 0);
801
802 /* Do an integrity check on each database file */
803 for(i=0; i<db->nDb; i++){
804 HashElem *x;
805 Hash *pTbls;
806 int cnt = 0;
807
808 if( OMIT_TEMPDB && i==1 ) continue;
809
810 sqlite3CodeVerifySchema(pParse, i);
811 addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0);
812 sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
813 sqlite3VdbeJumpHere(v, addr);
814
815 /* Do an integrity check of the B-Tree
816 */
817 pTbls = &db->aDb[i].pSchema->tblHash;
818 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
819 Table *pTab = sqliteHashData(x);
820 Index *pIdx;
821 sqlite3VdbeAddOp(v, OP_Integer, pTab->tnum, 0);
822 cnt++;
823 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
824 sqlite3VdbeAddOp(v, OP_Integer, pIdx->tnum, 0);
825 cnt++;
826 }
827 }
828 if( cnt==0 ) continue;
829 sqlite3VdbeAddOp(v, OP_IntegrityCk, 0, i);
830 addr = sqlite3VdbeAddOp(v, OP_IsNull, -1, 0);
831 sqlite3VdbeOp3(v, OP_String8, 0, 0,
832 sqlite3MPrintf("*** in database %s ***\n", db->aDb[i].zName),
833 P3_DYNAMIC);
834 sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
835 sqlite3VdbeAddOp(v, OP_Concat, 0, 0);
836 sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
837 sqlite3VdbeJumpHere(v, addr);
838
839 /* Make sure all the indices are constructed correctly.
840 */
841 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
842 Table *pTab = sqliteHashData(x);
843 Index *pIdx;
844 int loopTop;
845
846 if( pTab->pIndex==0 ) continue;
847 addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0);
848 sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
849 sqlite3VdbeJumpHere(v, addr);
850 sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
851 sqlite3VdbeAddOp(v, OP_MemInt, 0, 1);
852 loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
853 sqlite3VdbeAddOp(v, OP_MemIncr, 1, 1);
854 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
855 int jmp2;
856 static const VdbeOpList idxErr[] = {
857 { OP_MemIncr, -1, 0, 0},
858 { OP_String8, 0, 0, "rowid "},
859 { OP_Rowid, 1, 0, 0},
860 { OP_String8, 0, 0, " missing from index "},
861 { OP_String8, 0, 0, 0}, /* 4 */
862 { OP_Concat, 2, 0, 0},
863 { OP_Callback, 1, 0, 0},
864 };
865 sqlite3GenerateIndexKey(v, pIdx, 1);
866 jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0);
867 addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
868 sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
869 sqlite3VdbeJumpHere(v, jmp2);
870 }
871 sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1);
872 sqlite3VdbeJumpHere(v, loopTop);
873 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
874 static const VdbeOpList cntIdx[] = {
875 { OP_MemInt, 0, 2, 0},
876 { OP_Rewind, 0, 0, 0}, /* 1 */
877 { OP_MemIncr, 1, 2, 0},
878 { OP_Next, 0, 0, 0}, /* 3 */
879 { OP_MemLoad, 1, 0, 0},
880 { OP_MemLoad, 2, 0, 0},
881 { OP_Eq, 0, 0, 0}, /* 6 */
882 { OP_MemIncr, -1, 0, 0},
883 { OP_String8, 0, 0, "wrong # of entries in index "},
884 { OP_String8, 0, 0, 0}, /* 9 */
885 { OP_Concat, 0, 0, 0},
886 { OP_Callback, 1, 0, 0},
887 };
888 if( pIdx->tnum==0 ) continue;
889 addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0);
890 sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
891 sqlite3VdbeJumpHere(v, addr);
892 addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
893 sqlite3VdbeChangeP1(v, addr+1, j+2);
894 sqlite3VdbeChangeP2(v, addr+1, addr+4);
895 sqlite3VdbeChangeP1(v, addr+3, j+2);
896 sqlite3VdbeChangeP2(v, addr+3, addr+2);
897 sqlite3VdbeJumpHere(v, addr+6);
898 sqlite3VdbeChangeP3(v, addr+9, pIdx->zName, P3_STATIC);
899 }
900 }
901 }
902 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
903 sqlite3VdbeChangeP1(v, addr+1, mxErr);
904 sqlite3VdbeJumpHere(v, addr+2);
905 }else
906#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
907
908#ifndef SQLITE_OMIT_UTF16
909 /*
910 ** PRAGMA encoding
911 ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
912 **
913 ** In it's first form, this pragma returns the encoding of the main
914 ** database. If the database is not initialized, it is initialized now.
915 **
916 ** The second form of this pragma is a no-op if the main database file
917 ** has not already been initialized. In this case it sets the default
918 ** encoding that will be used for the main database file if a new file
919 ** is created. If an existing main database file is opened, then the
920 ** default text encoding for the existing database is used.
921 **
922 ** In all cases new databases created using the ATTACH command are
923 ** created to use the same default text encoding as the main database. If
924 ** the main database has not been initialized and/or created when ATTACH
925 ** is executed, this is done before the ATTACH operation.
926 **
927 ** In the second form this pragma sets the text encoding to be used in
928 ** new database files created using this database handle. It is only
929 ** useful if invoked immediately after the main database i
930 */
931 if( sqlite3StrICmp(zLeft, "encoding")==0 ){
932 static const struct EncName {
933 char *zName;
934 u8 enc;
935 } encnames[] = {
936 { "UTF-8", SQLITE_UTF8 },
937 { "UTF8", SQLITE_UTF8 },
938 { "UTF-16le", SQLITE_UTF16LE },
939 { "UTF16le", SQLITE_UTF16LE },
940 { "UTF-16be", SQLITE_UTF16BE },
941 { "UTF16be", SQLITE_UTF16BE },
942 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
943 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
944 { 0, 0 }
945 };
946 const struct EncName *pEnc;
947 if( !zRight ){ /* "PRAGMA encoding" */
948 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
949 sqlite3VdbeSetNumCols(v, 1);
950 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", P3_STATIC);
951 sqlite3VdbeAddOp(v, OP_String8, 0, 0);
952 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
953 if( pEnc->enc==ENC(pParse->db) ){
954 sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC);
955 break;
956 }
957 }
958 sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
959 }else{ /* "PRAGMA encoding = XXX" */
960 /* Only change the value of sqlite.enc if the database handle is not
961 ** initialized. If the main database exists, the new sqlite.enc value
962 ** will be overwritten when the schema is next loaded. If it does not
963 ** already exists, it will be created to use the new encoding value.
964 */
965 if(
966 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
967 DbHasProperty(db, 0, DB_Empty)
968 ){
969 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
970 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
971 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
972 break;
973 }
974 }
975 if( !pEnc->zName ){
976 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
977 }
978 }
979 }
980 }else
981#endif /* SQLITE_OMIT_UTF16 */
982
983#ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
984 /*
985 ** PRAGMA [database.]schema_version
986 ** PRAGMA [database.]schema_version = <integer>
987 **
988 ** PRAGMA [database.]user_version
989 ** PRAGMA [database.]user_version = <integer>
990 **
991 ** The pragma's schema_version and user_version are used to set or get
992 ** the value of the schema-version and user-version, respectively. Both
993 ** the schema-version and the user-version are 32-bit signed integers
994 ** stored in the database header.
995 **
996 ** The schema-cookie is usually only manipulated internally by SQLite. It
997 ** is incremented by SQLite whenever the database schema is modified (by
998 ** creating or dropping a table or index). The schema version is used by
999 ** SQLite each time a query is executed to ensure that the internal cache
1000 ** of the schema used when compiling the SQL query matches the schema of
1001 ** the database against which the compiled query is actually executed.
1002 ** Subverting this mechanism by using "PRAGMA schema_version" to modify
1003 ** the schema-version is potentially dangerous and may lead to program
1004 ** crashes or database corruption. Use with caution!
1005 **
1006 ** The user-version is not used internally by SQLite. It may be used by
1007 ** applications for any purpose.
1008 */
1009 if( sqlite3StrICmp(zLeft, "schema_version")==0 ||
1010 sqlite3StrICmp(zLeft, "user_version")==0 ){
1011
1012 int iCookie; /* Cookie index. 0 for schema-cookie, 6 for user-cookie. */
1013 if( zLeft[0]=='s' || zLeft[0]=='S' ){
1014 iCookie = 0;
1015 }else{
1016 iCookie = 5;
1017 }
1018
1019 if( zRight ){
1020 /* Write the specified cookie value */
1021 static const VdbeOpList setCookie[] = {
1022 { OP_Transaction, 0, 1, 0}, /* 0 */
1023 { OP_Integer, 0, 0, 0}, /* 1 */
1024 { OP_SetCookie, 0, 0, 0}, /* 2 */
1025 };
1026 int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
1027 sqlite3VdbeChangeP1(v, addr, iDb);
1028 sqlite3VdbeChangeP1(v, addr+1, atoi(zRight));
1029 sqlite3VdbeChangeP1(v, addr+2, iDb);
1030 sqlite3VdbeChangeP2(v, addr+2, iCookie);
1031 }else{
1032 /* Read the specified cookie value */
1033 static const VdbeOpList readCookie[] = {
1034 { OP_ReadCookie, 0, 0, 0}, /* 0 */
1035 { OP_Callback, 1, 0, 0}
1036 };
1037 int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
1038 sqlite3VdbeChangeP1(v, addr, iDb);
1039 sqlite3VdbeChangeP2(v, addr, iCookie);
1040 sqlite3VdbeSetNumCols(v, 1);
1041 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, P3_TRANSIENT);
1042 }
1043 }else
1044#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
1045
1046#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
1047 /*
1048 ** Report the current state of file logs for all databases
1049 */
1050 if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
1051 static const char *const azLockName[] = {
1052 "unlocked", "shared", "reserved", "pending", "exclusive"
1053 };
1054 int i;
1055 Vdbe *v = sqlite3GetVdbe(pParse);
1056 sqlite3VdbeSetNumCols(v, 2);
1057 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P3_STATIC);
1058 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", P3_STATIC);
1059 for(i=0; i<db->nDb; i++){
1060 Btree *pBt;
1061 Pager *pPager;
1062 if( db->aDb[i].zName==0 ) continue;
1063 sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC);
1064 pBt = db->aDb[i].pBt;
1065 if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
1066 sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC);
1067 }else{
1068 int j = sqlite3PagerLockstate(pPager);
1069 sqlite3VdbeOp3(v, OP_String8, 0, 0,
1070 (j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC);
1071 }
1072 sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
1073 }
1074 }else
1075#endif
1076
1077#ifdef SQLITE_SSE
1078 /*
1079 ** Check to see if the sqlite_statements table exists. Create it
1080 ** if it does not.
1081 */
1082 if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){
1083 extern int sqlite3CreateStatementsTable(Parse*);
1084 sqlite3CreateStatementsTable(pParse);
1085 }else
1086#endif
1087
1088#if SQLITE_HAS_CODEC
1089 if( sqlite3StrICmp(zLeft, "key")==0 ){
1090 sqlite3_key(db, zRight, strlen(zRight));
1091 }else
1092#endif
1093#if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD)
1094 if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){
1095#if SQLITE_HAS_CODEC
1096 if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){
1097 extern void sqlite3_activate_see(const char*);
1098 sqlite3_activate_see(&zRight[4]);
1099 }
1100#endif
1101#ifdef SQLITE_ENABLE_CEROD
1102 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
1103 extern void sqlite3_activate_cerod(const char*);
1104 sqlite3_activate_cerod(&zRight[6]);
1105 }
1106#endif
1107 }
1108#endif
1109
1110 {}
1111
1112 if( v ){
1113 /* Code an OP_Expire at the end of each PRAGMA program to cause
1114 ** the VDBE implementing the pragma to expire. Most (all?) pragmas
1115 ** are only valid for a single execution.
1116 */
1117 sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
1118
1119 /*
1120 ** Reset the safety level, in case the fullfsync flag or synchronous
1121 ** setting changed.
1122 */
1123#ifndef SQLITE_OMIT_PAGER_PRAGMAS
1124 if( db->autoCommit ){
1125 sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
1126 (db->flags&SQLITE_FullFSync)!=0);
1127 }
1128#endif
1129 }
1130pragma_out:
1131 sqliteFree(zLeft);
1132 sqliteFree(zRight);
1133}
1134
1135#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status