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