blob: bfb84305d0d6ff2de78fbc4cea99e0fcc6170bcc [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**
drh10861722009-04-07 00:49:16 +000014** $Id: pragma.c,v 1.208 2009/04/07 00:49:16 drh 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*/
drh0ccebe72005-06-07 22:22:50 +000020#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
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 },
drh87223182004-02-21 14:00:29 +0000193 };
194 int i;
drh722e95a2004-10-25 20:33:44 +0000195 const struct sPragmaType *p;
danielk197700e13612008-11-17 19:18:54 +0000196 for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
drh722e95a2004-10-25 20:33:44 +0000197 if( sqlite3StrICmp(zLeft, p->zName)==0 ){
drh9bb575f2004-09-06 17:24:11 +0000198 sqlite3 *db = pParse->db;
drh87223182004-02-21 14:00:29 +0000199 Vdbe *v;
danielk1977a21c6b62005-01-24 10:25:59 +0000200 v = sqlite3GetVdbe(pParse);
drhd2cb50b2009-01-09 21:41:17 +0000201 assert( v!=0 ); /* Already allocated by sqlite3Pragma() */
202 if( ALWAYS(v) ){
danielk1977a21c6b62005-01-24 10:25:59 +0000203 if( zRight==0 ){
drh722e95a2004-10-25 20:33:44 +0000204 returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
drhd89bd002005-01-22 03:03:54 +0000205 }else{
danielk1977a21c6b62005-01-24 10:25:59 +0000206 if( getBoolean(zRight) ){
207 db->flags |= p->mask;
208 }else{
209 db->flags &= ~p->mask;
210 }
danielk19778e556522007-11-13 10:30:24 +0000211
212 /* Many of the flag-pragmas modify the code generated by the SQL
213 ** compiler (eg. count_changes). So add an opcode to expire all
214 ** compiled SQL statements after modifying a pragma value.
215 */
drh66a51672008-01-03 00:01:23 +0000216 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
drhd89bd002005-01-22 03:03:54 +0000217 }
drh87223182004-02-21 14:00:29 +0000218 }
danielk19778e556522007-11-13 10:30:24 +0000219
drh87223182004-02-21 14:00:29 +0000220 return 1;
221 }
222 }
223 return 0;
224}
drhbf216272005-02-26 18:10:44 +0000225#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
drh87223182004-02-21 14:00:29 +0000226
drhd2cb50b2009-01-09 21:41:17 +0000227/*
228** Return a human-readable name for a constraint resolution action.
229*/
danielk197750af3e12008-10-10 17:47:21 +0000230static const char *actionName(u8 action){
drhd2cb50b2009-01-09 21:41:17 +0000231 const char *zName;
danielk197750af3e12008-10-10 17:47:21 +0000232 switch( action ){
drhd2cb50b2009-01-09 21:41:17 +0000233 case OE_SetNull: zName = "SET NULL"; break;
234 case OE_SetDflt: zName = "SET DEFAULT"; break;
235 case OE_Cascade: zName = "CASCADE"; break;
236 default: zName = "RESTRICT";
237 assert( action==OE_Restrict ); break;
danielk197750af3e12008-10-10 17:47:21 +0000238 }
drhd2cb50b2009-01-09 21:41:17 +0000239 return zName;
danielk197750af3e12008-10-10 17:47:21 +0000240}
241
drh87223182004-02-21 14:00:29 +0000242/*
drhc11d4f92003-04-06 21:08:24 +0000243** Process a pragma statement.
244**
245** Pragmas are of this form:
246**
danielk197791cf71b2004-06-26 06:37:06 +0000247** PRAGMA [database.]id [= value]
drhc11d4f92003-04-06 21:08:24 +0000248**
249** The identifier might also be a string. The value is a string, and
250** identifier, or a number. If minusFlag is true, then the value is
251** a number that was preceded by a minus sign.
drh90f5ecb2004-07-22 01:19:35 +0000252**
253** If the left side is "database.id" then pId1 is the database name
254** and pId2 is the id. If the left side is just "id" then pId1 is the
255** id and pId2 is any empty string.
drhc11d4f92003-04-06 21:08:24 +0000256*/
danielk197791cf71b2004-06-26 06:37:06 +0000257void sqlite3Pragma(
258 Parse *pParse,
259 Token *pId1, /* First part of [database.]id field */
260 Token *pId2, /* Second part of [database.]id field, or NULL */
261 Token *pValue, /* Token for <value>, or NULL */
262 int minusFlag /* True if a '-' sign preceded <value> */
263){
264 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
265 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
266 const char *zDb = 0; /* The database name */
267 Token *pId; /* Pointer to <id> token */
268 int iDb; /* Database index for <database> */
drh9bb575f2004-09-06 17:24:11 +0000269 sqlite3 *db = pParse->db;
drh90f5ecb2004-07-22 01:19:35 +0000270 Db *pDb;
drh949f9cd2008-01-12 21:35:57 +0000271 Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db);
drhc11d4f92003-04-06 21:08:24 +0000272 if( v==0 ) return;
drh9cbf3422008-01-17 16:22:13 +0000273 pParse->nMem = 2;
drhc11d4f92003-04-06 21:08:24 +0000274
danielk197791cf71b2004-06-26 06:37:06 +0000275 /* Interpret the [database.] part of the pragma statement. iDb is the
276 ** index of the database this pragma is being applied to in db.aDb[]. */
277 iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId);
278 if( iDb<0 ) return;
drh90f5ecb2004-07-22 01:19:35 +0000279 pDb = &db->aDb[iDb];
danielk197791cf71b2004-06-26 06:37:06 +0000280
danielk1977ddfb2f02006-02-17 12:25:14 +0000281 /* If the temp database has been explicitly named as part of the
282 ** pragma, make sure it is open.
283 */
284 if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){
285 return;
286 }
287
drh17435752007-08-16 04:30:38 +0000288 zLeft = sqlite3NameFromToken(db, pId);
danielk197796fb0dd2004-06-30 09:49:22 +0000289 if( !zLeft ) return;
drhc11d4f92003-04-06 21:08:24 +0000290 if( minusFlag ){
drh17435752007-08-16 04:30:38 +0000291 zRight = sqlite3MPrintf(db, "-%T", pValue);
drhc11d4f92003-04-06 21:08:24 +0000292 }else{
drh17435752007-08-16 04:30:38 +0000293 zRight = sqlite3NameFromToken(db, pValue);
drhc11d4f92003-04-06 21:08:24 +0000294 }
danielk197791cf71b2004-06-26 06:37:06 +0000295
drhd2cb50b2009-01-09 21:41:17 +0000296 assert( pId2 );
297 zDb = pId2->n>0 ? pDb->zName : 0;
danielk197791cf71b2004-06-26 06:37:06 +0000298 if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
danielk1977e0048402004-06-15 16:51:01 +0000299 goto pragma_out;
drhc11d4f92003-04-06 21:08:24 +0000300 }
301
drh13d70422004-11-13 15:59:14 +0000302#ifndef SQLITE_OMIT_PAGER_PRAGMAS
drhc11d4f92003-04-06 21:08:24 +0000303 /*
drh90f5ecb2004-07-22 01:19:35 +0000304 ** PRAGMA [database.]default_cache_size
305 ** PRAGMA [database.]default_cache_size=N
drhc11d4f92003-04-06 21:08:24 +0000306 **
307 ** The first form reports the current persistent setting for the
308 ** page cache size. The value returned is the maximum number of
309 ** pages in the page cache. The second form sets both the current
310 ** page cache size value and the persistent page cache size value
311 ** stored in the database file.
312 **
313 ** The default cache size is stored in meta-value 2 of page 1 of the
314 ** database file. The cache size is actually the absolute value of
315 ** this memory location. The sign of meta-value 2 determines the
316 ** synchronous setting. A negative value means synchronous is off
317 ** and a positive value means synchronous is on.
318 */
danielk19774adee202004-05-08 08:23:19 +0000319 if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
drh57196282004-10-06 15:41:16 +0000320 static const VdbeOpList getCacheSize[] = {
drh3c84ddf2008-01-09 02:15:38 +0000321 { OP_ReadCookie, 0, 1, 2}, /* 0 */
322 { OP_IfPos, 1, 6, 0},
323 { OP_Integer, 0, 2, 0},
324 { OP_Subtract, 1, 2, 1},
325 { OP_IfPos, 1, 6, 0},
326 { OP_Integer, 0, 1, 0}, /* 5 */
327 { OP_ResultRow, 1, 1, 0},
drhc11d4f92003-04-06 21:08:24 +0000328 };
drh905793e2004-02-21 13:31:09 +0000329 int addr;
danielk19778a414492004-06-29 08:59:35 +0000330 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drhfb982642007-08-30 01:19:59 +0000331 sqlite3VdbeUsesBtree(v, iDb);
danielk197791cf71b2004-06-26 06:37:06 +0000332 if( !zRight ){
danielk197722322fd2004-05-25 23:35:17 +0000333 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +0000334 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
drh3c84ddf2008-01-09 02:15:38 +0000335 pParse->nMem += 2;
danielk19774adee202004-05-08 08:23:19 +0000336 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
danielk197791cf71b2004-06-26 06:37:06 +0000337 sqlite3VdbeChangeP1(v, addr, iDb);
drhc797d4d2007-05-08 01:08:49 +0000338 sqlite3VdbeChangeP1(v, addr+5, SQLITE_DEFAULT_CACHE_SIZE);
drhc11d4f92003-04-06 21:08:24 +0000339 }else{
drhc11d4f92003-04-06 21:08:24 +0000340 int size = atoi(zRight);
341 if( size<0 ) size = -size;
danielk197791cf71b2004-06-26 06:37:06 +0000342 sqlite3BeginWriteOperation(pParse, 0, iDb);
drh9cbf3422008-01-17 16:22:13 +0000343 sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
344 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, 2, 2);
345 addr = sqlite3VdbeAddOp2(v, OP_IfPos, 2, 0);
346 sqlite3VdbeAddOp2(v, OP_Integer, -size, 1);
drh3c84ddf2008-01-09 02:15:38 +0000347 sqlite3VdbeJumpHere(v, addr);
drh9cbf3422008-01-17 16:22:13 +0000348 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, 2, 1);
danielk197714db2662006-01-09 16:12:04 +0000349 pDb->pSchema->cache_size = size;
350 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
drhc11d4f92003-04-06 21:08:24 +0000351 }
352 }else
353
354 /*
drh90f5ecb2004-07-22 01:19:35 +0000355 ** PRAGMA [database.]page_size
356 ** PRAGMA [database.]page_size=N
357 **
358 ** The first form reports the current setting for the
359 ** database page size in bytes. The second form sets the
360 ** database page size value. The value can only be set if
361 ** the database has not yet been created.
362 */
363 if( sqlite3StrICmp(zLeft,"page_size")==0 ){
364 Btree *pBt = pDb->pBt;
drhd2cb50b2009-01-09 21:41:17 +0000365 assert( pBt!=0 );
drh90f5ecb2004-07-22 01:19:35 +0000366 if( !zRight ){
drhd2cb50b2009-01-09 21:41:17 +0000367 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
drh5bb7ffe2004-09-02 15:14:00 +0000368 returnSingleInt(pParse, "page_size", size);
drh90f5ecb2004-07-22 01:19:35 +0000369 }else{
danielk1977992772c2007-08-30 10:07:38 +0000370 /* Malloc may fail when setting the page-size, as there is an internal
371 ** buffer that the pager module resizes using sqlite3_realloc().
372 */
danielk1977f653d782008-03-20 11:04:21 +0000373 db->nextPagesize = atoi(zRight);
drhce4869f2009-04-02 20:16:58 +0000374 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
danielk1977992772c2007-08-30 10:07:38 +0000375 db->mallocFailed = 1;
376 }
drh90f5ecb2004-07-22 01:19:35 +0000377 }
378 }else
danielk197741483462007-03-24 16:45:04 +0000379
380 /*
drhf8e632b2007-05-08 14:51:36 +0000381 ** PRAGMA [database.]max_page_count
382 ** PRAGMA [database.]max_page_count=N
383 **
384 ** The first form reports the current setting for the
385 ** maximum number of pages in the database file. The
386 ** second form attempts to change this setting. Both
387 ** forms return the current setting.
388 */
389 if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
390 Btree *pBt = pDb->pBt;
391 int newMax = 0;
drhd2cb50b2009-01-09 21:41:17 +0000392 assert( pBt!=0 );
drhf8e632b2007-05-08 14:51:36 +0000393 if( zRight ){
394 newMax = atoi(zRight);
395 }
drhd2cb50b2009-01-09 21:41:17 +0000396 if( ALWAYS(pBt) ){
drhf8e632b2007-05-08 14:51:36 +0000397 newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
398 }
399 returnSingleInt(pParse, "max_page_count", newMax);
400 }else
401
402 /*
danielk197759a93792008-05-15 17:48:20 +0000403 ** PRAGMA [database.]page_count
404 **
405 ** Return the number of pages in the specified database.
406 */
407 if( sqlite3StrICmp(zLeft,"page_count")==0 ){
danielk197759a93792008-05-15 17:48:20 +0000408 int iReg;
drhd2cb50b2009-01-09 21:41:17 +0000409 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
danielk197759a93792008-05-15 17:48:20 +0000410 sqlite3CodeVerifySchema(pParse, iDb);
411 iReg = ++pParse->nMem;
412 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
413 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
414 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +0000415 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", SQLITE_STATIC);
danielk197759a93792008-05-15 17:48:20 +0000416 }else
417
418 /*
danielk197741483462007-03-24 16:45:04 +0000419 ** PRAGMA [database.]locking_mode
420 ** PRAGMA [database.]locking_mode = (normal|exclusive)
421 */
422 if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){
423 const char *zRet = "normal";
424 int eMode = getLockingMode(zRight);
425
426 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
427 /* Simple "PRAGMA locking_mode;" statement. This is a query for
428 ** the current default locking mode (which may be different to
429 ** the locking-mode of the main database).
430 */
431 eMode = db->dfltLockMode;
432 }else{
433 Pager *pPager;
434 if( pId2->n==0 ){
435 /* This indicates that no database name was specified as part
436 ** of the PRAGMA command. In this case the locking-mode must be
437 ** set on all attached databases, as well as the main db file.
438 **
439 ** Also, the sqlite3.dfltLockMode variable is set so that
440 ** any subsequently attached databases also use the specified
441 ** locking mode.
442 */
443 int ii;
444 assert(pDb==&db->aDb[0]);
445 for(ii=2; ii<db->nDb; ii++){
446 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
447 sqlite3PagerLockingMode(pPager, eMode);
448 }
drh4f21c4a2008-12-10 22:15:00 +0000449 db->dfltLockMode = (u8)eMode;
danielk197741483462007-03-24 16:45:04 +0000450 }
451 pPager = sqlite3BtreePager(pDb->pBt);
452 eMode = sqlite3PagerLockingMode(pPager, eMode);
453 }
454
455 assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE);
456 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
457 zRet = "exclusive";
458 }
459 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +0000460 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
drh2d401ab2008-01-10 23:50:11 +0000461 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
462 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
danielk197741483462007-03-24 16:45:04 +0000463 }else
drh3b020132008-04-17 17:02:01 +0000464
465 /*
466 ** PRAGMA [database.]journal_mode
shanec782f692008-11-10 19:24:38 +0000467 ** PRAGMA [database.]journal_mode = (delete|persist|off|truncate|memory)
drh3b020132008-04-17 17:02:01 +0000468 */
469 if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
470 int eMode;
danielk1977b3175382008-10-17 18:51:52 +0000471 static char * const azModeName[] = {
472 "delete", "persist", "off", "truncate", "memory"
473 };
drh3b020132008-04-17 17:02:01 +0000474
475 if( zRight==0 ){
476 eMode = PAGER_JOURNALMODE_QUERY;
477 }else{
drhea678832008-12-10 19:26:22 +0000478 int n = sqlite3Strlen30(zRight);
drh04335882008-09-26 21:08:08 +0000479 eMode = sizeof(azModeName)/sizeof(azModeName[0]) - 1;
drh3b020132008-04-17 17:02:01 +0000480 while( eMode>=0 && sqlite3StrNICmp(zRight, azModeName[eMode], n)!=0 ){
481 eMode--;
482 }
483 }
484 if( pId2->n==0 && eMode==PAGER_JOURNALMODE_QUERY ){
danielk1977b53e4962008-06-04 06:45:59 +0000485 /* Simple "PRAGMA journal_mode;" statement. This is a query for
drh3b020132008-04-17 17:02:01 +0000486 ** the current default journal mode (which may be different to
487 ** the journal-mode of the main database).
488 */
489 eMode = db->dfltJournalMode;
490 }else{
491 Pager *pPager;
492 if( pId2->n==0 ){
493 /* This indicates that no database name was specified as part
494 ** of the PRAGMA command. In this case the journal-mode must be
495 ** set on all attached databases, as well as the main db file.
496 **
497 ** Also, the sqlite3.dfltJournalMode variable is set so that
498 ** any subsequently attached databases also use the specified
499 ** journal mode.
500 */
501 int ii;
502 assert(pDb==&db->aDb[0]);
drhfdc40e92008-04-17 20:59:37 +0000503 for(ii=1; ii<db->nDb; ii++){
504 if( db->aDb[ii].pBt ){
505 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
506 sqlite3PagerJournalMode(pPager, eMode);
507 }
drh3b020132008-04-17 17:02:01 +0000508 }
drh4f21c4a2008-12-10 22:15:00 +0000509 db->dfltJournalMode = (u8)eMode;
drh3b020132008-04-17 17:02:01 +0000510 }
511 pPager = sqlite3BtreePager(pDb->pBt);
512 eMode = sqlite3PagerJournalMode(pPager, eMode);
513 }
514 assert( eMode==PAGER_JOURNALMODE_DELETE
drh04335882008-09-26 21:08:08 +0000515 || eMode==PAGER_JOURNALMODE_TRUNCATE
drh3b020132008-04-17 17:02:01 +0000516 || eMode==PAGER_JOURNALMODE_PERSIST
danielk1977b3175382008-10-17 18:51:52 +0000517 || eMode==PAGER_JOURNALMODE_OFF
518 || eMode==PAGER_JOURNALMODE_MEMORY );
drh3b020132008-04-17 17:02:01 +0000519 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +0000520 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
drh3b020132008-04-17 17:02:01 +0000521 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0,
522 azModeName[eMode], P4_STATIC);
523 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
524 }else
danielk1977b53e4962008-06-04 06:45:59 +0000525
526 /*
527 ** PRAGMA [database.]journal_size_limit
528 ** PRAGMA [database.]journal_size_limit=N
529 **
drha9e364f2009-01-13 20:14:15 +0000530 ** Get or set the size limit on rollback journal files.
danielk1977b53e4962008-06-04 06:45:59 +0000531 */
532 if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){
533 Pager *pPager = sqlite3BtreePager(pDb->pBt);
534 i64 iLimit = -2;
535 if( zRight ){
drh3c713642009-04-04 16:02:32 +0000536 sqlite3Atoi64(zRight, &iLimit);
537 if( iLimit<-1 ) iLimit = -1;
danielk1977b53e4962008-06-04 06:45:59 +0000538 }
539 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
drh3c713642009-04-04 16:02:32 +0000540 returnSingleInt(pParse, "journal_size_limit", iLimit);
danielk1977b53e4962008-06-04 06:45:59 +0000541 }else
542
drh13d70422004-11-13 15:59:14 +0000543#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
drh90f5ecb2004-07-22 01:19:35 +0000544
545 /*
danielk1977951af802004-11-05 15:45:09 +0000546 ** PRAGMA [database.]auto_vacuum
547 ** PRAGMA [database.]auto_vacuum=N
548 **
drha9e364f2009-01-13 20:14:15 +0000549 ** Get or set the value of the database 'auto-vacuum' parameter.
550 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
danielk1977951af802004-11-05 15:45:09 +0000551 */
552#ifndef SQLITE_OMIT_AUTOVACUUM
553 if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
554 Btree *pBt = pDb->pBt;
drhd2cb50b2009-01-09 21:41:17 +0000555 assert( pBt!=0 );
danielk197727b1f952007-06-25 08:16:58 +0000556 if( sqlite3ReadSchema(pParse) ){
557 goto pragma_out;
558 }
danielk1977951af802004-11-05 15:45:09 +0000559 if( !zRight ){
drhd2cb50b2009-01-09 21:41:17 +0000560 int auto_vacuum;
561 if( ALWAYS(pBt) ){
562 auto_vacuum = sqlite3BtreeGetAutoVacuum(pBt);
563 }else{
564 auto_vacuum = SQLITE_DEFAULT_AUTOVACUUM;
565 }
danielk1977951af802004-11-05 15:45:09 +0000566 returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
567 }else{
danielk1977dddbcdc2007-04-26 14:42:34 +0000568 int eAuto = getAutoVacuum(zRight);
drhd2cb50b2009-01-09 21:41:17 +0000569 assert( eAuto>=0 && eAuto<=2 );
drh4f21c4a2008-12-10 22:15:00 +0000570 db->nextAutovac = (u8)eAuto;
drhd2cb50b2009-01-09 21:41:17 +0000571 if( ALWAYS(eAuto>=0) ){
danielk197727b1f952007-06-25 08:16:58 +0000572 /* Call SetAutoVacuum() to set initialize the internal auto and
573 ** incr-vacuum flags. This is required in case this connection
574 ** creates the database file. It is important that it is created
575 ** as an auto-vacuum capable db.
576 */
577 int rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
578 if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){
579 /* When setting the auto_vacuum mode to either "full" or
580 ** "incremental", write the value of meta[6] in the database
581 ** file. Before writing to meta[6], check that meta[3] indicates
582 ** that this really is an auto-vacuum capable database.
583 */
584 static const VdbeOpList setMeta6[] = {
585 { OP_Transaction, 0, 1, 0}, /* 0 */
drh1db639c2008-01-17 02:36:28 +0000586 { OP_ReadCookie, 0, 1, 3}, /* 1 */
587 { OP_If, 1, 0, 0}, /* 2 */
danielk197727b1f952007-06-25 08:16:58 +0000588 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
drh1db639c2008-01-17 02:36:28 +0000589 { OP_Integer, 0, 1, 0}, /* 4 */
590 { OP_SetCookie, 0, 6, 1}, /* 5 */
danielk197727b1f952007-06-25 08:16:58 +0000591 };
592 int iAddr;
593 iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);
594 sqlite3VdbeChangeP1(v, iAddr, iDb);
595 sqlite3VdbeChangeP1(v, iAddr+1, iDb);
596 sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
597 sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
598 sqlite3VdbeChangeP1(v, iAddr+5, iDb);
drhfb982642007-08-30 01:19:59 +0000599 sqlite3VdbeUsesBtree(v, iDb);
danielk197727b1f952007-06-25 08:16:58 +0000600 }
danielk1977dddbcdc2007-04-26 14:42:34 +0000601 }
danielk1977951af802004-11-05 15:45:09 +0000602 }
603 }else
604#endif
605
drhca5557f2007-05-04 18:30:40 +0000606 /*
607 ** PRAGMA [database.]incremental_vacuum(N)
608 **
609 ** Do N steps of incremental vacuuming on a database.
610 */
611#ifndef SQLITE_OMIT_AUTOVACUUM
612 if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){
613 int iLimit, addr;
danielk197717a240a2007-05-23 13:50:23 +0000614 if( sqlite3ReadSchema(pParse) ){
615 goto pragma_out;
616 }
drhca5557f2007-05-04 18:30:40 +0000617 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
618 iLimit = 0x7fffffff;
619 }
620 sqlite3BeginWriteOperation(pParse, 0, iDb);
drh4c583122008-01-04 22:01:03 +0000621 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
drh3c84ddf2008-01-09 02:15:38 +0000622 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
drh2d401ab2008-01-10 23:50:11 +0000623 sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
drh8558cde2008-01-05 05:20:10 +0000624 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
drh3c84ddf2008-01-09 02:15:38 +0000625 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
drhca5557f2007-05-04 18:30:40 +0000626 sqlite3VdbeJumpHere(v, addr);
627 }else
628#endif
629
drh13d70422004-11-13 15:59:14 +0000630#ifndef SQLITE_OMIT_PAGER_PRAGMAS
danielk1977951af802004-11-05 15:45:09 +0000631 /*
drh90f5ecb2004-07-22 01:19:35 +0000632 ** PRAGMA [database.]cache_size
633 ** PRAGMA [database.]cache_size=N
drhc11d4f92003-04-06 21:08:24 +0000634 **
635 ** The first form reports the current local setting for the
636 ** page cache size. The local setting can be different from
637 ** the persistent cache size value that is stored in the database
638 ** file itself. The value returned is the maximum number of
639 ** pages in the page cache. The second form sets the local
640 ** page cache size value. It does not change the persistent
641 ** cache size stored on the disk so the cache size will revert
642 ** to its default value when the database is closed and reopened.
643 ** N should be a positive integer.
644 */
danielk19774adee202004-05-08 08:23:19 +0000645 if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
danielk19778a414492004-06-29 08:59:35 +0000646 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
danielk197791cf71b2004-06-26 06:37:06 +0000647 if( !zRight ){
danielk197714db2662006-01-09 16:12:04 +0000648 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
drhc11d4f92003-04-06 21:08:24 +0000649 }else{
650 int size = atoi(zRight);
651 if( size<0 ) size = -size;
danielk197714db2662006-01-09 16:12:04 +0000652 pDb->pSchema->cache_size = size;
653 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
drhc11d4f92003-04-06 21:08:24 +0000654 }
655 }else
656
657 /*
drh90f5ecb2004-07-22 01:19:35 +0000658 ** PRAGMA temp_store
659 ** PRAGMA temp_store = "default"|"memory"|"file"
660 **
661 ** Return or set the local value of the temp_store flag. Changing
662 ** the local value does not make changes to the disk file and the default
663 ** value will be restored the next time the database is opened.
664 **
665 ** Note that it is possible for the library compile-time options to
666 ** override this setting
667 */
668 if( sqlite3StrICmp(zLeft, "temp_store")==0 ){
669 if( !zRight ){
drh5bb7ffe2004-09-02 15:14:00 +0000670 returnSingleInt(pParse, "temp_store", db->temp_store);
drh90f5ecb2004-07-22 01:19:35 +0000671 }else{
672 changeTempStorage(pParse, zRight);
673 }
674 }else
675
676 /*
tpoindex9a09a3c2004-12-20 19:01:32 +0000677 ** PRAGMA temp_store_directory
678 ** PRAGMA temp_store_directory = ""|"directory_name"
679 **
680 ** Return or set the local value of the temp_store_directory flag. Changing
681 ** the value sets a specific directory to be used for temporary files.
682 ** Setting to a null string reverts to the default temporary directory search.
683 ** If temporary directory is changed, then invalidateTempStorage.
684 **
685 */
686 if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
687 if( !zRight ){
688 if( sqlite3_temp_directory ){
689 sqlite3VdbeSetNumCols(v, 1);
danielk1977955de522006-02-10 02:27:42 +0000690 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
danielk197710fb7492008-10-31 10:53:22 +0000691 "temp_store_directory", SQLITE_STATIC);
drh2d401ab2008-01-10 23:50:11 +0000692 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
693 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
tpoindex9a09a3c2004-12-20 19:01:32 +0000694 }
695 }else{
drh78f82d12008-09-02 00:52:52 +0000696#ifndef SQLITE_OMIT_WSD
danielk1977861f7452008-06-05 11:39:11 +0000697 if( zRight[0] ){
danielk1977fab11272008-09-16 14:38:02 +0000698 int rc;
danielk1977861f7452008-06-05 11:39:11 +0000699 int res;
danielk1977fab11272008-09-16 14:38:02 +0000700 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
701 if( rc!=SQLITE_OK || res==0 ){
danielk1977861f7452008-06-05 11:39:11 +0000702 sqlite3ErrorMsg(pParse, "not a writable directory");
703 goto pragma_out;
704 }
drh268283b2005-01-08 15:44:25 +0000705 }
danielk1977b06a0b62008-06-26 10:54:12 +0000706 if( SQLITE_TEMP_STORE==0
707 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
708 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
drh268283b2005-01-08 15:44:25 +0000709 ){
710 invalidateTempStorage(pParse);
711 }
drh17435752007-08-16 04:30:38 +0000712 sqlite3_free(sqlite3_temp_directory);
drh268283b2005-01-08 15:44:25 +0000713 if( zRight[0] ){
drh633e6d52008-07-28 19:34:53 +0000714 sqlite3_temp_directory = sqlite3DbStrDup(0, zRight);
tpoindex9a09a3c2004-12-20 19:01:32 +0000715 }else{
drh268283b2005-01-08 15:44:25 +0000716 sqlite3_temp_directory = 0;
tpoindex9a09a3c2004-12-20 19:01:32 +0000717 }
drh78f82d12008-09-02 00:52:52 +0000718#endif /* SQLITE_OMIT_WSD */
tpoindex9a09a3c2004-12-20 19:01:32 +0000719 }
720 }else
721
drhd2cb50b2009-01-09 21:41:17 +0000722#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
723# if defined(__APPLE__)
724# define SQLITE_ENABLE_LOCKING_STYLE 1
725# else
726# define SQLITE_ENABLE_LOCKING_STYLE 0
727# endif
728#endif
729#if SQLITE_ENABLE_LOCKING_STYLE
tpoindex9a09a3c2004-12-20 19:01:32 +0000730 /*
aswiftaebf4132008-11-21 00:10:35 +0000731 ** PRAGMA [database.]lock_proxy_file
732 ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
733 **
734 ** Return or set the value of the lock_proxy_file flag. Changing
735 ** the value sets a specific file to be used for database access locks.
736 **
737 */
738 if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){
739 if( !zRight ){
740 Pager *pPager = sqlite3BtreePager(pDb->pBt);
741 char *proxy_file_path = NULL;
742 sqlite3_file *pFile = sqlite3PagerFile(pPager);
743 sqlite3OsFileControl(pFile, SQLITE_GET_LOCKPROXYFILE,
744 &proxy_file_path);
745
746 if( proxy_file_path ){
747 sqlite3VdbeSetNumCols(v, 1);
748 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
749 "lock_proxy_file", SQLITE_STATIC);
750 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0);
751 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
752 }
753 }else{
754 Pager *pPager = sqlite3BtreePager(pDb->pBt);
755 sqlite3_file *pFile = sqlite3PagerFile(pPager);
756 int res;
757 if( zRight[0] ){
758 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
759 zRight);
760 } else {
761 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
762 NULL);
763 }
764 if( res!=SQLITE_OK ){
765 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
766 goto pragma_out;
767 }
768 }
769 }else
drhd2cb50b2009-01-09 21:41:17 +0000770#endif /* SQLITE_ENABLE_LOCKING_STYLE */
aswiftaebf4132008-11-21 00:10:35 +0000771
772 /*
drh90f5ecb2004-07-22 01:19:35 +0000773 ** PRAGMA [database.]synchronous
774 ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
drhc11d4f92003-04-06 21:08:24 +0000775 **
776 ** Return or set the local value of the synchronous flag. Changing
777 ** the local value does not make changes to the disk file and the
778 ** default value will be restored the next time the database is
779 ** opened.
780 */
danielk19774adee202004-05-08 08:23:19 +0000781 if( sqlite3StrICmp(zLeft,"synchronous")==0 ){
danielk19778a414492004-06-29 08:59:35 +0000782 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
danielk197791cf71b2004-06-26 06:37:06 +0000783 if( !zRight ){
drh5bb7ffe2004-09-02 15:14:00 +0000784 returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
drhc11d4f92003-04-06 21:08:24 +0000785 }else{
danielk197791cf71b2004-06-26 06:37:06 +0000786 if( !db->autoCommit ){
787 sqlite3ErrorMsg(pParse,
788 "Safety level may not be changed inside a transaction");
789 }else{
drh90f5ecb2004-07-22 01:19:35 +0000790 pDb->safety_level = getSafetyLevel(zRight)+1;
danielk197791cf71b2004-06-26 06:37:06 +0000791 }
drhc11d4f92003-04-06 21:08:24 +0000792 }
793 }else
drh13d70422004-11-13 15:59:14 +0000794#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
drhc11d4f92003-04-06 21:08:24 +0000795
drhbf216272005-02-26 18:10:44 +0000796#ifndef SQLITE_OMIT_FLAG_PRAGMAS
drh87223182004-02-21 14:00:29 +0000797 if( flagPragma(pParse, zLeft, zRight) ){
drh90f5ecb2004-07-22 01:19:35 +0000798 /* The flagPragma() subroutine also generates any necessary code
799 ** there is nothing more to do here */
drhc11d4f92003-04-06 21:08:24 +0000800 }else
drhbf216272005-02-26 18:10:44 +0000801#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
drhc11d4f92003-04-06 21:08:24 +0000802
drh13d70422004-11-13 15:59:14 +0000803#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
danielk197791cf71b2004-06-26 06:37:06 +0000804 /*
805 ** PRAGMA table_info(<table>)
806 **
807 ** Return a single row for each column of the named table. The columns of
808 ** the returned data set are:
809 **
810 ** cid: Column id (numbered from left to right, starting at 0)
811 ** name: Column name
812 ** type: Column declaration type.
813 ** notnull: True if 'NOT NULL' is part of column declaration
814 ** dflt_value: The default value for the column, if any.
815 */
drh5260f7e2004-06-26 19:35:29 +0000816 if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
drhc11d4f92003-04-06 21:08:24 +0000817 Table *pTab;
danielk19778a414492004-06-29 08:59:35 +0000818 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drh2783e4b2004-10-05 15:42:53 +0000819 pTab = sqlite3FindTable(db, zRight, zDb);
drhc11d4f92003-04-06 21:08:24 +0000820 if( pTab ){
drhc11d4f92003-04-06 21:08:24 +0000821 int i;
danielk1977034ca142007-06-26 10:38:54 +0000822 int nHidden = 0;
drhf7eece62006-02-06 21:34:27 +0000823 Column *pCol;
drh9f6696a2006-02-09 16:52:23 +0000824 sqlite3VdbeSetNumCols(v, 6);
drh2d401ab2008-01-10 23:50:11 +0000825 pParse->nMem = 6;
danielk197710fb7492008-10-31 10:53:22 +0000826 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
827 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
828 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
829 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
830 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
831 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
danielk19774adee202004-05-08 08:23:19 +0000832 sqlite3ViewGetColumnNames(pParse, pTab);
drhf7eece62006-02-06 21:34:27 +0000833 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
danielk1977034ca142007-06-26 10:38:54 +0000834 if( IsHiddenColumn(pCol) ){
835 nHidden++;
836 continue;
837 }
drh2d401ab2008-01-10 23:50:11 +0000838 sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
839 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
840 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
drhbfa8b102006-03-03 21:20:16 +0000841 pCol->zType ? pCol->zType : "", 0);
danielk1977f96a3772008-10-23 05:45:07 +0000842 sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
drhd2cb50b2009-01-09 21:41:17 +0000843 if( pCol->pDflt ){
danielk19776ab3a2e2009-02-19 14:39:25 +0000844 const Token *p = &pCol->pDflt->span;
845 assert( p->z );
846 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)p->z, p->n);
drh6f835982006-09-25 13:48:30 +0000847 }else{
drh2d401ab2008-01-10 23:50:11 +0000848 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
drh6f835982006-09-25 13:48:30 +0000849 }
drh2d401ab2008-01-10 23:50:11 +0000850 sqlite3VdbeAddOp2(v, OP_Integer, pCol->isPrimKey, 6);
851 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
drhc11d4f92003-04-06 21:08:24 +0000852 }
853 }
854 }else
855
drh5260f7e2004-06-26 19:35:29 +0000856 if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
drhc11d4f92003-04-06 21:08:24 +0000857 Index *pIdx;
858 Table *pTab;
danielk19778a414492004-06-29 08:59:35 +0000859 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drh2783e4b2004-10-05 15:42:53 +0000860 pIdx = sqlite3FindIndex(db, zRight, zDb);
drhc11d4f92003-04-06 21:08:24 +0000861 if( pIdx ){
drhc11d4f92003-04-06 21:08:24 +0000862 int i;
863 pTab = pIdx->pTable;
danielk197722322fd2004-05-25 23:35:17 +0000864 sqlite3VdbeSetNumCols(v, 3);
drh2d401ab2008-01-10 23:50:11 +0000865 pParse->nMem = 3;
danielk197710fb7492008-10-31 10:53:22 +0000866 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
867 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
868 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
drhc11d4f92003-04-06 21:08:24 +0000869 for(i=0; i<pIdx->nColumn; i++){
870 int cnum = pIdx->aiColumn[i];
drh2d401ab2008-01-10 23:50:11 +0000871 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
872 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
drhc11d4f92003-04-06 21:08:24 +0000873 assert( pTab->nCol>cnum );
drh2d401ab2008-01-10 23:50:11 +0000874 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
875 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
drhc11d4f92003-04-06 21:08:24 +0000876 }
877 }
878 }else
879
drh5260f7e2004-06-26 19:35:29 +0000880 if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){
drhc11d4f92003-04-06 21:08:24 +0000881 Index *pIdx;
882 Table *pTab;
danielk19778a414492004-06-29 08:59:35 +0000883 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drh2783e4b2004-10-05 15:42:53 +0000884 pTab = sqlite3FindTable(db, zRight, zDb);
drhc11d4f92003-04-06 21:08:24 +0000885 if( pTab ){
danielk19774adee202004-05-08 08:23:19 +0000886 v = sqlite3GetVdbe(pParse);
drhc11d4f92003-04-06 21:08:24 +0000887 pIdx = pTab->pIndex;
danielk1977742f9472004-06-16 12:02:43 +0000888 if( pIdx ){
889 int i = 0;
890 sqlite3VdbeSetNumCols(v, 3);
drh2d401ab2008-01-10 23:50:11 +0000891 pParse->nMem = 3;
danielk197710fb7492008-10-31 10:53:22 +0000892 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
893 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
894 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
danielk1977742f9472004-06-16 12:02:43 +0000895 while(pIdx){
drh2d401ab2008-01-10 23:50:11 +0000896 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
897 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
898 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3);
899 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
danielk1977742f9472004-06-16 12:02:43 +0000900 ++i;
901 pIdx = pIdx->pNext;
902 }
drhc11d4f92003-04-06 21:08:24 +0000903 }
904 }
905 }else
906
drh13d70422004-11-13 15:59:14 +0000907 if( sqlite3StrICmp(zLeft, "database_list")==0 ){
908 int i;
909 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
910 sqlite3VdbeSetNumCols(v, 3);
drh2d401ab2008-01-10 23:50:11 +0000911 pParse->nMem = 3;
danielk197710fb7492008-10-31 10:53:22 +0000912 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
913 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
914 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
drh13d70422004-11-13 15:59:14 +0000915 for(i=0; i<db->nDb; i++){
916 if( db->aDb[i].pBt==0 ) continue;
917 assert( db->aDb[i].zName!=0 );
drh2d401ab2008-01-10 23:50:11 +0000918 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
919 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
920 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
drh13d70422004-11-13 15:59:14 +0000921 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
drh2d401ab2008-01-10 23:50:11 +0000922 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
drh13d70422004-11-13 15:59:14 +0000923 }
924 }else
danielk197748af65a2005-02-09 03:20:37 +0000925
926 if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
927 int i = 0;
928 HashElem *p;
929 sqlite3VdbeSetNumCols(v, 2);
drh2d401ab2008-01-10 23:50:11 +0000930 pParse->nMem = 2;
danielk197710fb7492008-10-31 10:53:22 +0000931 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
932 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
danielk197748af65a2005-02-09 03:20:37 +0000933 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
934 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
drh2d401ab2008-01-10 23:50:11 +0000935 sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
936 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
937 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
danielk197748af65a2005-02-09 03:20:37 +0000938 }
939 }else
drh13d70422004-11-13 15:59:14 +0000940#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
941
drhb7f91642004-10-31 02:22:47 +0000942#ifndef SQLITE_OMIT_FOREIGN_KEY
drh5260f7e2004-06-26 19:35:29 +0000943 if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
drh78100cc2003-08-23 22:40:53 +0000944 FKey *pFK;
945 Table *pTab;
danielk19778a414492004-06-29 08:59:35 +0000946 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drh2783e4b2004-10-05 15:42:53 +0000947 pTab = sqlite3FindTable(db, zRight, zDb);
drh78100cc2003-08-23 22:40:53 +0000948 if( pTab ){
danielk19774adee202004-05-08 08:23:19 +0000949 v = sqlite3GetVdbe(pParse);
drh78100cc2003-08-23 22:40:53 +0000950 pFK = pTab->pFKey;
danielk1977742f9472004-06-16 12:02:43 +0000951 if( pFK ){
952 int i = 0;
danielk197750af3e12008-10-10 17:47:21 +0000953 sqlite3VdbeSetNumCols(v, 8);
954 pParse->nMem = 8;
danielk197710fb7492008-10-31 10:53:22 +0000955 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC);
956 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
957 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
958 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
959 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
960 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
961 sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
962 sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
danielk1977742f9472004-06-16 12:02:43 +0000963 while(pFK){
964 int j;
965 for(j=0; j<pFK->nCol; j++){
drh2f471492005-06-23 03:15:07 +0000966 char *zCol = pFK->aCol[j].zCol;
danielk197750af3e12008-10-10 17:47:21 +0000967 char *zOnUpdate = (char *)actionName(pFK->updateConf);
968 char *zOnDelete = (char *)actionName(pFK->deleteConf);
drh2d401ab2008-01-10 23:50:11 +0000969 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
970 sqlite3VdbeAddOp2(v, OP_Integer, j, 2);
971 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0);
972 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
drh66a51672008-01-03 00:01:23 +0000973 pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
drh2d401ab2008-01-10 23:50:11 +0000974 sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0);
danielk197750af3e12008-10-10 17:47:21 +0000975 sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0);
976 sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0);
977 sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0);
978 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
danielk1977742f9472004-06-16 12:02:43 +0000979 }
980 ++i;
981 pFK = pFK->pNextFrom;
drh78100cc2003-08-23 22:40:53 +0000982 }
drh78100cc2003-08-23 22:40:53 +0000983 }
984 }
985 }else
drhb7f91642004-10-31 02:22:47 +0000986#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
drh78100cc2003-08-23 22:40:53 +0000987
drhc11d4f92003-04-06 21:08:24 +0000988#ifndef NDEBUG
danielk19774adee202004-05-08 08:23:19 +0000989 if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
drh55ef4d92005-08-14 01:20:37 +0000990 if( zRight ){
991 if( getBoolean(zRight) ){
992 sqlite3ParserTrace(stderr, "parser: ");
993 }else{
994 sqlite3ParserTrace(0, 0);
995 }
drhc11d4f92003-04-06 21:08:24 +0000996 }
997 }else
998#endif
999
drh55ef4d92005-08-14 01:20:37 +00001000 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
1001 ** used will be case sensitive or not depending on the RHS.
1002 */
1003 if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
1004 if( zRight ){
1005 sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
1006 }
1007 }else
1008
drh1dcdbc02007-01-27 02:24:54 +00001009#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
1010# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
1011#endif
1012
drhb7f91642004-10-31 02:22:47 +00001013#ifndef SQLITE_OMIT_INTEGRITY_CHECK
danielk197741c58b72007-12-29 13:39:19 +00001014 /* Pragma "quick_check" is an experimental reduced version of
1015 ** integrity_check designed to detect most database corruption
1016 ** without most of the overhead of a full integrity-check.
1017 */
1018 if( sqlite3StrICmp(zLeft, "integrity_check")==0
1019 || sqlite3StrICmp(zLeft, "quick_check")==0
1020 ){
drh1dcdbc02007-01-27 02:24:54 +00001021 int i, j, addr, mxErr;
drhed717fe2003-06-15 23:42:24 +00001022
drhed717fe2003-06-15 23:42:24 +00001023 /* Code that appears at the end of the integrity check. If no error
1024 ** messages have been generated, output OK. Otherwise output the
1025 ** error message
1026 */
drh57196282004-10-06 15:41:16 +00001027 static const VdbeOpList endCode[] = {
drh2d401ab2008-01-10 23:50:11 +00001028 { OP_AddImm, 1, 0, 0}, /* 0 */
1029 { OP_IfNeg, 1, 0, 0}, /* 1 */
1030 { OP_String8, 0, 3, 0}, /* 2 */
1031 { OP_ResultRow, 3, 1, 0},
drhc11d4f92003-04-06 21:08:24 +00001032 };
drhed717fe2003-06-15 23:42:24 +00001033
danielk197741c58b72007-12-29 13:39:19 +00001034 int isQuick = (zLeft[0]=='q');
1035
drhed717fe2003-06-15 23:42:24 +00001036 /* Initialize the VDBE program */
danielk19778a414492004-06-29 08:59:35 +00001037 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
drh2d401ab2008-01-10 23:50:11 +00001038 pParse->nMem = 6;
danielk197722322fd2004-05-25 23:35:17 +00001039 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +00001040 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
drh1dcdbc02007-01-27 02:24:54 +00001041
1042 /* Set the maximum error count */
1043 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
1044 if( zRight ){
1045 mxErr = atoi(zRight);
1046 if( mxErr<=0 ){
1047 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
1048 }
1049 }
drh2d401ab2008-01-10 23:50:11 +00001050 sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */
drhed717fe2003-06-15 23:42:24 +00001051
1052 /* Do an integrity check on each database file */
1053 for(i=0; i<db->nDb; i++){
1054 HashElem *x;
danielk1977da184232006-01-05 11:34:32 +00001055 Hash *pTbls;
drh79069752004-05-22 21:30:40 +00001056 int cnt = 0;
drhed717fe2003-06-15 23:42:24 +00001057
danielk197753c0f742005-03-29 03:10:59 +00001058 if( OMIT_TEMPDB && i==1 ) continue;
1059
drh80242052004-06-09 00:48:12 +00001060 sqlite3CodeVerifySchema(pParse, i);
drh2d401ab2008-01-10 23:50:11 +00001061 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
drh66a51672008-01-03 00:01:23 +00001062 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
drh1dcdbc02007-01-27 02:24:54 +00001063 sqlite3VdbeJumpHere(v, addr);
drh80242052004-06-09 00:48:12 +00001064
drhed717fe2003-06-15 23:42:24 +00001065 /* Do an integrity check of the B-Tree
drh2d401ab2008-01-10 23:50:11 +00001066 **
1067 ** Begin by filling registers 2, 3, ... with the root pages numbers
1068 ** for all tables and indices in the database.
drhed717fe2003-06-15 23:42:24 +00001069 */
danielk1977da184232006-01-05 11:34:32 +00001070 pTbls = &db->aDb[i].pSchema->tblHash;
1071 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
drh79069752004-05-22 21:30:40 +00001072 Table *pTab = sqliteHashData(x);
1073 Index *pIdx;
drh98757152008-01-09 23:04:12 +00001074 sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
drh79069752004-05-22 21:30:40 +00001075 cnt++;
1076 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
drh98757152008-01-09 23:04:12 +00001077 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt);
drh79069752004-05-22 21:30:40 +00001078 cnt++;
1079 }
1080 }
drh1dcdbc02007-01-27 02:24:54 +00001081 if( cnt==0 ) continue;
drh2d401ab2008-01-10 23:50:11 +00001082
1083 /* Make sure sufficient number of registers have been allocated */
danielk1977a7a8e142008-02-13 18:25:27 +00001084 if( pParse->nMem < cnt+4 ){
1085 pParse->nMem = cnt+4;
drh98757152008-01-09 23:04:12 +00001086 }
drh2d401ab2008-01-10 23:50:11 +00001087
1088 /* Do the b-tree integrity checks */
drh98757152008-01-09 23:04:12 +00001089 sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
drh4f21c4a2008-12-10 22:15:00 +00001090 sqlite3VdbeChangeP5(v, (u8)i);
drh98757152008-01-09 23:04:12 +00001091 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2);
1092 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
danielk19771e536952007-08-16 10:09:01 +00001093 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
drh66a51672008-01-03 00:01:23 +00001094 P4_DYNAMIC);
drhb21e7c72008-06-22 12:37:57 +00001095 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
danielk1977a7a8e142008-02-13 18:25:27 +00001096 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
drh98757152008-01-09 23:04:12 +00001097 sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
drh1dcdbc02007-01-27 02:24:54 +00001098 sqlite3VdbeJumpHere(v, addr);
drhed717fe2003-06-15 23:42:24 +00001099
1100 /* Make sure all the indices are constructed correctly.
1101 */
danielk197741c58b72007-12-29 13:39:19 +00001102 for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){
drhed717fe2003-06-15 23:42:24 +00001103 Table *pTab = sqliteHashData(x);
1104 Index *pIdx;
1105 int loopTop;
1106
1107 if( pTab->pIndex==0 ) continue;
drh2d401ab2008-01-10 23:50:11 +00001108 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
drh66a51672008-01-03 00:01:23 +00001109 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
drh1dcdbc02007-01-27 02:24:54 +00001110 sqlite3VdbeJumpHere(v, addr);
drh290c1942004-08-21 17:54:45 +00001111 sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
drh2d401ab2008-01-10 23:50:11 +00001112 sqlite3VdbeAddOp2(v, OP_Integer, 0, 2); /* reg(2) will count entries */
drh66a51672008-01-03 00:01:23 +00001113 loopTop = sqlite3VdbeAddOp2(v, OP_Rewind, 1, 0);
drh2d401ab2008-01-10 23:50:11 +00001114 sqlite3VdbeAddOp2(v, OP_AddImm, 2, 1); /* increment entry count */
drhed717fe2003-06-15 23:42:24 +00001115 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
danielk197713adf8a2004-06-03 16:08:41 +00001116 int jmp2;
drh57196282004-10-06 15:41:16 +00001117 static const VdbeOpList idxErr[] = {
drh8558cde2008-01-05 05:20:10 +00001118 { OP_AddImm, 1, -1, 0},
drh2d401ab2008-01-10 23:50:11 +00001119 { OP_String8, 0, 3, 0}, /* 1 */
1120 { OP_Rowid, 1, 4, 0},
1121 { OP_String8, 0, 5, 0}, /* 3 */
1122 { OP_String8, 0, 6, 0}, /* 4 */
1123 { OP_Concat, 4, 3, 3},
1124 { OP_Concat, 5, 3, 3},
1125 { OP_Concat, 6, 3, 3},
1126 { OP_ResultRow, 3, 1, 0},
drhbb8a2792008-03-19 00:21:30 +00001127 { OP_IfPos, 1, 0, 0}, /* 9 */
1128 { OP_Halt, 0, 0, 0},
drhed717fe2003-06-15 23:42:24 +00001129 };
drhe14006d2008-03-25 17:23:32 +00001130 sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 1);
drh2d401ab2008-01-10 23:50:11 +00001131 jmp2 = sqlite3VdbeAddOp3(v, OP_Found, j+2, 0, 3);
danielk19774adee202004-05-08 08:23:19 +00001132 addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
drh24003452008-01-03 01:28:59 +00001133 sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC);
1134 sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC);
drh66a51672008-01-03 00:01:23 +00001135 sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_STATIC);
drhbb8a2792008-03-19 00:21:30 +00001136 sqlite3VdbeJumpHere(v, addr+9);
drhd654be82005-09-20 17:42:23 +00001137 sqlite3VdbeJumpHere(v, jmp2);
drhed717fe2003-06-15 23:42:24 +00001138 }
drh66a51672008-01-03 00:01:23 +00001139 sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1);
drhd654be82005-09-20 17:42:23 +00001140 sqlite3VdbeJumpHere(v, loopTop);
drhed717fe2003-06-15 23:42:24 +00001141 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
drh57196282004-10-06 15:41:16 +00001142 static const VdbeOpList cntIdx[] = {
drh4c583122008-01-04 22:01:03 +00001143 { OP_Integer, 0, 3, 0},
drhd654be82005-09-20 17:42:23 +00001144 { OP_Rewind, 0, 0, 0}, /* 1 */
drh8558cde2008-01-05 05:20:10 +00001145 { OP_AddImm, 3, 1, 0},
drhd654be82005-09-20 17:42:23 +00001146 { OP_Next, 0, 0, 0}, /* 3 */
drh2d401ab2008-01-10 23:50:11 +00001147 { OP_Eq, 2, 0, 3}, /* 4 */
drh8558cde2008-01-05 05:20:10 +00001148 { OP_AddImm, 1, -1, 0},
drh2d401ab2008-01-10 23:50:11 +00001149 { OP_String8, 0, 2, 0}, /* 6 */
1150 { OP_String8, 0, 3, 0}, /* 7 */
1151 { OP_Concat, 3, 2, 2},
1152 { OP_ResultRow, 2, 1, 0},
drhed717fe2003-06-15 23:42:24 +00001153 };
1154 if( pIdx->tnum==0 ) continue;
drh3c84ddf2008-01-09 02:15:38 +00001155 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1);
drh66a51672008-01-03 00:01:23 +00001156 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
drh1dcdbc02007-01-27 02:24:54 +00001157 sqlite3VdbeJumpHere(v, addr);
danielk19774adee202004-05-08 08:23:19 +00001158 addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
drhd654be82005-09-20 17:42:23 +00001159 sqlite3VdbeChangeP1(v, addr+1, j+2);
1160 sqlite3VdbeChangeP2(v, addr+1, addr+4);
1161 sqlite3VdbeChangeP1(v, addr+3, j+2);
1162 sqlite3VdbeChangeP2(v, addr+3, addr+2);
drh2d401ab2008-01-10 23:50:11 +00001163 sqlite3VdbeJumpHere(v, addr+4);
1164 sqlite3VdbeChangeP4(v, addr+6,
drh24003452008-01-03 01:28:59 +00001165 "wrong # of entries in index ", P4_STATIC);
drh2d401ab2008-01-10 23:50:11 +00001166 sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_STATIC);
drhed717fe2003-06-15 23:42:24 +00001167 }
1168 }
1169 }
danielk19774adee202004-05-08 08:23:19 +00001170 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
drh2d401ab2008-01-10 23:50:11 +00001171 sqlite3VdbeChangeP2(v, addr, -mxErr);
1172 sqlite3VdbeJumpHere(v, addr+1);
1173 sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
drhc11d4f92003-04-06 21:08:24 +00001174 }else
drhb7f91642004-10-31 02:22:47 +00001175#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
1176
drh13d70422004-11-13 15:59:14 +00001177#ifndef SQLITE_OMIT_UTF16
danielk19778e227872004-06-07 07:52:17 +00001178 /*
1179 ** PRAGMA encoding
1180 ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
1181 **
drh85b623f2007-12-13 21:54:09 +00001182 ** In its first form, this pragma returns the encoding of the main
danielk19778e227872004-06-07 07:52:17 +00001183 ** database. If the database is not initialized, it is initialized now.
1184 **
1185 ** The second form of this pragma is a no-op if the main database file
1186 ** has not already been initialized. In this case it sets the default
1187 ** encoding that will be used for the main database file if a new file
1188 ** is created. If an existing main database file is opened, then the
1189 ** default text encoding for the existing database is used.
1190 **
1191 ** In all cases new databases created using the ATTACH command are
1192 ** created to use the same default text encoding as the main database. If
1193 ** the main database has not been initialized and/or created when ATTACH
1194 ** is executed, this is done before the ATTACH operation.
1195 **
1196 ** In the second form this pragma sets the text encoding to be used in
1197 ** new database files created using this database handle. It is only
1198 ** useful if invoked immediately after the main database i
1199 */
1200 if( sqlite3StrICmp(zLeft, "encoding")==0 ){
drh0f7eb612006-08-08 13:51:43 +00001201 static const struct EncName {
danielk19778e227872004-06-07 07:52:17 +00001202 char *zName;
1203 u8 enc;
1204 } encnames[] = {
drh998da3a2004-06-19 15:22:56 +00001205 { "UTF8", SQLITE_UTF8 },
drhd2cb50b2009-01-09 21:41:17 +00001206 { "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */
1207 { "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */
1208 { "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */
drh998da3a2004-06-19 15:22:56 +00001209 { "UTF16le", SQLITE_UTF16LE },
drh998da3a2004-06-19 15:22:56 +00001210 { "UTF16be", SQLITE_UTF16BE },
drh0f7eb612006-08-08 13:51:43 +00001211 { "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
1212 { "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
danielk19778e227872004-06-07 07:52:17 +00001213 { 0, 0 }
1214 };
drh0f7eb612006-08-08 13:51:43 +00001215 const struct EncName *pEnc;
danielk197791cf71b2004-06-26 06:37:06 +00001216 if( !zRight ){ /* "PRAGMA encoding" */
danielk19778a414492004-06-29 08:59:35 +00001217 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
danielk19778e227872004-06-07 07:52:17 +00001218 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +00001219 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
drh2d401ab2008-01-10 23:50:11 +00001220 sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
drhd2cb50b2009-01-09 21:41:17 +00001221 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
1222 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
1223 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
1224 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
drh2d401ab2008-01-10 23:50:11 +00001225 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
danielk19778e227872004-06-07 07:52:17 +00001226 }else{ /* "PRAGMA encoding = XXX" */
1227 /* Only change the value of sqlite.enc if the database handle is not
1228 ** initialized. If the main database exists, the new sqlite.enc value
1229 ** will be overwritten when the schema is next loaded. If it does not
1230 ** already exists, it will be created to use the new encoding value.
1231 */
danielk1977b82e7ed2006-01-11 14:09:31 +00001232 if(
1233 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
1234 DbHasProperty(db, 0, DB_Empty)
1235 ){
danielk19778e227872004-06-07 07:52:17 +00001236 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
1237 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
drh0f7eb612006-08-08 13:51:43 +00001238 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
danielk19778e227872004-06-07 07:52:17 +00001239 break;
1240 }
1241 }
1242 if( !pEnc->zName ){
drh5260f7e2004-06-26 19:35:29 +00001243 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
danielk19778e227872004-06-07 07:52:17 +00001244 }
1245 }
1246 }
1247 }else
drh13d70422004-11-13 15:59:14 +00001248#endif /* SQLITE_OMIT_UTF16 */
1249
1250#ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
danielk1977dae24952004-11-11 05:10:43 +00001251 /*
danielk1977b92b70b2004-11-12 16:11:59 +00001252 ** PRAGMA [database.]schema_version
1253 ** PRAGMA [database.]schema_version = <integer>
danielk1977dae24952004-11-11 05:10:43 +00001254 **
danielk1977b92b70b2004-11-12 16:11:59 +00001255 ** PRAGMA [database.]user_version
1256 ** PRAGMA [database.]user_version = <integer>
danielk1977dae24952004-11-11 05:10:43 +00001257 **
danielk1977b92b70b2004-11-12 16:11:59 +00001258 ** The pragma's schema_version and user_version are used to set or get
1259 ** the value of the schema-version and user-version, respectively. Both
1260 ** the schema-version and the user-version are 32-bit signed integers
danielk1977dae24952004-11-11 05:10:43 +00001261 ** stored in the database header.
1262 **
1263 ** The schema-cookie is usually only manipulated internally by SQLite. It
1264 ** is incremented by SQLite whenever the database schema is modified (by
danielk1977b92b70b2004-11-12 16:11:59 +00001265 ** creating or dropping a table or index). The schema version is used by
danielk1977dae24952004-11-11 05:10:43 +00001266 ** SQLite each time a query is executed to ensure that the internal cache
1267 ** of the schema used when compiling the SQL query matches the schema of
1268 ** the database against which the compiled query is actually executed.
danielk1977b92b70b2004-11-12 16:11:59 +00001269 ** Subverting this mechanism by using "PRAGMA schema_version" to modify
1270 ** the schema-version is potentially dangerous and may lead to program
danielk1977dae24952004-11-11 05:10:43 +00001271 ** crashes or database corruption. Use with caution!
1272 **
danielk1977b92b70b2004-11-12 16:11:59 +00001273 ** The user-version is not used internally by SQLite. It may be used by
danielk1977dae24952004-11-11 05:10:43 +00001274 ** applications for any purpose.
1275 */
danielk1977180b56a2007-06-24 08:00:42 +00001276 if( sqlite3StrICmp(zLeft, "schema_version")==0
1277 || sqlite3StrICmp(zLeft, "user_version")==0
1278 || sqlite3StrICmp(zLeft, "freelist_count")==0
1279 ){
danielk1977dae24952004-11-11 05:10:43 +00001280 int iCookie; /* Cookie index. 0 for schema-cookie, 6 for user-cookie. */
drhfb982642007-08-30 01:19:59 +00001281 sqlite3VdbeUsesBtree(v, iDb);
danielk1977180b56a2007-06-24 08:00:42 +00001282 switch( zLeft[0] ){
1283 case 's': case 'S':
1284 iCookie = 0;
1285 break;
1286 case 'f': case 'F':
1287 iCookie = 1;
1288 iDb = (-1*(iDb+1));
1289 assert(iDb<=0);
1290 break;
1291 default:
1292 iCookie = 5;
1293 break;
danielk1977dae24952004-11-11 05:10:43 +00001294 }
1295
danielk1977180b56a2007-06-24 08:00:42 +00001296 if( zRight && iDb>=0 ){
danielk1977dae24952004-11-11 05:10:43 +00001297 /* Write the specified cookie value */
1298 static const VdbeOpList setCookie[] = {
1299 { OP_Transaction, 0, 1, 0}, /* 0 */
drh9cbf3422008-01-17 16:22:13 +00001300 { OP_Integer, 0, 1, 0}, /* 1 */
1301 { OP_SetCookie, 0, 0, 1}, /* 2 */
danielk1977dae24952004-11-11 05:10:43 +00001302 };
1303 int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
1304 sqlite3VdbeChangeP1(v, addr, iDb);
1305 sqlite3VdbeChangeP1(v, addr+1, atoi(zRight));
1306 sqlite3VdbeChangeP1(v, addr+2, iDb);
1307 sqlite3VdbeChangeP2(v, addr+2, iCookie);
1308 }else{
1309 /* Read the specified cookie value */
1310 static const VdbeOpList readCookie[] = {
drh2d401ab2008-01-10 23:50:11 +00001311 { OP_ReadCookie, 0, 1, 0}, /* 0 */
1312 { OP_ResultRow, 1, 1, 0}
danielk1977dae24952004-11-11 05:10:43 +00001313 };
1314 int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
1315 sqlite3VdbeChangeP1(v, addr, iDb);
drh4c583122008-01-04 22:01:03 +00001316 sqlite3VdbeChangeP3(v, addr, iCookie);
danielk1977dae24952004-11-11 05:10:43 +00001317 sqlite3VdbeSetNumCols(v, 1);
danielk197710fb7492008-10-31 10:53:22 +00001318 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
danielk1977dae24952004-11-11 05:10:43 +00001319 }
drh6e345992007-03-30 11:12:08 +00001320 }else
drh13d70422004-11-13 15:59:14 +00001321#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
drhc11d4f92003-04-06 21:08:24 +00001322
dougcurrie81c95ef2004-06-18 23:21:47 +00001323#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
drh89ac8c12004-06-09 14:17:20 +00001324 /*
1325 ** Report the current state of file logs for all databases
1326 */
1327 if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
drh57196282004-10-06 15:41:16 +00001328 static const char *const azLockName[] = {
drh89ac8c12004-06-09 14:17:20 +00001329 "unlocked", "shared", "reserved", "pending", "exclusive"
1330 };
1331 int i;
drh89ac8c12004-06-09 14:17:20 +00001332 sqlite3VdbeSetNumCols(v, 2);
drh2d401ab2008-01-10 23:50:11 +00001333 pParse->nMem = 2;
danielk197710fb7492008-10-31 10:53:22 +00001334 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
1335 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
drh89ac8c12004-06-09 14:17:20 +00001336 for(i=0; i<db->nDb; i++){
1337 Btree *pBt;
1338 Pager *pPager;
drh9e33c2c2007-08-31 18:34:59 +00001339 const char *zState = "unknown";
1340 int j;
drh89ac8c12004-06-09 14:17:20 +00001341 if( db->aDb[i].zName==0 ) continue;
drh2d401ab2008-01-10 23:50:11 +00001342 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
drh89ac8c12004-06-09 14:17:20 +00001343 pBt = db->aDb[i].pBt;
1344 if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
drh9e33c2c2007-08-31 18:34:59 +00001345 zState = "closed";
drhc4dd3fd2008-01-22 01:48:05 +00001346 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
drh9e33c2c2007-08-31 18:34:59 +00001347 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
1348 zState = azLockName[j];
drh89ac8c12004-06-09 14:17:20 +00001349 }
drh2d401ab2008-01-10 23:50:11 +00001350 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
1351 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
drh89ac8c12004-06-09 14:17:20 +00001352 }
danielk1977a4de4532008-09-02 15:44:08 +00001353
drh89ac8c12004-06-09 14:17:20 +00001354 }else
1355#endif
1356
drh89dec812005-04-28 19:03:37 +00001357#ifdef SQLITE_SSE
1358 /*
1359 ** Check to see if the sqlite_statements table exists. Create it
1360 ** if it does not.
1361 */
1362 if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){
danielk19773a3f38e2005-05-22 06:49:56 +00001363 extern int sqlite3CreateStatementsTable(Parse*);
1364 sqlite3CreateStatementsTable(pParse);
drh89dec812005-04-28 19:03:37 +00001365 }else
1366#endif
1367
drh3c4f2a42005-12-08 18:12:56 +00001368#if SQLITE_HAS_CODEC
drhd2cb50b2009-01-09 21:41:17 +00001369 if( sqlite3StrICmp(zLeft, "key")==0 && zRight ){
drhea678832008-12-10 19:26:22 +00001370 sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
drh3c4f2a42005-12-08 18:12:56 +00001371 }else
drhd2cb50b2009-01-09 21:41:17 +00001372 if( sqlite3StrICmp(zLeft, "rekey")==0 && zRight ){
1373 sqlite3_rekey(db, zRight, sqlite3Strlen30(zRight));
1374 }else
1375 if( zRight && (sqlite3StrICmp(zLeft, "hexkey")==0 ||
1376 sqlite3StrICmp(zLeft, "hexrekey")==0) ){
1377 int i, h1, h2;
1378 char zKey[40];
1379 for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
1380 h1 += 9*(1&(h1>>6));
1381 h2 += 9*(1&(h2>>6));
1382 zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
1383 }
1384 if( (zLeft[3] & 0xf)==0xb ){
1385 sqlite3_key(db, zKey, i/2);
1386 }else{
1387 sqlite3_rekey(db, zKey, i/2);
1388 }
1389 }else
drh3c4f2a42005-12-08 18:12:56 +00001390#endif
drh21e2cab2006-09-25 18:01:57 +00001391#if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD)
1392 if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){
1393#if SQLITE_HAS_CODEC
1394 if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){
1395 extern void sqlite3_activate_see(const char*);
1396 sqlite3_activate_see(&zRight[4]);
1397 }
1398#endif
1399#ifdef SQLITE_ENABLE_CEROD
1400 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
1401 extern void sqlite3_activate_cerod(const char*);
1402 sqlite3_activate_cerod(&zRight[6]);
1403 }
1404#endif
drhd2cb50b2009-01-09 21:41:17 +00001405 }else
drh21e2cab2006-09-25 18:01:57 +00001406#endif
drh3c4f2a42005-12-08 18:12:56 +00001407
drhd2cb50b2009-01-09 21:41:17 +00001408
1409 {/* Empty ELSE clause */}
danielk1977a21c6b62005-01-24 10:25:59 +00001410
drhd2cb50b2009-01-09 21:41:17 +00001411 /* Code an OP_Expire at the end of each PRAGMA program to cause
1412 ** the VDBE implementing the pragma to expire. Most (all?) pragmas
1413 ** are only valid for a single execution.
1414 */
1415 sqlite3VdbeAddOp2(v, OP_Expire, 1, 0);
drhac530b12006-02-11 01:25:50 +00001416
drhd2cb50b2009-01-09 21:41:17 +00001417 /*
1418 ** Reset the safety level, in case the fullfsync flag or synchronous
1419 ** setting changed.
1420 */
danielk1977ddfb2f02006-02-17 12:25:14 +00001421#ifndef SQLITE_OMIT_PAGER_PRAGMAS
drhd2cb50b2009-01-09 21:41:17 +00001422 if( db->autoCommit ){
1423 sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
1424 (db->flags&SQLITE_FullFSync)!=0);
danielk1977a21c6b62005-01-24 10:25:59 +00001425 }
drhd2cb50b2009-01-09 21:41:17 +00001426#endif
danielk1977e0048402004-06-15 16:51:01 +00001427pragma_out:
drh633e6d52008-07-28 19:34:53 +00001428 sqlite3DbFree(db, zLeft);
1429 sqlite3DbFree(db, zRight);
drhc11d4f92003-04-06 21:08:24 +00001430}
drh13d70422004-11-13 15:59:14 +00001431
drh0ccebe72005-06-07 22:22:50 +00001432#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */