diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/alter.c | 5 | ||||
-rw-r--r-- | src/analyze.c | 2 | ||||
-rw-r--r-- | src/build.c | 38 | ||||
-rw-r--r-- | src/expr.c | 9 | ||||
-rw-r--r-- | src/insert.c | 8 | ||||
-rw-r--r-- | src/sqliteInt.h | 27 | ||||
-rw-r--r-- | src/upsert.c | 2 | ||||
-rw-r--r-- | src/vdbeapi.c | 4 | ||||
-rw-r--r-- | src/where.c | 4 | ||||
-rw-r--r-- | src/wherecode.c | 6 |
10 files changed, 64 insertions, 41 deletions
diff --git a/src/alter.c b/src/alter.c index f8cada0e3..b7389bf9c 100644 --- a/src/alter.c +++ b/src/alter.c @@ -1334,6 +1334,11 @@ static void renameColumnFunc( sqlite3WalkExprList(&sWalker, pIdx->aColExpr); } } +#ifndef SQLITE_OMIT_GENERATED_COLUMNS + for(i=0; i<sParse.pNewTable->nCol; i++){ + sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt); + } +#endif for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){ for(i=0; i<pFKey->nCol; i++){ diff --git a/src/analyze.c b/src/analyze.c index 8f73853c8..6df6e7a6e 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1182,7 +1182,7 @@ static void analyzeOneTable( int j, k, regKey; regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol); for(j=0; j<pPk->nKeyCol; j++){ - k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]); + k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]); assert( k>=0 && k<pIdx->nColumn ); sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j); VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName)); diff --git a/src/build.c b/src/build.c index f00dc32ad..48f3a1c1e 100644 --- a/src/build.c +++ b/src/build.c @@ -877,10 +877,12 @@ Index *sqlite3PrimaryKeyIndex(Table *pTab){ } /* -** Return the true column number of index pIdx that corresponds to table -** true column iCol. Return -1 if not found. +** Convert an table column number into a index column number. That is, +** for the column iCol in the table (as defined by the CREATE TABLE statement) +** find the (first) offset of that column in index pIdx. Or return -1 +** if column iCol is not used in index pIdx. */ -i16 sqlite3ColumnOfIndex(Index *pIdx, i16 iCol){ +i16 sqlite3TableColumnToIndex(Index *pIdx, i16 iCol){ int i; for(i=0; i<pIdx->nColumn; i++){ if( iCol==pIdx->aiColumn[i] ) return i; @@ -889,20 +891,20 @@ i16 sqlite3ColumnOfIndex(Index *pIdx, i16 iCol){ } #ifndef SQLITE_OMIT_GENERATED_COLUMNS -/* Convert a storage column number into a true column number. +/* Convert a storage column number into a table column number. ** ** The storage column number (0,1,2,....) is the index of the value ** as it appears in the record on disk. The true column number ** is the index (0,1,2,...) of the column in the CREATE TABLE statement. ** -** The storage column number is less than the true column number if -** and only there are virtual columns to the left. +** The storage column number is less than the table column number if +** and only there are VIRTUAL columns to the left. ** ** If SQLITE_OMIT_GENERATED_COLUMNS, this routine is a no-op macro. ** -** This function is the inverse of sqlite3ColumnOfTable(). +** This function is the inverse of sqlite3TableColumnToStorage(). */ -i16 sqlite3ColumnOfStorage(Table *pTab, i16 iCol){ +i16 sqlite3StorageColumnToTable(Table *pTab, i16 iCol){ if( pTab->tabFlags & TF_HasVirtual ){ int i; for(i=0; i<=iCol; i++){ @@ -914,7 +916,7 @@ i16 sqlite3ColumnOfStorage(Table *pTab, i16 iCol){ #endif #ifndef SQLITE_OMIT_GENERATED_COLUMNS -/* Convert a true column number into a storage column number. +/* Convert a table column number into a storage column number. ** ** The storage column number (0,1,2,....) is the index of the value ** as it appears in the record on disk. The true column number @@ -922,9 +924,9 @@ i16 sqlite3ColumnOfStorage(Table *pTab, i16 iCol){ ** ** If SQLITE_OMIT_GENERATED_COLUMNS, this routine is a no-op macro. ** -** This function is the inverse of sqlite3ColumnOfStorage(). +** This function is the inverse of sqlite3StorageColumnToTable(). */ -i16 sqlite3ColumnOfTable(Table *pTab, i16 iCol){ +i16 sqlite3TableColumnToStorage(Table *pTab, i16 iCol){ int i; i16 n; assert( iCol<pTab->nCol ); @@ -1577,11 +1579,12 @@ void sqlite3AddGenerated(Parse *pParse, Expr *pExpr, Token *pType){ u8 eType = COLFLAG_VIRTUAL; Table *pTab = pParse->pNewTable; Column *pCol; - if( IN_RENAME_OBJECT ){ - sqlite3RenameExprUnmap(pParse, pExpr); - } if( pTab==0 ) goto generated_done; pCol = &(pTab->aCol[pTab->nCol-1]); + if( IN_DECLARE_VTAB ){ + sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns"); + goto generated_done; + } if( pCol->pDflt ) goto generated_error; if( pType ){ if( pType->n==7 && sqlite3StrNICmp("virtual",pType->z,7)==0 ){ @@ -1597,7 +1600,8 @@ void sqlite3AddGenerated(Parse *pParse, Expr *pExpr, Token *pType){ assert( TF_HasVirtual==COLFLAG_VIRTUAL ); assert( TF_HasStored==COLFLAG_STORED ); pTab->tabFlags |= eType; - pCol->pDflt = sqlite3ExprDup(pParse->db, pExpr, 0); + pCol->pDflt = pExpr; + pExpr = 0; goto generated_done; generated_error: @@ -3651,13 +3655,13 @@ void sqlite3CreateIndex( /* If this index contains every column of its table, then mark ** it as a covering index */ assert( HasRowid(pTab) - || pTab->iPKey<0 || sqlite3ColumnOfIndex(pIndex, pTab->iPKey)>=0 ); + || pTab->iPKey<0 || sqlite3TableColumnToIndex(pIndex, pTab->iPKey)>=0 ); recomputeColumnsNotIndexed(pIndex); if( pTblName!=0 && pIndex->nColumn>=pTab->nCol ){ pIndex->isCovering = 1; for(j=0; j<pTab->nCol; j++){ if( j==pTab->iPKey ) continue; - if( sqlite3ColumnOfIndex(pIndex,j)>=0 ) continue; + if( sqlite3TableColumnToIndex(pIndex,j)>=0 ) continue; pIndex->isCovering = 0; break; } diff --git a/src/expr.c b/src/expr.c index 41ffe716e..c57a0000d 100644 --- a/src/expr.c +++ b/src/expr.c @@ -3410,10 +3410,10 @@ void sqlite3ExprCodeGetColumnOfTable( return; #endif }else if( !HasRowid(pTab) ){ - x = sqlite3ColumnOfIndex(sqlite3PrimaryKeyIndex(pTab), iCol); + x = sqlite3TableColumnToIndex(sqlite3PrimaryKeyIndex(pTab), iCol); op = OP_Column; }else{ - x = sqlite3ColumnOfTable(pTab,iCol); + x = sqlite3TableColumnToStorage(pTab,iCol); op = OP_Column; } sqlite3VdbeAddOp3(v, op, iTabCur, x, regOut); @@ -3591,7 +3591,8 @@ expr_code_doover: return -1-pParse->iSelfTab; } pCol = pTab->aCol + pExpr->iColumn; - iSrc = sqlite3ColumnOfTable(pTab, pExpr->iColumn) - pParse->iSelfTab; + iSrc = sqlite3TableColumnToStorage(pTab, pExpr->iColumn) + - pParse->iSelfTab; #ifndef SQLITE_OMIT_GENERATED_COLUMNS if( pCol->colFlags & COLFLAG_GENERATED ){ if( pCol->colFlags & COLFLAG_BUSY ){ @@ -5320,7 +5321,7 @@ struct IdxCover { static int exprIdxCover(Walker *pWalker, Expr *pExpr){ if( pExpr->op==TK_COLUMN && pExpr->iTable==pWalker->u.pIdxCover->iCur - && sqlite3ColumnOfIndex(pWalker->u.pIdxCover->pIdx, pExpr->iColumn)<0 + && sqlite3TableColumnToIndex(pWalker->u.pIdxCover->pIdx, pExpr->iColumn)<0 ){ pWalker->eCode = 1; return WRC_Abort; diff --git a/src/insert.c b/src/insert.c index fe275d5a0..88b8e6ad2 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1055,7 +1055,7 @@ void sqlite3Insert( int k; u32 colFlags; assert( i>=nHidden ); - assert( iRegStore==sqlite3ColumnOfTable(pTab,i)+regRowid+1 ); + assert( iRegStore==sqlite3TableColumnToStorage(pTab,i)+regRowid+1 ); if( i==pTab->iPKey ){ /* The value of the INTEGER PRIMARY KEY column is always a NULL. ** Whenever this column is read, the rowid will be substituted @@ -1464,7 +1464,7 @@ void sqlite3GenerateConstraintChecks( pParse->iSelfTab = 0; if( onError==OE_Replace ) onError = OE_Abort; }else{ - iReg = sqlite3ColumnOfTable(pTab, i) + regNewData + 1; + iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1; } switch( onError ){ case OE_Replace: { @@ -1782,7 +1782,7 @@ void sqlite3GenerateConstraintChecks( VdbeComment((v, "%s column %d", pIdx->zName, i)); #endif }else{ - x = sqlite3ColumnOfTable(pTab, iField) + regNewData + 1; + x = sqlite3TableColumnToStorage(pTab, iField) + regNewData + 1; sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); VdbeComment((v, "%s", pTab->aCol[iField].zName)); } @@ -1873,7 +1873,7 @@ void sqlite3GenerateConstraintChecks( if( pIdx!=pPk ){ for(i=0; i<pPk->nKeyCol; i++){ assert( pPk->aiColumn[i]>=0 ); - x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]); + x = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]); sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i); VdbeComment((v, "%s.%s", pTab->zName, pTab->aCol[pPk->aiColumn[i]].zName)); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a1e6e175b..10b2eeaf3 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1818,8 +1818,21 @@ struct Module { }; /* -** information about each column of an SQL table is held in an instance -** of this structure. +** Information about each column of an SQL table is held in an instance +** of the Column structure, in the Table.aCol[] array. +** +** Definitions: +** +** "table column index" This is the index of the column in the +** Table.aCol[] array, and also the index of +** the column in the original CREATE TABLE stmt. +** +** "storage column index" This is the index of the column in the +** record BLOB generated by the OP_MakeRecord +** opcode. The storage column index is less than +** or equal to the table column index. It is +** equal if and only if there are no VIRTUAL +** columns to the left. */ struct Column { char *zName; /* Name of this column, \000, then the type */ @@ -3952,13 +3965,13 @@ void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char); Table *sqlite3ResultSetOfSelect(Parse*,Select*,char); void sqlite3OpenMasterTable(Parse *, int); Index *sqlite3PrimaryKeyIndex(Table*); -i16 sqlite3ColumnOfIndex(Index*, i16); +i16 sqlite3TableColumnToIndex(Index*, i16); #ifdef SQLITE_OMIT_GENERATED_COLUMNS -# define sqlite3ColumnOfTable(T,X) (X) /* No-op pass-through */ -# define sqlite3ColumnOfStorage(T,X) (X) /* No-op pass-through */ +# define sqlite3TableColumnToStorage(T,X) (X) /* No-op pass-through */ +# define sqlite3StorageColumnToTable(T,X) (X) /* No-op pass-through */ #else - i16 sqlite3ColumnOfTable(Table*, i16); - i16 sqlite3ColumnOfStorage(Table*, i16); + i16 sqlite3TableColumnToStorage(Table*, i16); + i16 sqlite3StorageColumnToTable(Table*, i16); #endif void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); #if SQLITE_ENABLE_HIDDEN_COLUMNS diff --git a/src/upsert.c b/src/upsert.c index 7beb9ffae..5db4f5fc9 100644 --- a/src/upsert.c +++ b/src/upsert.c @@ -226,7 +226,7 @@ void sqlite3UpsertDoUpdate( for(i=0; i<nPk; i++){ int k; assert( pPk->aiColumn[i]>=0 ); - k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]); + k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[i]); sqlite3VdbeAddOp3(v, OP_Column, iCur, k, iPk+i); VdbeComment((v, "%s.%s", pIdx->zName, pTab->aCol[pPk->aiColumn[i]].zName)); diff --git a/src/vdbeapi.c b/src/vdbeapi.c index c7968ee60..074d45881 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -1831,7 +1831,7 @@ int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){ goto preupdate_old_out; } if( p->pPk ){ - iIdx = sqlite3ColumnOfIndex(p->pPk, iIdx); + iIdx = sqlite3TableColumnToIndex(p->pPk, iIdx); } if( iIdx>=p->pCsr->nField || iIdx<0 ){ rc = SQLITE_RANGE; @@ -1921,7 +1921,7 @@ int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppValue){ goto preupdate_new_out; } if( p->pPk && p->op!=SQLITE_UPDATE ){ - iIdx = sqlite3ColumnOfIndex(p->pPk, iIdx); + iIdx = sqlite3TableColumnToIndex(p->pPk, iIdx); } if( iIdx>=p->pCsr->nField || iIdx<0 ){ rc = SQLITE_RANGE; diff --git a/src/where.c b/src/where.c index 252e90665..ec2d3847b 100644 --- a/src/where.c +++ b/src/where.c @@ -5379,9 +5379,9 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ x = pPk->aiColumn[x]; assert( x>=0 ); }else{ - x = sqlite3ColumnOfStorage(pTab,x); + x = sqlite3StorageColumnToTable(pTab,x); } - x = sqlite3ColumnOfIndex(pIdx, x); + x = sqlite3TableColumnToIndex(pIdx, x); if( x>=0 ){ pOp->p2 = x; pOp->p1 = pLevel->iIdxCur; diff --git a/src/wherecode.c b/src/wherecode.c index af395a326..686a8d6f9 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -823,7 +823,7 @@ static int codeCursorHintCheckExpr(Walker *pWalker, Expr *pExpr){ assert( pHint->pIdx!=0 ); if( pExpr->op==TK_COLUMN && pExpr->iTable==pHint->iTabCur - && sqlite3ColumnOfIndex(pHint->pIdx, pExpr->iColumn)<0 + && sqlite3TableColumnToIndex(pHint->pIdx, pExpr->iColumn)<0 ){ pWalker->eCode = 1; } @@ -891,7 +891,7 @@ static int codeCursorHintFixExpr(Walker *pWalker, Expr *pExpr){ pExpr->iTable = reg; }else if( pHint->pIdx!=0 ){ pExpr->iTable = pHint->iIdxCur; - pExpr->iColumn = sqlite3ColumnOfIndex(pHint->pIdx, pExpr->iColumn); + pExpr->iColumn = sqlite3TableColumnToIndex(pHint->pIdx, pExpr->iColumn); assert( pExpr->iColumn>=0 ); } }else if( pExpr->op==TK_AGG_FUNCTION ){ @@ -1826,7 +1826,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable); iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol); for(j=0; j<pPk->nKeyCol; j++){ - k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]); + k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]); sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j); } sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont, |