diff options
author | drh <drh@noemail.net> | 2019-11-16 13:51:31 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-11-16 13:51:31 +0000 |
commit | 070ae3beeabde3cb0538dad323d15a9b0411e6a0 (patch) | |
tree | f3f685fde6da1026d93f1f1666031b0a41835fd7 /src | |
parent | d0c51d1a041966bccc598d114aa17a13cf64d662 (diff) | |
download | sqlite-070ae3beeabde3cb0538dad323d15a9b0411e6a0.tar.gz sqlite-070ae3beeabde3cb0538dad323d15a9b0411e6a0.zip |
Break out the test for writable shadow tables into a separate subroutine.
FossilOrigin-Name: 8ad34d36a141fa8f5d9bd784dfeb892c983897a6dc6b867607cc668508acf944
Diffstat (limited to 'src')
-rw-r--r-- | src/alter.c | 5 | ||||
-rw-r--r-- | src/build.c | 25 | ||||
-rw-r--r-- | src/delete.c | 6 | ||||
-rw-r--r-- | src/sqliteInt.h | 1 |
4 files changed, 24 insertions, 13 deletions
diff --git a/src/alter.c b/src/alter.c index 0a82327d6..38446f998 100644 --- a/src/alter.c +++ b/src/alter.c @@ -31,9 +31,8 @@ static int isAlterableTable(Parse *pParse, Table *pTab){ if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) #ifndef SQLITE_OMIT_VIRTUALTABLE - || ( (pTab->tabFlags & TF_Shadow) - && (pParse->db->flags & SQLITE_Defensive) - && pParse->db->nVdbeExec==0 + || ( (pTab->tabFlags & TF_Shadow)!=0 + && sqlite3ReadOnlyShadowTables(pParse->db) ) #endif ){ diff --git a/src/build.c b/src/build.c index 2cc00d9d8..05b753dbb 100644 --- a/src/build.c +++ b/src/build.c @@ -2895,17 +2895,32 @@ void sqlite3CodeDropTable(Parse *pParse, Table *pTab, int iDb, int isView){ } /* +** Return TRUE if shadow tables should be read-only in the current +** context. +*/ +int sqlite3ReadOnlyShadowTables(sqlite3 *db){ +#ifndef SQLITE_OMIT_VIRTUALTABLE + if( (db->flags & SQLITE_Defensive)!=0 + && db->pVtabCtx==0 + && db->nVdbeExec==0 + ){ + return 1; + } +#endif + return 0; +} + +/* ** Return true if it is not allowed to drop the given table */ -static int tableMayNotBeDropped(Parse *pParse, Table *pTab){ +static int tableMayNotBeDropped(sqlite3 *db, Table *pTab){ if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){ if( sqlite3StrNICmp(pTab->zName+7, "stat", 4)==0 ) return 0; if( sqlite3StrNICmp(pTab->zName+7, "parameters", 10)==0 ) return 0; return 1; } - if( pTab->tabFlags & TF_Shadow ){ - sqlite3 *db = pParse->db; - if( (db->flags & SQLITE_Defensive)!=0 && db->nVdbeExec==0 ) return 1; + if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){ + return 1; } return 0; } @@ -2979,7 +2994,7 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, int noErr){ } } #endif - if( tableMayNotBeDropped(pParse, pTab) ){ + if( tableMayNotBeDropped(db, pTab) ){ sqlite3ErrorMsg(pParse, "table %s may not be dropped", pTab->zName); goto exit_drop_table; } diff --git a/src/delete.c b/src/delete.c index a18026712..0a83f1b64 100644 --- a/src/delete.c +++ b/src/delete.c @@ -70,11 +70,7 @@ static int tabIsReadOnly(Parse *pParse, Table *pTab){ return sqlite3WritableSchema(db)==0 && pParse->nested==0; } assert( pTab->tabFlags & TF_Shadow ); - return (db->flags & SQLITE_Defensive)!=0 -#ifndef SQLITE_OMIT_VIRTUALTABLE - && db->pVtabCtx==0 -#endif - && db->nVdbeExec==0; + return sqlite3ReadOnlyShadowTables(db); } /* diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 73dbdbfc7..1ec1018a5 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4547,6 +4547,7 @@ void sqlite3AutoLoadExtensions(sqlite3*); ); # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) #endif +int sqlite3ReadOnlyShadowTables(sqlite3 *db); int sqlite3VtabEponymousTableInit(Parse*,Module*); void sqlite3VtabEponymousTableClear(sqlite3*,Module*); void sqlite3VtabMakeWritable(Parse*,Table*); |