Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -2623,11 +2623,14 @@ db->xAuth = xAuth; #else pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE); #endif pParse->nTab = n; - if( pTable->pCheck ){ + if( pSelTab==0 ){ + pTable->nCol = 0; + nErr++; + }else if( pTable->pCheck ){ /* CREATE VIEW name(arglist) AS ... ** The names of the columns in the table are taken from ** arglist which is stored in pTable->pCheck. The pCheck field ** normally holds CHECK constraints on an ordinary table, but for ** a VIEW it holds the list of column names. @@ -2639,23 +2642,20 @@ && pTable->nCol==pSel->pEList->nExpr ){ sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel, SQLITE_AFF_NONE); } - }else if( pSelTab ){ + }else{ /* CREATE VIEW name AS... without an argument list. Construct ** the column names from the SELECT statement that defines the view. */ assert( pTable->aCol==0 ); pTable->nCol = pSelTab->nCol; pTable->aCol = pSelTab->aCol; pSelTab->nCol = 0; pSelTab->aCol = 0; assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) ); - }else{ - pTable->nCol = 0; - nErr++; } pTable->nNVCol = pTable->nCol; sqlite3DeleteTable(db, pSelTab); sqlite3SelectDelete(db, pSel); EnableLookaside; Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -4976,11 +4976,11 @@ } } /* Process NATURAL keywords, and ON and USING clauses of joins. */ - if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){ + if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){ return WRC_Abort; } /* For every "*" that occurs in the column list, insert the names of ** all columns in all tables. And for every TABLE.* insert the names Index: test/altertab3.test ================================================================== --- test/altertab3.test +++ test/altertab3.test @@ -529,6 +529,28 @@ do_catchsql_test 23.2 { ALTER TABLE t1 RENAME TO t1x; } {1 {error in trigger r1: no such table: main.t2}} +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 23.1 { + CREATE TABLE v0 (a); + CREATE VIEW v2 (v3) AS + WITH x1 AS (SELECT * FROM v2) + SELECT v3 AS x, v3 AS y FROM v2; +} + +do_catchsql_test 23.2 { + SELECT * FROM v2 +} {1 {view v2 is circularly defined}} + +db close +sqlite3 db test.db + +do_catchsql_test 23.3 { + ALTER TABLE v0 RENAME TO t3 ; +} {1 {error in view v2: view v2 is circularly defined}} + finish_test +