Change the name of the sanity_check PRAGMA to "integrity_check" and make
it available on all compiles. (CVS 381)

FossilOrigin-Name: c6e9048e66c8d8e2d5f6c62aa724eef3e9d9f572
diff --git a/src/btree.c b/src/btree.c
index 4f90df6..8831ad4 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.52 2002/02/03 19:15:02 drh Exp $
+** $Id: btree.c,v 1.53 2002/02/19 13:39:22 drh Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -2458,15 +2458,13 @@
 ** The complete implementation of the BTree subsystem is above this line.
 ** All the code the follows is for testing and troubleshooting the BTree
 ** subsystem.  None of the code that follows is used during normal operation.
-** All of the following code is omitted if the library is compiled with
-** the -DNDEBUG2=1 compiler option.
 ******************************************************************************/
-#ifndef NDEBUG2
 
 /*
 ** Print a disassembly of the given page on standard output.  This routine
 ** is used for debugging and testing only.
 */
+#ifdef SQLITE_TEST
 int sqliteBtreePageDump(Btree *pBt, int pgno, int recursive){
   int rc;
   MemPage *pPage;
@@ -2535,7 +2533,9 @@
   sqlitepager_unref(pPage);
   return SQLITE_OK;
 }
+#endif
 
+#ifdef SQLITE_TEST
 /*
 ** Fill aResult[] with information about the entry and page that the
 ** cursor is pointing to.
@@ -2575,7 +2575,9 @@
   aResult[7] = pPage->u.hdr.rightChild;
   return SQLITE_OK;
 }
+#endif
 
+#ifdef SQLITE_TEST
 /*
 ** Return the pager associated with a BTree.  This routine is used for
 ** testing and debugging only.
@@ -2583,13 +2585,14 @@
 Pager *sqliteBtreePager(Btree *pBt){
   return pBt->pPager;
 }
+#endif
 
 /*
 ** This structure is passed around through all the sanity checking routines
 ** in order to keep track of some global state information.
 */
-typedef struct SanityCheck SanityCheck;
-struct SanityCheck {
+typedef struct IntegrityCk IntegrityCk;
+struct IntegrityCk {
   Btree *pBt;    /* The tree being checked out */
   Pager *pPager; /* The associated pager.  Also accessible by pBt->pPager */
   int nPage;     /* Number of pages in the database */
@@ -2602,7 +2605,7 @@
 /*
 ** Append a message to the error message string.
 */
-static void checkAppendMsg(SanityCheck *pCheck, char *zMsg1, char *zMsg2){
+static void checkAppendMsg(IntegrityCk *pCheck, char *zMsg1, char *zMsg2){
   if( pCheck->zErrMsg ){
     char *zOld = pCheck->zErrMsg;
     pCheck->zErrMsg = 0;
@@ -2621,7 +2624,7 @@
 **
 ** Also check that the page number is in bounds.
 */
-static int checkRef(SanityCheck *pCheck, int iPage, char *zContext){
+static int checkRef(IntegrityCk *pCheck, int iPage, char *zContext){
   if( iPage==0 ) return 1;
   if( iPage>pCheck->nPage ){
     char zBuf[100];
@@ -2642,7 +2645,7 @@
 ** Check the integrity of the freelist or of an overflow page list.
 ** Verify that the number of pages on the list is N.
 */
-static void checkList(SanityCheck *pCheck, int iPage, int N, char *zContext){
+static void checkList(IntegrityCk *pCheck, int iPage, int N, char *zContext){
   char zMsg[100];
   while( N-- ){
     OverflowPage *pOvfl;
@@ -2698,7 +2701,7 @@
 **          the root of the tree.
 */
 static int checkTreePage(
-  SanityCheck *pCheck,  /* Context for the sanity check */
+  IntegrityCk *pCheck,  /* Context for the sanity check */
   int iPage,            /* Page number of the page to check */
   MemPage *pParent,     /* Parent page */
   char *zParentContext, /* Parent context */
@@ -2843,10 +2846,10 @@
 ** and a pointer to that error message is returned.  The calling function
 ** is responsible for freeing the error message when it is done.
 */
-char *sqliteBtreeSanityCheck(Btree *pBt, int *aRoot, int nRoot){
+char *sqliteBtreeIntegrityCheck(Btree *pBt, int *aRoot, int nRoot){
   int i;
   int nRef;
-  SanityCheck sCheck;
+  IntegrityCk sCheck;
 
   nRef = *sqlitepager_stats(pBt->pPager);
   if( lockBtree(pBt)!=SQLITE_OK ){
@@ -2897,5 +2900,3 @@
   sqliteFree(sCheck.anRef);
   return sCheck.zErrMsg;
 }
-
-#endif /* !defined(NDEBUG) */
diff --git a/src/btree.h b/src/btree.h
index e6edc4c..2c63f5d 100644
--- a/src/btree.h
+++ b/src/btree.h
@@ -13,7 +13,7 @@
 ** subsystem.  See comments in the source code for a detailed description
 ** of what each interface routine does.
 **
-** @(#) $Id: btree.h,v 1.22 2002/02/03 19:15:02 drh Exp $
+** @(#) $Id: btree.h,v 1.23 2002/02/19 13:39:22 drh Exp $
 */
 #ifndef _BTREE_H_
 #define _BTREE_H_
@@ -56,12 +56,12 @@
 int sqliteBtreeGetMeta(Btree*, int*);
 int sqliteBtreeUpdateMeta(Btree*, int*);
 
+char *sqliteBtreeIntegrityCheck(Btree*, int*, int);
 
-#ifndef NDEBUG2
+#ifdef SQLITE_TEST
 int sqliteBtreePageDump(Btree*, int, int);
 int sqliteBtreeCursorDump(BtCursor*, int*);
 struct Pager *sqliteBtreePager(Btree*);
-char *sqliteBtreeSanityCheck(Btree*, int*, int);
 #endif
 
 #endif /* _BTREE_H_ */
diff --git a/src/build.c b/src/build.c
index 6aa51b9..afa4db7 100644
--- a/src/build.c
+++ b/src/build.c
@@ -25,7 +25,7 @@
 **     ROLLBACK
 **     PRAGMA
 **
-** $Id: build.c,v 1.76 2002/02/18 22:49:59 drh Exp $
+** $Id: build.c,v 1.77 2002/02/19 13:39:22 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1799,8 +1799,7 @@
   }else
 #endif
 
-#ifndef NDEBUG
-  if( sqliteStrICmp(zLeft, "sanity_check")==0 ){
+  if( sqliteStrICmp(zLeft, "integrity_check")==0 ){
     static VdbeOp checkDb[] = {
       { OP_SetInsert,   0, 0,        "2"},
       { OP_Open,        0, 2,        0},
@@ -1808,7 +1807,7 @@
       { OP_Column,      0, 3,        0},
       { OP_SetInsert,   0, 0,        0},
       { OP_Next,        0, 3,        0},
-      { OP_SanityCheck, 0, 0,        0},
+      { OP_IntegrityCk, 0, 0,        0},
       { OP_ColumnCount, 1, 0,        0},
       { OP_ColumnName,  0, 0,        "sanity_check"},
       { OP_Callback,    1, 0,        0},
@@ -1817,7 +1816,6 @@
     if( v==0 ) return;
     sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb);
   }else
-#endif
 
   {}
   sqliteFree(zLeft);
diff --git a/src/insert.c b/src/insert.c
index aa49c40..2efabfd 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle INSERT statements in SQLite.
 **
-** $Id: insert.c,v 1.43 2002/02/18 13:56:37 drh Exp $
+** $Id: insert.c,v 1.44 2002/02/19 13:39:22 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -368,7 +368,7 @@
 ** is used.  Or if pParse->onError==OE_Default then the onError value
 ** for the constraint is used.
 **
-** The calling routine must an open read/write cursor for pTab with
+** The calling routine must open a read/write cursor for pTab with
 ** cursor number "base".  All indices of pTab must also have open
 ** read/write cursors with cursor number base+i for the i-th cursor.
 ** Except, if there is no possibility of a REPLACE action then
diff --git a/src/pager.c b/src/pager.c
index bdb5741..1cf1d2b 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.39 2002/02/14 12:50:35 drh Exp $
+** @(#) $Id: pager.c,v 1.40 2002/02/19 13:39:22 drh Exp $
 */
 #include "sqliteInt.h"
 #include "pager.h"
@@ -653,7 +653,7 @@
 **
 ** Writing all free dirty pages to the database after the sync is a
 ** non-obvious optimization.  fsync() is an expensive operation so we
-** want to minimize the number it is called.  After an fsync() call,
+** want to minimize the number ot times it is called. After an fsync() call,
 ** we are free to write dirty pages back to the database.  It is best
 ** to go ahead and write as many dirty pages as possible to minimize 
 ** the risk of having to do another fsync() later on.  Writing dirty
@@ -1234,7 +1234,7 @@
 **
 ** This routine should be called with the transaction journal already
 ** open.  A new checkpoint journal is created that can be used to rollback
-** changes of a single command within a larger transaction.
+** changes of a single SQL command within a larger transaction.
 */
 int sqlitepager_ckpt_begin(Pager *pPager){
   int rc;
diff --git a/src/random.c b/src/random.c
index 2f669ae..39148b4 100644
--- a/src/random.c
+++ b/src/random.c
@@ -15,7 +15,7 @@
 ** Random numbers are used by some of the database backends in order
 ** to generate random integer keys for tables or random filenames.
 **
-** $Id: random.c,v 1.9 2002/01/16 21:00:27 drh Exp $
+** $Id: random.c,v 1.10 2002/02/19 13:39:23 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -31,7 +31,7 @@
 ** well be good enough.  But maybe not.  Or maybe lrand48() has some
 ** subtle problems on some systems that could cause problems.  It is hard
 ** to know.  To minimize the risk of problems due to bad lrand48()
-** implementations, SQLite uses is this random number generator based
+** implementations, SQLite uses this random number generator based
 ** on RC4, which we know works very well.
 */
 static int randomByte(){
diff --git a/src/test3.c b/src/test3.c
index 54f9462..59f7209 100644
--- a/src/test3.c
+++ b/src/test3.c
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test3.c,v 1.13 2001/11/09 13:41:10 drh Exp $
+** $Id: test3.c,v 1.14 2002/02/19 13:39:23 drh Exp $
 */
 #include "sqliteInt.h"
 #include "pager.h"
@@ -461,13 +461,13 @@
 }
 
 /*
-** Usage:   btree_sanity_check ID ROOT ...
+** Usage:   btree_integrity_check ID ROOT ...
 **
 ** Look through every page of the given BTree file to verify correct
 ** formatting and linkage.  Return a line of text for each problem found.
 ** Return an empty string if everything worked.
 */
-static int btree_sanity_check(
+static int btree_integrity_check(
   void *NotUsed,
   Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   int argc,              /* Number of arguments */
@@ -490,7 +490,7 @@
   for(i=0; i<argc-2; i++){
     if( Tcl_GetInt(interp, argv[i+2], &aRoot[i]) ) return TCL_ERROR;
   }
-  zResult = sqliteBtreeSanityCheck(pBt, aRoot, nRoot);
+  zResult = sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot);
   if( zResult ){
     Tcl_AppendResult(interp, zResult, 0);
     free(zResult); 
@@ -833,7 +833,7 @@
   Tcl_CreateCommand(interp, "btree_key", btree_key, 0, 0);
   Tcl_CreateCommand(interp, "btree_data", btree_data, 0, 0);
   Tcl_CreateCommand(interp, "btree_cursor_dump", btree_cursor_dump, 0, 0);
-  Tcl_CreateCommand(interp, "btree_sanity_check", btree_sanity_check, 0, 0);
+  Tcl_CreateCommand(interp, "btree_integrity_check", btree_integrity_check,0,0);
   Tcl_LinkVar(interp, "pager_refinfo_enable", (char*)&pager_refinfo_enable,
      TCL_LINK_INT);
   return TCL_OK;
diff --git a/src/vdbe.c b/src/vdbe.c
index aa2273d..a356a15 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -30,7 +30,7 @@
 ** But other routines are also provided to help in building up
 ** a program instruction by instruction.
 **
-** $Id: vdbe.c,v 1.117 2002/02/03 19:06:03 drh Exp $
+** $Id: vdbe.c,v 1.118 2002/02/19 13:39:23 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -868,7 +868,7 @@
   "IsUnique",          "NotExists",         "Delete",            "Column",
   "KeyAsData",         "Recno",             "FullKey",           "Rewind",
   "Next",              "Destroy",           "Clear",             "CreateIndex",
-  "CreateTable",       "SanityCheck",       "IdxPut",            "IdxDelete",
+  "CreateTable",       "IntegrityCk",       "IdxPut",            "IdxDelete",
   "IdxRecno",          "IdxGT",             "IdxGE",             "MemLoad",
   "MemStore",          "ListWrite",         "ListRewind",        "ListRead",
   "ListReset",         "SortPut",           "SortMakeRec",       "SortMakeKey",
@@ -3481,7 +3481,7 @@
   break;
 }
 
-/* Opcode: SanityCheck P1 * *
+/* Opcode: IntegrityCk P1 * *
 **
 ** Do an analysis of the currently open database.  Push onto the
 ** stack the text of an error message describing any problems.
@@ -3492,8 +3492,7 @@
 **
 ** This opcode is used for testing purposes only.
 */
-case OP_SanityCheck: {
-#ifndef NDEBUG  /* This opcode used for testing only */
+case OP_IntegrityCk: {
   int nRoot;
   int *aRoot;
   int tos = ++p->tos;
@@ -3503,8 +3502,8 @@
   HashElem *i;
   char *z;
 
-  if( iSet<0 || iSet>=p->nSet ) goto bad_instruction;
-  if( NeedStack(p, p->tos) ) goto no_mem;
+  VERIFY( if( iSet<0 || iSet>=p->nSet ) goto bad_instruction; )
+  VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
   pSet = &p->aSet[iSet];
   nRoot = sqliteHashCount(&pSet->hash);
   aRoot = sqliteMalloc( sizeof(int)*(nRoot+1) );
@@ -3512,7 +3511,7 @@
     aRoot[j] = atoi((char*)sqliteHashKey(i));
   }
   aRoot[j] = 0;
-  z = sqliteBtreeSanityCheck(pBt, aRoot, nRoot);
+  z = sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot);
   if( z==0 || z[0]==0 ){
     zStack[tos] = "ok";
     aStack[tos].n = 3;
@@ -3524,7 +3523,6 @@
     aStack[tos].flags = STK_Str | STK_Dyn;
   }
   sqliteFree(aRoot);
-#endif /* !define(NDEBUG) */
   break;
 }
 
diff --git a/src/vdbe.h b/src/vdbe.h
index 93945f6..7936b13 100644
--- a/src/vdbe.h
+++ b/src/vdbe.h
@@ -15,7 +15,7 @@
 ** or VDBE.  The VDBE implements an abstract machine that runs a
 ** simple program to access and modify the underlying database.
 **
-** $Id: vdbe.h,v 1.41 2002/02/03 03:34:09 drh Exp $
+** $Id: vdbe.h,v 1.42 2002/02/19 13:39:23 drh Exp $
 */
 #ifndef _SQLITE_VDBE_H_
 #define _SQLITE_VDBE_H_
@@ -104,7 +104,7 @@
 #define OP_Clear              31
 #define OP_CreateIndex        32
 #define OP_CreateTable        33
-#define OP_SanityCheck        34
+#define OP_IntegrityCk        34
 
 #define OP_IdxPut             35
 #define OP_IdxDelete          36