mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Change the name of the sanity_check PRAGMA to "integrity_check" and make
it available on all compiles. (CVS 381) FossilOrigin-Name: c6e9048e66c8d8e2d5f6c62aa724eef3e9d9f572
This commit is contained in:
29
src/btree.c
29
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 @@ int sqliteBtreeUpdateMeta(Btree *pBt, int *aMeta){
|
||||
** 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 @@ int sqliteBtreePageDump(Btree *pBt, int pgno, int recursive){
|
||||
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 @@ int sqliteBtreeCursorDump(BtCursor *pCur, int *aResult){
|
||||
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 @@ int sqliteBtreeCursorDump(BtCursor *pCur, int *aResult){
|
||||
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 @@ struct SanityCheck {
|
||||
/*
|
||||
** 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 @@ static void checkAppendMsg(SanityCheck *pCheck, char *zMsg1, char *zMsg2){
|
||||
**
|
||||
** 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 @@ static int checkRef(SanityCheck *pCheck, int iPage, char *zContext){
|
||||
** 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 @@ static int keyCompare(
|
||||
** 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 @@ static int checkTreePage(
|
||||
** 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 @@ char *sqliteBtreeSanityCheck(Btree *pBt, int *aRoot, int nRoot){
|
||||
sqliteFree(sCheck.anRef);
|
||||
return sCheck.zErrMsg;
|
||||
}
|
||||
|
||||
#endif /* !defined(NDEBUG) */
|
||||
|
@ -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 sqliteBtreeCloseCursor(BtCursor*);
|
||||
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_ */
|
||||
|
@ -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 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
}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 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
{ 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 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
|
||||
if( v==0 ) return;
|
||||
sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb);
|
||||
}else
|
||||
#endif
|
||||
|
||||
{}
|
||||
sqliteFree(zLeft);
|
||||
|
@ -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 @@ insert_cleanup:
|
||||
** 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
|
||||
|
@ -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 @@ int sqlitepager_ref(void *pData){
|
||||
**
|
||||
** 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 @@ int *sqlitepager_stats(Pager *pPager){
|
||||
**
|
||||
** 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;
|
||||
|
@ -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(){
|
||||
|
10
src/test3.c
10
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 @@ static int btree_pager_ref_dump(
|
||||
}
|
||||
|
||||
/*
|
||||
** 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 @@ static int btree_sanity_check(
|
||||
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 @@ int Sqlitetest3_Init(Tcl_Interp *interp){
|
||||
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;
|
||||
|
16
src/vdbe.c
16
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 @@ static char *zOpName[] = { 0,
|
||||
"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 @@ case OP_CreateTable: {
|
||||
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 @@ case OP_CreateTable: {
|
||||
**
|
||||
** 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 @@ case OP_SanityCheck: {
|
||||
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 @@ case OP_SanityCheck: {
|
||||
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 @@ case OP_SanityCheck: {
|
||||
aStack[tos].flags = STK_Str | STK_Dyn;
|
||||
}
|
||||
sqliteFree(aRoot);
|
||||
#endif /* !define(NDEBUG) */
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -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 @@ typedef struct VdbeOp VdbeOp;
|
||||
#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
|
||||
|
Reference in New Issue
Block a user