Fix an offset problem in the meta values that was causing problems for

many tests. (CVS 1357)

FossilOrigin-Name: 6d378cb7e7e081bb3bcd3a347bc1e02f50ee25cc
This commit is contained in:
drh 2004-05-11 09:31:31 +00:00
parent 33825340cb
commit a3b321df91
7 changed files with 72 additions and 47 deletions

View File

@ -1,5 +1,5 @@
C Remove\sthe\sunused\supgrade_3_schema\ssubroutine\sfrom\smain.c.\s(CVS\s1356)
D 2004-05-11T09:05:49
C Fix\san\soffset\sproblem\sin\sthe\smeta\svalues\sthat\swas\scausing\sproblems\sfor\nmany\stests.\s(CVS\s1357)
D 2004-05-11T09:31:32
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -23,7 +23,7 @@ F sqlite.def fc4f5734786fe4743cfe2aa98eb2da4b089edb5f
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
F src/attach.c c315c58cb16fd6e913b3bfa6412aedecb4567fa5
F src/auth.c 5c2f0bea4729c98c2be3b69d6b466fc51448fe79
F src/btree.c 4e9ed30d1239e077d94efe3d6b9a5ee205e2f979
F src/btree.c 35df9e6d3a30bbe2d32d6b08f51e2a16b835c6e8
F src/btree.h 578dc465c801cf4e7666efbb0fa1c46a54758008
F src/btree_rb.c 9d7973e266ee6f9c61ce592f68742ce9cd5b10e5
F src/build.c 97d8b3fc6c48fcd355fcfe7b2e291f6e57159d62
@ -36,7 +36,7 @@ F src/func.c 6cf6501f092b41c8cd9368b09c287016c0576438
F src/hash.c 440c2f8cb373ee1b4e13a0988489c7cd95d55b6f
F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb
F src/insert.c 1e63d2774c4d893363e0c072f19d4c92a4ab982d
F src/main.c 170992aeeec83b260ef5cfb1e56ecf94b6d79b46
F src/main.c 4cbf83c0933fe713c4afd3dc5e401621f28f0304
F src/md5.c 8e39fdae6d8776b87558e91dcc94740c9b635a9c
F src/os.c ddcda92f7fd71b4513c57c1ec797917f206d504e
F src/os.h fbb2f6595fc34fa351830d88fe1c6b85118f0383
@ -63,13 +63,13 @@ F src/update.c 6ca82fc4a0fb4d7f134e961921c906f6f3c8bc74
F src/utf.c fc799748d43fe1982d157b871e3e420a19c85d4f
F src/util.c 778a8cd03ad6e52778602d20a3132c7d2d1b0a0c
F src/vacuum.c c134702e023db8778e6be59ac0ea7b02315b5476
F src/vdbe.c b9a499da850260eca461883b50319036338e4d25
F src/vdbe.c 85da2e53c38c334c055a8da480eb1bff74c19e94
F src/vdbe.h 2dc4d1161b64f5684faa6a2d292e318a185ecb2e
F src/vdbeInt.h ff85e432a43eb7533b17c9cece2baaf813ba8711
F src/vdbeaux.c feee0e94cd5fe520cd024287446d8b387a221a4b
F src/vdbeaux.c cf24281436ef850da84d706f0e560ad12e9a332a
F src/where.c 487e55b1f64c8fbf0f46a9a90c2247fc45ae6a9a
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
F test/attach.test 76f096f384221f775cc0a856e51d5a35f9ee1541
F test/attach.test 3afaf8e3dfaf8e576070126ab087ceb9a71734c2
F test/attach2.test ce61e6185b3cd891cc0e9a4c868fcc65eb92fc55
F test/auth.test 5c4d95cdaf539c0c236e20ce1f71a93e7dde9185
F test/bigfile.test ea904b853ce2d703b16c5ce90e2b54951bc1ae81
@ -188,7 +188,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P 6dc6004684a97fbdba2f2dce94086dc2c4967a42
R 2f7606b77bec37379c738329814fe8c4
P b5d2771ee0e9c77967b4a64a97dcd56c067bc7b8
R 1b4242c65713f0f29255a1791a6ffefa
U drh
Z 1c7a05de9e42438d1c26640df8e9bcae
Z 8117037867ee67a6186c1779813eefbc

View File

@ -1 +1 @@
b5d2771ee0e9c77967b4a64a97dcd56c067bc7b8
6d378cb7e7e081bb3bcd3a347bc1e02f50ee25cc

View File

@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.126 2004/05/11 02:10:07 danielk1977 Exp $
** $Id: btree.c,v 1.127 2004/05/11 09:31:32 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@ -3436,7 +3436,12 @@ int sqlite3BtreeDropTable(Btree *pBt, int iTable){
/*
** Read the meta-information out of a database file. Meta[0]
** is the number of free pages currently in the database. Meta[1]
** through meta[15] are available for use by higher layers.
** through meta[15] are available for use by higher layers. Meta[0]
** is read-only, the others are read/write.
**
** The schema layer numbers meta values differently. At the schema
** layer (and the SetCookie and ReadCookie opcodes) the number of
** free pages is not visible. So Cookie[0] is the same as Meta[1].
*/
int sqlite3BtreeGetMeta(Btree *pBt, int idx, u32 *pMeta){
int rc;

View File

@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.172 2004/05/11 09:05:49 drh Exp $
** $Id: main.c,v 1.173 2004/05/11 09:31:32 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -138,7 +138,7 @@ static int sqlite3InitOne(sqlite *db, int iDb, char **pzErrMsg){
Table *pTab;
char *azArg[6];
char zDbNum[30];
int meta[SQLITE_N_BTREE_META];
int meta[10];
InitData initData;
/*
@ -210,12 +210,24 @@ static int sqlite3InitOne(sqlite *db, int iDb, char **pzErrMsg){
return rc;
}
/* Get the database meta information
/* Get the database meta information.
**
** Meta values are as follows:
** meta[0] Schema cookie. Changes with each schema change.
** meta[1] File format of schema layer.
** meta[2] Size of the page cache.
** meta[3] Synchronous setting. 1:off, 2:normal, 3:full
** meta[4]
** meta[5] Pragma temp_store value. See comments on BtreeFactory
** meta[6]
** meta[7]
** meta[8]
** meta[9]
*/
if( rc==SQLITE_OK ){
int i;
for(i=0; rc==SQLITE_OK && i<SQLITE_N_BTREE_META; i++){
rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, i, &meta[i]);
for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){
rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, i+1, &meta[i]);
}
if( rc ){
sqlite3SetString(pzErrMsg, sqlite3_error_string(rc), (char*)0);
@ -225,16 +237,16 @@ static int sqlite3InitOne(sqlite *db, int iDb, char **pzErrMsg){
}else{
memset(meta, 0, sizeof(meta));
}
db->aDb[iDb].schema_cookie = meta[1];
db->aDb[iDb].schema_cookie = meta[0];
if( iDb==0 ){
db->next_cookie = meta[1];
db->file_format = meta[2];
size = meta[3];
db->next_cookie = meta[0];
db->file_format = meta[1];
size = meta[2];
if( size==0 ){ size = MAX_PAGES; }
db->cache_size = size;
db->safety_level = meta[4];
if( meta[6]>0 && meta[6]<=2 && db->temp_store==0 ){
db->temp_store = meta[6];
db->safety_level = meta[3];
if( meta[5]>0 && meta[5]<=2 && db->temp_store==0 ){
db->temp_store = meta[5];
}
if( db->safety_level==0 ) db->safety_level = 2;
@ -249,8 +261,8 @@ static int sqlite3InitOne(sqlite *db, int iDb, char **pzErrMsg){
sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0);
return SQLITE_ERROR;
}
}else if( db->file_format!=meta[2] ){
if( meta[2]==0 ){
}else if( db->file_format!=meta[1] ){
if( meta[1]==0 ){
sqlite3SetString(pzErrMsg, "cannot attach empty database: ",
db->aDb[iDb].zName, (char*)0);
}else{
@ -262,7 +274,7 @@ static int sqlite3InitOne(sqlite *db, int iDb, char **pzErrMsg){
return SQLITE_FORMAT;
}
sqlite3BtreeSetCacheSize(db->aDb[iDb].pBt, db->cache_size);
sqlite3BtreeSetSafetyLevel(db->aDb[iDb].pBt, meta[4]==0 ? 2 : meta[4]);
sqlite3BtreeSetSafetyLevel(db->aDb[iDb].pBt, meta[3]==0 ? 2 : meta[3]);
/* Read the schema information out of the schema tables
*/

View File

@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.280 2004/05/11 08:48:11 danielk1977 Exp $
** $Id: vdbe.c,v 1.281 2004/05/11 09:31:32 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -2532,7 +2532,14 @@ case OP_ReadCookie: {
assert( pOp->p2<SQLITE_N_BTREE_META );
assert( pOp->p1>=0 && pOp->p1<db->nDb );
assert( db->aDb[pOp->p1].pBt!=0 );
rc = sqlite3BtreeGetMeta(db->aDb[pOp->p1].pBt, pOp->p2+1, &iMeta);
/* The indexing of meta values at the schema layer is off by one from
** the indexing in the btree layer. The btree considers meta[0] to
** be the number of free pages in the database (a read-only value)
** and meta[1] to be the schema cookie. The schema layer considers
** meta[1] to be the schema cookie. So we have to shift the index
** by one in the following statement.
*/
rc = sqlite3BtreeGetMeta(db->aDb[pOp->p1].pBt, 1 + pOp->p2, &iMeta);
pTos++;
pTos->i = iMeta;
pTos->flags = MEM_Int;
@ -2555,6 +2562,7 @@ case OP_SetCookie: {
assert( db->aDb[pOp->p1].pBt!=0 );
assert( pTos>=p->aStack );
Integerify(pTos);
/* See note about index shifting on OP_ReadCookie */
rc = sqlite3BtreeUpdateMeta(db->aDb[pOp->p1].pBt, 1+pOp->p2, (int)pTos->i);
Release(pTos);
pTos--;
@ -2935,8 +2943,8 @@ case OP_Found: {
** using MakeIdxKey. Call it K. This instruction pops R from the
** stack but it leaves K unchanged.
**
** P1 is an index. So all but the last eight bytes of K are an
** index string. The last eight bytes of K are a record number.
** P1 is an index. So all but the last four bytes of K are an
** index string. The last four bytes of K are a record number.
**
** This instruction asks if there is an entry in P1 where the
** index string matches K but the record number is different
@ -2953,7 +2961,7 @@ case OP_IsUnique: {
Mem *pNos = &pTos[-1];
Cursor *pCx;
BtCursor *pCrsr;
i64 R;
int R;
/* Pop the value R off the top of the stack
*/
@ -2966,7 +2974,7 @@ case OP_IsUnique: {
pCrsr = pCx->pCursor;
if( pCrsr!=0 ){
int res, rc;
i64 v; /* The record number on the P1 entry that matches K */
int v; /* The record number on the P1 entry that matches K */
char *zKey; /* The value of K */
int nKey; /* Number of bytes in K */
@ -2975,14 +2983,13 @@ case OP_IsUnique: {
Stringify(pNos);
zKey = pNos->z;
nKey = pNos->n;
assert( nKey >= 8 );
assert( nKey >= 4 );
/* Search for an entry in P1 where all but the last eight bytes match K.
/* Search for an entry in P1 where all but the last four bytes match K.
** If there is no such entry, jump immediately to P2.
*/
assert( p->aCsr[i].deferredMoveto==0 );
assert( p->aCsr[i].intKey==0 );
rc = sqlite3BtreeMoveto(pCrsr, zKey, nKey-8, &res);
rc = sqlite3BtreeMoveto(pCrsr, zKey, nKey-4, &res);
if( rc!=SQLITE_OK ) goto abort_due_to_error;
if( res<0 ){
rc = sqlite3BtreeNext(pCrsr, &res);
@ -2992,7 +2999,7 @@ case OP_IsUnique: {
}
}
/* FIX ME - the sqlite2BtreeKeyCompare() function is a temporary hack */
rc = sqlite2BtreeKeyCompare(pCrsr, zKey, nKey-8, 8, &res);
rc = sqlite2BtreeKeyCompare(pCrsr, zKey, nKey-4, 4, &res);
if( rc!=SQLITE_OK ) goto abort_due_to_error;
if( res>0 ){
pc = pOp->p2 - 1;
@ -3000,11 +3007,11 @@ case OP_IsUnique: {
}
/* At this point, pCrsr is pointing to an entry in P1 where all but
** the last eight bytes of the key match K. Check to see if the last
** eight bytes of the key are different from R. If the last four
** the last for bytes of the key match K. Check to see if the last
** four bytes of the key are different from R. If the last four
** bytes equal R then jump immediately to P2.
*/
sqlite3BtreeKey(pCrsr, nKey - sizeof(i64), sizeof(i64), (char*)&v);
sqlite3BtreeKey(pCrsr, nKey - 4, 4, (char*)&v);
v = keyToInt(v);
if( v==R ){
pc = pOp->p2 - 1;
@ -3433,8 +3440,8 @@ case OP_Column: {
if( pC->nullRow ){
payloadSize = 0;
}else if( pC->keyAsData ){
assert( !pC->intKey );
u64 pl64;
assert( !pC->intKey );
sqlite3BtreeKeySize(pCrsr, &pl64);
payloadSize = pl64;
}else{
@ -5091,9 +5098,9 @@ default: {
if( pTos[i].flags & MEM_Null ){
fprintf(p->trace, " NULL");
}else if( (pTos[i].flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
fprintf(p->trace, " si:%d", pTos[i].i);
fprintf(p->trace, " si:%lld", pTos[i].i);
}else if( pTos[i].flags & MEM_Int ){
fprintf(p->trace, " i:%d", pTos[i].i);
fprintf(p->trace, " i:%lld", pTos[i].i);
}else if( pTos[i].flags & MEM_Real ){
fprintf(p->trace, " r:%g", pTos[i].r);
}else if( pTos[i].flags & MEM_Str ){

View File

@ -1048,6 +1048,7 @@ int sqlite3VdbeCursorMoveto(Cursor *p){
if( p->deferredMoveto ){
int res;
extern int sqlite3_search_count;
assert( p->intKey );
if( p->intKey ){
sqlite3BtreeMoveto(p->pCursor, 0, p->movetoTarget, &res);
}else{

View File

@ -12,7 +12,7 @@
# focus of this script is testing the ATTACH and DETACH commands
# and related functionality.
#
# $Id: attach.test,v 1.14 2004/05/10 23:29:51 drh Exp $
# $Id: attach.test,v 1.15 2004/05/11 09:31:32 drh Exp $
#
set testdir [file dirname $argv0]
@ -23,7 +23,7 @@ for {set i 2} {$i<=15} {incr i} {
file delete -force test$i.db-journal
}
set btree_trace 1
set btree_trace 0
do_test attach-1.1 {
execsql {
CREATE TABLE t1(a,b);