diff options
author | drh <drh@noemail.net> | 2019-10-22 13:01:24 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-10-22 13:01:24 +0000 |
commit | 427b96aedf422b1a8e906e47e8852033c70939c4 (patch) | |
tree | bafbbb3a6d6bc0146d7d7829ec22d9c7eecfb9bf /src/insert.c | |
parent | 6b910364bbf531670aa0c02ad004bcdf2f5b66ad (diff) | |
download | sqlite-427b96aedf422b1a8e906e47e8852033c70939c4.tar.gz sqlite-427b96aedf422b1a8e906e47e8852033c70939c4.zip |
New testcase() macros. Fix a problem with INSERT when the IPK is to the
right of generated columns.
FossilOrigin-Name: 412799fc5527aaca987e4e04b8a4f774dcdb70fb80e3a126dc3a26d48a66935c
Diffstat (limited to 'src/insert.c')
-rw-r--r-- | src/insert.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/insert.c b/src/insert.c index c90f9d272..1995f9634 100644 --- a/src/insert.c +++ b/src/insert.c @@ -222,6 +222,8 @@ void sqlite3ComputeGeneratedColumns( */ for(i=0; i<pTab->nCol; i++){ if( pTab->aCol[i].colFlags & COLFLAG_GENERATED ){ + testcase( pTab->aCol[i].colflags & COLFLAG_VIRTUAL ); + testcase( pTab->aCol[i].colflags & COLFLAG_STORED ); pTab->aCol[i].colFlags |= COLFLAG_NOTAVAIL; } } @@ -854,6 +856,19 @@ void sqlite3Insert( */ if( pColumn==0 && nColumn>0 ){ ipkColumn = pTab->iPKey; +#ifndef SQLITE_OMIT_GENERATED_COLUMNS + if( pTab->tabFlags & TF_HasGenerated ){ + testcase( pTab->tabFlags & TF_HasVirtual ); + testcase( pTab->tabFlags & TF_HasGenerated ); + for(i=ipkColumn-1; i>=0; i--){ + if( pTab->aCol[i].colFlags & COLFLAG_GENERATED ){ + testcase( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ); + testcase( pTab->aCol[i].colFlags & COLFLAG_GENERATED ); + ipkColumn--; + } + } + } +#endif } /* Make sure the number of columns in the source data matches the number @@ -1070,7 +1085,9 @@ void sqlite3Insert( ** columns have already been computed. This must be done after ** computing the ROWID in case one of the generated columns ** refers to the ROWID. */ - if( pTab->tabFlags & (TF_HasStored|TF_HasVirtual) ){ + if( pTab->tabFlags & TF_HasGenerated ){ + testcase( pTab->tabFlags & TF_HasVirtual ); + testcase( pTab->tabFlags & TF_HasStored ); sqlite3ComputeGeneratedColumns(pParse, regCols+1, pTab); } #endif @@ -1139,7 +1156,9 @@ void sqlite3Insert( ** columns have already been computed. This must be done after ** computing the ROWID in case one of the generated columns ** refers to the ROWID. */ - if( pTab->tabFlags & (TF_HasStored|TF_HasVirtual) ){ + if( pTab->tabFlags & TF_HasGenerated ){ + testcase( pTab->tabFlags & TF_HasVirtual ); + testcase( pTab->tabFlags & TF_HasStored ); sqlite3ComputeGeneratedColumns(pParse, regRowid+1, pTab); } #endif @@ -1486,7 +1505,6 @@ void sqlite3GenerateConstraintChecks( testcase( i!=sqlite3TableColumnToStorage(pTab, i) ); testcase( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ); testcase( pTab->aCol[i].colFlags & COLFLAG_STORED ); - testcase( pTab->aCol[i].colFlags & COLFLAG_GENERATED ); iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1; switch( onError ){ case OE_Replace: { @@ -2422,7 +2440,9 @@ static int xferOptimization( /* Generator expressions for generated columns must match */ if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){ if( sqlite3ExprCompare(0, pSrcCol->pDflt, pDestCol->pDflt, -1)!=0 ){ - return 0; /* Different generator expressions */ + testcase( pDestCol->colflags & COLFLAG_VIRTUAL ); + testcase( pDestCol->colflags & COLFLAG_STORED ); + return 0; /* Different generator expressions */ } } } |