Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -899,11 +899,11 @@ */ i16 sqlite3ColumnOfTable(Table *pTab, i16 iCol){ int i; i16 n; assert( iColnCol ); - if( pTab->nVCol==0 ) return iCol; + if( (pTab->tabFlags & TF_HasVirtual)==0 ) return iCol; for(i=0, n=0; iaCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) n++; } return n; } @@ -1562,11 +1562,10 @@ eType = COLFLAG_STORED; }else{ goto generated_error; } } - if( eType==COLFLAG_VIRTUAL ) pTab->nVCol++; pCol->colFlags |= eType; assert( TF_HasVirtual==COLFLAG_VIRTUAL ); assert( TF_HasStored==COLFLAG_STORED ); pTab->tabFlags |= eType; pCol->pDflt = sqlite3ExprDup(pParse->db, pExpr, 0); @@ -2125,10 +2124,11 @@ return; } assert( !db->mallocFailed ); p = pParse->pNewTable; if( p==0 ) return; + p->nNVCol = p->nCol; if( pSelect==0 && isShadowTableName(db, p->zName) ){ p->tabFlags |= TF_Shadow; } @@ -2181,11 +2181,16 @@ #endif /* !defined(SQLITE_OMIT_CHECK) */ #ifndef SQLITE_OMIT_GENERATED_COLUMNS if( p->tabFlags & (TF_HasVirtual|TF_HasStored) ){ int ii; for(ii=0; iinCol; ii++){ - if( (p->aCol[ii].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL))!=0 ){ + u32 colFlags = p->aCol[ii].colFlags; + if( (colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL))!=0 ){ + if( colFlags & COLFLAG_VIRTUAL ){ + p->nNVCol--; + assert( p->nNVCol>=0 ); + } sqlite3ResolveSelfReference(pParse, p, NC_GenCol, p->aCol[ii].pDflt, 0); } } } Index: src/insert.c ================================================================== --- src/insert.c +++ src/insert.c @@ -35,12 +35,11 @@ v = sqlite3GetVdbe(pParse); assert( opcode==OP_OpenWrite || opcode==OP_OpenRead ); sqlite3TableLock(pParse, iDb, pTab->tnum, (opcode==OP_OpenWrite)?1:0, pTab->zName); if( HasRowid(pTab) ){ - sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, - pTab->nCol - pTab->nVCol); + sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nNVCol); VdbeComment((v, "%s", pTab->zName)); }else{ Index *pPk = sqlite3PrimaryKeyIndex(pTab); assert( pPk!=0 ); assert( pPk->tnum==pTab->tnum ); @@ -1931,12 +1930,11 @@ } /* Generate the table record */ if( HasRowid(pTab) ){ int regRec = aRegIdx[ix]; - sqlite3VdbeAddOp3(v, OP_MakeRecord, regNewData+1, - pTab->nCol-pTab->nVCol, regRec); + sqlite3VdbeAddOp3(v, OP_MakeRecord, regNewData+1, pTab->nNVCol, regRec); sqlite3SetMakeRecordP5(v, pTab); if( !bAffinityDone ){ sqlite3TableAffinity(v, pTab, 0); } } Index: src/pragma.c ================================================================== --- src/pragma.c +++ src/pragma.c @@ -1584,11 +1584,11 @@ assert( sqlite3NoTempsInRange(pParse,1,7+j) ); sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v); loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1); if( !isQuick ){ /* Sanity check on record header decoding */ - sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nCol-pTab->nVCol-1,3); + sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nNVCol-1,3); sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); } /* Verify that all NOT NULL columns really are NOT NULL */ for(j=0; jnCol; j++){ char *zErr; Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -1980,11 +1980,11 @@ int tnum; /* Root BTree page for this table */ u32 nTabRef; /* Number of pointers to this Table */ u32 tabFlags; /* Mask of TF_* values */ i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */ i16 nCol; /* Number of columns in this table */ - i16 nVCol; /* Number of virtual columns */ + i16 nNVCol; /* Number of columns that are not VIRTUAL */ LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ LogEst szTabRow; /* Estimated size of each table row in bytes */ #ifdef SQLITE_ENABLE_COSTMULT LogEst costMult; /* Cost multiplier for using this table */ #endif