aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/build.c39
-rw-r--r--src/main.c29
-rw-r--r--src/parse.y4
-rw-r--r--src/pragma.c4
-rw-r--r--src/sqliteInt.h15
-rw-r--r--src/test1.c8
-rw-r--r--src/trigger.c4
-rw-r--r--src/vdbe.c4
8 files changed, 69 insertions, 38 deletions
diff --git a/src/build.c b/src/build.c
index f4b7003c4..bff72c40c 100644
--- a/src/build.c
+++ b/src/build.c
@@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
-** $Id: build.c,v 1.317 2005/03/28 03:39:56 drh Exp $
+** $Id: build.c,v 1.318 2005/03/29 03:10:59 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -168,7 +168,7 @@ Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
int i;
assert( zName!=0 );
assert( (db->flags & SQLITE_Initialized) || db->init.busy );
- for(i=0; i<db->nDb; i++){
+ for(i=OMIT_TEMPDB; i<db->nDb; i++){
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
p = sqlite3HashFind(&db->aDb[j].tblHash, zName, strlen(zName)+1);
@@ -227,7 +227,7 @@ Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
Index *p = 0;
int i;
assert( (db->flags & SQLITE_Initialized) || db->init.busy );
- for(i=0; i<db->nDb; i++){
+ for(i=OMIT_TEMPDB; i<db->nDb; i++){
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
p = sqlite3HashFind(&db->aDb[j].idxHash, zName, strlen(zName)+1);
@@ -537,7 +537,8 @@ static int findDb(sqlite3 *db, Token *pName){
if( zName ){
n = strlen(zName);
for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
- if( n==strlen(pDb->zName) && 0==sqlite3StrICmp(pDb->zName, zName) ){
+ if( (!OMIT_TEMPDB || i!=1 ) && n==strlen(pDb->zName) &&
+ 0==sqlite3StrICmp(pDb->zName, zName) ){
break;
}
}
@@ -656,12 +657,12 @@ void sqlite3StartTable(
*/
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
if( iDb<0 ) return;
- if( isTemp && iDb>1 ){
+ if( !OMIT_TEMPDB && isTemp && iDb>1 ){
/* If creating a temp table, the name may not be qualified */
sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
return;
}
- if( isTemp ) iDb = 1;
+ if( !OMIT_TEMPDB && isTemp ) iDb = 1;
pParse->sNameToken = *pName;
zName = sqlite3NameFromToken(pName);
@@ -679,13 +680,13 @@ void sqlite3StartTable(
goto begin_table_error;
}
if( isView ){
- if( isTemp ){
+ if( !OMIT_TEMPDB && isTemp ){
code = SQLITE_CREATE_TEMP_VIEW;
}else{
code = SQLITE_CREATE_VIEW;
}
}else{
- if( isTemp ){
+ if( !OMIT_TEMPDB && isTemp ){
code = SQLITE_CREATE_TEMP_TABLE;
}else{
code = SQLITE_CREATE_TABLE;
@@ -1376,7 +1377,7 @@ static char *createTableStmt(Table *p){
n += 35 + 6*p->nCol;
zStmt = sqliteMallocRaw( n );
if( zStmt==0 ) return 0;
- strcpy(zStmt, p->iDb==1 ? "CREATE TEMP TABLE " : "CREATE TABLE ");
+ strcpy(zStmt, !OMIT_TEMPDB&&p->iDb==1 ? "CREATE TEMP TABLE ":"CREATE TABLE ");
k = strlen(zStmt);
identPut(zStmt, &k, p->zName);
zStmt[k++] = '(';
@@ -1865,13 +1866,13 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView){
goto exit_drop_table;
}
if( isView ){
- if( iDb==1 ){
+ if( !OMIT_TEMPDB && iDb==1 ){
code = SQLITE_DROP_TEMP_VIEW;
}else{
code = SQLITE_DROP_VIEW;
}
}else{
- if( iDb==1 ){
+ if( !OMIT_TEMPDB && iDb==1 ){
code = SQLITE_DROP_TEMP_TABLE;
}else{
code = SQLITE_DROP_TABLE;
@@ -2189,7 +2190,6 @@ void sqlite3CreateIndex(
int i, j;
Token nullId; /* Fake token for an empty ID list */
DbFixer sFix; /* For assigning database names to pTable */
- int isTemp; /* True for a temporary index */
sqlite3 *db = pParse->db;
int iDb; /* Index of the database that is being written */
@@ -2210,6 +2210,7 @@ void sqlite3CreateIndex(
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
if( iDb<0 ) goto exit_create_index;
+#ifndef SQLITE_OMIT_TEMPDB
/* If the index name was unqualified, check if the the table
** is a temp table. If so, set the database to 1.
*/
@@ -2217,6 +2218,7 @@ void sqlite3CreateIndex(
if( pName2 && pName2->n==0 && pTab && pTab->iDb==1 ){
iDb = 1;
}
+#endif
if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) &&
sqlite3FixSrcList(&sFix, pTblName)
@@ -2244,7 +2246,6 @@ void sqlite3CreateIndex(
goto exit_create_index;
}
#endif
- isTemp = pTab->iDb==1;
/*
** Find the name of the index. Make sure there is not already another
@@ -2294,12 +2295,12 @@ void sqlite3CreateIndex(
*/
#ifndef SQLITE_OMIT_AUTHORIZATION
{
- const char *zDb = db->aDb[pTab->iDb].zName;
- if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
+ const char *zDb = db->aDb[iDb].zName;
+ if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
goto exit_create_index;
}
i = SQLITE_CREATE_INDEX;
- if( isTemp ) i = SQLITE_CREATE_TEMP_INDEX;
+ if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
if( sqlite3AuthCheck(pParse, i, zName, pTab->zName, zDb) ){
goto exit_create_index;
}
@@ -2562,7 +2563,7 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName){
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
goto exit_drop_index;
}
- if( pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX;
+ if( !OMIT_TEMPDB && pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX;
if( sqlite3AuthCheck(pParse, code, pIndex->zName, pTab->zName, zDb) ){
goto exit_drop_index;
}
@@ -2870,7 +2871,7 @@ void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
if( (pParse->cookieMask & mask)==0 ){
pParse->cookieMask |= mask;
pParse->cookieValue[iDb] = db->aDb[iDb].schema_cookie;
- if( iDb==1 ){
+ if( !OMIT_TEMPDB && iDb==1 ){
sqlite3OpenTempDatabase(pParse);
}
}
@@ -2903,7 +2904,7 @@ void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
if( setStatement && pParse->nested==0 ){
sqlite3VdbeAddOp(v, OP_Statement, iDb, 0);
}
- if( iDb!=1 && pParse->db->aDb[1].pBt!=0 ){
+ if( (OMIT_TEMPDB || iDb!=1) && pParse->db->aDb[1].pBt!=0 ){
sqlite3BeginWriteOperation(pParse, setStatement, 1);
}
}
diff --git a/src/main.c b/src/main.c
index dca52977c..20335a01d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: main.c,v 1.283 2005/03/21 04:04:03 danielk1977 Exp $
+** $Id: main.c,v 1.284 2005/03/29 03:10:59 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -133,7 +133,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
int meta[10];
InitData initData;
char const *zMasterSchema;
- char const *zMasterName;
+ char const *zMasterName = SCHEMA_TABLE(iDb);
/*
** The master database table has a structure like this
@@ -147,6 +147,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
" sql text\n"
")"
;
+#ifndef SQLITE_OMIT_TEMPDB
static const char temp_master_schema[] =
"CREATE TEMP TABLE sqlite_temp_master(\n"
" type text,\n"
@@ -156,6 +157,9 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
" sql text\n"
")"
;
+#else
+ #define temp_master_schema 0
+#endif
assert( iDb>=0 && iDb<db->nDb );
@@ -163,13 +167,12 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
** and initialisation script appropriate for the database being
** initialised. zMasterName is the name of the master table.
*/
- if( iDb==1 ){
+ if( !OMIT_TEMPDB && iDb==1 ){
zMasterSchema = temp_master_schema;
- zMasterName = TEMP_MASTER_NAME;
}else{
zMasterSchema = master_schema;
- zMasterName = MASTER_NAME;
}
+ zMasterName = SCHEMA_TABLE(iDb);
/* Construct the schema tables. */
sqlite3SafetyOff(db);
@@ -195,7 +198,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
/* Create a cursor to hold the database open
*/
if( db->aDb[iDb].pBt==0 ){
- if( iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
+ if( !OMIT_TEMPDB && iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
return SQLITE_OK;
}
rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain);
@@ -351,12 +354,14 @@ int sqlite3Init(sqlite3 *db, char **pzErrMsg){
** for the TEMP database. This is loaded last, as the TEMP database
** schema may contain references to objects in other databases.
*/
+#ifndef SQLITE_OMIT_TEMPDB
if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
rc = sqlite3InitOne(db, 1, pzErrMsg);
if( rc ){
sqlite3ResetInternalSchema(db, 1);
}
}
+#endif
db->init.busy = 0;
if( rc==SQLITE_OK ){
@@ -1205,13 +1210,17 @@ static int openDatabase(
db->magic = SQLITE_MAGIC_CLOSED;
goto opendb_out;
}
- db->aDb[0].zName = "main";
- db->aDb[1].zName = "temp";
- /* The default safety_level for the main database is 'full' for the temp
- ** database it is 'NONE'. This matches the pager layer defaults. */
+ /* The default safety_level for the main database is 'full'; for the temp
+ ** database it is 'NONE'. This matches the pager layer defaults.
+ */
+ db->aDb[0].zName = "main";
db->aDb[0].safety_level = 3;
+#ifndef SQLITE_OMIT_TEMPDB
+ db->aDb[1].zName = "temp";
db->aDb[1].safety_level = 1;
+#endif
+
/* Register all built-in functions, but do not attempt to read the
** database schema yet. This is delayed until the first time the database
diff --git a/src/parse.y b/src/parse.y
index ad7fb2f98..e60fe1a43 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -14,7 +14,7 @@
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
-** @(#) $Id: parse.y,v 1.169 2005/03/17 05:03:40 danielk1977 Exp $
+** @(#) $Id: parse.y,v 1.170 2005/03/29 03:10:59 danielk1977 Exp $
*/
%token_prefix TK_
%token_type {Token}
@@ -112,7 +112,9 @@ create_table ::= CREATE(X) temp(T) TABLE nm(Y) dbnm(Z). {
sqlite3StartTable(pParse,&X,&Y,&Z,T,0);
}
%type temp {int}
+%ifndef SQLITE_OMIT_TEMPDB
temp(A) ::= TEMP. {A = 1;}
+%endif
temp(A) ::= . {A = 0;}
create_table_args ::= LP columnlist conslist_opt(X) RP(Y). {
sqlite3EndTable(pParse,&X,&Y,0);
diff --git a/src/pragma.c b/src/pragma.c
index e46d374b5..22b47af9d 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
-** $Id: pragma.c,v 1.90 2005/02/26 18:10:44 drh Exp $
+** $Id: pragma.c,v 1.91 2005/03/29 03:10:59 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -645,6 +645,8 @@ void sqlite3Pragma(
HashElem *x;
int cnt = 0;
+ if( OMIT_TEMPDB && i==1 ) continue;
+
sqlite3CodeVerifySchema(pParse, i);
/* Do an integrity check of the B-Tree
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 3934a6b63..2cd0e9595 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.374 2005/03/21 04:04:03 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.375 2005/03/29 03:10:59 danielk1977 Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@@ -68,6 +68,17 @@
#endif
/*
+** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
+** afterward. Having this macro allows us to cause the C compiler
+** to omit code used by TEMP tables without messy #ifndef statements.
+*/
+#ifdef SQLITE_OMIT_TEMPDB
+#define OMIT_TEMPDB 1
+#else
+#define OMIT_TEMPDB 0
+#endif
+
+/*
** If the following macro is set to 1, then NULL values are considered
** distinct for the SELECT DISTINCT statement and for UNION or EXCEPT
** compound queries. No other SQL database engine (among those tested)
@@ -292,7 +303,7 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
/*
** The name of the schema table.
*/
-#define SCHEMA_TABLE(x) (x==1?TEMP_MASTER_NAME:MASTER_NAME)
+#define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
/*
** A convenience macro that returns the number of elements in
diff --git a/src/test1.c b/src/test1.c
index 62855f695..2acfe7530 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test1.c,v 1.135 2005/03/21 04:04:02 danielk1977 Exp $
+** $Id: test1.c,v 1.136 2005/03/29 03:11:00 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -2862,6 +2862,12 @@ static void set_options(Tcl_Interp *interp){
Tcl_SetVar2(interp, "sqlite_options", "trigger", "1", TCL_GLOBAL_ONLY);
#endif
+#ifdef SQLITE_OMIT_TEMPDB
+ Tcl_SetVar2(interp, "sqlite_options", "tempdb", "0", TCL_GLOBAL_ONLY);
+#else
+ Tcl_SetVar2(interp, "sqlite_options", "tempdb", "1", TCL_GLOBAL_ONLY);
+#endif
+
#ifdef SQLITE_OMIT_UTF16
Tcl_SetVar2(interp, "sqlite_options", "utf16", "0", TCL_GLOBAL_ONLY);
#else
diff --git a/src/trigger.c b/src/trigger.c
index cdae012ea..29cbc3779 100644
--- a/src/trigger.c
+++ b/src/trigger.c
@@ -197,9 +197,9 @@ void sqlite3FinishTrigger(
sqlite3 *db = pParse->db; /* The database */
DbFixer sFix;
- if( pParse->nErr || pParse->pNewTrigger==0 ) goto triggerfinish_cleanup;
pTrig = pParse->pNewTrigger;
pParse->pNewTrigger = 0;
+ if( pParse->nErr || pTrig==0 ) goto triggerfinish_cleanup;
pTrig->step_list = pStepList;
while( pStepList ){
pStepList->pTrig = pTrig;
@@ -439,7 +439,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
zDb = pName->a[0].zDatabase;
zName = pName->a[0].zName;
nName = strlen(zName);
- for(i=0; i<db->nDb; i++){
+ for(i=OMIT_TEMPDB; i<db->nDb; i++){
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1);
diff --git a/src/vdbe.c b/src/vdbe.c
index 434183a5a..d4901a74c 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
-** $Id: vdbe.c,v 1.460 2005/03/21 03:53:38 danielk1977 Exp $
+** $Id: vdbe.c,v 1.461 2005/03/29 03:11:00 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -3819,7 +3819,7 @@ case OP_ParseSchema: {
assert( iDb>=0 && iDb<db->nDb );
if( !DbHasProperty(db, iDb, DB_SchemaLoaded) ) break;
- zMaster = iDb==1 ? TEMP_MASTER_NAME : MASTER_NAME;
+ zMaster = SCHEMA_TABLE(iDb);
initData.db = db;
initData.pzErrMsg = &p->zErrMsg;
zSql = sqlite3MPrintf(