/ Check-in [b92c31d6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improvements to the way PRAGMA integrity_check works. More likely to output userful information when given a corrupt database. (CVS 1132)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b92c31d6c138f9462730cecfe14f7dde19778e79
User & Date: drh 2003-12-16 03:44:48
Context
2003-12-17
23:57
Make sure the pagers in-memory cache states in sync with the disk file. Ticket #529. (CVS 1133) check-in: da00efb1 user: drh tags: trunk
2003-12-16
03:44
Improvements to the way PRAGMA integrity_check works. More likely to output userful information when given a corrupt database. (CVS 1132) check-in: b92c31d6 user: drh tags: trunk
2003-12-15
17:51
Updates to the homepage - fix the CVS access instructions. (CVS 1131) check-in: 653a7dd9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.96 2003/12/06 21:43:56 drh Exp $
           12  +** $Id: btree.c,v 1.97 2003/12/16 03:44:48 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** For a detailed discussion of BTrees, refer to
    16     16   **
    17     17   **     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
    18     18   **     "Sorting And Searching", pages 473-480. Addison-Wesley
    19     19   **     Publishing Company, Reading, Massachusetts.
................................................................................
  1398   1398     assert( pCur->idx<pCur->pPage->nCell
  1399   1399             || pCur->pPage->u.hdr.rightChild==SWAB32(pBt,newPgno) );
  1400   1400     pNewPage->idxParent = pCur->idx;
  1401   1401     pCur->pPage->idxShift = 0;
  1402   1402     sqlitepager_unref(pCur->pPage);
  1403   1403     pCur->pPage = pNewPage;
  1404   1404     pCur->idx = 0;
  1405         -  if( pNewPage->nCell<1 ) return SQLITE_CORRUPT;
         1405  +  if( pNewPage->nCell<1 ){
         1406  +    return SQLITE_CORRUPT;
         1407  +  }
  1406   1408     return SQLITE_OK;
  1407   1409   }
  1408   1410   
  1409   1411   /*
  1410   1412   ** Move the cursor up to the parent page.
  1411   1413   **
  1412   1414   ** pCur->idx is set to the cell index that contains the pointer

Changes to src/pragma.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the PRAGMA command.
    13     13   **
    14         -** $Id: pragma.c,v 1.11 2003/08/23 22:40:54 drh Exp $
           14  +** $Id: pragma.c,v 1.12 2003/12/16 03:44:48 drh Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include <ctype.h>
    18     18   
    19     19   /*
    20     20   ** Interpret the given string as a boolean value.
    21     21   */
................................................................................
   551    551     }else
   552    552   #endif
   553    553   
   554    554     if( sqliteStrICmp(zLeft, "integrity_check")==0 ){
   555    555       int i, j, addr;
   556    556   
   557    557       /* Code that initializes the integrity check program.  Set the
   558         -    ** error message to an empty string and register the callback
   559         -    ** column name.
          558  +    ** error count 0
   560    559       */
   561    560       static VdbeOp initCode[] = {
   562         -      { OP_String,      0, 0,        ""},
          561  +      { OP_Integer,     0, 0,        0},
   563    562         { OP_MemStore,    0, 1,        0},
   564    563         { OP_ColumnName,  0, 0,        "integrity_check"},
   565    564       };
   566    565   
   567    566       /* Code to do an BTree integrity check on a single database file.
   568    567       */
   569    568       static VdbeOp checkDb[] = {
................................................................................
   574    573         { OP_Column,      0, 3,        0},    /* 4 */
   575    574         { OP_SetInsert,   0, 0,        0},
   576    575         { OP_Next,        0, 4,        0},    /* 6 */
   577    576         { OP_IntegrityCk, 0, 0,        0},    /* 7 */
   578    577         { OP_Dup,         0, 1,        0},
   579    578         { OP_String,      0, 0,        "ok"},
   580    579         { OP_StrEq,       0, 12,       0},    /* 10 */
   581         -      { OP_MemLoad,     0, 0,        0},
          580  +      { OP_MemIncr,     0, 0,        0},
   582    581         { OP_String,      0, 0,        "*** in database "},
   583    582         { OP_String,      0, 0,        0},    /* 13 */
   584    583         { OP_String,      0, 0,        " ***\n"},
   585         -      { OP_Pull,        4, 0,        0},
   586         -      { OP_Concat,      5, 1,        0},
   587         -      { OP_MemStore,    0, 1,        0},
   588         -      { OP_Integer,     0, 0,        0},
   589         -      { OP_Pop,         1, 0,        0},
          584  +      { OP_Pull,        3, 0,        0},
          585  +      { OP_Concat,      4, 1,        0},
          586  +      { OP_Callback,    1, 0,        0},
   590    587       };
   591    588   
   592    589       /* Code that appears at the end of the integrity check.  If no error
   593    590       ** messages have been generated, output OK.  Otherwise output the
   594    591       ** error message
   595    592       */
   596    593       static VdbeOp endCode[] = {
   597    594         { OP_MemLoad,     0, 0,        0},
   598         -      { OP_Dup,         0, 1,        0},
   599         -      { OP_String,      0, 0,        ""},
   600         -      { OP_StrNe,       0, 0,        0},    /* 3 */
   601         -      { OP_Pop,         1, 0,        0},
          595  +      { OP_Integer,     0, 0,        0},
          596  +      { OP_Ne,          0, 0,        0},    /* 2 */
   602    597         { OP_String,      0, 0,        "ok"},
   603    598         { OP_Callback,    1, 0,        0},
   604    599       };
   605    600   
   606    601       /* Initialize the VDBE program */
   607    602       sqliteVdbeAddOpList(v, ArraySize(initCode), initCode);
   608    603   
................................................................................
   613    608         /* Do an integrity check of the B-Tree
   614    609         */
   615    610         addr = sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb);
   616    611         sqliteVdbeChangeP1(v, addr+1, i);
   617    612         sqliteVdbeChangeP2(v, addr+3, addr+7);
   618    613         sqliteVdbeChangeP2(v, addr+6, addr+4);
   619    614         sqliteVdbeChangeP2(v, addr+7, i);
   620         -      sqliteVdbeChangeP2(v, addr+10, addr+ArraySize(checkDb)-1);
          615  +      sqliteVdbeChangeP2(v, addr+10, addr+ArraySize(checkDb));
   621    616         sqliteVdbeChangeP3(v, addr+13, db->aDb[i].zName, P3_STATIC);
   622    617   
   623    618         /* Make sure all the indices are constructed correctly.
   624    619         */
   625    620         sqliteCodeVerifySchema(pParse, i);
   626    621         for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
   627    622           Table *pTab = sqliteHashData(x);
................................................................................
   641    636           sqliteVdbeAddOp(v, OP_Integer, 0, 0);
   642    637           sqliteVdbeAddOp(v, OP_MemStore, 1, 1);
   643    638           loopTop = sqliteVdbeAddOp(v, OP_Rewind, 1, 0);
   644    639           sqliteVdbeAddOp(v, OP_MemIncr, 1, 0);
   645    640           for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
   646    641             int k, jmp2;
   647    642             static VdbeOp idxErr[] = {
   648         -            { OP_MemLoad,     0,  0,  0},
          643  +            { OP_MemIncr,     0,  0,  0},
   649    644               { OP_String,      0,  0,  "rowid "},
   650    645               { OP_Recno,       1,  0,  0},
   651    646               { OP_String,      0,  0,  " missing from index "},
   652    647               { OP_String,      0,  0,  0},    /* 4 */
   653         -            { OP_String,      0,  0,  "\n"},
   654         -            { OP_Concat,      6,  0,  0},
   655         -            { OP_MemStore,    0,  1,  0},
          648  +            { OP_Concat,      4,  0,  0},
          649  +            { OP_Callback,    1,  0,  0},
   656    650             };
   657    651             sqliteVdbeAddOp(v, OP_Recno, 1, 0);
   658    652             for(k=0; k<pIdx->nColumn; k++){
   659    653               int idx = pIdx->aiColumn[k];
   660    654               if( idx==pTab->iPKey ){
   661    655                 sqliteVdbeAddOp(v, OP_Recno, 1, 0);
   662    656               }else{
................................................................................
   678    672                { OP_MemStore,     2,  1,  0},
   679    673                { OP_Rewind,       0,  0,  0},  /* 2 */
   680    674                { OP_MemIncr,      2,  0,  0},
   681    675                { OP_Next,         0,  0,  0},  /* 4 */
   682    676                { OP_MemLoad,      1,  0,  0},
   683    677                { OP_MemLoad,      2,  0,  0},
   684    678                { OP_Eq,           0,  0,  0},  /* 7 */
   685         -             { OP_MemLoad,      0,  0,  0},
          679  +             { OP_MemIncr,      0,  0,  0},
   686    680                { OP_String,       0,  0,  "wrong # of entries in index "},
   687    681                { OP_String,       0,  0,  0},  /* 10 */
   688         -             { OP_String,       0,  0,  "\n"},
   689         -             { OP_Concat,       4,  0,  0},
   690         -             { OP_MemStore,     0,  1,  0},
          682  +             { OP_Concat,       2,  0,  0},
          683  +             { OP_Callback,     1,  0,  0},
   691    684             };
   692    685             if( pIdx->tnum==0 ) continue;
   693    686             addr = sqliteVdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
   694    687             sqliteVdbeChangeP1(v, addr+2, j+2);
   695    688             sqliteVdbeChangeP2(v, addr+2, addr+5);
   696    689             sqliteVdbeChangeP1(v, addr+4, j+2);
   697    690             sqliteVdbeChangeP2(v, addr+4, addr+3);
   698    691             sqliteVdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
   699    692             sqliteVdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
   700    693           }
   701    694         } 
   702    695       }
   703    696       addr = sqliteVdbeAddOpList(v, ArraySize(endCode), endCode);
   704         -    sqliteVdbeChangeP2(v, addr+3, addr+ArraySize(endCode)-1);
          697  +    sqliteVdbeChangeP2(v, addr+2, addr+ArraySize(endCode));
   705    698     }else
   706    699   
   707    700     {}
   708    701     sqliteFree(zLeft);
   709    702     sqliteFree(zRight);
   710    703   }

Changes to test/pragma.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for the PRAGMA command.
    14     14   #
    15         -# $Id: pragma.test,v 1.6 2003/07/27 17:26:23 drh Exp $
           15  +# $Id: pragma.test,v 1.7 2003/12/16 03:44:48 drh Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Delete the preexisting database to avoid the special setup
    21     21   # that the "all.test" script does.
    22     22   #
................................................................................
   260    260     btree_begin_transaction $db
   261    261     set c [btree_cursor $db $rootpage 1]
   262    262     btree_first $c
   263    263     btree_delete $c
   264    264     btree_commit $db
   265    265     btree_close $db
   266    266     execsql {PRAGMA integrity_check}
   267         -} {{rowid 1 missing from index i2
   268         -wrong # of entries in index i2
   269         -}}
          267  +} {{rowid 1 missing from index i2} {wrong # of entries in index i2}}
   270    268   
   271    269   finish_test