Fix a problem with foreign keys and generated columns discovered by

Manuel Rigger.

FossilOrigin-Name: 27c0fdab1ba4d4993b164eb4b777c63e82aa247c3fa406121dc8ed94970a0b35
This commit is contained in:
drh
2019-12-07 00:22:18 +00:00
parent 5102cf8df5
commit 7fe2fc0dcb
5 changed files with 70 additions and 12 deletions
+4 -2
View File
@@ -947,13 +947,15 @@ i16 sqlite3StorageColumnToTable(Table *pTab, i16 iCol){
** the end.
**
** If SQLITE_OMIT_GENERATED_COLUMNS then there are no virtual columns and
** this routine is a no-op macro.
** this routine is a no-op macro. If the pTab does not have any virtual
** columns, then this routine is no-op that always return iCol. If iCol
** is negative (indicating the ROWID column) then this routine return iCol.
*/
i16 sqlite3TableColumnToStorage(Table *pTab, i16 iCol){
int i;
i16 n;
assert( iCol<pTab->nCol );
if( (pTab->tabFlags & TF_HasVirtual)==0 ) return iCol;
if( (pTab->tabFlags & TF_HasVirtual)==0 || iCol<0 ) return iCol;
for(i=0, n=0; i<iCol; i++){
if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) n++;
}
+1 -1
View File
@@ -4136,7 +4136,7 @@ expr_code_doover:
Table *pTab = pExpr->y.pTab;
int iCol = pExpr->iColumn;
int p1 = pExpr->iTable * (pTab->nCol+1) + 1
+ (iCol>=0 ? sqlite3TableColumnToStorage(pTab, iCol) : -1);
+ sqlite3TableColumnToStorage(pTab, iCol);
assert( pExpr->iTable==0 || pExpr->iTable==1 );
assert( iCol>=-1 && iCol<pTab->nCol );