aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2022-10-10 19:38:01 +0000
committerdrh <>2022-10-10 19:38:01 +0000
commitdb6940ab457adfaa02c102f6f9d9e80e1853d984 (patch)
treeffae1e22ae6d9fe3c37c5c06fe7243245c60d123 /src
parent49d77ee6426de5516957dc486205837fd1af3d95 (diff)
downloadsqlite-db6940ab457adfaa02c102f6f9d9e80e1853d984.tar.gz
sqlite-db6940ab457adfaa02c102f6f9d9e80e1853d984.zip
Fix corner-case bugs in the new integrity_check logic. All tests pass now.
FossilOrigin-Name: dbab9d52a842085da67f5d0b8e96c665adc16331accf380b4c234e9b05bdb7fb
Diffstat (limited to 'src')
-rw-r--r--src/pragma.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/pragma.c b/src/pragma.c
index 018fed5ef..c7f349740 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -1752,8 +1752,9 @@ void sqlite3Pragma(
int loopTop;
int iDataCur, iIdxCur;
int r1 = -1;
- int bStrict;
+ int bStrict; /* True for a STRICT table */
int r2; /* Previous key for WITHOUT ROWID tables */
+ int mxCol; /* Maximum non-virtual column number */
if( !IsOrdinaryTable(pTab) ) continue;
if( pObjTab && pObjTab!=pTab ) continue;
@@ -1778,10 +1779,20 @@ void sqlite3Pragma(
assert( sqlite3NoTempsInRange(pParse,1,7+j) );
sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
- /* Sanity check on record header decoding */
- sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nNVCol-1,3);
- sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
- VdbeComment((v, "(right-most column)"));
+
+ /* Fetch the right-most column from the table. This will cause
+ ** the entire record header to be parsed and sanity checked. It
+ ** will also prepopulate the */
+ mxCol = pTab->nCol-1;
+ while( mxCol>=0
+ && ((pTab->aCol[mxCol].colFlags & COLFLAG_VIRTUAL)!=0
+ || pTab->iPKey==mxCol) ) mxCol--;
+ if( mxCol>=0 ){
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, mxCol, 3);
+ if( sqlite3VdbeGetLastOp(v)->opcode==OP_Column ){
+ sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
+ }
+ }
if( !isQuick ){
if( pPk ){
/* Verify WITHOUT ROWID keys are in ascending order */
@@ -1826,7 +1837,7 @@ void sqlite3Pragma(
doTypeCheck = pCol->affinity>SQLITE_AFF_BLOB;
}
if( pCol->notNull==0 && !doTypeCheck ) continue;
- p4 = 0x10;
+ p4 = SQLITE_NULL;
if( pCol->colFlags & COLFLAG_VIRTUAL ){
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
p1 = -1;