diff options
author | dan <Dan Kennedy> | 2023-01-28 17:37:37 +0000 |
---|---|---|
committer | dan <Dan Kennedy> | 2023-01-28 17:37:37 +0000 |
commit | 20438431c88c2852a501765c7dbb57c3fc5f45ed (patch) | |
tree | 24e31a678e2677dd24a9164927034bcb914014cf /src | |
parent | 54c9250b09c18507b0a169200219b2d351f6865f (diff) | |
download | sqlite-20438431c88c2852a501765c7dbb57c3fc5f45ed.tar.gz sqlite-20438431c88c2852a501765c7dbb57c3fc5f45ed.zip |
Fix a problem causing "PRAGMA quick_check" to return spurious corruption errors for a WITHOUT ROWID for which all columns are either virtual or part of the primary key, and for which the order of the columns in the primary key definition is different from the order in the table.
FossilOrigin-Name: a7530f897127f35a212db6557edbcbbb286cc0e094754c1c1b74ce8dbf724470
Diffstat (limited to 'src')
-rw-r--r-- | src/pragma.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/pragma.c b/src/pragma.c index 527b2a734..522a12d33 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1785,12 +1785,21 @@ void sqlite3Pragma( ** will also prepopulate the cursor column cache that is used ** by the OP_IsType code, so it is a required step. */ - mxCol = pTab->nCol-1; - while( mxCol>=0 - && ((pTab->aCol[mxCol].colFlags & COLFLAG_VIRTUAL)!=0 - || pTab->iPKey==mxCol) ) mxCol--; + assert( !IsVirtual(pTab) ); + if( HasRowid(pTab) ){ + mxCol = -1; + for(j=0; j<pTab->nCol; j++){ + if( (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)==0 ) mxCol++; + } + if( mxCol==pTab->iPKey ) mxCol--; + }else{ + /* COLFLAG_VIRTUAL columns are not included in the WITHOUT ROWID + ** PK index column-count, so there is no need to account for them + ** in this case. */ + mxCol = sqlite3PrimaryKeyIndex(pTab)->nColumn-1; + } if( mxCol>=0 ){ - sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, mxCol, 3); + sqlite3VdbeAddOp3(v, OP_Column, iDataCur, mxCol, 3); sqlite3VdbeTypeofColumn(v, 3); } |