diff --git a/manifest b/manifest index 46e2059505..a3554f6fa0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\ssome\sissues\swith\sINSTEAD\sOF\striggers.\s(CVS\s930) -D 2003-04-24T01:45:04 +C Get\sVACUUM\sworking\sagain\s-\swith\stest\scases.\s\sSome\sother\sminor\scleanups.\s(CVS\s931) +D 2003-04-25T02:43:08 F Makefile.in 004acec253ecdde985c8ecd5b7c9accdb210378f F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -22,8 +22,8 @@ F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2 F src/attach.c 7ebc7487de43e357a64226f8abef81f2669f2183 F src/auth.c a4afd27964fb9f661147115790c8ae2ee230ebcc F src/btree.c b9487cceb9ea78af9cbae9def34114902f511736 -F src/btree.h 529c98cb0715c62214544fbbe50b946f99a85540 -F src/btree_rb.c 85cbf6720db54b844747ce4dba4c3fcc8fd6f0a8 +F src/btree.h dc899dd3a10ec9a0c9b51308610d2f53e36b4820 +F src/btree_rb.c b427e6f2df7807cd338636259efadb4e43dba669 F src/build.c d5a26baeffa5bc49b4b7009a7723c6ab7e1b02d9 F src/copy.c 44b13fd4d2444fb53bff8a5ecee1c5f6f86a8263 F src/delete.c 23d33fd8967c6cc492943bbecea93be6491edc6a @@ -40,7 +40,7 @@ F src/os.h 9e5bbddff123187295e3d00d49af06192cd1cd49 F src/pager.c df4c81350cbd80c1ab48341ae0768ba78d99ad49 F src/pager.h e3702f7d384921f6cd5ce0b3ed589185433e9f6c F src/parse.y 15ae47e7dd84304c1c6ae9205558405127977541 -F src/pragma.c 3b1e8da84304d5efa1db5802c67261335b663327 +F src/pragma.c 118fe400d71b7fdcc03580d5eab6bb5aa00772a5 F src/printf.c fc5fdef6e92ad205005263661fe9716f55a49f3e F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe F src/select.c dfc13cb62ba658c4463179713c40ee25a062b2ba @@ -58,7 +58,7 @@ F src/tokenize.c 067d1a477a94af7712ca74e09aaa6bd0f7299527 F src/trigger.c e763f4015c96e06b694184ead5754985c1dfdae0 F src/update.c b7fa7c427b74aee6db56ecfa09e5e151e6f9fa6a F src/util.c 87635cfdfffa056a8d3147719357aa442374f78c -F src/vacuum.c e24781e38db36d1c9f578b6b3613bf0989ebd63c +F src/vacuum.c 67199f3d626aed21940b3b428c25979a98fda03d F src/vdbe.c f0868ac926d98395d28c2a29119364ff11b77852 F src/vdbe.h 985c24f312d10f9ef8f9a8b8ea62fcdf68e82f21 F src/where.c f632cd30f013163484a4d60c249d36fe31f5be12 @@ -125,7 +125,7 @@ F test/trigger3.test 870afef7997a5b86bf3ea893ce0c2e85d6356c72 F test/trigger4.test 9a5c1406344d743020c2753ae8d6dfe6eb75f818 F test/unique.test 22a46df72a3e0a3fd1a2d39e96fb59f18448dd5f F test/update.test 198360dfa14e65354dbcc66d5b98d8070780e42b -F test/vacuum.test 059871b312eb910bbe49dafde1d01490cc2c6bbe +F test/vacuum.test baf8e0c44587322da5669996ffc55daf8cc60266 F test/version.test 605fd0d7e7d571370c32b12dbf395b58953de246 F test/view.test d356f445d481c04ffa6036a4c61cb8ba70289f69 F test/where.test d719129a052280fe245a2ddcbd09bcc0b8c17ce4 @@ -165,7 +165,7 @@ F www/speed.tcl cb4c10a722614aea76d2c51f32ee43400d5951be F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218 -P 6289b863590ecc5de3d1efaaa60aa6f3f64fefb3 -R 566c0486d0b4bc8e9732c5c29c3b5dcc +P 206b17397b1d2b55179c935927ff1d8215728c32 +R ee4f9dd4d9d805754b2a7a86e47142bb U drh -Z d31c46a8e175a3b83b9efc55c7de92d9 +Z eedc7e5fec762d2a0f0ca33e2eecb73f diff --git a/manifest.uuid b/manifest.uuid index a442ea316d..9066ba85e0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -206b17397b1d2b55179c935927ff1d8215728c32 \ No newline at end of file +5afb88008fed253e6d1fc0ed5172370b61d3727b \ No newline at end of file diff --git a/src/btree.h b/src/btree.h index c7eae121af..46e42fa636 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.31 2003/04/16 01:28:16 drh Exp $ +** @(#) $Id: btree.h,v 1.32 2003/04/25 02:43:08 drh Exp $ */ #ifndef _BTREE_H_ #define _BTREE_H_ @@ -95,6 +95,7 @@ struct BtCursorOps { #define SQLITE_N_BTREE_META 10 int sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree); +int sqliteRBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree); #define btOps(pBt) (*((BtOps **)(pBt))) #define btCOps(pCur) (*((BtCursorOps **)(pCur))) diff --git a/src/btree_rb.c b/src/btree_rb.c index 35c09e3aff..0167a1f9d2 100644 --- a/src/btree_rb.c +++ b/src/btree_rb.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree_rb.c,v 1.7 2003/04/24 01:45:04 drh Exp $ +** $Id: btree_rb.c,v 1.8 2003/04/25 02:43:08 drh Exp $ ** ** This file implements an in-core database using Red-Black balanced ** binary trees. @@ -1327,7 +1327,7 @@ static struct Pager *memBtreePager(Btree* tree) ** Return the full pathname of the underlying database file. */ static const char *memBtreeGetFilename(Btree *pBt){ - return ":memory:"; + return 0; /* A NULL return indicates there is no underlying file */ } /* diff --git a/src/pragma.c b/src/pragma.c index 6b26048447..1d09e66197 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.4 2003/04/22 20:30:39 drh Exp $ +** $Id: pragma.c,v 1.5 2003/04/25 02:43:08 drh Exp $ */ #include "sqliteInt.h" #include @@ -71,9 +71,11 @@ static int getSafetyLevel(char *z){ ** and 0 to use the compile-time default. */ static int getTempStore(char *z){ - if (sqliteStrICmp(z, "file") == 0) { + if( z[0]>='0' || z[0]<='2' ){ + return z[0] - '0'; + }else if( sqliteStrICmp(z, "file")==0 ){ return 1; - }else if(sqliteStrICmp(z, "memory") == 0) { + }else if( sqliteStrICmp(z, "memory")==0 ){ return 2; }else{ return 0; diff --git a/src/vacuum.c b/src/vacuum.c index 9cf9d6b7df..bdc6a3770f 100644 --- a/src/vacuum.c +++ b/src/vacuum.c @@ -14,7 +14,7 @@ ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** -** $Id: vacuum.c,v 1.3 2003/04/18 02:31:04 drh Exp $ +** $Id: vacuum.c,v 1.4 2003/04/25 02:43:08 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -41,6 +41,7 @@ struct vacuumStruct { sqlite *dbNew; /* New database */ Parse *pParse; /* The parser context */ const char *zTable; /* Name of a table being copied */ + const char *zPragma; /* Pragma to execute with results */ dynStr s1, s2; /* Two dynamic strings */ }; @@ -160,6 +161,24 @@ static int vacuumCallback1(void *pArg, int argc, char **argv, char **NotUsed){ return rc; } +/* +** This callback is used to transfer PRAGMA settings from one database +** to the other. The value in argv[0] should be passed to a pragma +** identified by ((vacuumStruct*)pArg)->zPragma. +*/ +static int vacuumCallback3(void *pArg, int argc, char **argv, char **NotUsed){ + vacuumStruct *p = (vacuumStruct*)pArg; + int rc = 0; + char zBuf[200]; + assert( argc==1 ); + assert( argv[0]!=0 ); + assert( strlen(p->zPragma)<100 ); + assert( strlen(argv[0])<30 ); + sprintf(zBuf,"PRAGMA %s=%s;", p->zPragma, argv[0]); + rc = execsql(p->pParse, p->dbNew, zBuf); + return rc; +} + /* ** Generate a random name of 20 character in length. */ @@ -199,6 +218,14 @@ void sqliteVacuum(Parse *pParse, Token *pTableName){ int safety = 0; vacuumStruct sVac; + /* These are all of the pragmas that need to be transferred over + ** to the new database */ + static const char *zPragma[] = { + "default_synchronous", + "default_cache_size", + /* "default_temp_store", */ + }; + /* Initial error checks */ if( pParse->explain ){ @@ -256,14 +283,17 @@ void sqliteVacuum(Parse *pParse, Token *pTableName){ sVac.dbOld = db; sVac.dbNew = dbNew; sVac.pParse = pParse; + for(i=0; izErrMsg==0 ){ - sqliteErrorMsg(pParse, "unable to vacuum database - %s", zErrMsg); - } - goto end_of_vacuum; - } + if( rc ) goto vacuum_error; if( sqliteOsFileRename(zFilename, zTemp2) ){ sqliteErrorMsg(pParse, "unable to rename database file"); @@ -285,6 +315,12 @@ void sqliteVacuum(Parse *pParse, Token *pTableName){ if( sqliteOsDelete(zTemp2) ){ sqliteErrorMsg(pParse, "unable to delete old database: %s", zTemp2); } + sqliteBtreeClose(db->aDb[0].pBt); + zTemp2[nFilename] = 0; + if( sqliteBtreeOpen(zTemp2, 0, MAX_PAGES, &db->aDb[0].pBt) ){ + sqliteErrorMsg(pParse, "unable to reopen database after vacuuming"); + } + sqliteResetInternalSchema(db, 0); end_of_vacuum: sqlite_exec(db, "COMMIT", 0, 0, 0); @@ -298,5 +334,12 @@ end_of_vacuum: sqliteFree(sVac.s1.z); sqliteFree(sVac.s2.z); if( zErrMsg ) sqlite_freemem(zErrMsg); + return; + +vacuum_error: + if( pParse->zErrMsg==0 ){ + sqliteErrorMsg(pParse, "unable to vacuum database - %s", zErrMsg); + } + goto end_of_vacuum; #endif } diff --git a/test/vacuum.test b/test/vacuum.test index 83f99484bd..7fef069c0c 100644 --- a/test/vacuum.test +++ b/test/vacuum.test @@ -11,12 +11,89 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the VACUUM statement. # -# $Id: vacuum.test,v 1.7 2002/03/03 02:49:52 drh Exp $ +# $Id: vacuum.test,v 1.8 2003/04/25 02:43:08 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl -# The vacuum command no longer functions. There is -# nothing to test. +proc cksum {filename} { + set txt [db eval {SELECT name, type, sql FROM sqlite_master}]\n + foreach tbl [db eval {SELECT name FROM sqlite_master WHERE type='table'}] { + append txt [db eval "SELECT * FROM $tbl"]\n + } + foreach prag {default_synchronous default_cache_size} { + append txt $prag-[db eval "PRAGMA $prag"]\n + } + # set fd [open $filename w] + # puts $fd $txt + # close $fd + return [string length $txt]-[md5 $txt] +} + +do_test vacuum-1.1 { + execsql { + BEGIN; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); + INSERT INTO t1 VALUES(NULL,randstr(10,100),randstr(5,50)); + INSERT INTO t1 VALUES(123456,randstr(10,100),randstr(5,50)); + INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1; + INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1; + INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1; + INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1; + INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1; + INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1; + INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1; + CREATE INDEX i1 ON t1(b,c); + CREATE TABLE t2 AS SELECT * FROM t1; + COMMIT; + DROP TABLE t2; + } + set ::size1 [file size test.db] + set ::cksum [cksum vacuum1.txt] + expr {$::cksum!=""} +} {1} +do_test vacuum-1.2 { + execsql { + VACUUM; + } + cksum vacuum2.txt +} $cksum +do_test vacuum-1.3 { + expr {[file size test.db]<$::size1} +} {1} +do_test vacuum-1.4 { + execsql { + BEGIN; + CREATE TABLE t2 AS SELECT * FROM t1; + CREATE TABLE t3 AS SELECT * FROM t1; + CREATE VIEW v1 AS SELECT b, c FROM t3; + CREATE TRIGGER r1 AFTER DELETE ON t2 BEGIN + SELECT 1; + END; + COMMIT; + DROP TABLE t2; + } + set ::size1 [file size test.db] + set ::cksum [cksum vacuum3.txt] + expr {$::cksum!=""} +} {1} +do_test vacuum-1.5 { + execsql { + VACUUM; + } + cksum vacuum4.txt +} $cksum +do_test vacuum-1.6 { + expr {[file size test.db]<$::size1} +} {1} + +do_test vacuum-2.1 { + catchsql { + BEGIN; + VACUUM; + COMMIT; + } +} {1 {cannot VACUUM from within a transaction}} +execsql COMMIT # finish_test