1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Define a set of constants to use as the "index" argument to sqlite3BtreeGetMeta and UpdateMeta. This makes some parts of the code easier to follow. (CVS 6709)

FossilOrigin-Name: 6dbf4eca00f845baa7200aba421d0bc158ba96aa
This commit is contained in:
danielk1977
2009-06-03 11:25:07 +00:00
parent 50d654da3b
commit 0d19f7ac57
11 changed files with 107 additions and 112 deletions

View File

@@ -1,5 +1,5 @@
C Additional\schanges\sto\sreduce\sstack\susage.\s\sThe\sSQLITE_SMALL_STACK\scompile-time\noption\sis\snow\savailable.\s(CVS\s6708) C Define\sa\sset\sof\sconstants\sto\suse\sas\sthe\s"index"\sargument\sto\ssqlite3BtreeGetMeta\sand\sUpdateMeta.\sThis\smakes\ssome\sparts\sof\sthe\scode\seasier\sto\sfollow.\s(CVS\s6709)
D 2009-06-03T01:24:54 D 2009-06-03T11:25:07
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 8b8fb7823264331210cddf103831816c286ba446 F Makefile.in 8b8fb7823264331210cddf103831816c286ba446
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -99,17 +99,17 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca
F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
F src/alter.c 88b8cc66c09853b5723f66cfd0103dbebb62c562 F src/alter.c 95f41d957f56407aac6224041ca5b954042318d1
F src/analyze.c e239496cfb5394ac8867f1c112905ddab8d01cd9 F src/analyze.c e239496cfb5394ac8867f1c112905ddab8d01cd9
F src/attach.c 13995348fc5a26cdd136a50806faf292aabc173f F src/attach.c 13995348fc5a26cdd136a50806faf292aabc173f
F src/auth.c 98db07c2088455797678eb1031f42d4d94d18a71 F src/auth.c 98db07c2088455797678eb1031f42d4d94d18a71
F src/backup.c d189bc157268570e79377544caeaed2c0e00aac9 F src/backup.c ff50af53184a5fd7bdee4d620b5dabef74717c79
F src/bitvec.c 0ef0651714728055d43de7a4cdd95e703fac0119 F src/bitvec.c 0ef0651714728055d43de7a4cdd95e703fac0119
F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c
F src/btree.c 41bee6e4699e61f9d33beabfcf13caba4467c20a F src/btree.c 5afa1b5b68217afc9dc96e18ab1ab2f888709139
F src/btree.h 3748683b382bc3022f23840c0a35d3231b24fc6e F src/btree.h f70b694e8c163227369a66863b01fbff9009f323
F src/btreeInt.h df64030d632f8c8ac217ed52e8b6b3eacacb33a5 F src/btreeInt.h df64030d632f8c8ac217ed52e8b6b3eacacb33a5
F src/build.c 6d5276345e4019441932501921e6d2b440f40563 F src/build.c 20e02fd72249159ff6829009f3029d16d59cdff5
F src/callback.c 57359fa93de47c341b6b8ee504a88ff276397686 F src/callback.c 57359fa93de47c341b6b8ee504a88ff276397686
F src/complete.c 5ad5c6cd4548211867c204c41a126d73a9fbcea0 F src/complete.c 5ad5c6cd4548211867c204c41a126d73a9fbcea0
F src/date.c ab5f7137656652a48434d64f96bdcdc823bb23b3 F src/date.c ab5f7137656652a48434d64f96bdcdc823bb23b3
@@ -152,8 +152,8 @@ F src/parse.y 07690df997d50b3fdb5e5121e5a27f1a080db13d
F src/pcache.c 395f752a13574120bd7513a400ba02a265aaa76d F src/pcache.c 395f752a13574120bd7513a400ba02a265aaa76d
F src/pcache.h 9b927ccc5a538e31b4c3bc7eec4f976db42a1324 F src/pcache.h 9b927ccc5a538e31b4c3bc7eec4f976db42a1324
F src/pcache1.c bed75f157283e7c666f323df0c874c6a2515f76e F src/pcache1.c bed75f157283e7c666f323df0c874c6a2515f76e
F src/pragma.c d4a6fd74fd1dba0f22c8930791f7fbbe80d2ef26 F src/pragma.c 06b3a4b93a5e587f1c04b4a40016eb360792cdf3
F src/prepare.c 706efe9fb08b2f01c14c8077dce8ab8450c47cfb F src/prepare.c c98c1d306ef72dd448ecbc3c52624439c72ad413
F src/printf.c 508a1c59433353552b6553cba175eaa7331f8fc1 F src/printf.c 508a1c59433353552b6553cba175eaa7331f8fc1
F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628 F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
F src/resolve.c f86d3490cf93a12f8a451720defc622cbc79873a F src/resolve.c f86d3490cf93a12f8a451720defc622cbc79873a
@@ -202,8 +202,8 @@ F src/trigger.c c07c5157c58fcdb704f65d5f5e4775276e45bb8b
F src/update.c 6ae6c26adff8dc34532d578f66e6cfde04b5d177 F src/update.c 6ae6c26adff8dc34532d578f66e6cfde04b5d177
F src/utf.c 9541d28f40441812c0b40f00334372a0542c00ff F src/utf.c 9541d28f40441812c0b40f00334372a0542c00ff
F src/util.c a9719d309f6c65b3b79fa3ca8512fa8e3947a391 F src/util.c a9719d309f6c65b3b79fa3ca8512fa8e3947a391
F src/vacuum.c 981686c910b2ff9fe3db814e01da31cf9dbd48c7 F src/vacuum.c 0e14f371ea3326c6b8cfba257286d798cd20db59
F src/vdbe.c 6bb5bc95316784d67deaa84e2a158d28595abeee F src/vdbe.c d105cc58a6a0fa08a3fade86633e90d57a7a8129
F src/vdbe.h 35a648bc3279a120da24f34d9a25213ec15daf8a F src/vdbe.h 35a648bc3279a120da24f34d9a25213ec15daf8a
F src/vdbeInt.h 43183a2a18654fa570219ab65e53a608057c48ae F src/vdbeInt.h 43183a2a18654fa570219ab65e53a608057c48ae
F src/vdbeapi.c 86aa27a5f3493aaffb8ac051782aa3b22670d7ed F src/vdbeapi.c 86aa27a5f3493aaffb8ac051782aa3b22670d7ed
@@ -732,7 +732,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746 F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
P 04bad9eb6dd8bf7cafc9f3918b676e95d5b1c984 P baea79fd0cfeb860973846c3f2776776c87f0ae3
R 819b41a44ba4dfbb1c77a8f2c2ff7973 R 9dba26e86c2e22da89e4d07f10eb0cbe
U drh U danielk1977
Z 141e71b5f088c642002d589792c976a2 Z 4e60210e731fb6afe9c94533b62cf6ef

View File

@@ -1 +1 @@
baea79fd0cfeb860973846c3f2776776c87f0ae3 6dbf4eca00f845baa7200aba421d0bc158ba96aa

View File

@@ -12,7 +12,7 @@
** This file contains C code routines that used to generate VDBE code ** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command. ** that implements the ALTER TABLE command.
** **
** $Id: alter.c,v 1.60 2009/05/28 01:00:55 drh Exp $ ** $Id: alter.c,v 1.61 2009/06/03 11:25:07 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -440,11 +440,11 @@ void sqlite3MinimumFileFormat(Parse *pParse, int iDb, int minFormat){
int r1 = sqlite3GetTempReg(pParse); int r1 = sqlite3GetTempReg(pParse);
int r2 = sqlite3GetTempReg(pParse); int r2 = sqlite3GetTempReg(pParse);
int j1; int j1;
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, 1); sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
sqlite3VdbeUsesBtree(v, iDb); sqlite3VdbeUsesBtree(v, iDb);
sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2); sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1); j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, 1, r2); sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);
sqlite3VdbeJumpHere(v, j1); sqlite3VdbeJumpHere(v, j1);
sqlite3ReleaseTempReg(pParse, r1); sqlite3ReleaseTempReg(pParse, r1);
sqlite3ReleaseTempReg(pParse, r2); sqlite3ReleaseTempReg(pParse, r2);

View File

@@ -12,7 +12,7 @@
** This file contains the implementation of the sqlite3_backup_XXX() ** This file contains the implementation of the sqlite3_backup_XXX()
** API functions and the related features. ** API functions and the related features.
** **
** $Id: backup.c,v 1.16 2009/06/02 21:31:39 drh Exp $ ** $Id: backup.c,v 1.17 2009/06/03 11:25:07 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "btreeInt.h" #include "btreeInt.h"
@@ -318,7 +318,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
&& SQLITE_OK==(rc = sqlite3BtreeBeginTrans(p->pDest, 2)) && SQLITE_OK==(rc = sqlite3BtreeBeginTrans(p->pDest, 2))
){ ){
p->bDestLocked = 1; p->bDestLocked = 1;
rc = sqlite3BtreeGetMeta(p->pDest, 1, &p->iDestSchema); rc = sqlite3BtreeGetMeta(p->pDest, BTREE_SCHEMA_VERSION, &p->iDestSchema);
} }
/* If there is no open read-transaction on the source database, open /* If there is no open read-transaction on the source database, open

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give. ** May you share freely, never taking more than you give.
** **
************************************************************************* *************************************************************************
** $Id: btree.c,v 1.609 2009/05/28 11:05:57 danielk1977 Exp $ ** $Id: btree.c,v 1.610 2009/06/03 11:25:07 danielk1977 Exp $
** **
** This file implements a external (disk-based) database using BTrees. ** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information. ** See the header comment on "btreeInt.h" for additional information.
@@ -6539,7 +6539,7 @@ static int btreeCreateTable(Btree *p, int *piTable, int flags){
** root page of the new table should go. meta[3] is the largest root-page ** root page of the new table should go. meta[3] is the largest root-page
** created so far, so the new root-page is (meta[3]+1). ** created so far, so the new root-page is (meta[3]+1).
*/ */
rc = sqlite3BtreeGetMeta(p, 4, &pgnoRoot); rc = sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
return rc; return rc;
} }
@@ -6772,7 +6772,7 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){
#else #else
if( pBt->autoVacuum ){ if( pBt->autoVacuum ){
Pgno maxRootPgno; Pgno maxRootPgno;
rc = sqlite3BtreeGetMeta(p, 4, &maxRootPgno); rc = sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &maxRootPgno);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
releasePage(pPage); releasePage(pPage);
return rc; return rc;
@@ -6913,7 +6913,7 @@ int sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
** access an autovacuumed database, then make the database readonly. ** access an autovacuumed database, then make the database readonly.
*/ */
#ifdef SQLITE_OMIT_AUTOVACUUM #ifdef SQLITE_OMIT_AUTOVACUUM
if( idx==4 && *pMeta>0 ) pBt->readOnly = 1; if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ) pBt->readOnly = 1;
#endif #endif
/* If there is currently an open transaction, grab a read-lock /* If there is currently an open transaction, grab a read-lock
@@ -6945,7 +6945,7 @@ int sqlite3BtreeUpdateMeta(Btree *p, int idx, u32 iMeta){
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
put4byte(&pP1[36 + idx*4], iMeta); put4byte(&pP1[36 + idx*4], iMeta);
#ifndef SQLITE_OMIT_AUTOVACUUM #ifndef SQLITE_OMIT_AUTOVACUUM
if( idx==7 ){ if( idx==BTREE_INCR_VACUUM ){
assert( pBt->autoVacuum || iMeta==0 ); assert( pBt->autoVacuum || iMeta==0 );
assert( iMeta==0 || iMeta==1 ); assert( iMeta==0 || iMeta==1 );
pBt->incrVacuum = (u8)iMeta; pBt->incrVacuum = (u8)iMeta;

View File

@@ -13,7 +13,7 @@
** subsystem. See comments in the source code for a detailed description ** subsystem. See comments in the source code for a detailed description
** of what each interface routine does. ** of what each interface routine does.
** **
** @(#) $Id: btree.h,v 1.115 2009/05/28 11:05:57 danielk1977 Exp $ ** @(#) $Id: btree.h,v 1.116 2009/06/03 11:25:07 danielk1977 Exp $
*/ */
#ifndef _BTREE_H_ #ifndef _BTREE_H_
#define _BTREE_H_ #define _BTREE_H_
@@ -58,7 +58,7 @@ struct BtreeMutexArray {
int sqlite3BtreeOpen( int sqlite3BtreeOpen(
const char *zFilename, /* Name of database file to open */ const char *zFilename, /* Name of database file to open */
sqlite3 *db, /* Associated database connection */ sqlite3 *db, /* Associated database connection */
Btree **, /* Return open Btree* here */ Btree **ppBtree, /* Return open Btree* here */
int flags, /* Flags */ int flags, /* Flags */
int vfsFlags /* Flags passed through to VFS open */ int vfsFlags /* Flags passed through to VFS open */
); );
@@ -80,7 +80,7 @@ int sqlite3BtreeClose(Btree*);
int sqlite3BtreeSetCacheSize(Btree*,int); int sqlite3BtreeSetCacheSize(Btree*,int);
int sqlite3BtreeSetSafetyLevel(Btree*,int,int); int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
int sqlite3BtreeSyncDisabled(Btree*); int sqlite3BtreeSyncDisabled(Btree*);
int sqlite3BtreeSetPageSize(Btree*,int,int,int); int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
int sqlite3BtreeGetPageSize(Btree*); int sqlite3BtreeGetPageSize(Btree*);
int sqlite3BtreeMaxPageCount(Btree*,int); int sqlite3BtreeMaxPageCount(Btree*,int);
int sqlite3BtreeGetReserve(Btree*); int sqlite3BtreeGetReserve(Btree*);
@@ -116,9 +116,31 @@ int sqlite3BtreeIncrVacuum(Btree *);
int sqlite3BtreeDropTable(Btree*, int, int*); int sqlite3BtreeDropTable(Btree*, int, int*);
int sqlite3BtreeClearTable(Btree*, int, int*); int sqlite3BtreeClearTable(Btree*, int, int*);
void sqlite3BtreeTripAllCursors(Btree*, int);
int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue); int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value); int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
void sqlite3BtreeTripAllCursors(Btree*, int);
/*
** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta
** should be one of the following values. The integer values are assigned
** to constants so that the offset of the corresponding field in an
** SQLite database header may be found using the following formula:
**
** offset = 36 + (idx * 4)
**
** For example, the free-page-count field is located at byte offset 36 of
** the database file header. The incr-vacuum-flag field is located at
** byte offset 64 (== 36+4*7).
*/
#define BTREE_FREE_PAGE_COUNT 0
#define BTREE_SCHEMA_VERSION 1
#define BTREE_FILE_FORMAT 2
#define BTREE_DEFAULT_CACHE_SIZE 3
#define BTREE_LARGEST_ROOT_PAGE 4
#define BTREE_TEXT_ENCODING 5
#define BTREE_USER_VERSION 6
#define BTREE_INCR_VACUUM 7
int sqlite3BtreeCursor( int sqlite3BtreeCursor(
Btree*, /* BTree containing table to open */ Btree*, /* BTree containing table to open */

View File

@@ -22,7 +22,7 @@
** COMMIT ** COMMIT
** ROLLBACK ** ROLLBACK
** **
** $Id: build.c,v 1.548 2009/06/01 16:53:10 shane Exp $ ** $Id: build.c,v 1.549 2009/06/03 11:25:07 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -856,15 +856,15 @@ void sqlite3StartTable(
reg1 = pParse->regRowid = ++pParse->nMem; reg1 = pParse->regRowid = ++pParse->nMem;
reg2 = pParse->regRoot = ++pParse->nMem; reg2 = pParse->regRoot = ++pParse->nMem;
reg3 = ++pParse->nMem; reg3 = ++pParse->nMem;
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, 1); /* file_format */ sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
sqlite3VdbeUsesBtree(v, iDb); sqlite3VdbeUsesBtree(v, iDb);
j1 = sqlite3VdbeAddOp1(v, OP_If, reg3); j1 = sqlite3VdbeAddOp1(v, OP_If, reg3);
fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ? fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
1 : SQLITE_MAX_FILE_FORMAT; 1 : SQLITE_MAX_FILE_FORMAT;
sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3); sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3);
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, 1, reg3); sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3);
sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3); sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, 4, reg3); sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, reg3);
sqlite3VdbeJumpHere(v, j1); sqlite3VdbeJumpHere(v, j1);
/* This just creates a place-holder record in the sqlite_master table. /* This just creates a place-holder record in the sqlite_master table.
@@ -1284,7 +1284,7 @@ void sqlite3ChangeCookie(Parse *pParse, int iDb){
sqlite3 *db = pParse->db; sqlite3 *db = pParse->db;
Vdbe *v = pParse->pVdbe; Vdbe *v = pParse->pVdbe;
sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1); sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, 0, r1); sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, r1);
sqlite3ReleaseTempReg(pParse, r1); sqlite3ReleaseTempReg(pParse, r1);
} }

View File

@@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** This file contains code used to implement the PRAGMA command. ** This file contains code used to implement the PRAGMA command.
** **
** $Id: pragma.c,v 1.211 2009/05/28 01:00:55 drh Exp $ ** $Id: pragma.c,v 1.212 2009/06/03 11:25:07 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -318,7 +318,7 @@ void sqlite3Pragma(
*/ */
if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){ if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
static const VdbeOpList getCacheSize[] = { static const VdbeOpList getCacheSize[] = {
{ OP_ReadCookie, 0, 1, 2}, /* 0 */ { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 0 */
{ OP_IfPos, 1, 6, 0}, { OP_IfPos, 1, 6, 0},
{ OP_Integer, 0, 2, 0}, { OP_Integer, 0, 2, 0},
{ OP_Subtract, 1, 2, 1}, { OP_Subtract, 1, 2, 1},
@@ -341,11 +341,11 @@ void sqlite3Pragma(
if( size<0 ) size = -size; if( size<0 ) size = -size;
sqlite3BeginWriteOperation(pParse, 0, iDb); sqlite3BeginWriteOperation(pParse, 0, iDb);
sqlite3VdbeAddOp2(v, OP_Integer, size, 1); sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, 2, 2); sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, 2, BTREE_DEFAULT_CACHE_SIZE);
addr = sqlite3VdbeAddOp2(v, OP_IfPos, 2, 0); addr = sqlite3VdbeAddOp2(v, OP_IfPos, 2, 0);
sqlite3VdbeAddOp2(v, OP_Integer, -size, 1); sqlite3VdbeAddOp2(v, OP_Integer, -size, 1);
sqlite3VdbeJumpHere(v, addr); sqlite3VdbeJumpHere(v, addr);
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, 2, 1); sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
pDb->pSchema->cache_size = size; pDb->pSchema->cache_size = size;
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
} }
@@ -582,12 +582,12 @@ void sqlite3Pragma(
** that this really is an auto-vacuum capable database. ** that this really is an auto-vacuum capable database.
*/ */
static const VdbeOpList setMeta6[] = { static const VdbeOpList setMeta6[] = {
{ OP_Transaction, 0, 1, 0}, /* 0 */ { OP_Transaction, 0, 1, 0}, /* 0 */
{ OP_ReadCookie, 0, 1, 3}, /* 1 */ { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
{ OP_If, 1, 0, 0}, /* 2 */ { OP_If, 1, 0, 0}, /* 2 */
{ OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
{ OP_Integer, 0, 1, 0}, /* 4 */ { OP_Integer, 0, 1, 0}, /* 4 */
{ OP_SetCookie, 0, 6, 1}, /* 5 */ { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */
}; };
int iAddr; int iAddr;
iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6); iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);
@@ -1273,23 +1273,21 @@ void sqlite3Pragma(
|| sqlite3StrICmp(zLeft, "user_version")==0 || sqlite3StrICmp(zLeft, "user_version")==0
|| sqlite3StrICmp(zLeft, "freelist_count")==0 || sqlite3StrICmp(zLeft, "freelist_count")==0
){ ){
int iCookie; /* Cookie index. 0 for schema-cookie, 6 for user-cookie. */ int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
sqlite3VdbeUsesBtree(v, iDb); sqlite3VdbeUsesBtree(v, iDb);
switch( zLeft[0] ){ switch( zLeft[0] ){
case 's': case 'S':
iCookie = 0;
break;
case 'f': case 'F': case 'f': case 'F':
iCookie = 1; iCookie = BTREE_FREE_PAGE_COUNT;
iDb = (-1*(iDb+1)); break;
assert(iDb<=0); case 's': case 'S':
iCookie = BTREE_SCHEMA_VERSION;
break; break;
default: default:
iCookie = 5; iCookie = BTREE_USER_VERSION;
break; break;
} }
if( zRight && iDb>=0 ){ if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){
/* Write the specified cookie value */ /* Write the specified cookie value */
static const VdbeOpList setCookie[] = { static const VdbeOpList setCookie[] = {
{ OP_Transaction, 0, 1, 0}, /* 0 */ { OP_Transaction, 0, 1, 0}, /* 0 */

View File

@@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema ** interface, and routines that contribute to loading the database schema
** from disk. ** from disk.
** **
** $Id: prepare.c,v 1.119 2009/06/01 18:18:21 drh Exp $ ** $Id: prepare.c,v 1.120 2009/06/03 11:25:07 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -133,7 +133,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
Table *pTab; Table *pTab;
Db *pDb; Db *pDb;
char const *azArg[4]; char const *azArg[4];
int meta[10]; int meta[5];
InitData initData; InitData initData;
char const *zMasterSchema; char const *zMasterSchema;
char const *zMasterName = SCHEMA_TABLE(iDb); char const *zMasterName = SCHEMA_TABLE(iDb);
@@ -218,10 +218,6 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
sqlite3BtreeEnter(pDb->pBt); sqlite3BtreeEnter(pDb->pBt);
rc = sqlite3BtreeCursor(pDb->pBt, MASTER_ROOT, 0, 0, curMain); rc = sqlite3BtreeCursor(pDb->pBt, MASTER_ROOT, 0, 0, curMain);
if( rc==SQLITE_EMPTY ) rc = SQLITE_OK; if( rc==SQLITE_EMPTY ) rc = SQLITE_OK;
if( rc!=SQLITE_OK ){
sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
goto initone_error_out;
}
/* Get the database meta information. /* Get the database meta information.
** **
@@ -231,37 +227,32 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
** meta[2] Size of the page cache. ** meta[2] Size of the page cache.
** meta[3] Use freelist if 0. Autovacuum if greater than zero. ** meta[3] Use freelist if 0. Autovacuum if greater than zero.
** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE ** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
** meta[5] The user cookie. Used by the application.
** meta[6] Incremental-vacuum flag.
** meta[7]
** meta[8]
** meta[9]
** **
** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to ** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
** the possible values of meta[4]. ** the possible values of meta[4].
*/ */
for(i=0; i<ArraySize(meta); i++){ for(i=0; rc==SQLITE_OK && i<ArraySize(meta); i++){
rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]); rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
if( rc ){
sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
goto initone_error_out;
}
} }
pDb->pSchema->schema_cookie = meta[0]; if( rc ){
sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
goto initone_error_out;
}
pDb->pSchema->schema_cookie = meta[BTREE_SCHEMA_VERSION-1];
/* If opening a non-empty database, check the text encoding. For the /* If opening a non-empty database, check the text encoding. For the
** main database, set sqlite3.enc to the encoding of the main database. ** main database, set sqlite3.enc to the encoding of the main database.
** For an attached db, it is an error if the encoding is not the same ** For an attached db, it is an error if the encoding is not the same
** as sqlite3.enc. ** as sqlite3.enc.
*/ */
if( meta[4] ){ /* text encoding */ if( meta[BTREE_TEXT_ENCODING-1] ){ /* text encoding */
if( iDb==0 ){ if( iDb==0 ){
/* If opening the main database, set ENC(db). */ /* If opening the main database, set ENC(db). */
ENC(db) = (u8)meta[4]; ENC(db) = (u8)meta[BTREE_TEXT_ENCODING-1];
db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0); db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
}else{ }else{
/* If opening an attached database, the encoding much match ENC(db) */ /* If opening an attached database, the encoding much match ENC(db) */
if( meta[4]!=ENC(db) ){ if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
sqlite3SetString(pzErrMsg, db, "attached databases must use the same" sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
" text encoding as main database"); " text encoding as main database");
rc = SQLITE_ERROR; rc = SQLITE_ERROR;
@@ -274,7 +265,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
pDb->pSchema->enc = ENC(db); pDb->pSchema->enc = ENC(db);
if( pDb->pSchema->cache_size==0 ){ if( pDb->pSchema->cache_size==0 ){
size = meta[2]; size = meta[BTREE_DEFAULT_CACHE_SIZE-1];
if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; } if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; }
if( size<0 ) size = -size; if( size<0 ) size = -size;
pDb->pSchema->cache_size = size; pDb->pSchema->cache_size = size;
@@ -287,7 +278,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
** file_format==3 Version 3.1.4. // ditto but with non-NULL defaults ** file_format==3 Version 3.1.4. // ditto but with non-NULL defaults
** file_format==4 Version 3.3.0. // DESC indices. Boolean constants ** file_format==4 Version 3.3.0. // DESC indices. Boolean constants
*/ */
pDb->pSchema->file_format = (u8)meta[1]; pDb->pSchema->file_format = (u8)meta[BTREE_FILE_FORMAT-1];
if( pDb->pSchema->file_format==0 ){ if( pDb->pSchema->file_format==0 ){
pDb->pSchema->file_format = 1; pDb->pSchema->file_format = 1;
} }
@@ -302,7 +293,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
** not downgrade the database and thus invalidate any descending ** not downgrade the database and thus invalidate any descending
** indices that the user might have created. ** indices that the user might have created.
*/ */
if( iDb==0 && meta[1]>=4 ){ if( iDb==0 && meta[BTREE_FILE_FORMAT-1]>=4 ){
db->flags &= ~SQLITE_LegacyFileFmt; db->flags &= ~SQLITE_LegacyFileFmt;
} }
@@ -458,7 +449,7 @@ static int schemaIsValid(sqlite3 *db){
memset(curTemp, 0, sqlite3BtreeCursorSize()); memset(curTemp, 0, sqlite3BtreeCursorSize());
rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, curTemp); rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, curTemp);
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&cookie); rc = sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
if( rc==SQLITE_OK && cookie!=db->aDb[iDb].pSchema->schema_cookie ){ if( rc==SQLITE_OK && cookie!=db->aDb[iDb].pSchema->schema_cookie ){
allOk = 0; allOk = 0;
} }

View File

@@ -14,7 +14,7 @@
** Most of the code in this file may be omitted by defining the ** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro. ** SQLITE_OMIT_VACUUM macro.
** **
** $Id: vacuum.c,v 1.89 2009/05/30 10:46:10 danielk1977 Exp $ ** $Id: vacuum.c,v 1.90 2009/06/03 11:25:07 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "vdbeInt.h" #include "vdbeInt.h"
@@ -241,10 +241,10 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
** connections to the same database will know to reread the schema. ** connections to the same database will know to reread the schema.
*/ */
static const unsigned char aCopy[] = { static const unsigned char aCopy[] = {
1, 1, /* Add one to the old schema cookie */ BTREE_SCHEMA_VERSION, 1, /* Add one to the old schema cookie */
3, 0, /* Preserve the default page cache size */ BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
5, 0, /* Preserve the default text encoding */ BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
6, 0, /* Preserve the user version */ BTREE_USER_VERSION, 0, /* Preserve the user version */
}; };
assert( 1==sqlite3BtreeIsInTrans(pTemp) ); assert( 1==sqlite3BtreeIsInTrans(pTemp) );

View File

@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing ** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code. ** commenting and indentation practices when changing or adding code.
** **
** $Id: vdbe.c,v 1.845 2009/06/02 16:06:04 drh Exp $ ** $Id: vdbe.c,v 1.846 2009/06/03 11:25:07 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "vdbeInt.h" #include "vdbeInt.h"
@@ -2712,16 +2712,11 @@ case OP_Transaction: {
/* Opcode: ReadCookie P1 P2 P3 * * /* Opcode: ReadCookie P1 P2 P3 * *
** **
** Read cookie number P3 from database P1 and write it into register P2. ** Read cookie number P3 from database P1 and write it into register P2.
** P3==0 is the schema version. P3==1 is the database format. ** P3==1 is the schema version. P3==2 is the database format.
** P3==2 is the recommended pager cache size, and so forth. P1==0 is ** P3==3 is the recommended pager cache size, and so forth. P1==0 is
** the main database file and P1==1 is the database file used to store ** the main database file and P1==1 is the database file used to store
** temporary tables. ** temporary tables.
** **
** If P1 is negative, then this is a request to read the size of a
** databases free-list. P3 must be set to 1 in this case. The actual
** database accessed is ((P1+1)*-1). For example, a P1 parameter of -1
** corresponds to database 0 ("main"), a P1 of -2 is database 1 ("temp").
**
** There must be a read-lock on the database (either a transaction ** There must be a read-lock on the database (either a transaction
** must be started or there must be an open cursor) before ** must be started or there must be an open cursor) before
** executing this instruction. ** executing this instruction.
@@ -2734,21 +2729,11 @@ case OP_ReadCookie: { /* out2-prerelease */
iDb = pOp->p1; iDb = pOp->p1;
iCookie = pOp->p3; iCookie = pOp->p3;
assert( pOp->p3<SQLITE_N_BTREE_META ); assert( pOp->p3<SQLITE_N_BTREE_META );
if( iDb<0 ){
iDb = (-1*(iDb+1));
iCookie *= -1;
}
assert( iDb>=0 && iDb<db->nDb ); assert( iDb>=0 && iDb<db->nDb );
assert( db->aDb[iDb].pBt!=0 ); assert( db->aDb[iDb].pBt!=0 );
assert( (p->btreeMask & (1<<iDb))!=0 ); assert( (p->btreeMask & (1<<iDb))!=0 );
/* 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 rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
** 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[iDb].pBt, 1 + iCookie, (u32 *)&iMeta);
pOut->u.i = iMeta; pOut->u.i = iMeta;
MemSetTypeFlag(pOut, MEM_Int); MemSetTypeFlag(pOut, MEM_Int);
break; break;
@@ -2757,11 +2742,10 @@ case OP_ReadCookie: { /* out2-prerelease */
/* Opcode: SetCookie P1 P2 P3 * * /* Opcode: SetCookie P1 P2 P3 * *
** **
** Write the content of register P3 (interpreted as an integer) ** Write the content of register P3 (interpreted as an integer)
** into cookie number P2 of database P1. ** into cookie number P2 of database P1. P2==1 is the schema version.
** P2==0 is the schema version. P2==1 is the database format. ** P2==2 is the database format. P2==3 is the recommended pager cache
** P2==2 is the recommended pager cache size, and so forth. P1==0 is ** size, and so forth. P1==0 is the main database file and P1==1 is the
** the main database file and P1==1 is the database file used to store ** database file used to store temporary tables.
** temporary tables.
** **
** A transaction must be started before executing this opcode. ** A transaction must be started before executing this opcode.
*/ */
@@ -2774,12 +2758,12 @@ case OP_SetCookie: { /* in3 */
assert( pDb->pBt!=0 ); assert( pDb->pBt!=0 );
sqlite3VdbeMemIntegerify(pIn3); sqlite3VdbeMemIntegerify(pIn3);
/* See note about index shifting on OP_ReadCookie */ /* See note about index shifting on OP_ReadCookie */
rc = sqlite3BtreeUpdateMeta(pDb->pBt, 1+pOp->p2, (int)pIn3->u.i); rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i);
if( pOp->p2==0 ){ if( pOp->p2==BTREE_SCHEMA_VERSION ){
/* When the schema cookie changes, record the new cookie internally */ /* When the schema cookie changes, record the new cookie internally */
pDb->pSchema->schema_cookie = (int)pIn3->u.i; pDb->pSchema->schema_cookie = (int)pIn3->u.i;
db->flags |= SQLITE_InternChanges; db->flags |= SQLITE_InternChanges;
}else if( pOp->p2==1 ){ }else if( pOp->p2==BTREE_FILE_FORMAT ){
/* Record changes in the file format */ /* Record changes in the file format */
pDb->pSchema->file_format = (u8)pIn3->u.i; pDb->pSchema->file_format = (u8)pIn3->u.i;
} }
@@ -2814,7 +2798,7 @@ case OP_VerifyCookie: {
assert( (p->btreeMask & (1<<pOp->p1))!=0 ); assert( (p->btreeMask & (1<<pOp->p1))!=0 );
pBt = db->aDb[pOp->p1].pBt; pBt = db->aDb[pOp->p1].pBt;
if( pBt ){ if( pBt ){
rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&iMeta); rc = sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
}else{ }else{
rc = SQLITE_OK; rc = SQLITE_OK;
iMeta = 0; iMeta = 0;