Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -2660,12 +2660,14 @@ ** on disk. */ v = sqlite3GetVdbe(pParse); if( v ){ sqlite3BeginWriteOperation(pParse, 1, iDb); - sqlite3ClearStatTables(pParse, iDb, "tbl", pTab->zName); - sqlite3FkDropTable(pParse, pName, pTab); + if( !isView ){ + sqlite3ClearStatTables(pParse, iDb, "tbl", pTab->zName); + sqlite3FkDropTable(pParse, pName, pTab); + } sqlite3CodeDropTable(pParse, pTab, iDb, isView); } exit_drop_table: sqlite3SrcListDelete(db, pName); Index: src/fkey.c ================================================================== --- src/fkey.c +++ src/fkey.c @@ -708,15 +708,16 @@ ** the table from the database. Triggers are disabled while running this ** DELETE, but foreign key actions are not. */ void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){ sqlite3 *db = pParse->db; - if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) && !pTab->pSelect ){ + if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){ int iSkip = 0; Vdbe *v = sqlite3GetVdbe(pParse); assert( v ); /* VDBE has already been allocated */ + assert( pTab->pSelect==0 ); /* Not a view */ if( sqlite3FkReferences(pTab)==0 ){ /* Search for a deferred foreign key constraint for which this table ** is the child table. If one cannot be found, return without ** generating any VDBE code. If one can be found, then jump over ** the entire DELETE if there are no outstanding deferred constraints Index: test/view.test ================================================================== --- test/view.test +++ test/view.test @@ -672,7 +672,29 @@ unset -nocomplain x db eval {SELECT * FROM x1} x break lsort [array names x] } {{} * :1 :2} +do_test view-25.1 { + db eval { + CREATE TABLE t25 (x); + INSERT INTO t25 (x) VALUES (1); + ANALYZE; + } + proc authLogDelete {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && [string match sqlite_stat* $arg1]} { + lappend ::log [list $code $arg1 $arg2 $arg3 $arg4 $args] + } + return SQLITE_OK + } + set log "" + db authorizer ::authLogDelete + db eval {DROP VIEW x1;} + set log +} {} +do_test view-25.2 { + set log "" + db eval {DROP TABLE t25;} + set log +} {{SQLITE_DELETE sqlite_stat1 {} main {} {}}} finish_test