2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A** 2003 April 6
2N/A**
2N/A** The author disclaims copyright to this source code. In place of
2N/A** a legal notice, here is a blessing:
2N/A**
2N/A** May you do good and not evil.
2N/A** May you find forgiveness for yourself and forgive others.
2N/A** May you share freely, never taking more than you give.
2N/A**
2N/A*************************************************************************
2N/A** This file contains code used to implement the PRAGMA command.
2N/A**
2N/A** $Id: pragma.c,v 1.19 2004/04/23 17:04:45 drh Exp $
2N/A*/
2N/A#include "sqliteInt.h"
2N/A#include <ctype.h>
2N/A
2N/A/*
2N/A** Interpret the given string as a boolean value.
2N/A*/
2N/Astatic int getBoolean(const char *z){
2N/A static char *azTrue[] = { "yes", "on", "true" };
2N/A int i;
2N/A if( z[0]==0 ) return 0;
2N/A if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){
2N/A return atoi(z);
2N/A }
2N/A for(i=0; i<sizeof(azTrue)/sizeof(azTrue[0]); i++){
2N/A if( sqliteStrICmp(z,azTrue[i])==0 ) return 1;
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/A/*
2N/A** Interpret the given string as a safety level. Return 0 for OFF,
2N/A** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
2N/A** unrecognized string argument.
2N/A**
2N/A** Note that the values returned are one less that the values that
2N/A** should be passed into sqliteBtreeSetSafetyLevel(). The is done
2N/A** to support legacy SQL code. The safety level used to be boolean
2N/A** and older scripts may have used numbers 0 for OFF and 1 for ON.
2N/A*/
2N/Astatic int getSafetyLevel(char *z){
2N/A static const struct {
2N/A const char *zWord;
2N/A int val;
2N/A } aKey[] = {
2N/A { "no", 0 },
2N/A { "off", 0 },
2N/A { "false", 0 },
2N/A { "yes", 1 },
2N/A { "on", 1 },
2N/A { "true", 1 },
2N/A { "full", 2 },
2N/A };
2N/A int i;
2N/A if( z[0]==0 ) return 1;
2N/A if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){
2N/A return atoi(z);
2N/A }
2N/A for(i=0; i<sizeof(aKey)/sizeof(aKey[0]); i++){
2N/A if( sqliteStrICmp(z,aKey[i].zWord)==0 ) return aKey[i].val;
2N/A }
2N/A return 1;
2N/A}
2N/A
2N/A/*
2N/A** Interpret the given string as a temp db location. Return 1 for file
2N/A** backed temporary databases, 2 for the Red-Black tree in memory database
2N/A** and 0 to use the compile-time default.
2N/A*/
2N/Astatic int getTempStore(const char *z){
2N/A if( z[0]>='0' && z[0]<='2' ){
2N/A return z[0] - '0';
2N/A }else if( sqliteStrICmp(z, "file")==0 ){
2N/A return 1;
2N/A }else if( sqliteStrICmp(z, "memory")==0 ){
2N/A return 2;
2N/A }else{
2N/A return 0;
2N/A }
2N/A}
2N/A
2N/A/*
2N/A** If the TEMP database is open, close it and mark the database schema
2N/A** as needing reloading. This must be done when using the TEMP_STORE
2N/A** or DEFAULT_TEMP_STORE pragmas.
2N/A*/
2N/Astatic int changeTempStorage(Parse *pParse, const char *zStorageType){
2N/A int ts = getTempStore(zStorageType);
2N/A sqlite *db = pParse->db;
2N/A if( db->temp_store==ts ) return SQLITE_OK;
2N/A if( db->aDb[1].pBt!=0 ){
2N/A if( db->flags & SQLITE_InTrans ){
2N/A sqliteErrorMsg(pParse, "temporary storage cannot be changed "
2N/A "from within a transaction");
2N/A return SQLITE_ERROR;
2N/A }
2N/A sqliteBtreeClose(db->aDb[1].pBt);
2N/A db->aDb[1].pBt = 0;
2N/A sqliteResetInternalSchema(db, 0);
2N/A }
2N/A db->temp_store = ts;
2N/A return SQLITE_OK;
2N/A}
2N/A
2N/A/*
2N/A** Check to see if zRight and zLeft refer to a pragma that queries
2N/A** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
2N/A** Also, implement the pragma.
2N/A*/
2N/Astatic int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
2N/A static const struct {
2N/A const char *zName; /* Name of the pragma */
2N/A int mask; /* Mask for the db->flags value */
2N/A } aPragma[] = {
2N/A { "vdbe_trace", SQLITE_VdbeTrace },
2N/A { "full_column_names", SQLITE_FullColNames },
2N/A { "short_column_names", SQLITE_ShortColNames },
2N/A { "show_datatypes", SQLITE_ReportTypes },
2N/A { "count_changes", SQLITE_CountRows },
2N/A { "empty_result_callbacks", SQLITE_NullCallback },
2N/A };
2N/A int i;
2N/A for(i=0; i<sizeof(aPragma)/sizeof(aPragma[0]); i++){
2N/A if( sqliteStrICmp(zLeft, aPragma[i].zName)==0 ){
2N/A sqlite *db = pParse->db;
2N/A Vdbe *v;
2N/A if( strcmp(zLeft,zRight)==0 && (v = sqliteGetVdbe(pParse))!=0 ){
2N/A sqliteVdbeOp3(v, OP_ColumnName, 0, 1, aPragma[i].zName, P3_STATIC);
2N/A sqliteVdbeOp3(v, OP_ColumnName, 1, 0, "boolean", P3_STATIC);
2N/A sqliteVdbeCode(v, OP_Integer, (db->flags & aPragma[i].mask)!=0, 0,
2N/A OP_Callback, 1, 0,
2N/A 0);
2N/A }else if( getBoolean(zRight) ){
2N/A db->flags |= aPragma[i].mask;
2N/A }else{
2N/A db->flags &= ~aPragma[i].mask;
2N/A }
2N/A return 1;
2N/A }
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/A/*
2N/A** Process a pragma statement.
2N/A**
2N/A** Pragmas are of this form:
2N/A**
2N/A** PRAGMA id = value
2N/A**
2N/A** The identifier might also be a string. The value is a string, and
2N/A** identifier, or a number. If minusFlag is true, then the value is
2N/A** a number that was preceded by a minus sign.
2N/A*/
2N/Avoid sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
2N/A char *zLeft = 0;
2N/A char *zRight = 0;
2N/A sqlite *db = pParse->db;
2N/A Vdbe *v = sqliteGetVdbe(pParse);
2N/A if( v==0 ) return;
2N/A
2N/A zLeft = sqliteStrNDup(pLeft->z, pLeft->n);
2N/A sqliteDequote(zLeft);
2N/A if( minusFlag ){
2N/A zRight = 0;
2N/A sqliteSetNString(&zRight, "-", 1, pRight->z, pRight->n, 0);
2N/A }else{
2N/A zRight = sqliteStrNDup(pRight->z, pRight->n);
2N/A sqliteDequote(zRight);
2N/A }
2N/A if( sqliteAuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, 0) ){
2N/A sqliteFree(zLeft);
2N/A sqliteFree(zRight);
2N/A return;
2N/A }
2N/A
2N/A /*
2N/A ** PRAGMA default_cache_size
2N/A ** PRAGMA default_cache_size=N
2N/A **
2N/A ** The first form reports the current persistent setting for the
2N/A ** page cache size. The value returned is the maximum number of
2N/A ** pages in the page cache. The second form sets both the current
2N/A ** page cache size value and the persistent page cache size value
2N/A ** stored in the database file.
2N/A **
2N/A ** The default cache size is stored in meta-value 2 of page 1 of the
2N/A ** database file. The cache size is actually the absolute value of
2N/A ** this memory location. The sign of meta-value 2 determines the
2N/A ** synchronous setting. A negative value means synchronous is off
2N/A ** and a positive value means synchronous is on.
2N/A */
2N/A if( sqliteStrICmp(zLeft,"default_cache_size")==0 ){
2N/A static VdbeOpList getCacheSize[] = {
2N/A { OP_ReadCookie, 0, 2, 0},
2N/A { OP_AbsValue, 0, 0, 0},
2N/A { OP_Dup, 0, 0, 0},
2N/A { OP_Integer, 0, 0, 0},
2N/A { OP_Ne, 0, 6, 0},
2N/A { OP_Integer, 0, 0, 0}, /* 5 */
2N/A { OP_ColumnName, 0, 1, "cache_size"},
2N/A { OP_Callback, 1, 0, 0},
2N/A };
2N/A int addr;
2N/A if( pRight->z==pLeft->z ){
2N/A addr = sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
2N/A sqliteVdbeChangeP1(v, addr+5, MAX_PAGES);
2N/A }else{
2N/A int size = atoi(zRight);
2N/A if( size<0 ) size = -size;
2N/A sqliteBeginWriteOperation(pParse, 0, 0);
2N/A sqliteVdbeAddOp(v, OP_Integer, size, 0);
2N/A sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2);
2N/A addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0);
2N/A sqliteVdbeAddOp(v, OP_Ge, 0, addr+3);
2N/A sqliteVdbeAddOp(v, OP_Negative, 0, 0);
2N/A sqliteVdbeAddOp(v, OP_SetCookie, 0, 2);
2N/A sqliteEndWriteOperation(pParse);
2N/A db->cache_size = db->cache_size<0 ? -size : size;
2N/A sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
2N/A }
2N/A }else
2N/A
2N/A /*
2N/A ** PRAGMA cache_size
2N/A ** PRAGMA cache_size=N
2N/A **
2N/A ** The first form reports the current local setting for the
2N/A ** page cache size. The local setting can be different from
2N/A ** the persistent cache size value that is stored in the database
2N/A ** file itself. The value returned is the maximum number of
2N/A ** pages in the page cache. The second form sets the local
2N/A ** page cache size value. It does not change the persistent
2N/A ** cache size stored on the disk so the cache size will revert
2N/A ** to its default value when the database is closed and reopened.
2N/A ** N should be a positive integer.
2N/A */
2N/A if( sqliteStrICmp(zLeft,"cache_size")==0 ){
2N/A static VdbeOpList getCacheSize[] = {
2N/A { OP_ColumnName, 0, 1, "cache_size"},
2N/A { OP_Callback, 1, 0, 0},
2N/A };
2N/A if( pRight->z==pLeft->z ){
2N/A int size = db->cache_size;;
2N/A if( size<0 ) size = -size;
2N/A sqliteVdbeAddOp(v, OP_Integer, size, 0);
2N/A sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
2N/A }else{
2N/A int size = atoi(zRight);
2N/A if( size<0 ) size = -size;
2N/A if( db->cache_size<0 ) size = -size;
2N/A db->cache_size = size;
2N/A sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
2N/A }
2N/A }else
2N/A
2N/A /*
2N/A ** PRAGMA default_synchronous
2N/A ** PRAGMA default_synchronous=ON|OFF|NORMAL|FULL
2N/A **
2N/A ** The first form returns the persistent value of the "synchronous" setting
2N/A ** that is stored in the database. This is the synchronous setting that
2N/A ** is used whenever the database is opened unless overridden by a separate
2N/A ** "synchronous" pragma. The second form changes the persistent and the
2N/A ** local synchronous setting to the value given.
2N/A **
2N/A ** If synchronous is OFF, SQLite does not attempt any fsync() systems calls
2N/A ** to make sure data is committed to disk. Write operations are very fast,
2N/A ** but a power failure can leave the database in an inconsistent state.
2N/A ** If synchronous is ON or NORMAL, SQLite will do an fsync() system call to
2N/A ** make sure data is being written to disk. The risk of corruption due to
2N/A ** a power loss in this mode is negligible but non-zero. If synchronous
2N/A ** is FULL, extra fsync()s occur to reduce the risk of corruption to near
2N/A ** zero, but with a write performance penalty. The default mode is NORMAL.
2N/A */
2N/A if( sqliteStrICmp(zLeft,"default_synchronous")==0 ){
2N/A static VdbeOpList getSync[] = {
2N/A { OP_ColumnName, 0, 1, "synchronous"},
2N/A { OP_ReadCookie, 0, 3, 0},
2N/A { OP_Dup, 0, 0, 0},
2N/A { OP_If, 0, 0, 0}, /* 3 */
2N/A { OP_ReadCookie, 0, 2, 0},
2N/A { OP_Integer, 0, 0, 0},
2N/A { OP_Lt, 0, 5, 0},
2N/A { OP_AddImm, 1, 0, 0},
2N/A { OP_Callback, 1, 0, 0},
2N/A { OP_Halt, 0, 0, 0},
2N/A { OP_AddImm, -1, 0, 0}, /* 10 */
2N/A { OP_Callback, 1, 0, 0}
2N/A };
2N/A if( pRight->z==pLeft->z ){
2N/A int addr = sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
2N/A sqliteVdbeChangeP2(v, addr+3, addr+10);
2N/A }else{
2N/A int addr;
2N/A int size = db->cache_size;
2N/A if( size<0 ) size = -size;
2N/A sqliteBeginWriteOperation(pParse, 0, 0);
2N/A sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2);
2N/A sqliteVdbeAddOp(v, OP_Dup, 0, 0);
2N/A addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0);
2N/A sqliteVdbeAddOp(v, OP_Ne, 0, addr+3);
2N/A sqliteVdbeAddOp(v, OP_AddImm, MAX_PAGES, 0);
2N/A sqliteVdbeAddOp(v, OP_AbsValue, 0, 0);
2N/A db->safety_level = getSafetyLevel(zRight)+1;
2N/A if( db->safety_level==1 ){
2N/A sqliteVdbeAddOp(v, OP_Negative, 0, 0);
2N/A size = -size;
2N/A }
2N/A sqliteVdbeAddOp(v, OP_SetCookie, 0, 2);
2N/A sqliteVdbeAddOp(v, OP_Integer, db->safety_level, 0);
2N/A sqliteVdbeAddOp(v, OP_SetCookie, 0, 3);
2N/A sqliteEndWriteOperation(pParse);
2N/A db->cache_size = size;
2N/A sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
2N/A sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
2N/A }
2N/A }else
2N/A
2N/A /*
2N/A ** PRAGMA synchronous
2N/A ** PRAGMA synchronous=OFF|ON|NORMAL|FULL
2N/A **
2N/A ** Return or set the local value of the synchronous flag. Changing
2N/A ** the local value does not make changes to the disk file and the
2N/A ** default value will be restored the next time the database is
2N/A ** opened.
2N/A */
2N/A if( sqliteStrICmp(zLeft,"synchronous")==0 ){
2N/A static VdbeOpList getSync[] = {
2N/A { OP_ColumnName, 0, 1, "synchronous"},
2N/A { OP_Callback, 1, 0, 0},
2N/A };
2N/A if( pRight->z==pLeft->z ){
2N/A sqliteVdbeAddOp(v, OP_Integer, db->safety_level-1, 0);
2N/A sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
2N/A }else{
2N/A int size = db->cache_size;
2N/A if( size<0 ) size = -size;
2N/A db->safety_level = getSafetyLevel(zRight)+1;
2N/A if( db->safety_level==1 ) size = -size;
2N/A db->cache_size = size;
2N/A sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size);
2N/A sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level);
2N/A }
2N/A }else
2N/A
2N/A#ifndef NDEBUG
2N/A if( sqliteStrICmp(zLeft, "trigger_overhead_test")==0 ){
2N/A if( getBoolean(zRight) ){
2N/A always_code_trigger_setup = 1;
2N/A }else{
2N/A always_code_trigger_setup = 0;
2N/A }
2N/A }else
2N/A#endif
2N/A
2N/A if( flagPragma(pParse, zLeft, zRight) ){
2N/A /* The flagPragma() call also generates any necessary code */
2N/A }else
2N/A
2N/A if( sqliteStrICmp(zLeft, "table_info")==0 ){
2N/A Table *pTab;
2N/A pTab = sqliteFindTable(db, zRight, 0);
2N/A if( pTab ){
2N/A static VdbeOpList tableInfoPreface[] = {
2N/A { OP_ColumnName, 0, 0, "cid"},
2N/A { OP_ColumnName, 1, 0, "name"},
2N/A { OP_ColumnName, 2, 0, "type"},
2N/A { OP_ColumnName, 3, 0, "notnull"},
2N/A { OP_ColumnName, 4, 0, "dflt_value"},
2N/A { OP_ColumnName, 5, 1, "pk"},
2N/A };
2N/A int i;
2N/A sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
2N/A sqliteViewGetColumnNames(pParse, pTab);
2N/A for(i=0; i<pTab->nCol; i++){
2N/A sqliteVdbeAddOp(v, OP_Integer, i, 0);
2N/A sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zName, 0);
2N/A sqliteVdbeOp3(v, OP_String, 0, 0,
2N/A pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", 0);
2N/A sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0);
2N/A sqliteVdbeOp3(v, OP_String, 0, 0,
2N/A pTab->aCol[i].zDflt, P3_STATIC);
2N/A sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0);
2N/A sqliteVdbeAddOp(v, OP_Callback, 6, 0);
2N/A }
2N/A }
2N/A }else
2N/A
2N/A if( sqliteStrICmp(zLeft, "index_info")==0 ){
2N/A Index *pIdx;
2N/A Table *pTab;
2N/A pIdx = sqliteFindIndex(db, zRight, 0);
2N/A if( pIdx ){
2N/A static VdbeOpList tableInfoPreface[] = {
2N/A { OP_ColumnName, 0, 0, "seqno"},
2N/A { OP_ColumnName, 1, 0, "cid"},
2N/A { OP_ColumnName, 2, 1, "name"},
2N/A };
2N/A int i;
2N/A pTab = pIdx->pTable;
2N/A sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
2N/A for(i=0; i<pIdx->nColumn; i++){
2N/A int cnum = pIdx->aiColumn[i];
2N/A sqliteVdbeAddOp(v, OP_Integer, i, 0);
2N/A sqliteVdbeAddOp(v, OP_Integer, cnum, 0);
2N/A assert( pTab->nCol>cnum );
2N/A sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[cnum].zName, 0);
2N/A sqliteVdbeAddOp(v, OP_Callback, 3, 0);
2N/A }
2N/A }
2N/A }else
2N/A
2N/A if( sqliteStrICmp(zLeft, "index_list")==0 ){
2N/A Index *pIdx;
2N/A Table *pTab;
2N/A pTab = sqliteFindTable(db, zRight, 0);
2N/A if( pTab ){
2N/A v = sqliteGetVdbe(pParse);
2N/A pIdx = pTab->pIndex;
2N/A }
2N/A if( pTab && pIdx ){
2N/A int i = 0;
2N/A static VdbeOpList indexListPreface[] = {
2N/A { OP_ColumnName, 0, 0, "seq"},
2N/A { OP_ColumnName, 1, 0, "name"},
2N/A { OP_ColumnName, 2, 1, "unique"},
2N/A };
2N/A
2N/A sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
2N/A while(pIdx){
2N/A sqliteVdbeAddOp(v, OP_Integer, i, 0);
2N/A sqliteVdbeOp3(v, OP_String, 0, 0, pIdx->zName, 0);
2N/A sqliteVdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
2N/A sqliteVdbeAddOp(v, OP_Callback, 3, 0);
2N/A ++i;
2N/A pIdx = pIdx->pNext;
2N/A }
2N/A }
2N/A }else
2N/A
2N/A if( sqliteStrICmp(zLeft, "foreign_key_list")==0 ){
2N/A FKey *pFK;
2N/A Table *pTab;
2N/A pTab = sqliteFindTable(db, zRight, 0);
2N/A if( pTab ){
2N/A v = sqliteGetVdbe(pParse);
2N/A pFK = pTab->pFKey;
2N/A }
2N/A if( pTab && pFK ){
2N/A int i = 0;
2N/A static VdbeOpList indexListPreface[] = {
2N/A { OP_ColumnName, 0, 0, "id"},
2N/A { OP_ColumnName, 1, 0, "seq"},
2N/A { OP_ColumnName, 2, 0, "table"},
2N/A { OP_ColumnName, 3, 0, "from"},
2N/A { OP_ColumnName, 4, 1, "to"},
2N/A };
2N/A
2N/A sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
2N/A while(pFK){
2N/A int j;
2N/A for(j=0; j<pFK->nCol; j++){
2N/A sqliteVdbeAddOp(v, OP_Integer, i, 0);
2N/A sqliteVdbeAddOp(v, OP_Integer, j, 0);
2N/A sqliteVdbeOp3(v, OP_String, 0, 0, pFK->zTo, 0);
2N/A sqliteVdbeOp3(v, OP_String, 0, 0,
2N/A pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
2N/A sqliteVdbeOp3(v, OP_String, 0, 0, pFK->aCol[j].zCol, 0);
2N/A sqliteVdbeAddOp(v, OP_Callback, 5, 0);
2N/A }
2N/A ++i;
2N/A pFK = pFK->pNextFrom;
2N/A }
2N/A }
2N/A }else
2N/A
2N/A if( sqliteStrICmp(zLeft, "database_list")==0 ){
2N/A int i;
2N/A static VdbeOpList indexListPreface[] = {
2N/A { OP_ColumnName, 0, 0, "seq"},
2N/A { OP_ColumnName, 1, 0, "name"},
2N/A { OP_ColumnName, 2, 1, "file"},
2N/A };
2N/A
2N/A sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
2N/A for(i=0; i<db->nDb; i++){
2N/A if( db->aDb[i].pBt==0 ) continue;
2N/A assert( db->aDb[i].zName!=0 );
2N/A sqliteVdbeAddOp(v, OP_Integer, i, 0);
2N/A sqliteVdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, 0);
2N/A sqliteVdbeOp3(v, OP_String, 0, 0,
2N/A sqliteBtreeGetFilename(db->aDb[i].pBt), 0);
2N/A sqliteVdbeAddOp(v, OP_Callback, 3, 0);
2N/A }
2N/A }else
2N/A
2N/A
2N/A /*
2N/A ** PRAGMA temp_store
2N/A ** PRAGMA temp_store = "default"|"memory"|"file"
2N/A **
2N/A ** Return or set the local value of the temp_store flag. Changing
2N/A ** the local value does not make changes to the disk file and the default
2N/A ** value will be restored the next time the database is opened.
2N/A **
2N/A ** Note that it is possible for the library compile-time options to
2N/A ** override this setting
2N/A */
2N/A if( sqliteStrICmp(zLeft, "temp_store")==0 ){
2N/A static VdbeOpList getTmpDbLoc[] = {
2N/A { OP_ColumnName, 0, 1, "temp_store"},
2N/A { OP_Callback, 1, 0, 0},
2N/A };
2N/A if( pRight->z==pLeft->z ){
2N/A sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0);
2N/A sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
2N/A }else{
2N/A changeTempStorage(pParse, zRight);
2N/A }
2N/A }else
2N/A
2N/A /*
2N/A ** PRAGMA default_temp_store
2N/A ** PRAGMA default_temp_store = "default"|"memory"|"file"
2N/A **
2N/A ** Return or set the value of the persistent temp_store flag. Any
2N/A ** change does not take effect until the next time the database is
2N/A ** opened.
2N/A **
2N/A ** Note that it is possible for the library compile-time options to
2N/A ** override this setting
2N/A */
2N/A if( sqliteStrICmp(zLeft, "default_temp_store")==0 ){
2N/A static VdbeOpList getTmpDbLoc[] = {
2N/A { OP_ColumnName, 0, 1, "temp_store"},
2N/A { OP_ReadCookie, 0, 5, 0},
2N/A { OP_Callback, 1, 0, 0}};
2N/A if( pRight->z==pLeft->z ){
2N/A sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc);
2N/A }else{
2N/A sqliteBeginWriteOperation(pParse, 0, 0);
2N/A sqliteVdbeAddOp(v, OP_Integer, getTempStore(zRight), 0);
2N/A sqliteVdbeAddOp(v, OP_SetCookie, 0, 5);
2N/A sqliteEndWriteOperation(pParse);
2N/A }
2N/A }else
2N/A
2N/A#ifndef NDEBUG
2N/A if( sqliteStrICmp(zLeft, "parser_trace")==0 ){
2N/A extern void sqliteParserTrace(FILE*, char *);
2N/A if( getBoolean(zRight) ){
2N/A sqliteParserTrace(stdout, "parser: ");
2N/A }else{
2N/A sqliteParserTrace(0, 0);
2N/A }
2N/A }else
2N/A#endif
2N/A
2N/A if( sqliteStrICmp(zLeft, "integrity_check")==0 ){
2N/A int i, j, addr;
2N/A
2N/A /* Code that initializes the integrity check program. Set the
2N/A ** error count 0
2N/A */
2N/A static VdbeOpList initCode[] = {
2N/A { OP_Integer, 0, 0, 0},
2N/A { OP_MemStore, 0, 1, 0},
2N/A { OP_ColumnName, 0, 1, "integrity_check"},
2N/A };
2N/A
2N/A /* Code to do an BTree integrity check on a single database file.
2N/A */
2N/A static VdbeOpList checkDb[] = {
2N/A { OP_SetInsert, 0, 0, "2"},
2N/A { OP_Integer, 0, 0, 0}, /* 1 */
2N/A { OP_OpenRead, 0, 2, 0},
2N/A { OP_Rewind, 0, 7, 0}, /* 3 */
2N/A { OP_Column, 0, 3, 0}, /* 4 */
2N/A { OP_SetInsert, 0, 0, 0},
2N/A { OP_Next, 0, 4, 0}, /* 6 */
2N/A { OP_IntegrityCk, 0, 0, 0}, /* 7 */
2N/A { OP_Dup, 0, 1, 0},
2N/A { OP_String, 0, 0, "ok"},
2N/A { OP_StrEq, 0, 12, 0}, /* 10 */
2N/A { OP_MemIncr, 0, 0, 0},
2N/A { OP_String, 0, 0, "*** in database "},
2N/A { OP_String, 0, 0, 0}, /* 13 */
2N/A { OP_String, 0, 0, " ***\n"},
2N/A { OP_Pull, 3, 0, 0},
2N/A { OP_Concat, 4, 1, 0},
2N/A { OP_Callback, 1, 0, 0},
2N/A };
2N/A
2N/A /* Code that appears at the end of the integrity check. If no error
2N/A ** messages have been generated, output OK. Otherwise output the
2N/A ** error message
2N/A */
2N/A static VdbeOpList endCode[] = {
2N/A { OP_MemLoad, 0, 0, 0},
2N/A { OP_Integer, 0, 0, 0},
2N/A { OP_Ne, 0, 0, 0}, /* 2 */
2N/A { OP_String, 0, 0, "ok"},
2N/A { OP_Callback, 1, 0, 0},
2N/A };
2N/A
2N/A /* Initialize the VDBE program */
2N/A sqliteVdbeAddOpList(v, ArraySize(initCode), initCode);
2N/A
2N/A /* Do an integrity check on each database file */
2N/A for(i=0; i<db->nDb; i++){
2N/A HashElem *x;
2N/A
2N/A /* Do an integrity check of the B-Tree
2N/A */
2N/A addr = sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb);
2N/A sqliteVdbeChangeP1(v, addr+1, i);
2N/A sqliteVdbeChangeP2(v, addr+3, addr+7);
2N/A sqliteVdbeChangeP2(v, addr+6, addr+4);
2N/A sqliteVdbeChangeP2(v, addr+7, i);
2N/A sqliteVdbeChangeP2(v, addr+10, addr+ArraySize(checkDb));
2N/A sqliteVdbeChangeP3(v, addr+13, db->aDb[i].zName, P3_STATIC);
2N/A
2N/A /* Make sure all the indices are constructed correctly.
2N/A */
2N/A sqliteCodeVerifySchema(pParse, i);
2N/A for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
2N/A Table *pTab = sqliteHashData(x);
2N/A Index *pIdx;
2N/A int loopTop;
2N/A
2N/A if( pTab->pIndex==0 ) continue;
2N/A sqliteVdbeAddOp(v, OP_Integer, i, 0);
2N/A sqliteVdbeOp3(v, OP_OpenRead, 1, pTab->tnum, pTab->zName, 0);
2N/A for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
2N/A if( pIdx->tnum==0 ) continue;
2N/A sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
2N/A sqliteVdbeOp3(v, OP_OpenRead, j+2, pIdx->tnum, pIdx->zName, 0);
2N/A }
2N/A sqliteVdbeAddOp(v, OP_Integer, 0, 0);
2N/A sqliteVdbeAddOp(v, OP_MemStore, 1, 1);
2N/A loopTop = sqliteVdbeAddOp(v, OP_Rewind, 1, 0);
2N/A sqliteVdbeAddOp(v, OP_MemIncr, 1, 0);
2N/A for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
2N/A int k, jmp2;
2N/A static VdbeOpList idxErr[] = {
2N/A { OP_MemIncr, 0, 0, 0},
2N/A { OP_String, 0, 0, "rowid "},
2N/A { OP_Recno, 1, 0, 0},
2N/A { OP_String, 0, 0, " missing from index "},
2N/A { OP_String, 0, 0, 0}, /* 4 */
2N/A { OP_Concat, 4, 0, 0},
2N/A { OP_Callback, 1, 0, 0},
2N/A };
2N/A sqliteVdbeAddOp(v, OP_Recno, 1, 0);
2N/A for(k=0; k<pIdx->nColumn; k++){
2N/A int idx = pIdx->aiColumn[k];
2N/A if( idx==pTab->iPKey ){
2N/A sqliteVdbeAddOp(v, OP_Recno, 1, 0);
2N/A }else{
2N/A sqliteVdbeAddOp(v, OP_Column, 1, idx);
2N/A }
2N/A }
2N/A sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0);
2N/A if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIdx);
2N/A jmp2 = sqliteVdbeAddOp(v, OP_Found, j+2, 0);
2N/A addr = sqliteVdbeAddOpList(v, ArraySize(idxErr), idxErr);
2N/A sqliteVdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
2N/A sqliteVdbeChangeP2(v, jmp2, sqliteVdbeCurrentAddr(v));
2N/A }
2N/A sqliteVdbeAddOp(v, OP_Next, 1, loopTop+1);
2N/A sqliteVdbeChangeP2(v, loopTop, sqliteVdbeCurrentAddr(v));
2N/A for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
2N/A static VdbeOpList cntIdx[] = {
2N/A { OP_Integer, 0, 0, 0},
2N/A { OP_MemStore, 2, 1, 0},
2N/A { OP_Rewind, 0, 0, 0}, /* 2 */
2N/A { OP_MemIncr, 2, 0, 0},
2N/A { OP_Next, 0, 0, 0}, /* 4 */
2N/A { OP_MemLoad, 1, 0, 0},
2N/A { OP_MemLoad, 2, 0, 0},
2N/A { OP_Eq, 0, 0, 0}, /* 7 */
2N/A { OP_MemIncr, 0, 0, 0},
2N/A { OP_String, 0, 0, "wrong # of entries in index "},
2N/A { OP_String, 0, 0, 0}, /* 10 */
2N/A { OP_Concat, 2, 0, 0},
2N/A { OP_Callback, 1, 0, 0},
2N/A };
2N/A if( pIdx->tnum==0 ) continue;
2N/A addr = sqliteVdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
2N/A sqliteVdbeChangeP1(v, addr+2, j+2);
2N/A sqliteVdbeChangeP2(v, addr+2, addr+5);
2N/A sqliteVdbeChangeP1(v, addr+4, j+2);
2N/A sqliteVdbeChangeP2(v, addr+4, addr+3);
2N/A sqliteVdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
2N/A sqliteVdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
2N/A }
2N/A }
2N/A }
2N/A addr = sqliteVdbeAddOpList(v, ArraySize(endCode), endCode);
2N/A sqliteVdbeChangeP2(v, addr+2, addr+ArraySize(endCode));
2N/A }else
2N/A
2N/A {}
2N/A sqliteFree(zLeft);
2N/A sqliteFree(zRight);
2N/A}