diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/expr.c | 2 | ||||
-rw-r--r-- | src/insert.c | 21 | ||||
-rw-r--r-- | src/parse.y | 6 | ||||
-rw-r--r-- | src/pragma.c | 2 | ||||
-rw-r--r-- | src/sqliteInt.h | 1 |
5 files changed, 22 insertions, 10 deletions
diff --git a/src/expr.c b/src/expr.c index fea7b0a18..e02e14658 100644 --- a/src/expr.c +++ b/src/expr.c @@ -3398,7 +3398,7 @@ void sqlite3ExprCodeGetColumnOfTable( }else if( pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL ){ int savedSelfTab = pParse->iSelfTab; pParse->iSelfTab = iTabCur+1; - sqlite3ExprCode(pParse, pTab->aCol[iCol].pDflt, iCol); + sqlite3ExprCode(pParse, pTab->aCol[iCol].pDflt, regOut); pParse->iSelfTab = savedSelfTab; return; #endif diff --git a/src/insert.c b/src/insert.c index d9078b89d..f2ed9d9a3 100644 --- a/src/insert.c +++ b/src/insert.c @@ -37,7 +37,8 @@ void sqlite3OpenTable( sqlite3TableLock(pParse, iDb, pTab->tnum, (opcode==OP_OpenWrite)?1:0, pTab->zName); if( HasRowid(pTab) ){ - sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nCol); + sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, + pTab->nCol - pTab->nVCol); VdbeComment((v, "%s", pTab->zName)); }else{ Index *pPk = sqlite3PrimaryKeyIndex(pTab); @@ -673,6 +674,14 @@ void sqlite3Insert( if( j==pTab->iPKey ){ ipkColumn = i; assert( !withoutRowid ); } +#ifndef SQLITE_OMIT_GENERATED_COLUMNS + if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){ + sqlite3ErrorMsg(pParse, + "cannot INSERT into generated column \"%s\"", + pTab->aCol[j].zName); + goto insert_cleanup; + } +#endif break; } } @@ -788,7 +797,7 @@ void sqlite3Insert( ** of columns to be inserted into the table. */ for(i=0; i<pTab->nCol; i++){ - nHidden += (IsHiddenColumn(&pTab->aCol[i]) ? 1 : 0); + if( pTab->aCol[i].colFlags & COLFLAG_NOINSERT ) nHidden++; } if( pColumn==0 && nColumn && nColumn!=(pTab->nCol-nHidden) ){ sqlite3ErrorMsg(pParse, @@ -1006,9 +1015,12 @@ void sqlite3Insert( continue; } if( pColumn==0 ){ - if( IsHiddenColumn(&pTab->aCol[i]) ){ + if( pTab->aCol[i].colFlags & COLFLAG_NOINSERT ){ j = -1; nHidden++; + if( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ){ + continue; + } }else{ j = i - nHidden; } @@ -1862,7 +1874,8 @@ void sqlite3GenerateConstraintChecks( /* Generate the table record */ if( HasRowid(pTab) ){ int regRec = aRegIdx[ix]; - sqlite3VdbeAddOp3(v, OP_MakeRecord, regNewData+1, pTab->nCol, regRec); + sqlite3VdbeAddOp3(v, OP_MakeRecord, regNewData+1, + pTab->nCol-pTab->nVCol, regRec); sqlite3SetMakeRecordP5(v, pTab); if( !bAffinityDone ){ sqlite3TableAffinity(v, pTab, 0); diff --git a/src/parse.y b/src/parse.y index 028a8c77d..b38304aa7 100644 --- a/src/parse.y +++ b/src/parse.y @@ -349,10 +349,8 @@ ccons ::= defer_subclause(D). {sqlite3DeferForeignKey(pParse,D);} ccons ::= COLLATE ids(C). {sqlite3AddCollateType(pParse, &C);} ccons ::= GENERATED ALWAYS AS generated. ccons ::= AS generated. -generated ::= LP expr(E) RP. - {sqlite3AddGenerated(pParse,E,0);} -generated ::= LP expr(E) RP ID(TYPE). - {sqlite3AddGenerated(pParse,E,&TYPE);} +generated ::= LP expr(E) RP. {sqlite3AddGenerated(pParse,E,0);} +generated ::= LP expr(E) RP ID(TYPE). {sqlite3AddGenerated(pParse,E,&TYPE);} // The optional AUTOINCREMENT keyword %type autoinc {int} diff --git a/src/pragma.c b/src/pragma.c index 4c715019e..652810eae 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1577,7 +1577,7 @@ void sqlite3Pragma( loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1); if( !isQuick ){ /* Sanity check on record header decoding */ - sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nCol-1, 3); + sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nCol-pTab->nVCol-1,3); sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); } /* Verify that all NOT NULL columns really are NOT NULL */ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index e16a5066c..94d7107a0 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1840,6 +1840,7 @@ struct Column { #define COLFLAG_SORTERREF 0x0010 /* Use sorter-refs with this column */ #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */ #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */ +#define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */ /* ** A "Collating Sequence" is defined by an instance of the following |