blob: e2ad17d76f1bd93fd53be036eba392397e18265f [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.
13**
danielk1977602b4662009-07-02 07:47:33 +000014** $Id: pragma.c,v 1.214 2009/07/02 07:47:33 danielk1977 Exp $
drhc11d4f92003-04-06 21:08:24 +000015*/
16#include "sqliteInt.h"
17
drh13d70422004-11-13 15:59:14 +000018/* Ignore this whole file if pragmas are disabled
19*/
drh8bfdf722009-06-19 14:06:03 +000020#if !defined(SQLITE_OMIT_PRAGMA)
drh13d70422004-11-13 15:59:14 +000021
drhc11d4f92003-04-06 21:08:24 +000022/*
drhc11d4f92003-04-06 21:08:24 +000023** Interpret the given string as a safety level. Return 0 for OFF,
jplyonb1639ff2004-01-19 04:52:29 +000024** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
25** unrecognized string argument.
drhc11d4f92003-04-06 21:08:24 +000026**
27** Note that the values returned are one less that the values that
danielk19774adee202004-05-08 08:23:19 +000028** should be passed into sqlite3BtreeSetSafetyLevel(). The is done
drhc11d4f92003-04-06 21:08:24 +000029** to support legacy SQL code. The safety level used to be boolean
30** and older scripts may have used numbers 0 for OFF and 1 for ON.
31*/
drh4f21c4a2008-12-10 22:15:00 +000032static u8 getSafetyLevel(const char *z){
drh722e95a2004-10-25 20:33:44 +000033 /* 123456789 123456789 */
34 static const char zText[] = "onoffalseyestruefull";
35 static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
36 static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
37 static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2};
38 int i, n;
danielk197778ca0e72009-01-20 16:53:39 +000039 if( sqlite3Isdigit(*z) ){
drh3abbd392008-12-10 23:04:13 +000040 return (u8)atoi(z);
drhc11d4f92003-04-06 21:08:24 +000041 }
drhea678832008-12-10 19:26:22 +000042 n = sqlite3Strlen30(z);
danielk197700e13612008-11-17 19:18:54 +000043 for(i=0; i<ArraySize(iLength); i++){
drh722e95a2004-10-25 20:33:44 +000044 if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
45 return iValue[i];
46 }
drhc11d4f92003-04-06 21:08:24 +000047 }
48 return 1;
49}
50
51/*
drh722e95a2004-10-25 20:33:44 +000052** Interpret the given string as a boolean value.
53*/
drh4f21c4a2008-12-10 22:15:00 +000054static u8 getBoolean(const char *z){
drh722e95a2004-10-25 20:33:44 +000055 return getSafetyLevel(z)&1;
56}
57
danielk197741483462007-03-24 16:45:04 +000058/*
59** Interpret the given string as a locking mode value.
60*/
61static int getLockingMode(const char *z){
62 if( z ){
63 if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE;
64 if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL;
65 }
66 return PAGER_LOCKINGMODE_QUERY;
67}
68
danielk1977dddbcdc2007-04-26 14:42:34 +000069#ifndef SQLITE_OMIT_AUTOVACUUM
70/*
71** Interpret the given string as an auto-vacuum mode value.
72**
73** The following strings, "none", "full" and "incremental" are
74** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
75*/
76static int getAutoVacuum(const char *z){
77 int i;
78 if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE;
79 if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL;
80 if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR;
81 i = atoi(z);
drh4f21c4a2008-12-10 22:15:00 +000082 return (u8)((i>=0&&i<=2)?i:0);
danielk1977dddbcdc2007-04-26 14:42:34 +000083}
84#endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
85
danielk1977b84f96f2005-01-20 11:32:23 +000086#ifndef SQLITE_OMIT_PAGER_PRAGMAS
drh722e95a2004-10-25 20:33:44 +000087/*
drh90f5ecb2004-07-22 01:19:35 +000088** Interpret the given string as a temp db location. Return 1 for file
89** backed temporary databases, 2 for the Red-Black tree in memory database
90** and 0 to use the compile-time default.
91*/
92static int getTempStore(const char *z){
93 if( z[0]>='0' && z[0]<='2' ){
94 return z[0] - '0';
95 }else if( sqlite3StrICmp(z, "file")==0 ){
96 return 1;
97 }else if( sqlite3StrICmp(z, "memory")==0 ){
98 return 2;
99 }else{
100 return 0;
101 }
102}
drhbf216272005-02-26 18:10:44 +0000103#endif /* SQLITE_PAGER_PRAGMAS */
drh90f5ecb2004-07-22 01:19:35 +0000104
drhbf216272005-02-26 18:10:44 +0000105#ifndef SQLITE_OMIT_PAGER_PRAGMAS
drh90f5ecb2004-07-22 01:19:35 +0000106/*
tpoindex9a09a3c2004-12-20 19:01:32 +0000107** Invalidate temp storage, either when the temp storage is changed
108** from default, or when 'file' and the temp_store_directory has changed
drh90f5ecb2004-07-22 01:19:35 +0000109*/
tpoindex9a09a3c2004-12-20 19:01:32 +0000110static int invalidateTempStorage(Parse *pParse){
drh9bb575f2004-09-06 17:24:11 +0000111 sqlite3 *db = pParse->db;
drh90f5ecb2004-07-22 01:19:35 +0000112 if( db->aDb[1].pBt!=0 ){
danielk1977983e2302008-07-08 07:35:51 +0000113 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
drh90f5ecb2004-07-22 01:19:35 +0000114 sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
115 "from within a transaction");
116 return SQLITE_ERROR;
117 }
118 sqlite3BtreeClose(db->aDb[1].pBt);
119 db->aDb[1].pBt = 0;
120 sqlite3ResetInternalSchema(db, 0);
121 }
tpoindex9a09a3c2004-12-20 19:01:32 +0000122 return SQLITE_OK;
123}
drhbf216272005-02-26 18:10:44 +0000124#endif /* SQLITE_PAGER_PRAGMAS */
tpoindex9a09a3c2004-12-20 19:01:32 +0000125
drhbf216272005-02-26 18:10:44 +0000126#ifndef SQLITE_OMIT_PAGER_PRAGMAS
tpoindex9a09a3c2004-12-20 19:01:32 +0000127/*
128** If the TEMP database is open, close it and mark the database schema
danielk1977b06a0b62008-06-26 10:54:12 +0000129** as needing reloading. This must be done when using the SQLITE_TEMP_STORE
tpoindex9a09a3c2004-12-20 19:01:32 +0000130** or DEFAULT_TEMP_STORE pragmas.
131*/
132static int changeTempStorage(Parse *pParse, const char *zStorageType){
133 int ts = getTempStore(zStorageType);
134 sqlite3 *db = pParse->db;
135 if( db->temp_store==ts ) return SQLITE_OK;
136 if( invalidateTempStorage( pParse ) != SQLITE_OK ){
137 return SQLITE_ERROR;
138 }
drh4f21c4a2008-12-10 22:15:00 +0000139 db->temp_store = (u8)ts;
drh90f5ecb2004-07-22 01:19:35 +0000140 return SQLITE_OK;
141}
drhbf216272005-02-26 18:10:44 +0000142#endif /* SQLITE_PAGER_PRAGMAS */
drh90f5ecb2004-07-22 01:19:35 +0000143
144/*
145** Generate code to return a single integer value.
146*/
drh3c713642009-04-04 16:02:32 +0000147static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
drh5bb7ffe2004-09-02 15:14:00 +0000148 Vdbe *v = sqlite3GetVdbe(pParse);
drh0a07c102008-01-03 18:03:08 +0000149 int mem = ++pParse->nMem;
drh3c713642009-04-04 16:02:32 +0000150 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
151 if( pI64 ){
152 memcpy(pI64, &value, sizeof(value));
153 }
154 sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64);
drh10861722009-04-07 00:49:16 +0000155 sqlite3VdbeSetNumCols(v, 1);
156 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
drh66a51672008-01-03 00:01:23 +0000157 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
drh90f5ecb2004-07-22 01:19:35 +0000158}
159
drhbf216272005-02-26 18:10:44 +0000160#ifndef SQLITE_OMIT_FLAG_PRAGMAS
drh90f5ecb2004-07-22 01:19:35 +0000161/*
drh87223182004-02-21 14:00:29 +0000162** Check to see if zRight and zLeft refer to a pragma that queries
163** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
164** Also, implement the pragma.
165*/
166static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
drh722e95a2004-10-25 20:33:44 +0000167 static const struct sPragmaType {
drh87223182004-02-21 14:00:29 +0000168 const char *zName; /* Name of the pragma */
169 int mask; /* Mask for the db->flags value */
170 } aPragma[] = {
drh87223182004-02-21 14:00:29 +0000171 { "full_column_names", SQLITE_FullColNames },
172 { "short_column_names", SQLITE_ShortColNames },
drh87223182004-02-21 14:00:29 +0000173 { "count_changes", SQLITE_CountRows },
174 { "empty_result_callbacks", SQLITE_NullCallback },
drhe321c292006-01-12 01:56:43 +0000175 { "legacy_file_format", SQLITE_LegacyFileFmt },
drhac530b12006-02-11 01:25:50 +0000176 { "fullfsync", SQLITE_FullFSync },
drh699b3d42009-02-23 16:52:07 +0000177 { "reverse_unordered_selects", SQLITE_ReverseOrder },
drhcf1023c2007-05-08 20:59:49 +0000178#ifdef SQLITE_DEBUG
179 { "sql_trace", SQLITE_SqlTrace },
180 { "vdbe_listing", SQLITE_VdbeListing },
181 { "vdbe_trace", SQLITE_VdbeTrace },
182#endif
drh0cd2d4c2005-11-03 02:15:02 +0000183#ifndef SQLITE_OMIT_CHECK
184 { "ignore_check_constraints", SQLITE_IgnoreChecks },
185#endif
drh722e95a2004-10-25 20:33:44 +0000186 /* The following is VERY experimental */
danielk197734c68fb2007-03-14 15:37:04 +0000187 { "writable_schema", SQLITE_WriteSchema|SQLITE_RecoveryMode },
drh7bec5052005-02-06 02:45:41 +0000188 { "omit_readlock", SQLITE_NoReadlock },
danielk1977da184232006-01-05 11:34:32 +0000189
190 /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
191 ** flag if there are any active statements. */
192 { "read_uncommitted", SQLITE_ReadUncommitted },
dan5bde73c2009-09-01 17:11:07 +0000193 { "recursive_triggers", SQLITE_RecTriggers },
dan1da40a32009-09-19 17:00:31 +0000194
195 /* TODO: Prevent this flag from being set if not in auto-commit mode? */
196 { "foreign_keys", SQLITE_ForeignKeys },
drh87223182004-02-21 14:00:29 +0000197 };
198 int i;
drh722e95a2004-10-25 20:33:44 +0000199 const struct sPragmaType *p;
danielk197700e13612008-11-17 19:18:54 +0000200 for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
drh722e95a2004-10-25 20:33:44 +0000201 if( sqlite3StrICmp(zLeft, p->zName)==0 ){
drh9bb575f2004-09-06 17:24:11 +0000202 sqlite3 *db = pParse->db;
drh87223182004-02-21 14:00:29 +0000203 Vdbe *v;
danielk1977a21c6b62005-01-24 10:25:59 +0000204 v = sqlite3GetVdbe(pParse);
drhd2cb50b2009-01-09 21:41:17 +0000205 assert( v!=0 ); /* Already allocated by sqlite3Pragma() */
206 if( ALWAYS(v) ){
danielk1977a21c6b62005-01-24 10:25:59 +0000207 if( zRight==0 ){
drh722e95a2004-10-25 20:33:44 +0000208 returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
drhd89bd002005-01-22 03:03:54 +0000209 }else{
danielk1977a21c6b62005-01-24 10:25:59 +0000210 if( getBoolean(zRight) ){
211 db->flags |= p->mask;
212 }else{
213 db->flags &= ~p->mask;
214 }
danielk19778e556522007-11-13 10:30:24 +0000215
216 /* Many of the flag-pragmas modify the code generated by the SQL
217 ** compiler (eg. count_changes). So add an opcode to expire all
218 ** compiled SQL statements after modifying a pragma value.
219 */
drh66a51672008-01-03 00:01:23 +0000220 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
drhd89bd002005-01-22 03:03:54 +0000221 }
drh87223182004-02-21 14:00:29 +0000222 }
danielk19778e556522007-11-13 10:30:24 +0000223
drh87223182004-02-21 14:00:29 +0000224 return 1;
225 }
226 }
227 return 0;
228}
drhbf216272005-02-26 18:10:44 +0000229#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
drh87223182004-02-21 14:00:29 +0000230
drhd2cb50b2009-01-09 21:41:17 +0000231/*
232** Return a human-readable name for a constraint resolution action.
233*/
danielk197750af3e12008-10-10 17:47:21 +0000234static const char *actionName(u8 action){
drhd2cb50b2009-01-09 21:41:17 +0000235 const char *zName;
danielk197750af3e12008-10-10 17:47:21 +0000236 switch( action ){
dan1da40a32009-09-19 17:00:31 +0000237 case OE_SetNull: zName = "SET NULL"; break;
238 case OE_SetDflt: zName = "SET DEFAULT"; break;
239 case OE_Cascade: zName = "CASCADE"; break;
240 case OE_Restrict: zName = "RESTRICT"; break;
241 default: zName = "NO ACTION";
242 assert( action==OE_None ); break;
danielk197750af3e12008-10-10 17:47:21 +0000243 }
drhd2cb50b2009-01-09 21:41:17 +0000244 return zName;
danielk197750af3e12008-10-10 17:47:21 +0000245}
246
drh87223182004-02-21 14:00:29 +0000247/*
drhc11d4f92003-04-06 21:08:24 +0000248** Process a pragma statement.
249**
250** Pragmas are of this form:
251**
danielk197791cf71b2004-06-26 06:37:06 +0000252** PRAGMA [database.]id [= value]
drhc11d4f92003-04-06 21:08:24 +0000253**
254** The identifier might also be a string. The value is a string, and
255** identifier, or a number. If minusFlag is true, then the value is
256** a number that was preceded by a minus sign.
drh90f5ecb2004-07-22 01:19:35 +0000257**
258** If the left side is "database.id" then pId1 is the database name
259** and pId2 is the id. If the left side is just "id" then pId1 is the
260** id and pId2 is any empty string.
drhc11d4f92003-04-06 21:08:24 +0000261*/
danielk197791cf71b2004-06-26 06:37:06 +0000262void sqlite3Pragma(
263 Parse *pParse,
264 Token *pId1, /* First part of [database.]id field */
265 Token *pId2, /* Second part of [database.]id field, or NULL */
266 Token *pValue, /* Token for <value>, or NULL */
267 int minusFlag /* True if a '-' sign preceded <value> */
268){
269 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
270 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
271 const char *zDb = 0; /* The database name */
272 Token *pId; /* Pointer to <id> token */
273 int iDb; /* Database index for <database> */
drh9bb575f2004-09-06 17:24:11 +0000274 sqlite3 *db = pParse->db;
drh90f5ecb2004-07-22 01:19:35 +0000275 Db *pDb;
drh949f9cd2008-01-12 21:35:57 +0000276 Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db);
drhc11d4f92003-04-06 21:08:24 +0000277 if( v==0 ) return;
drh9cbf3422008-01-17 16:22:13 +0000278 pParse->nMem = 2;
drhc11d4f92003-04-06 21:08:24 +0000279
danielk197791cf71b2004-06-26 06:37:06 +0000280 /* Interpret the [database.] part of the pragma statement. iDb is the
281 ** index of the database this pragma is being applied to in db.aDb[]. */
282 iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId);
283 if( iDb<0 ) return;
drh90f5ecb2004-07-22 01:19:35 +0000284 pDb = &db->aDb[iDb];
danielk197791cf71b2004-06-26 06:37:06 +0000285
danielk1977ddfb2f02006-02-17 12:25:14 +0000286 /* If the temp database has been explicitly named as part of the
287 ** pragma, make sure it is open.
288 */
289 if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){
290 return;
291 }
292
drh17435752007-08-16 04:30:38 +0000293 zLeft = sqlite3NameFromToken(db, pId);
danielk197796fb0dd2004-06-30 09:49:22 +0000294 if( !zLeft ) return;
drhc11d4f92003-04-06 21:08:24 +0000295 if( minusFlag ){
drh17435752007-08-16 04:30:38 +0000296 zRight = sqlite3MPrintf(db, "-%T", pValue);
drhc11d4f92003-04-06 21:08:24 +0000297 }else{
drh17435752007-08-16 04:30:38 +0000298 zRight = sqlite3NameFromToken(db, pValue);
drhc11d4f92003-04-06 21:08:24 +0000299 }
danielk197791cf71b2004-06-26 06:37:06 +0000300
drhd2cb50b2009-01-09 21:41:17 +0000301 assert( pId2 );
302 zDb = pId2->n>0 ? pDb->zName : 0;
danielk197791cf71b2004-06-26 06:37:06 +0000303 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
danielk1977e0048402004-06-15 16:51:01 +0000304 goto pragma_out;
drhc11d4f92003-04-06 21:08:24 +0000305 }
306
drh13d70422004-11-13 15:59:14 +0000307#ifndef SQLITE_OMIT_PAGER_PRAGMAS
drhc11d4f92003-04-06 21:08:24 +0000308 /*
drh90f5ecb2004-07-22 01:19:35 +0000309 ** PRAGMA [database.]default_cache_size
310 ** PRAGMA [database.]default_cache_size=N
drhc11d4f92003-04-06 21:08:24 +0000311 **
312 ** The first form reports the current persistent setting for the
313 ** page cache size. The value returned is the maximum number of
314 ** pages in the page cache. The second form sets both the current
315 ** page cache size value and the persistent page cache size value
316 ** stored in the database file.
317 **
318 ** The default cache size is stored in meta-value 2 of page 1 of the
319 ** database file. The cache size is actually the absolute value of
320 ** this memory location. The sign of meta-value 2 determines the
321 ** synchronous setting. A negative value means synchronous is off
322 ** and a positive value means synchronous is on.
323 */
danielk19774adee202004-05-08 08:23:19 +0000324 if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
drh57196282004-10-06 15:41:16 +0000325 static const VdbeOpList getCacheSize[] = {
danielk1977602b4662009-07-02 07:47:33 +0000326 { OP_Transaction, 0, 0, 0}, /* 0 */
327 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
328 { OP_IfPos, 1, 7, 0},
drh3c84ddf2008-01-09 02:15:38 +0000329 { OP_Integer, 0, 2, 0},
330 { OP_Subtract, 1, 2, 1},
danielk1977602b4662009-07-02 07:47:33 +0000331 { OP_IfPos, 1, 7, 0},
332 { OP_Integer, 0, 1, 0}, /* 6 */
drh3c84ddf2008-01-09 02:15:38 +0000333 { OP_ResultRow, 1, 1, 0},
drhc11d4f92003-04-06 21:08:24 +0000334 };
drh905793e2004-02-21 13:31:09 +0000335 int addr;
danielk19778a414492004-06-29 08:59:35 +0000336 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drhfb982642007-08-30 01:19:59 +0000337 sqlite3VdbeUsesBtree(v, iDb);
danielk197791cf71b2004-06-26 06:37:06 +0000338 if( !zRight ){
danielk197722322fd2004-05-25 23:35:17 +0000339 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +0000340 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
drh3c84ddf2008-01-09 02:15:38 +0000341 pParse->nMem += 2;
danielk19774adee202004-05-08 08:23:19 +0000342 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
danielk197791cf71b2004-06-26 06:37:06 +0000343 sqlite3VdbeChangeP1(v, addr, iDb);
danielk1977602b4662009-07-02 07:47:33 +0000344 sqlite3VdbeChangeP1(v, addr+1, iDb);
345 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
drhc11d4f92003-04-06 21:08:24 +0000346 }else{
drhc11d4f92003-04-06 21:08:24 +0000347 int size = atoi(zRight);
348 if( size<0 ) size = -size;
danielk197791cf71b2004-06-26 06:37:06 +0000349 sqlite3BeginWriteOperation(pParse, 0, iDb);
drh9cbf3422008-01-17 16:22:13 +0000350 sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
danielk19770d19f7a2009-06-03 11:25:07 +0000351 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, 2, BTREE_DEFAULT_CACHE_SIZE);
drh9cbf3422008-01-17 16:22:13 +0000352 addr = sqlite3VdbeAddOp2(v, OP_IfPos, 2, 0);
353 sqlite3VdbeAddOp2(v, OP_Integer, -size, 1);
drh3c84ddf2008-01-09 02:15:38 +0000354 sqlite3VdbeJumpHere(v, addr);
danielk19770d19f7a2009-06-03 11:25:07 +0000355 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
danielk197714db2662006-01-09 16:12:04 +0000356 pDb->pSchema->cache_size = size;
357 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
drhc11d4f92003-04-06 21:08:24 +0000358 }
359 }else
360
361 /*
drh90f5ecb2004-07-22 01:19:35 +0000362 ** PRAGMA [database.]page_size
363 ** PRAGMA [database.]page_size=N
364 **
365 ** The first form reports the current setting for the
366 ** database page size in bytes. The second form sets the
367 ** database page size value. The value can only be set if
368 ** the database has not yet been created.
369 */
370 if( sqlite3StrICmp(zLeft,"page_size")==0 ){
371 Btree *pBt = pDb->pBt;
drhd2cb50b2009-01-09 21:41:17 +0000372 assert( pBt!=0 );
drh90f5ecb2004-07-22 01:19:35 +0000373 if( !zRight ){
drhd2cb50b2009-01-09 21:41:17 +0000374 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
drh5bb7ffe2004-09-02 15:14:00 +0000375 returnSingleInt(pParse, "page_size", size);
drh90f5ecb2004-07-22 01:19:35 +0000376 }else{
danielk1977992772c2007-08-30 10:07:38 +0000377 /* Malloc may fail when setting the page-size, as there is an internal
378 ** buffer that the pager module resizes using sqlite3_realloc().
379 */
danielk1977f653d782008-03-20 11:04:21 +0000380 db->nextPagesize = atoi(zRight);
drhce4869f2009-04-02 20:16:58 +0000381 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
danielk1977992772c2007-08-30 10:07:38 +0000382 db->mallocFailed = 1;
383 }
drh90f5ecb2004-07-22 01:19:35 +0000384 }
385 }else
danielk197741483462007-03-24 16:45:04 +0000386
387 /*
drhf8e632b2007-05-08 14:51:36 +0000388 ** PRAGMA [database.]max_page_count
389 ** PRAGMA [database.]max_page_count=N
390 **
391 ** The first form reports the current setting for the
392 ** maximum number of pages in the database file. The
393 ** second form attempts to change this setting. Both
394 ** forms return the current setting.
395 */
396 if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
397 Btree *pBt = pDb->pBt;
398 int newMax = 0;
drhd2cb50b2009-01-09 21:41:17 +0000399 assert( pBt!=0 );
drhf8e632b2007-05-08 14:51:36 +0000400 if( zRight ){
401 newMax = atoi(zRight);
402 }
drhd2cb50b2009-01-09 21:41:17 +0000403 if( ALWAYS(pBt) ){
drhf8e632b2007-05-08 14:51:36 +0000404 newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
405 }
406 returnSingleInt(pParse, "max_page_count", newMax);
407 }else
408
409 /*
danielk197759a93792008-05-15 17:48:20 +0000410 ** PRAGMA [database.]page_count
411 **
412 ** Return the number of pages in the specified database.
413 */
414 if( sqlite3StrICmp(zLeft,"page_count")==0 ){
danielk197759a93792008-05-15 17:48:20 +0000415 int iReg;
drhd2cb50b2009-01-09 21:41:17 +0000416 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
danielk197759a93792008-05-15 17:48:20 +0000417 sqlite3CodeVerifySchema(pParse, iDb);
418 iReg = ++pParse->nMem;
419 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
420 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
421 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +0000422 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", SQLITE_STATIC);
danielk197759a93792008-05-15 17:48:20 +0000423 }else
424
425 /*
danielk197741483462007-03-24 16:45:04 +0000426 ** PRAGMA [database.]locking_mode
427 ** PRAGMA [database.]locking_mode = (normal|exclusive)
428 */
429 if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){
430 const char *zRet = "normal";
431 int eMode = getLockingMode(zRight);
432
433 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
434 /* Simple "PRAGMA locking_mode;" statement. This is a query for
435 ** the current default locking mode (which may be different to
436 ** the locking-mode of the main database).
437 */
438 eMode = db->dfltLockMode;
439 }else{
440 Pager *pPager;
441 if( pId2->n==0 ){
442 /* This indicates that no database name was specified as part
443 ** of the PRAGMA command. In this case the locking-mode must be
444 ** set on all attached databases, as well as the main db file.
445 **
446 ** Also, the sqlite3.dfltLockMode variable is set so that
447 ** any subsequently attached databases also use the specified
448 ** locking mode.
449 */
450 int ii;
451 assert(pDb==&db->aDb[0]);
452 for(ii=2; ii<db->nDb; ii++){
453 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
454 sqlite3PagerLockingMode(pPager, eMode);
455 }
drh4f21c4a2008-12-10 22:15:00 +0000456 db->dfltLockMode = (u8)eMode;
danielk197741483462007-03-24 16:45:04 +0000457 }
458 pPager = sqlite3BtreePager(pDb->pBt);
459 eMode = sqlite3PagerLockingMode(pPager, eMode);
460 }
461
462 assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE);
463 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
464 zRet = "exclusive";
465 }
466 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +0000467 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
drh2d401ab2008-01-10 23:50:11 +0000468 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
469 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
danielk197741483462007-03-24 16:45:04 +0000470 }else
drh3b020132008-04-17 17:02:01 +0000471
472 /*
473 ** PRAGMA [database.]journal_mode
shanec782f692008-11-10 19:24:38 +0000474 ** PRAGMA [database.]journal_mode = (delete|persist|off|truncate|memory)
drh3b020132008-04-17 17:02:01 +0000475 */
476 if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
477 int eMode;
danielk1977b3175382008-10-17 18:51:52 +0000478 static char * const azModeName[] = {
479 "delete", "persist", "off", "truncate", "memory"
480 };
drh3b020132008-04-17 17:02:01 +0000481
482 if( zRight==0 ){
483 eMode = PAGER_JOURNALMODE_QUERY;
484 }else{
drhea678832008-12-10 19:26:22 +0000485 int n = sqlite3Strlen30(zRight);
drh04335882008-09-26 21:08:08 +0000486 eMode = sizeof(azModeName)/sizeof(azModeName[0]) - 1;
drh3b020132008-04-17 17:02:01 +0000487 while( eMode>=0 && sqlite3StrNICmp(zRight, azModeName[eMode], n)!=0 ){
488 eMode--;
489 }
490 }
491 if( pId2->n==0 && eMode==PAGER_JOURNALMODE_QUERY ){
danielk1977b53e4962008-06-04 06:45:59 +0000492 /* Simple "PRAGMA journal_mode;" statement. This is a query for
drh3b020132008-04-17 17:02:01 +0000493 ** the current default journal mode (which may be different to
494 ** the journal-mode of the main database).
495 */
496 eMode = db->dfltJournalMode;
497 }else{
498 Pager *pPager;
499 if( pId2->n==0 ){
500 /* This indicates that no database name was specified as part
501 ** of the PRAGMA command. In this case the journal-mode must be
502 ** set on all attached databases, as well as the main db file.
503 **
504 ** Also, the sqlite3.dfltJournalMode variable is set so that
505 ** any subsequently attached databases also use the specified
506 ** journal mode.
507 */
508 int ii;
509 assert(pDb==&db->aDb[0]);
drhfdc40e92008-04-17 20:59:37 +0000510 for(ii=1; ii<db->nDb; ii++){
511 if( db->aDb[ii].pBt ){
512 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
513 sqlite3PagerJournalMode(pPager, eMode);
514 }
drh3b020132008-04-17 17:02:01 +0000515 }
drh4f21c4a2008-12-10 22:15:00 +0000516 db->dfltJournalMode = (u8)eMode;
drh3b020132008-04-17 17:02:01 +0000517 }
518 pPager = sqlite3BtreePager(pDb->pBt);
519 eMode = sqlite3PagerJournalMode(pPager, eMode);
520 }
521 assert( eMode==PAGER_JOURNALMODE_DELETE
drh04335882008-09-26 21:08:08 +0000522 || eMode==PAGER_JOURNALMODE_TRUNCATE
drh3b020132008-04-17 17:02:01 +0000523 || eMode==PAGER_JOURNALMODE_PERSIST
danielk1977b3175382008-10-17 18:51:52 +0000524 || eMode==PAGER_JOURNALMODE_OFF
525 || eMode==PAGER_JOURNALMODE_MEMORY );
drh3b020132008-04-17 17:02:01 +0000526 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +0000527 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
drh3b020132008-04-17 17:02:01 +0000528 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0,
529 azModeName[eMode], P4_STATIC);
530 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
531 }else
danielk1977b53e4962008-06-04 06:45:59 +0000532
533 /*
534 ** PRAGMA [database.]journal_size_limit
535 ** PRAGMA [database.]journal_size_limit=N
536 **
drha9e364f2009-01-13 20:14:15 +0000537 ** Get or set the size limit on rollback journal files.
danielk1977b53e4962008-06-04 06:45:59 +0000538 */
539 if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){
540 Pager *pPager = sqlite3BtreePager(pDb->pBt);
541 i64 iLimit = -2;
542 if( zRight ){
drh3c713642009-04-04 16:02:32 +0000543 sqlite3Atoi64(zRight, &iLimit);
544 if( iLimit<-1 ) iLimit = -1;
danielk1977b53e4962008-06-04 06:45:59 +0000545 }
546 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
drh3c713642009-04-04 16:02:32 +0000547 returnSingleInt(pParse, "journal_size_limit", iLimit);
danielk1977b53e4962008-06-04 06:45:59 +0000548 }else
549
drh13d70422004-11-13 15:59:14 +0000550#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
drh90f5ecb2004-07-22 01:19:35 +0000551
552 /*
danielk1977951af802004-11-05 15:45:09 +0000553 ** PRAGMA [database.]auto_vacuum
554 ** PRAGMA [database.]auto_vacuum=N
555 **
drha9e364f2009-01-13 20:14:15 +0000556 ** Get or set the value of the database 'auto-vacuum' parameter.
557 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
danielk1977951af802004-11-05 15:45:09 +0000558 */
559#ifndef SQLITE_OMIT_AUTOVACUUM
560 if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
561 Btree *pBt = pDb->pBt;
drhd2cb50b2009-01-09 21:41:17 +0000562 assert( pBt!=0 );
danielk197727b1f952007-06-25 08:16:58 +0000563 if( sqlite3ReadSchema(pParse) ){
564 goto pragma_out;
565 }
danielk1977951af802004-11-05 15:45:09 +0000566 if( !zRight ){
drhd2cb50b2009-01-09 21:41:17 +0000567 int auto_vacuum;
568 if( ALWAYS(pBt) ){
569 auto_vacuum = sqlite3BtreeGetAutoVacuum(pBt);
570 }else{
571 auto_vacuum = SQLITE_DEFAULT_AUTOVACUUM;
572 }
danielk1977951af802004-11-05 15:45:09 +0000573 returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
574 }else{
danielk1977dddbcdc2007-04-26 14:42:34 +0000575 int eAuto = getAutoVacuum(zRight);
drhd2cb50b2009-01-09 21:41:17 +0000576 assert( eAuto>=0 && eAuto<=2 );
drh4f21c4a2008-12-10 22:15:00 +0000577 db->nextAutovac = (u8)eAuto;
drhd2cb50b2009-01-09 21:41:17 +0000578 if( ALWAYS(eAuto>=0) ){
danielk197727b1f952007-06-25 08:16:58 +0000579 /* Call SetAutoVacuum() to set initialize the internal auto and
580 ** incr-vacuum flags. This is required in case this connection
581 ** creates the database file. It is important that it is created
582 ** as an auto-vacuum capable db.
583 */
584 int rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
585 if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){
586 /* When setting the auto_vacuum mode to either "full" or
587 ** "incremental", write the value of meta[6] in the database
588 ** file. Before writing to meta[6], check that meta[3] indicates
589 ** that this really is an auto-vacuum capable database.
590 */
591 static const VdbeOpList setMeta6[] = {
danielk19770d19f7a2009-06-03 11:25:07 +0000592 { OP_Transaction, 0, 1, 0}, /* 0 */
593 { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
594 { OP_If, 1, 0, 0}, /* 2 */
595 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
596 { OP_Integer, 0, 1, 0}, /* 4 */
597 { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */
danielk197727b1f952007-06-25 08:16:58 +0000598 };
599 int iAddr;
600 iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);
601 sqlite3VdbeChangeP1(v, iAddr, iDb);
602 sqlite3VdbeChangeP1(v, iAddr+1, iDb);
603 sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
604 sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
605 sqlite3VdbeChangeP1(v, iAddr+5, iDb);
drhfb982642007-08-30 01:19:59 +0000606 sqlite3VdbeUsesBtree(v, iDb);
danielk197727b1f952007-06-25 08:16:58 +0000607 }
danielk1977dddbcdc2007-04-26 14:42:34 +0000608 }
danielk1977951af802004-11-05 15:45:09 +0000609 }
610 }else
611#endif
612
drhca5557f2007-05-04 18:30:40 +0000613 /*
614 ** PRAGMA [database.]incremental_vacuum(N)
615 **
616 ** Do N steps of incremental vacuuming on a database.
617 */
618#ifndef SQLITE_OMIT_AUTOVACUUM
619 if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){
620 int iLimit, addr;
danielk197717a240a2007-05-23 13:50:23 +0000621 if( sqlite3ReadSchema(pParse) ){
622 goto pragma_out;
623 }
drhca5557f2007-05-04 18:30:40 +0000624 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
625 iLimit = 0x7fffffff;
626 }
627 sqlite3BeginWriteOperation(pParse, 0, iDb);
drh4c583122008-01-04 22:01:03 +0000628 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
drh3c84ddf2008-01-09 02:15:38 +0000629 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
drh2d401ab2008-01-10 23:50:11 +0000630 sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
drh8558cde2008-01-05 05:20:10 +0000631 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
drh3c84ddf2008-01-09 02:15:38 +0000632 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
drhca5557f2007-05-04 18:30:40 +0000633 sqlite3VdbeJumpHere(v, addr);
634 }else
635#endif
636
drh13d70422004-11-13 15:59:14 +0000637#ifndef SQLITE_OMIT_PAGER_PRAGMAS
danielk1977951af802004-11-05 15:45:09 +0000638 /*
drh90f5ecb2004-07-22 01:19:35 +0000639 ** PRAGMA [database.]cache_size
640 ** PRAGMA [database.]cache_size=N
drhc11d4f92003-04-06 21:08:24 +0000641 **
642 ** The first form reports the current local setting for the
643 ** page cache size. The local setting can be different from
644 ** the persistent cache size value that is stored in the database
645 ** file itself. The value returned is the maximum number of
646 ** pages in the page cache. The second form sets the local
647 ** page cache size value. It does not change the persistent
648 ** cache size stored on the disk so the cache size will revert
649 ** to its default value when the database is closed and reopened.
650 ** N should be a positive integer.
651 */
danielk19774adee202004-05-08 08:23:19 +0000652 if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
danielk19778a414492004-06-29 08:59:35 +0000653 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
danielk197791cf71b2004-06-26 06:37:06 +0000654 if( !zRight ){
danielk197714db2662006-01-09 16:12:04 +0000655 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
drhc11d4f92003-04-06 21:08:24 +0000656 }else{
657 int size = atoi(zRight);
658 if( size<0 ) size = -size;
danielk197714db2662006-01-09 16:12:04 +0000659 pDb->pSchema->cache_size = size;
660 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
drhc11d4f92003-04-06 21:08:24 +0000661 }
662 }else
663
664 /*
drh90f5ecb2004-07-22 01:19:35 +0000665 ** PRAGMA temp_store
666 ** PRAGMA temp_store = "default"|"memory"|"file"
667 **
668 ** Return or set the local value of the temp_store flag. Changing
669 ** the local value does not make changes to the disk file and the default
670 ** value will be restored the next time the database is opened.
671 **
672 ** Note that it is possible for the library compile-time options to
673 ** override this setting
674 */
675 if( sqlite3StrICmp(zLeft, "temp_store")==0 ){
676 if( !zRight ){
drh5bb7ffe2004-09-02 15:14:00 +0000677 returnSingleInt(pParse, "temp_store", db->temp_store);
drh90f5ecb2004-07-22 01:19:35 +0000678 }else{
679 changeTempStorage(pParse, zRight);
680 }
681 }else
682
683 /*
tpoindex9a09a3c2004-12-20 19:01:32 +0000684 ** PRAGMA temp_store_directory
685 ** PRAGMA temp_store_directory = ""|"directory_name"
686 **
687 ** Return or set the local value of the temp_store_directory flag. Changing
688 ** the value sets a specific directory to be used for temporary files.
689 ** Setting to a null string reverts to the default temporary directory search.
690 ** If temporary directory is changed, then invalidateTempStorage.
691 **
692 */
693 if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
694 if( !zRight ){
695 if( sqlite3_temp_directory ){
696 sqlite3VdbeSetNumCols(v, 1);
danielk1977955de522006-02-10 02:27:42 +0000697 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
danielk197710fb7492008-10-31 10:53:22 +0000698 "temp_store_directory", SQLITE_STATIC);
drh2d401ab2008-01-10 23:50:11 +0000699 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
700 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
tpoindex9a09a3c2004-12-20 19:01:32 +0000701 }
702 }else{
drh78f82d12008-09-02 00:52:52 +0000703#ifndef SQLITE_OMIT_WSD
danielk1977861f7452008-06-05 11:39:11 +0000704 if( zRight[0] ){
danielk1977fab11272008-09-16 14:38:02 +0000705 int rc;
danielk1977861f7452008-06-05 11:39:11 +0000706 int res;
danielk1977fab11272008-09-16 14:38:02 +0000707 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
708 if( rc!=SQLITE_OK || res==0 ){
danielk1977861f7452008-06-05 11:39:11 +0000709 sqlite3ErrorMsg(pParse, "not a writable directory");
710 goto pragma_out;
711 }
drh268283b2005-01-08 15:44:25 +0000712 }
danielk1977b06a0b62008-06-26 10:54:12 +0000713 if( SQLITE_TEMP_STORE==0
714 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
715 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
drh268283b2005-01-08 15:44:25 +0000716 ){
717 invalidateTempStorage(pParse);
718 }
drh17435752007-08-16 04:30:38 +0000719 sqlite3_free(sqlite3_temp_directory);
drh268283b2005-01-08 15:44:25 +0000720 if( zRight[0] ){
drh633e6d52008-07-28 19:34:53 +0000721 sqlite3_temp_directory = sqlite3DbStrDup(0, zRight);
tpoindex9a09a3c2004-12-20 19:01:32 +0000722 }else{
drh268283b2005-01-08 15:44:25 +0000723 sqlite3_temp_directory = 0;
tpoindex9a09a3c2004-12-20 19:01:32 +0000724 }
drh78f82d12008-09-02 00:52:52 +0000725#endif /* SQLITE_OMIT_WSD */
tpoindex9a09a3c2004-12-20 19:01:32 +0000726 }
727 }else
728
drhd2cb50b2009-01-09 21:41:17 +0000729#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
730# if defined(__APPLE__)
731# define SQLITE_ENABLE_LOCKING_STYLE 1
732# else
733# define SQLITE_ENABLE_LOCKING_STYLE 0
734# endif
735#endif
736#if SQLITE_ENABLE_LOCKING_STYLE
tpoindex9a09a3c2004-12-20 19:01:32 +0000737 /*
aswiftaebf4132008-11-21 00:10:35 +0000738 ** PRAGMA [database.]lock_proxy_file
739 ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
740 **
741 ** Return or set the value of the lock_proxy_file flag. Changing
742 ** the value sets a specific file to be used for database access locks.
743 **
744 */
745 if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){
746 if( !zRight ){
747 Pager *pPager = sqlite3BtreePager(pDb->pBt);
748 char *proxy_file_path = NULL;
749 sqlite3_file *pFile = sqlite3PagerFile(pPager);
750 sqlite3OsFileControl(pFile, SQLITE_GET_LOCKPROXYFILE,
751 &proxy_file_path);
752
753 if( proxy_file_path ){
754 sqlite3VdbeSetNumCols(v, 1);
755 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
756 "lock_proxy_file", SQLITE_STATIC);
757 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0);
758 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
759 }
760 }else{
761 Pager *pPager = sqlite3BtreePager(pDb->pBt);
762 sqlite3_file *pFile = sqlite3PagerFile(pPager);
763 int res;
764 if( zRight[0] ){
765 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
766 zRight);
767 } else {
768 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
769 NULL);
770 }
771 if( res!=SQLITE_OK ){
772 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
773 goto pragma_out;
774 }
775 }
776 }else
drhd2cb50b2009-01-09 21:41:17 +0000777#endif /* SQLITE_ENABLE_LOCKING_STYLE */
aswiftaebf4132008-11-21 00:10:35 +0000778
779 /*
drh90f5ecb2004-07-22 01:19:35 +0000780 ** PRAGMA [database.]synchronous
781 ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
drhc11d4f92003-04-06 21:08:24 +0000782 **
783 ** Return or set the local value of the synchronous flag. Changing
784 ** the local value does not make changes to the disk file and the
785 ** default value will be restored the next time the database is
786 ** opened.
787 */
danielk19774adee202004-05-08 08:23:19 +0000788 if( sqlite3StrICmp(zLeft,"synchronous")==0 ){
danielk19778a414492004-06-29 08:59:35 +0000789 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
danielk197791cf71b2004-06-26 06:37:06 +0000790 if( !zRight ){
drh5bb7ffe2004-09-02 15:14:00 +0000791 returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
drhc11d4f92003-04-06 21:08:24 +0000792 }else{
danielk197791cf71b2004-06-26 06:37:06 +0000793 if( !db->autoCommit ){
794 sqlite3ErrorMsg(pParse,
795 "Safety level may not be changed inside a transaction");
796 }else{
drh90f5ecb2004-07-22 01:19:35 +0000797 pDb->safety_level = getSafetyLevel(zRight)+1;
danielk197791cf71b2004-06-26 06:37:06 +0000798 }
drhc11d4f92003-04-06 21:08:24 +0000799 }
800 }else
drh13d70422004-11-13 15:59:14 +0000801#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
drhc11d4f92003-04-06 21:08:24 +0000802
drhbf216272005-02-26 18:10:44 +0000803#ifndef SQLITE_OMIT_FLAG_PRAGMAS
drh87223182004-02-21 14:00:29 +0000804 if( flagPragma(pParse, zLeft, zRight) ){
drh90f5ecb2004-07-22 01:19:35 +0000805 /* The flagPragma() subroutine also generates any necessary code
806 ** there is nothing more to do here */
drhc11d4f92003-04-06 21:08:24 +0000807 }else
drhbf216272005-02-26 18:10:44 +0000808#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
drhc11d4f92003-04-06 21:08:24 +0000809
drh13d70422004-11-13 15:59:14 +0000810#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
danielk197791cf71b2004-06-26 06:37:06 +0000811 /*
812 ** PRAGMA table_info(<table>)
813 **
814 ** Return a single row for each column of the named table. The columns of
815 ** the returned data set are:
816 **
817 ** cid: Column id (numbered from left to right, starting at 0)
818 ** name: Column name
819 ** type: Column declaration type.
820 ** notnull: True if 'NOT NULL' is part of column declaration
821 ** dflt_value: The default value for the column, if any.
822 */
drh5260f7e2004-06-26 19:35:29 +0000823 if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
drhc11d4f92003-04-06 21:08:24 +0000824 Table *pTab;
danielk19778a414492004-06-29 08:59:35 +0000825 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drh2783e4b2004-10-05 15:42:53 +0000826 pTab = sqlite3FindTable(db, zRight, zDb);
drhc11d4f92003-04-06 21:08:24 +0000827 if( pTab ){
drhc11d4f92003-04-06 21:08:24 +0000828 int i;
danielk1977034ca142007-06-26 10:38:54 +0000829 int nHidden = 0;
drhf7eece62006-02-06 21:34:27 +0000830 Column *pCol;
drh9f6696a2006-02-09 16:52:23 +0000831 sqlite3VdbeSetNumCols(v, 6);
drh2d401ab2008-01-10 23:50:11 +0000832 pParse->nMem = 6;
danielk197710fb7492008-10-31 10:53:22 +0000833 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
834 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
835 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
836 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
837 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
838 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
danielk19774adee202004-05-08 08:23:19 +0000839 sqlite3ViewGetColumnNames(pParse, pTab);
drhf7eece62006-02-06 21:34:27 +0000840 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
danielk1977034ca142007-06-26 10:38:54 +0000841 if( IsHiddenColumn(pCol) ){
842 nHidden++;
843 continue;
844 }
drh2d401ab2008-01-10 23:50:11 +0000845 sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
846 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
847 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
drhbfa8b102006-03-03 21:20:16 +0000848 pCol->zType ? pCol->zType : "", 0);
danielk1977f96a3772008-10-23 05:45:07 +0000849 sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
drhb7916a72009-05-27 10:31:29 +0000850 if( pCol->zDflt ){
851 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
drh6f835982006-09-25 13:48:30 +0000852 }else{
drh2d401ab2008-01-10 23:50:11 +0000853 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
drh6f835982006-09-25 13:48:30 +0000854 }
drh2d401ab2008-01-10 23:50:11 +0000855 sqlite3VdbeAddOp2(v, OP_Integer, pCol->isPrimKey, 6);
856 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
drhc11d4f92003-04-06 21:08:24 +0000857 }
858 }
859 }else
860
drh5260f7e2004-06-26 19:35:29 +0000861 if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
drhc11d4f92003-04-06 21:08:24 +0000862 Index *pIdx;
863 Table *pTab;
danielk19778a414492004-06-29 08:59:35 +0000864 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drh2783e4b2004-10-05 15:42:53 +0000865 pIdx = sqlite3FindIndex(db, zRight, zDb);
drhc11d4f92003-04-06 21:08:24 +0000866 if( pIdx ){
drhc11d4f92003-04-06 21:08:24 +0000867 int i;
868 pTab = pIdx->pTable;
danielk197722322fd2004-05-25 23:35:17 +0000869 sqlite3VdbeSetNumCols(v, 3);
drh2d401ab2008-01-10 23:50:11 +0000870 pParse->nMem = 3;
danielk197710fb7492008-10-31 10:53:22 +0000871 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
872 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
873 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
drhc11d4f92003-04-06 21:08:24 +0000874 for(i=0; i<pIdx->nColumn; i++){
875 int cnum = pIdx->aiColumn[i];
drh2d401ab2008-01-10 23:50:11 +0000876 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
877 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
drhc11d4f92003-04-06 21:08:24 +0000878 assert( pTab->nCol>cnum );
drh2d401ab2008-01-10 23:50:11 +0000879 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
880 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
drhc11d4f92003-04-06 21:08:24 +0000881 }
882 }
883 }else
884
drh5260f7e2004-06-26 19:35:29 +0000885 if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){
drhc11d4f92003-04-06 21:08:24 +0000886 Index *pIdx;
887 Table *pTab;
danielk19778a414492004-06-29 08:59:35 +0000888 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drh2783e4b2004-10-05 15:42:53 +0000889 pTab = sqlite3FindTable(db, zRight, zDb);
drhc11d4f92003-04-06 21:08:24 +0000890 if( pTab ){
danielk19774adee202004-05-08 08:23:19 +0000891 v = sqlite3GetVdbe(pParse);
drhc11d4f92003-04-06 21:08:24 +0000892 pIdx = pTab->pIndex;
danielk1977742f9472004-06-16 12:02:43 +0000893 if( pIdx ){
894 int i = 0;
895 sqlite3VdbeSetNumCols(v, 3);
drh2d401ab2008-01-10 23:50:11 +0000896 pParse->nMem = 3;
danielk197710fb7492008-10-31 10:53:22 +0000897 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
898 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
899 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
danielk1977742f9472004-06-16 12:02:43 +0000900 while(pIdx){
drh2d401ab2008-01-10 23:50:11 +0000901 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
902 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
903 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3);
904 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
danielk1977742f9472004-06-16 12:02:43 +0000905 ++i;
906 pIdx = pIdx->pNext;
907 }
drhc11d4f92003-04-06 21:08:24 +0000908 }
909 }
910 }else
911
drh13d70422004-11-13 15:59:14 +0000912 if( sqlite3StrICmp(zLeft, "database_list")==0 ){
913 int i;
914 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
915 sqlite3VdbeSetNumCols(v, 3);
drh2d401ab2008-01-10 23:50:11 +0000916 pParse->nMem = 3;
danielk197710fb7492008-10-31 10:53:22 +0000917 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
918 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
919 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
drh13d70422004-11-13 15:59:14 +0000920 for(i=0; i<db->nDb; i++){
921 if( db->aDb[i].pBt==0 ) continue;
922 assert( db->aDb[i].zName!=0 );
drh2d401ab2008-01-10 23:50:11 +0000923 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
924 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
925 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
drh13d70422004-11-13 15:59:14 +0000926 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
drh2d401ab2008-01-10 23:50:11 +0000927 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
drh13d70422004-11-13 15:59:14 +0000928 }
929 }else
danielk197748af65a2005-02-09 03:20:37 +0000930
931 if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
932 int i = 0;
933 HashElem *p;
934 sqlite3VdbeSetNumCols(v, 2);
drh2d401ab2008-01-10 23:50:11 +0000935 pParse->nMem = 2;
danielk197710fb7492008-10-31 10:53:22 +0000936 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
937 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
danielk197748af65a2005-02-09 03:20:37 +0000938 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
939 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
drh2d401ab2008-01-10 23:50:11 +0000940 sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
941 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
942 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
danielk197748af65a2005-02-09 03:20:37 +0000943 }
944 }else
drh13d70422004-11-13 15:59:14 +0000945#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
946
drhb7f91642004-10-31 02:22:47 +0000947#ifndef SQLITE_OMIT_FOREIGN_KEY
drh5260f7e2004-06-26 19:35:29 +0000948 if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
drh78100cc2003-08-23 22:40:53 +0000949 FKey *pFK;
950 Table *pTab;
danielk19778a414492004-06-29 08:59:35 +0000951 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drh2783e4b2004-10-05 15:42:53 +0000952 pTab = sqlite3FindTable(db, zRight, zDb);
drh78100cc2003-08-23 22:40:53 +0000953 if( pTab ){
danielk19774adee202004-05-08 08:23:19 +0000954 v = sqlite3GetVdbe(pParse);
drh78100cc2003-08-23 22:40:53 +0000955 pFK = pTab->pFKey;
danielk1977742f9472004-06-16 12:02:43 +0000956 if( pFK ){
957 int i = 0;
danielk197750af3e12008-10-10 17:47:21 +0000958 sqlite3VdbeSetNumCols(v, 8);
959 pParse->nMem = 8;
danielk197710fb7492008-10-31 10:53:22 +0000960 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC);
961 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
962 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
963 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
964 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
965 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
966 sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
967 sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
danielk1977742f9472004-06-16 12:02:43 +0000968 while(pFK){
969 int j;
970 for(j=0; j<pFK->nCol; j++){
drh2f471492005-06-23 03:15:07 +0000971 char *zCol = pFK->aCol[j].zCol;
danielk197750af3e12008-10-10 17:47:21 +0000972 char *zOnUpdate = (char *)actionName(pFK->updateConf);
973 char *zOnDelete = (char *)actionName(pFK->deleteConf);
drh2d401ab2008-01-10 23:50:11 +0000974 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
975 sqlite3VdbeAddOp2(v, OP_Integer, j, 2);
976 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0);
977 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
drh66a51672008-01-03 00:01:23 +0000978 pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
drh2d401ab2008-01-10 23:50:11 +0000979 sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0);
danielk197750af3e12008-10-10 17:47:21 +0000980 sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0);
981 sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0);
982 sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0);
983 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
danielk1977742f9472004-06-16 12:02:43 +0000984 }
985 ++i;
986 pFK = pFK->pNextFrom;
drh78100cc2003-08-23 22:40:53 +0000987 }
drh78100cc2003-08-23 22:40:53 +0000988 }
989 }
990 }else
drhb7f91642004-10-31 02:22:47 +0000991#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
drh78100cc2003-08-23 22:40:53 +0000992
drhc11d4f92003-04-06 21:08:24 +0000993#ifndef NDEBUG
danielk19774adee202004-05-08 08:23:19 +0000994 if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
drh55ef4d92005-08-14 01:20:37 +0000995 if( zRight ){
996 if( getBoolean(zRight) ){
997 sqlite3ParserTrace(stderr, "parser: ");
998 }else{
999 sqlite3ParserTrace(0, 0);
1000 }
drhc11d4f92003-04-06 21:08:24 +00001001 }
1002 }else
1003#endif
1004
drh55ef4d92005-08-14 01:20:37 +00001005 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
1006 ** used will be case sensitive or not depending on the RHS.
1007 */
1008 if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
1009 if( zRight ){
1010 sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
1011 }
1012 }else
1013
drh1dcdbc02007-01-27 02:24:54 +00001014#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
1015# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
1016#endif
1017
drhb7f91642004-10-31 02:22:47 +00001018#ifndef SQLITE_OMIT_INTEGRITY_CHECK
danielk197741c58b72007-12-29 13:39:19 +00001019 /* Pragma "quick_check" is an experimental reduced version of
1020 ** integrity_check designed to detect most database corruption
1021 ** without most of the overhead of a full integrity-check.
1022 */
1023 if( sqlite3StrICmp(zLeft, "integrity_check")==0
1024 || sqlite3StrICmp(zLeft, "quick_check")==0
1025 ){
drh1dcdbc02007-01-27 02:24:54 +00001026 int i, j, addr, mxErr;
drhed717fe2003-06-15 23:42:24 +00001027
drhed717fe2003-06-15 23:42:24 +00001028 /* Code that appears at the end of the integrity check. If no error
1029 ** messages have been generated, output OK. Otherwise output the
1030 ** error message
1031 */
drh57196282004-10-06 15:41:16 +00001032 static const VdbeOpList endCode[] = {
drh2d401ab2008-01-10 23:50:11 +00001033 { OP_AddImm, 1, 0, 0}, /* 0 */
1034 { OP_IfNeg, 1, 0, 0}, /* 1 */
1035 { OP_String8, 0, 3, 0}, /* 2 */
1036 { OP_ResultRow, 3, 1, 0},
drhc11d4f92003-04-06 21:08:24 +00001037 };
drhed717fe2003-06-15 23:42:24 +00001038
danielk197741c58b72007-12-29 13:39:19 +00001039 int isQuick = (zLeft[0]=='q');
1040
drhed717fe2003-06-15 23:42:24 +00001041 /* Initialize the VDBE program */
danielk19778a414492004-06-29 08:59:35 +00001042 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drh2d401ab2008-01-10 23:50:11 +00001043 pParse->nMem = 6;
danielk197722322fd2004-05-25 23:35:17 +00001044 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +00001045 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
drh1dcdbc02007-01-27 02:24:54 +00001046
1047 /* Set the maximum error count */
1048 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
1049 if( zRight ){
1050 mxErr = atoi(zRight);
1051 if( mxErr<=0 ){
1052 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
1053 }
1054 }
drh2d401ab2008-01-10 23:50:11 +00001055 sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */
drhed717fe2003-06-15 23:42:24 +00001056
1057 /* Do an integrity check on each database file */
1058 for(i=0; i<db->nDb; i++){
1059 HashElem *x;
danielk1977da184232006-01-05 11:34:32 +00001060 Hash *pTbls;
drh79069752004-05-22 21:30:40 +00001061 int cnt = 0;
drhed717fe2003-06-15 23:42:24 +00001062
danielk197753c0f742005-03-29 03:10:59 +00001063 if( OMIT_TEMPDB && i==1 ) continue;
1064
drh80242052004-06-09 00:48:12 +00001065 sqlite3CodeVerifySchema(pParse, i);
drh2d401ab2008-01-10 23:50:11 +00001066 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
drh66a51672008-01-03 00:01:23 +00001067 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
drh1dcdbc02007-01-27 02:24:54 +00001068 sqlite3VdbeJumpHere(v, addr);
drh80242052004-06-09 00:48:12 +00001069
drhed717fe2003-06-15 23:42:24 +00001070 /* Do an integrity check of the B-Tree
drh2d401ab2008-01-10 23:50:11 +00001071 **
1072 ** Begin by filling registers 2, 3, ... with the root pages numbers
1073 ** for all tables and indices in the database.
drhed717fe2003-06-15 23:42:24 +00001074 */
danielk1977da184232006-01-05 11:34:32 +00001075 pTbls = &db->aDb[i].pSchema->tblHash;
1076 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
drh79069752004-05-22 21:30:40 +00001077 Table *pTab = sqliteHashData(x);
1078 Index *pIdx;
drh98757152008-01-09 23:04:12 +00001079 sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
drh79069752004-05-22 21:30:40 +00001080 cnt++;
1081 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
drh98757152008-01-09 23:04:12 +00001082 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt);
drh79069752004-05-22 21:30:40 +00001083 cnt++;
1084 }
1085 }
drh2d401ab2008-01-10 23:50:11 +00001086
1087 /* Make sure sufficient number of registers have been allocated */
danielk1977a7a8e142008-02-13 18:25:27 +00001088 if( pParse->nMem < cnt+4 ){
1089 pParse->nMem = cnt+4;
drh98757152008-01-09 23:04:12 +00001090 }
drh2d401ab2008-01-10 23:50:11 +00001091
1092 /* Do the b-tree integrity checks */
drh98757152008-01-09 23:04:12 +00001093 sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
drh4f21c4a2008-12-10 22:15:00 +00001094 sqlite3VdbeChangeP5(v, (u8)i);
drh98757152008-01-09 23:04:12 +00001095 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2);
1096 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
danielk19771e536952007-08-16 10:09:01 +00001097 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
drh66a51672008-01-03 00:01:23 +00001098 P4_DYNAMIC);
drhb21e7c72008-06-22 12:37:57 +00001099 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
danielk1977a7a8e142008-02-13 18:25:27 +00001100 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
drh98757152008-01-09 23:04:12 +00001101 sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
drh1dcdbc02007-01-27 02:24:54 +00001102 sqlite3VdbeJumpHere(v, addr);
drhed717fe2003-06-15 23:42:24 +00001103
1104 /* Make sure all the indices are constructed correctly.
1105 */
danielk197741c58b72007-12-29 13:39:19 +00001106 for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){
drhed717fe2003-06-15 23:42:24 +00001107 Table *pTab = sqliteHashData(x);
1108 Index *pIdx;
1109 int loopTop;
1110
1111 if( pTab->pIndex==0 ) continue;
drh2d401ab2008-01-10 23:50:11 +00001112 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
drh66a51672008-01-03 00:01:23 +00001113 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
drh1dcdbc02007-01-27 02:24:54 +00001114 sqlite3VdbeJumpHere(v, addr);
drh290c1942004-08-21 17:54:45 +00001115 sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
drh2d401ab2008-01-10 23:50:11 +00001116 sqlite3VdbeAddOp2(v, OP_Integer, 0, 2); /* reg(2) will count entries */
drh66a51672008-01-03 00:01:23 +00001117 loopTop = sqlite3VdbeAddOp2(v, OP_Rewind, 1, 0);
drh2d401ab2008-01-10 23:50:11 +00001118 sqlite3VdbeAddOp2(v, OP_AddImm, 2, 1); /* increment entry count */
drhed717fe2003-06-15 23:42:24 +00001119 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
danielk197713adf8a2004-06-03 16:08:41 +00001120 int jmp2;
drh57196282004-10-06 15:41:16 +00001121 static const VdbeOpList idxErr[] = {
drh8558cde2008-01-05 05:20:10 +00001122 { OP_AddImm, 1, -1, 0},
drh2d401ab2008-01-10 23:50:11 +00001123 { OP_String8, 0, 3, 0}, /* 1 */
1124 { OP_Rowid, 1, 4, 0},
1125 { OP_String8, 0, 5, 0}, /* 3 */
1126 { OP_String8, 0, 6, 0}, /* 4 */
1127 { OP_Concat, 4, 3, 3},
1128 { OP_Concat, 5, 3, 3},
1129 { OP_Concat, 6, 3, 3},
1130 { OP_ResultRow, 3, 1, 0},
drhbb8a2792008-03-19 00:21:30 +00001131 { OP_IfPos, 1, 0, 0}, /* 9 */
1132 { OP_Halt, 0, 0, 0},
drhed717fe2003-06-15 23:42:24 +00001133 };
drhe14006d2008-03-25 17:23:32 +00001134 sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 1);
drh2d401ab2008-01-10 23:50:11 +00001135 jmp2 = sqlite3VdbeAddOp3(v, OP_Found, j+2, 0, 3);
danielk19774adee202004-05-08 08:23:19 +00001136 addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
drh24003452008-01-03 01:28:59 +00001137 sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC);
1138 sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC);
drh66a51672008-01-03 00:01:23 +00001139 sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_STATIC);
drhbb8a2792008-03-19 00:21:30 +00001140 sqlite3VdbeJumpHere(v, addr+9);
drhd654be82005-09-20 17:42:23 +00001141 sqlite3VdbeJumpHere(v, jmp2);
drhed717fe2003-06-15 23:42:24 +00001142 }
drh66a51672008-01-03 00:01:23 +00001143 sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1);
drhd654be82005-09-20 17:42:23 +00001144 sqlite3VdbeJumpHere(v, loopTop);
drhed717fe2003-06-15 23:42:24 +00001145 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
drh57196282004-10-06 15:41:16 +00001146 static const VdbeOpList cntIdx[] = {
drh4c583122008-01-04 22:01:03 +00001147 { OP_Integer, 0, 3, 0},
drhd654be82005-09-20 17:42:23 +00001148 { OP_Rewind, 0, 0, 0}, /* 1 */
drh8558cde2008-01-05 05:20:10 +00001149 { OP_AddImm, 3, 1, 0},
drhd654be82005-09-20 17:42:23 +00001150 { OP_Next, 0, 0, 0}, /* 3 */
drh2d401ab2008-01-10 23:50:11 +00001151 { OP_Eq, 2, 0, 3}, /* 4 */
drh8558cde2008-01-05 05:20:10 +00001152 { OP_AddImm, 1, -1, 0},
drh2d401ab2008-01-10 23:50:11 +00001153 { OP_String8, 0, 2, 0}, /* 6 */
1154 { OP_String8, 0, 3, 0}, /* 7 */
1155 { OP_Concat, 3, 2, 2},
1156 { OP_ResultRow, 2, 1, 0},
drhed717fe2003-06-15 23:42:24 +00001157 };
drh3c84ddf2008-01-09 02:15:38 +00001158 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1);
drh66a51672008-01-03 00:01:23 +00001159 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
drh1dcdbc02007-01-27 02:24:54 +00001160 sqlite3VdbeJumpHere(v, addr);
danielk19774adee202004-05-08 08:23:19 +00001161 addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
drhd654be82005-09-20 17:42:23 +00001162 sqlite3VdbeChangeP1(v, addr+1, j+2);
1163 sqlite3VdbeChangeP2(v, addr+1, addr+4);
1164 sqlite3VdbeChangeP1(v, addr+3, j+2);
1165 sqlite3VdbeChangeP2(v, addr+3, addr+2);
drh2d401ab2008-01-10 23:50:11 +00001166 sqlite3VdbeJumpHere(v, addr+4);
1167 sqlite3VdbeChangeP4(v, addr+6,
drh24003452008-01-03 01:28:59 +00001168 "wrong # of entries in index ", P4_STATIC);
drh2d401ab2008-01-10 23:50:11 +00001169 sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_STATIC);
drhed717fe2003-06-15 23:42:24 +00001170 }
1171 }
1172 }
danielk19774adee202004-05-08 08:23:19 +00001173 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
drh2d401ab2008-01-10 23:50:11 +00001174 sqlite3VdbeChangeP2(v, addr, -mxErr);
1175 sqlite3VdbeJumpHere(v, addr+1);
1176 sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
drhc11d4f92003-04-06 21:08:24 +00001177 }else
drhb7f91642004-10-31 02:22:47 +00001178#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
1179
drh13d70422004-11-13 15:59:14 +00001180#ifndef SQLITE_OMIT_UTF16
danielk19778e227872004-06-07 07:52:17 +00001181 /*
1182 ** PRAGMA encoding
1183 ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
1184 **
drh85b623f2007-12-13 21:54:09 +00001185 ** In its first form, this pragma returns the encoding of the main
danielk19778e227872004-06-07 07:52:17 +00001186 ** database. If the database is not initialized, it is initialized now.
1187 **
1188 ** The second form of this pragma is a no-op if the main database file
1189 ** has not already been initialized. In this case it sets the default
1190 ** encoding that will be used for the main database file if a new file
1191 ** is created. If an existing main database file is opened, then the
1192 ** default text encoding for the existing database is used.
1193 **
1194 ** In all cases new databases created using the ATTACH command are
1195 ** created to use the same default text encoding as the main database. If
1196 ** the main database has not been initialized and/or created when ATTACH
1197 ** is executed, this is done before the ATTACH operation.
1198 **
1199 ** In the second form this pragma sets the text encoding to be used in
1200 ** new database files created using this database handle. It is only
1201 ** useful if invoked immediately after the main database i
1202 */
1203 if( sqlite3StrICmp(zLeft, "encoding")==0 ){
drh0f7eb612006-08-08 13:51:43 +00001204 static const struct EncName {
danielk19778e227872004-06-07 07:52:17 +00001205 char *zName;
1206 u8 enc;
1207 } encnames[] = {
drh998da3a2004-06-19 15:22:56 +00001208 { "UTF8", SQLITE_UTF8 },
drhd2cb50b2009-01-09 21:41:17 +00001209 { "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */
1210 { "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */
1211 { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */
drh998da3a2004-06-19 15:22:56 +00001212 { "UTF16le", SQLITE_UTF16LE },
drh998da3a2004-06-19 15:22:56 +00001213 { "UTF16be", SQLITE_UTF16BE },
drh0f7eb612006-08-08 13:51:43 +00001214 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
1215 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
danielk19778e227872004-06-07 07:52:17 +00001216 { 0, 0 }
1217 };
drh0f7eb612006-08-08 13:51:43 +00001218 const struct EncName *pEnc;
danielk197791cf71b2004-06-26 06:37:06 +00001219 if( !zRight ){ /* "PRAGMA encoding" */
danielk19778a414492004-06-29 08:59:35 +00001220 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
danielk19778e227872004-06-07 07:52:17 +00001221 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +00001222 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
drh2d401ab2008-01-10 23:50:11 +00001223 sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
drhd2cb50b2009-01-09 21:41:17 +00001224 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
1225 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
1226 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
1227 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
drh2d401ab2008-01-10 23:50:11 +00001228 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
danielk19778e227872004-06-07 07:52:17 +00001229 }else{ /* "PRAGMA encoding = XXX" */
1230 /* Only change the value of sqlite.enc if the database handle is not
1231 ** initialized. If the main database exists, the new sqlite.enc value
1232 ** will be overwritten when the schema is next loaded. If it does not
1233 ** already exists, it will be created to use the new encoding value.
1234 */
danielk1977b82e7ed2006-01-11 14:09:31 +00001235 if(
1236 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
1237 DbHasProperty(db, 0, DB_Empty)
1238 ){
danielk19778e227872004-06-07 07:52:17 +00001239 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
1240 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
drh0f7eb612006-08-08 13:51:43 +00001241 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
danielk19778e227872004-06-07 07:52:17 +00001242 break;
1243 }
1244 }
1245 if( !pEnc->zName ){
drh5260f7e2004-06-26 19:35:29 +00001246 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
danielk19778e227872004-06-07 07:52:17 +00001247 }
1248 }
1249 }
1250 }else
drh13d70422004-11-13 15:59:14 +00001251#endif /* SQLITE_OMIT_UTF16 */
1252
1253#ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
danielk1977dae24952004-11-11 05:10:43 +00001254 /*
danielk1977b92b70b2004-11-12 16:11:59 +00001255 ** PRAGMA [database.]schema_version
1256 ** PRAGMA [database.]schema_version = <integer>
danielk1977dae24952004-11-11 05:10:43 +00001257 **
danielk1977b92b70b2004-11-12 16:11:59 +00001258 ** PRAGMA [database.]user_version
1259 ** PRAGMA [database.]user_version = <integer>
danielk1977dae24952004-11-11 05:10:43 +00001260 **
danielk1977b92b70b2004-11-12 16:11:59 +00001261 ** The pragma's schema_version and user_version are used to set or get
1262 ** the value of the schema-version and user-version, respectively. Both
1263 ** the schema-version and the user-version are 32-bit signed integers
danielk1977dae24952004-11-11 05:10:43 +00001264 ** stored in the database header.
1265 **
1266 ** The schema-cookie is usually only manipulated internally by SQLite. It
1267 ** is incremented by SQLite whenever the database schema is modified (by
danielk1977b92b70b2004-11-12 16:11:59 +00001268 ** creating or dropping a table or index). The schema version is used by
danielk1977dae24952004-11-11 05:10:43 +00001269 ** SQLite each time a query is executed to ensure that the internal cache
1270 ** of the schema used when compiling the SQL query matches the schema of
1271 ** the database against which the compiled query is actually executed.
danielk1977b92b70b2004-11-12 16:11:59 +00001272 ** Subverting this mechanism by using "PRAGMA schema_version" to modify
1273 ** the schema-version is potentially dangerous and may lead to program
danielk1977dae24952004-11-11 05:10:43 +00001274 ** crashes or database corruption. Use with caution!
1275 **
danielk1977b92b70b2004-11-12 16:11:59 +00001276 ** The user-version is not used internally by SQLite. It may be used by
danielk1977dae24952004-11-11 05:10:43 +00001277 ** applications for any purpose.
1278 */
danielk1977180b56a2007-06-24 08:00:42 +00001279 if( sqlite3StrICmp(zLeft, "schema_version")==0
1280 || sqlite3StrICmp(zLeft, "user_version")==0
1281 || sqlite3StrICmp(zLeft, "freelist_count")==0
1282 ){
danielk19770d19f7a2009-06-03 11:25:07 +00001283 int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
drhfb982642007-08-30 01:19:59 +00001284 sqlite3VdbeUsesBtree(v, iDb);
danielk1977180b56a2007-06-24 08:00:42 +00001285 switch( zLeft[0] ){
danielk1977180b56a2007-06-24 08:00:42 +00001286 case 'f': case 'F':
danielk19770d19f7a2009-06-03 11:25:07 +00001287 iCookie = BTREE_FREE_PAGE_COUNT;
1288 break;
1289 case 's': case 'S':
1290 iCookie = BTREE_SCHEMA_VERSION;
danielk1977180b56a2007-06-24 08:00:42 +00001291 break;
1292 default:
danielk19770d19f7a2009-06-03 11:25:07 +00001293 iCookie = BTREE_USER_VERSION;
danielk1977180b56a2007-06-24 08:00:42 +00001294 break;
danielk1977dae24952004-11-11 05:10:43 +00001295 }
1296
danielk19770d19f7a2009-06-03 11:25:07 +00001297 if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){
danielk1977dae24952004-11-11 05:10:43 +00001298 /* Write the specified cookie value */
1299 static const VdbeOpList setCookie[] = {
1300 { OP_Transaction, 0, 1, 0}, /* 0 */
drh9cbf3422008-01-17 16:22:13 +00001301 { OP_Integer, 0, 1, 0}, /* 1 */
1302 { OP_SetCookie, 0, 0, 1}, /* 2 */
danielk1977dae24952004-11-11 05:10:43 +00001303 };
1304 int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
1305 sqlite3VdbeChangeP1(v, addr, iDb);
1306 sqlite3VdbeChangeP1(v, addr+1, atoi(zRight));
1307 sqlite3VdbeChangeP1(v, addr+2, iDb);
1308 sqlite3VdbeChangeP2(v, addr+2, iCookie);
1309 }else{
1310 /* Read the specified cookie value */
1311 static const VdbeOpList readCookie[] = {
danielk1977602b4662009-07-02 07:47:33 +00001312 { OP_Transaction, 0, 0, 0}, /* 0 */
1313 { OP_ReadCookie, 0, 1, 0}, /* 1 */
drh2d401ab2008-01-10 23:50:11 +00001314 { OP_ResultRow, 1, 1, 0}
danielk1977dae24952004-11-11 05:10:43 +00001315 };
1316 int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
1317 sqlite3VdbeChangeP1(v, addr, iDb);
danielk1977602b4662009-07-02 07:47:33 +00001318 sqlite3VdbeChangeP1(v, addr+1, iDb);
1319 sqlite3VdbeChangeP3(v, addr+1, iCookie);
danielk1977dae24952004-11-11 05:10:43 +00001320 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +00001321 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
danielk1977dae24952004-11-11 05:10:43 +00001322 }
drh6e345992007-03-30 11:12:08 +00001323 }else
drh13d70422004-11-13 15:59:14 +00001324#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
drhc11d4f92003-04-06 21:08:24 +00001325
dougcurrie81c95ef2004-06-18 23:21:47 +00001326#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
drh89ac8c12004-06-09 14:17:20 +00001327 /*
1328 ** Report the current state of file logs for all databases
1329 */
1330 if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
drh57196282004-10-06 15:41:16 +00001331 static const char *const azLockName[] = {
drh89ac8c12004-06-09 14:17:20 +00001332 "unlocked", "shared", "reserved", "pending", "exclusive"
1333 };
1334 int i;
drh89ac8c12004-06-09 14:17:20 +00001335 sqlite3VdbeSetNumCols(v, 2);
drh2d401ab2008-01-10 23:50:11 +00001336 pParse->nMem = 2;
danielk197710fb7492008-10-31 10:53:22 +00001337 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
1338 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
drh89ac8c12004-06-09 14:17:20 +00001339 for(i=0; i<db->nDb; i++){
1340 Btree *pBt;
1341 Pager *pPager;
drh9e33c2c2007-08-31 18:34:59 +00001342 const char *zState = "unknown";
1343 int j;
drh89ac8c12004-06-09 14:17:20 +00001344 if( db->aDb[i].zName==0 ) continue;
drh2d401ab2008-01-10 23:50:11 +00001345 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
drh89ac8c12004-06-09 14:17:20 +00001346 pBt = db->aDb[i].pBt;
1347 if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
drh9e33c2c2007-08-31 18:34:59 +00001348 zState = "closed";
drhc4dd3fd2008-01-22 01:48:05 +00001349 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
drh9e33c2c2007-08-31 18:34:59 +00001350 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
1351 zState = azLockName[j];
drh89ac8c12004-06-09 14:17:20 +00001352 }
drh2d401ab2008-01-10 23:50:11 +00001353 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
1354 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
drh89ac8c12004-06-09 14:17:20 +00001355 }
danielk1977a4de4532008-09-02 15:44:08 +00001356
drh89ac8c12004-06-09 14:17:20 +00001357 }else
1358#endif
1359
drh3c4f2a42005-12-08 18:12:56 +00001360#if SQLITE_HAS_CODEC
drhd2cb50b2009-01-09 21:41:17 +00001361 if( sqlite3StrICmp(zLeft, "key")==0 && zRight ){
drhea678832008-12-10 19:26:22 +00001362 sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
drh3c4f2a42005-12-08 18:12:56 +00001363 }else
drhd2cb50b2009-01-09 21:41:17 +00001364 if( sqlite3StrICmp(zLeft, "rekey")==0 && zRight ){
1365 sqlite3_rekey(db, zRight, sqlite3Strlen30(zRight));
1366 }else
1367 if( zRight && (sqlite3StrICmp(zLeft, "hexkey")==0 ||
1368 sqlite3StrICmp(zLeft, "hexrekey")==0) ){
1369 int i, h1, h2;
1370 char zKey[40];
1371 for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
1372 h1 += 9*(1&(h1>>6));
1373 h2 += 9*(1&(h2>>6));
1374 zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
1375 }
1376 if( (zLeft[3] & 0xf)==0xb ){
1377 sqlite3_key(db, zKey, i/2);
1378 }else{
1379 sqlite3_rekey(db, zKey, i/2);
1380 }
1381 }else
drh3c4f2a42005-12-08 18:12:56 +00001382#endif
drh21e2cab2006-09-25 18:01:57 +00001383#if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD)
1384 if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){
1385#if SQLITE_HAS_CODEC
1386 if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){
1387 extern void sqlite3_activate_see(const char*);
1388 sqlite3_activate_see(&zRight[4]);
1389 }
1390#endif
1391#ifdef SQLITE_ENABLE_CEROD
1392 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
1393 extern void sqlite3_activate_cerod(const char*);
1394 sqlite3_activate_cerod(&zRight[6]);
1395 }
1396#endif
drhd2cb50b2009-01-09 21:41:17 +00001397 }else
drh21e2cab2006-09-25 18:01:57 +00001398#endif
drh3c4f2a42005-12-08 18:12:56 +00001399
drhd2cb50b2009-01-09 21:41:17 +00001400
1401 {/* Empty ELSE clause */}
danielk1977a21c6b62005-01-24 10:25:59 +00001402
drhd2cb50b2009-01-09 21:41:17 +00001403 /* Code an OP_Expire at the end of each PRAGMA program to cause
1404 ** the VDBE implementing the pragma to expire. Most (all?) pragmas
1405 ** are only valid for a single execution.
1406 */
1407 sqlite3VdbeAddOp2(v, OP_Expire, 1, 0);
drhac530b12006-02-11 01:25:50 +00001408
drhd2cb50b2009-01-09 21:41:17 +00001409 /*
1410 ** Reset the safety level, in case the fullfsync flag or synchronous
1411 ** setting changed.
1412 */
danielk1977ddfb2f02006-02-17 12:25:14 +00001413#ifndef SQLITE_OMIT_PAGER_PRAGMAS
drhd2cb50b2009-01-09 21:41:17 +00001414 if( db->autoCommit ){
1415 sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
1416 (db->flags&SQLITE_FullFSync)!=0);
danielk1977a21c6b62005-01-24 10:25:59 +00001417 }
drhd2cb50b2009-01-09 21:41:17 +00001418#endif
danielk1977e0048402004-06-15 16:51:01 +00001419pragma_out:
drh633e6d52008-07-28 19:34:53 +00001420 sqlite3DbFree(db, zLeft);
1421 sqlite3DbFree(db, zRight);
drhc11d4f92003-04-06 21:08:24 +00001422}
drh13d70422004-11-13 15:59:14 +00001423
drh8bfdf722009-06-19 14:06:03 +00001424#endif /* SQLITE_OMIT_PRAGMA */