From: drh <> Date: Wed, 17 Aug 2022 18:07:52 +0000 (+0000) Subject: Enhance the "PRAGMA integrity_check" statement so that it verifies the rows of X-Git-Tag: version-3.40.0~234 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=16b03c01965a6feae64ca5e202717f68df9415ad;p=thirdparty%2Fsqlite.git Enhance the "PRAGMA integrity_check" statement so that it verifies the rows of a WITHOUT ROWID table are in the correct order. FossilOrigin-Name: 62f934bff495850d0763e07ffa44a557f066ecba9d039363f32287213cba819f --- diff --git a/manifest b/manifest index 761fdc8196..68c53fa159 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\scode\ssimplification\sin\sthe\scode\sgenerator\sfor\sPRAGMA\sintegrity\scheck. -D 2022-08-17T17:14:36.514 +C Enhance\sthe\s"PRAGMA\sintegrity_check"\sstatement\sso\sthat\sit\sverifies\sthe\srows\sof\na\sWITHOUT\sROWID\stable\sare\sin\sthe\scorrect\sorder. +D 2022-08-17T18:07:52.686 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -581,7 +581,7 @@ F src/parse.y 8e67d820030d2655b9942ffe61c1e7e6b96cea2f2f72183533299393907d0564 F src/pcache.c 084e638432c610f95aea72b8509f0845d2791293f39d1b82f0c0a7e089c3bb6b F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586 F src/pcache1.c 0b4245cd4964e635f2630908c2533cd8e9da7af3ca592e23ae8730aa25ae5eb9 -F src/pragma.c f857ee5dfdaa9ea00a04c37dbd33075d9d12b6f8c59cc8dec6de691d7bf08d3f +F src/pragma.c b57a859a366472131194a9ad35cd76d5920577226b04c884b1b9085605faa280 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c c62820c15dcb63013519c8e41d9f928d7478672cc902cfd0581c733c271dbf45 F src/printf.c e99ee9741e79ae3873458146f59644276657340385ade4e76a5f5d1c25793764 @@ -1999,8 +1999,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a0f801151925e882e120f6ab685dcacb9d3268d25b52bc665c5b927bcc7dda1e -R b8c3444adb3f1879cc53cf493efeffeb +P a3b9c7a6c9be5c78a93e5125f16237d2d84b977eca81f527af0198e96435a995 +R 3530f38cdde3fed1dbda570f4de01c0d U drh -Z a499216437f80b2eceb710f14f96178a +Z 5bcc55f0fe2746025d33da0258adb944 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fc5f8a601c..d75fa3c90f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a3b9c7a6c9be5c78a93e5125f16237d2d84b977eca81f527af0198e96435a995 \ No newline at end of file +62f934bff495850d0763e07ffa44a557f066ecba9d039363f32287213cba819f \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 37a73bdb62..2dd792f274 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1742,15 +1742,23 @@ void sqlite3Pragma( for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ Table *pTab = sqliteHashData(x); Index *pIdx, *pPk; - Index *pPrior = 0; + Index *pPrior = 0; /* Previous index */ int loopTop; int iDataCur, iIdxCur; int r1 = -1; int bStrict; + int r2; /* Previous key for WITHOUT ROWID tables */ if( !IsOrdinaryTable(pTab) ) continue; if( pObjTab && pObjTab!=pTab ) continue; - pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); + if( isQuick || HasRowid(pTab) ){ + pPk = 0; + r2 = 0; + }else{ + pPk = sqlite3PrimaryKeyIndex(pTab); + r2 = sqlite3GetTempRange(pParse, pPk->nKeyCol); + sqlite3VdbeAddOp3(v, OP_Null, 1, r2, r2+pPk->nKeyCol-1); + } sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0, 1, 0, &iDataCur, &iIdxCur); /* reg[7] counts the number of entries in the table. @@ -1769,6 +1777,24 @@ void sqlite3Pragma( sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nNVCol-1,3); sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); VdbeComment((v, "(right-most column)")); + if( pPk ){ + /* Verify WITHOUT ROWID keys are in ascending order */ + int a1; + char *zErr; + a1 = sqlite3VdbeAddOp4Int(v, OP_IdxGT, iDataCur, 0,r2,pPk->nKeyCol); + VdbeCoverage(v); + sqlite3VdbeAddOp1(v, OP_IsNull, r2); VdbeCoverage(v); + zErr = sqlite3MPrintf(db, + "row not in PRIMARY KEY order for %s", + pTab->zName); + sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); + integrityCheckResultRow(v); + sqlite3VdbeJumpHere(v, a1); + sqlite3VdbeJumpHere(v, a1+1); + for(j=0; jnKeyCol; j++){ + sqlite3ExprCodeLoadIndexColumn(pParse, pPk, iDataCur, j, r2+j); + } + } } /* Verify that all NOT NULL columns really are NOT NULL. At the ** same time verify the type of the content of STRICT tables */ @@ -1895,6 +1921,9 @@ void sqlite3Pragma( integrityCheckResultRow(v); sqlite3VdbeJumpHere(v, addr); } + if( pPk ){ + sqlite3ReleaseTempRange(pParse, r2, pPk->nKeyCol); + } } } }