From 4be295be077474f61eec22ff7cb9aa0efde7d171 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 16 Dec 2003 03:44:47 +0000 Subject: [PATCH] Improvements to the way PRAGMA integrity_check works. More likely to output userful information when given a corrupt database. (CVS 1132) FossilOrigin-Name: b92c31d6c138f9462730cecfe14f7dde19778e79 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/btree.c | 6 ++++-- src/pragma.c | 41 +++++++++++++++++------------------------ test/pragma.test | 6 ++---- 5 files changed, 32 insertions(+), 39 deletions(-) diff --git a/manifest b/manifest index 677c32e411..e5f5ca8045 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Updates\sto\sthe\shomepage\s-\sfix\sthe\sCVS\saccess\sinstructions.\s(CVS\s1131) -D 2003-12-15T17:51:19 +C Improvements\sto\sthe\sway\sPRAGMA\sintegrity_check\sworks.\s\sMore\slikely\sto\soutput\nuserful\sinformation\swhen\sgiven\sa\scorrupt\sdatabase.\s(CVS\s1132) +D 2003-12-16T03:44:48 F Makefile.in 5cb273b7d0e945d47ee8b9ad1c2a04ce79927d2d F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -23,7 +23,7 @@ F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2 F src/attach.c 9a3764bbccb1c8b39321630006fbaa0fb8bd1822 F src/auth.c c59ad0dab501888f8b1fccc25e2f5965d2265116 -F src/btree.c bcb466c2939582a3a62f577cd8a9e5d637f3698d +F src/btree.c 89a77be5ca8bb229f9e230de534098ea5b06c2c1 F src/btree.h 9b7c09f1e64274d7bb74a57bbfc63778f67b1048 F src/btree_rb.c e4084b6a12270674b0cd7034655f55e6a2639c78 F src/build.c a7493c433de5b552f9535d8fa7ed80aaf135491e @@ -43,7 +43,7 @@ F src/os.h 729395fefcca4b81ae056aa9ff67b72bb40dd9e0 F src/pager.c 62702dff51d50694d039bc210f31990d1fbba2dd F src/pager.h 5da62c83443f26b1792cfd72c96c422f91aadd31 F src/parse.y c65aa6c5508763806ac9734b0589b93480ec7e7a -F src/pragma.c cee60f17679210e8acd30d5bdee855716d0c898c +F src/pragma.c deec7342741e371f3042adaee53fcc324c5dd1d4 F src/printf.c 12e45d482ac8abcc6f786fc99e5bed7dd9a51af0 F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe F src/select.c d79ac60ba1595ff3c94b12892e87098329776482 @@ -109,7 +109,7 @@ F test/misuse.test a3aa2b18a97e4c409a1fcaff5151a4dd804a0162 F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0 F test/null.test c14d0f4739f21e929b8115b72bf0c765b6bb1721 F test/pager.test dd31da9bee94a82e2e87e58cf286cfe809f8fc5f -F test/pragma.test e7cb7ffd765c9158868b0b7a3771d54a0d5f5072 +F test/pragma.test 17ff54f4abe187fa1e9dd20afef63d14c650d737 F test/printf.test 3ed02f1361402c0767492cd5cef4650e61df8308 F test/progress.test 701b6115c2613128ececdfe1398a1bd0e1a4cfb3 x F test/quick.test c527bdb899b12a8cd8ceecce45f72922099f4095 @@ -176,7 +176,7 @@ F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3 F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 -P d6549954408b01e5eaf865b9100739c94de28f16 -R edcd3752c4dbf2f82999564759ef2959 +P 653a7dd97ed95e66bd2973169735ee73ee348576 +R 435a13e877cf1f013db1660aef5f3d2f U drh -Z ee4c4b73919cef5782114fea0f6ce2ec +Z b27d1bd5a7237f952a32b8adb3b13abd diff --git a/manifest.uuid b/manifest.uuid index 86c7a5d205..9090b812aa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -653a7dd97ed95e66bd2973169735ee73ee348576 \ No newline at end of file +b92c31d6c138f9462730cecfe14f7dde19778e79 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 0a7ac0cf87..a61511ee2b 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.96 2003/12/06 21:43:56 drh Exp $ +** $Id: btree.c,v 1.97 2003/12/16 03:44:48 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -1402,7 +1402,9 @@ static int moveToChild(BtCursor *pCur, int newPgno){ sqlitepager_unref(pCur->pPage); pCur->pPage = pNewPage; pCur->idx = 0; - if( pNewPage->nCell<1 ) return SQLITE_CORRUPT; + if( pNewPage->nCell<1 ){ + return SQLITE_CORRUPT; + } return SQLITE_OK; } diff --git a/src/pragma.c b/src/pragma.c index 77055351c0..5f83e1bfb4 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.11 2003/08/23 22:40:54 drh Exp $ +** $Id: pragma.c,v 1.12 2003/12/16 03:44:48 drh Exp $ */ #include "sqliteInt.h" #include @@ -555,11 +555,10 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ int i, j, addr; /* Code that initializes the integrity check program. Set the - ** error message to an empty string and register the callback - ** column name. + ** error count 0 */ static VdbeOp initCode[] = { - { OP_String, 0, 0, ""}, + { OP_Integer, 0, 0, 0}, { OP_MemStore, 0, 1, 0}, { OP_ColumnName, 0, 0, "integrity_check"}, }; @@ -578,15 +577,13 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ { OP_Dup, 0, 1, 0}, { OP_String, 0, 0, "ok"}, { OP_StrEq, 0, 12, 0}, /* 10 */ - { OP_MemLoad, 0, 0, 0}, + { OP_MemIncr, 0, 0, 0}, { OP_String, 0, 0, "*** in database "}, { OP_String, 0, 0, 0}, /* 13 */ { OP_String, 0, 0, " ***\n"}, - { OP_Pull, 4, 0, 0}, - { OP_Concat, 5, 1, 0}, - { OP_MemStore, 0, 1, 0}, - { OP_Integer, 0, 0, 0}, - { OP_Pop, 1, 0, 0}, + { OP_Pull, 3, 0, 0}, + { OP_Concat, 4, 1, 0}, + { OP_Callback, 1, 0, 0}, }; /* Code that appears at the end of the integrity check. If no error @@ -595,10 +592,8 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ */ static VdbeOp endCode[] = { { OP_MemLoad, 0, 0, 0}, - { OP_Dup, 0, 1, 0}, - { OP_String, 0, 0, ""}, - { OP_StrNe, 0, 0, 0}, /* 3 */ - { OP_Pop, 1, 0, 0}, + { OP_Integer, 0, 0, 0}, + { OP_Ne, 0, 0, 0}, /* 2 */ { OP_String, 0, 0, "ok"}, { OP_Callback, 1, 0, 0}, }; @@ -617,7 +612,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ sqliteVdbeChangeP2(v, addr+3, addr+7); sqliteVdbeChangeP2(v, addr+6, addr+4); sqliteVdbeChangeP2(v, addr+7, i); - sqliteVdbeChangeP2(v, addr+10, addr+ArraySize(checkDb)-1); + sqliteVdbeChangeP2(v, addr+10, addr+ArraySize(checkDb)); sqliteVdbeChangeP3(v, addr+13, db->aDb[i].zName, P3_STATIC); /* Make sure all the indices are constructed correctly. @@ -645,14 +640,13 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ int k, jmp2; static VdbeOp idxErr[] = { - { OP_MemLoad, 0, 0, 0}, + { OP_MemIncr, 0, 0, 0}, { OP_String, 0, 0, "rowid "}, { OP_Recno, 1, 0, 0}, { OP_String, 0, 0, " missing from index "}, { OP_String, 0, 0, 0}, /* 4 */ - { OP_String, 0, 0, "\n"}, - { OP_Concat, 6, 0, 0}, - { OP_MemStore, 0, 1, 0}, + { OP_Concat, 4, 0, 0}, + { OP_Callback, 1, 0, 0}, }; sqliteVdbeAddOp(v, OP_Recno, 1, 0); for(k=0; knColumn; k++){ @@ -682,12 +676,11 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ { OP_MemLoad, 1, 0, 0}, { OP_MemLoad, 2, 0, 0}, { OP_Eq, 0, 0, 0}, /* 7 */ - { OP_MemLoad, 0, 0, 0}, + { OP_MemIncr, 0, 0, 0}, { OP_String, 0, 0, "wrong # of entries in index "}, { OP_String, 0, 0, 0}, /* 10 */ - { OP_String, 0, 0, "\n"}, - { OP_Concat, 4, 0, 0}, - { OP_MemStore, 0, 1, 0}, + { OP_Concat, 2, 0, 0}, + { OP_Callback, 1, 0, 0}, }; if( pIdx->tnum==0 ) continue; addr = sqliteVdbeAddOpList(v, ArraySize(cntIdx), cntIdx); @@ -701,7 +694,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ } } addr = sqliteVdbeAddOpList(v, ArraySize(endCode), endCode); - sqliteVdbeChangeP2(v, addr+3, addr+ArraySize(endCode)-1); + sqliteVdbeChangeP2(v, addr+2, addr+ArraySize(endCode)); }else {} diff --git a/test/pragma.test b/test/pragma.test index a721c90e09..a7256d1a87 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -12,7 +12,7 @@ # # This file implements tests for the PRAGMA command. # -# $Id: pragma.test,v 1.6 2003/07/27 17:26:23 drh Exp $ +# $Id: pragma.test,v 1.7 2003/12/16 03:44:48 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -264,8 +264,6 @@ do_test pragma-3.2 { btree_commit $db btree_close $db execsql {PRAGMA integrity_check} -} {{rowid 1 missing from index i2 -wrong # of entries in index i2 -}} +} {{rowid 1 missing from index i2} {wrong # of entries in index i2}} finish_test