Disallow temporary indices on persistent tables. (CVS 1122)

FossilOrigin-Name: 72bf73b2c1e3594aa85920e47fc345bba56c80d0
This commit is contained in:
drh
2003-11-27 00:48:57 +00:00
parent 0802fd836d
commit 4925ca00a3
7 changed files with 33 additions and 32 deletions
+8 -11
View File
@@ -23,7 +23,7 @@
** ROLLBACK
** PRAGMA
**
** $Id: build.c,v 1.160 2003/09/06 22:18:08 drh Exp $
** $Id: build.c,v 1.161 2003/11/27 00:48:58 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -734,7 +734,7 @@ void sqliteAddPrimaryKey(Parse *pParse, IdList *pList, int onError){
pTab->iPKey = iCol;
pTab->keyConf = onError;
}else{
sqliteCreateIndex(pParse, 0, 0, pList, onError, 0, 0, 0);
sqliteCreateIndex(pParse, 0, 0, pList, onError, 0, 0);
pList = 0;
}
@@ -1537,7 +1537,6 @@ void sqliteCreateIndex(
SrcList *pTable, /* Name of the table to index. Use pParse->pNewTable if 0 */
IdList *pList, /* A list of columns to be indexed */
int onError, /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
int isTemp, /* True if this is a temporary index */
Token *pStart, /* The CREATE token that begins a CREATE TABLE statement */
Token *pEnd /* The ")" that closes the CREATE INDEX statement */
){
@@ -1547,10 +1546,11 @@ void sqliteCreateIndex(
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 */
sqlite *db = pParse->db;
if( pParse->nErr || sqlite_malloc_failed ) goto exit_create_index;
if( !isTemp && pParse->initFlag
if( pParse->initFlag
&& sqliteFixInit(&sFix, pParse, pParse->iDb, "index", pName)
&& sqliteFixSrcList(&sFix, pTable)
){
@@ -1575,9 +1575,9 @@ void sqliteCreateIndex(
pParse->nErr++;
goto exit_create_index;
}
if( !isTemp && pTab->iDb>=2 && pParse->initFlag==0 ){
if( pTab->iDb>=2 && pParse->initFlag==0 ){
sqliteSetString(&pParse->zErrMsg, "table ", pTab->zName,
" may not have non-temporary indices added", 0);
" may not have indices added", 0);
pParse->nErr++;
goto exit_create_index;
}
@@ -1586,9 +1586,7 @@ void sqliteCreateIndex(
pParse->nErr++;
goto exit_create_index;
}
if( pTab->iDb==1 ){
isTemp = 1;
}
isTemp = pTab->iDb==1;
/*
** Find the name of the index. Make sure there is not already another
@@ -1639,8 +1637,7 @@ void sqliteCreateIndex(
{
const char *zDb = db->aDb[pTab->iDb].zName;
assert( isTemp==0 || isTemp==1 );
assert( pTab->iDb==pParse->iDb || isTemp==1 );
assert( pTab->iDb==pParse->iDb || isTemp );
if( sqliteAuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
goto exit_create_index;
}
+5 -5
View File
@@ -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.103 2003/09/30 01:54:14 drh Exp $
** @(#) $Id: parse.y,v 1.104 2003/11/27 00:48:58 drh Exp $
*/
%token_prefix TK_
%token_type {Token}
@@ -177,7 +177,7 @@ carg ::= DEFAULT NULL.
ccons ::= NULL onconf.
ccons ::= NOT NULL onconf(R). {sqliteAddNotNull(pParse, R);}
ccons ::= PRIMARY KEY sortorder onconf(R). {sqliteAddPrimaryKey(pParse,0,R);}
ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0,0);}
ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);}
ccons ::= CHECK LP expr RP onconf.
ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R).
{sqliteCreateForeignKey(pParse,0,&T,TA,R);}
@@ -224,7 +224,7 @@ tcons ::= CONSTRAINT nm.
tcons ::= PRIMARY KEY LP idxlist(X) RP onconf(R).
{sqliteAddPrimaryKey(pParse,X,R);}
tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
{sqliteCreateIndex(pParse,0,0,X,R,0,0,0);}
{sqliteCreateIndex(pParse,0,0,X,R,0,0);}
tcons ::= CHECK expr onconf.
tcons ::= FOREIGN KEY LP idxlist(FA) RP
REFERENCES nm(T) idxlist_opt(TA) refargs(R) defer_subclause_opt(D). {
@@ -701,12 +701,12 @@ expritem(A) ::= . {A = 0;}
///////////////////////////// The CREATE INDEX command ///////////////////////
//
cmd ::= CREATE(S) temp(T) uniqueflag(U) INDEX nm(X)
cmd ::= CREATE(S) uniqueflag(U) INDEX nm(X)
ON nm(Y) dbnm(D) LP idxlist(Z) RP(E) onconf(R). {
SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D);
if( U!=OE_None ) U = R;
if( U==OE_Default) U = OE_Abort;
sqliteCreateIndex(pParse, &X, pSrc, Z, U, T, &S, &E);
sqliteCreateIndex(pParse, &X, pSrc, Z, U, &S, &E);
}
%type uniqueflag {int}
+2 -2
View File
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.202 2003/11/11 23:30:36 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.203 2003/11/27 00:48:58 drh Exp $
*/
#include "config.h"
#include "sqlite.h"
@@ -1101,7 +1101,7 @@ void sqliteSrcListAddAlias(SrcList*, Token*);
void sqliteSrcListAssignCursors(Parse*, SrcList*);
void sqliteIdListDelete(IdList*);
void sqliteSrcListDelete(SrcList*);
void sqliteCreateIndex(Parse*,Token*,SrcList*,IdList*,int,int,Token*,Token*);
void sqliteCreateIndex(Parse*,Token*,SrcList*,IdList*,int,Token*,Token*);
void sqliteDropIndex(Parse*, SrcList*);
void sqliteAddKeyType(Vdbe*, ExprList*);
void sqliteAddIdxKeyType(Vdbe*, Index*);