]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
VACUUM works even on an empty database. Ticket #1512. (CVS 2760)
authordrh <drh@noemail.net>
Fri, 4 Nov 2005 22:03:30 +0000 (22:03 +0000)
committerdrh <drh@noemail.net>
Fri, 4 Nov 2005 22:03:30 +0000 (22:03 +0000)
FossilOrigin-Name: 1b6bf4188e8ebf55cf1972b7081f6d31bf525555

manifest
manifest.uuid
src/os_common.h
src/pager.c
src/test2.c
src/vacuum.c
test/tester.tcl
test/tkt1512.test [new file with mode: 0644]
tool/showdb.c

index 72b79237d8b9c97da2d083f2a8bfce235e7a9302..310cb4676007dde8ee4775d7084a5f1cd352b359 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C sqlite3_column_int()\sand\ssimilar\sroutines\sreturn\s0\sor\s0.0\son\san\nout-of-memory\scondition,\snot\ssome\smysterious\serror\scode.\s(CVS\s2759)
-D 2005-11-03T14:29:55
+C VACUUM\sworks\seven\son\san\sempty\sdatabase.\s\sTicket\s#1512.\s(CVS\s2760)
+D 2005-11-04T22:03:30
 F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -50,14 +50,14 @@ F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
 F src/main.c 97bb830cdbd378d1f87469618471f52d9d263d09
 F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
 F src/os.h c51f2747f7bd1840447e2c7d26db749604626814
-F src/os_common.h 1ff88c7e7e6bd3e5f85443106c91cc26a4f8600b
+F src/os_common.h d74a11728ad2444b6b695b94c28c06881f049e49
 F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
 F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
 F src/os_unix.c 2af2d2cea9cc6282c02b48aacf2995193440cf00
 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
 F src/os_win.c fbccc85e7011174068c27d54256746321a1f0059
 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c adbb27f13ac75cd5bc29a3d84803e0cab1edfa88
+F src/pager.c 0d8dda8bba9efbda30626cdc3c6573fe10adafdc
 F src/pager.h e7b41ce8e7b5f629d456708b7ad9a8c8ede37140
 F src/parse.y 1d5afb972ed5ef3ec8712a2b5953b48f086091da
 F src/pragma.c b40189967155a522433b8470f363192a927ba22c
@@ -71,7 +71,7 @@ F src/sqliteInt.h e546554bdd4e3c903dd033bb1e2476193c2d4f37
 F src/table.c e03b60eaabaeb54a00d7e931566d77302dfc19b0
 F src/tclsqlite.c 4f274fae3d4a1863451a553dd8e5015747a5d91d
 F src/test1.c 77506b6b88125c26f00a11bf3ff5c8dc824e837e
-F src/test2.c 4196848c845626e7df894470f27329e80bfe92aa
+F src/test2.c d55861d8ba5a8b434544da366ba6efe206e1ec97
 F src/test3.c f4e6a16a602091696619a1171bda25c0e3df49f7
 F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
 F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5
@@ -80,7 +80,7 @@ F src/trigger.c f51dec15921629591cb98bf2e350018e268b109a
 F src/update.c ac506fb7400158f826ec6c3a0dbe65e7ed3928d5
 F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c
 F src/util.c 48fecbbef4391d102a23096d32f0d74173428406
-F src/vacuum.c 2ed18a4e9c894de7239bc1c68fe455fcb39571c6
+F src/vacuum.c baae8681282c7a03900043043dc7ce07d43b5a1e
 F src/vdbe.c e83de8a017fe5c495fcef3093dbdca30fa6b1ea4
 F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
 F src/vdbeInt.h 6eba0b967dc4fc4d5dea6e3bcc66e70a44981cc9
@@ -217,7 +217,7 @@ F test/table.test ec0e6c2186bb8f6824f470caa118524dfd8fe057
 F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1
 F test/tclsqlite.test 2da3e4b3a79b13c1511c9d0cd995e08f8362e782
 F test/temptable.test 7927261befdbc7b0a7ffebb85ecc70a74fa7b15b
-F test/tester.tcl 1e75553d320f5d2720613d8483c934488fc2c56f
+F test/tester.tcl bf4e288cd8b968e4514c0bdee27f4f31b21b7271
 F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
 F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
 F test/threadtest2.c 97a830d53c24c42290501fdfba4a6e5bdd34748b
@@ -226,6 +226,7 @@ F test/tkt1443.test 1e83b6a1e7f6e261682e67106ab3bc05f6c70e90
 F test/tkt1444.test 0f0fc1f277691f904dea2abece6db919dcae2351
 F test/tkt1449.test f8de8a84ec12ee805ed80055e1209560f8bee4d8
 F test/tkt1473.test e4637c27d606fd002de78113a8e1a142e48ffb18
+F test/tkt1512.test 8efd8d07e27e99d7462f75b5711de65eb7708baf
 F test/trace.test 9fd28695c463b90c2d32c387a432e01eb26e8ccf
 F test/trans.test 10506dc30305cfb8c4098359f7f6f64786f69c5e
 F test/trigger1.test 152aed5a1fa90709fe171f2ca501a6b7f7901479
@@ -257,7 +258,7 @@ F tool/mkkeywordhash.c 5263a654e5c9fd8d6e3238fb39c2d5c3126be32f
 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
 F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
 F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
-F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
+F tool/showdb.c a086a3d788c7a23cb008317c3180ceb19f20bce0
 F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
 F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
 F tool/spaceanal.tcl 5b47b70b9a0d216ec63a5b5547b3642dd308e53a
@@ -316,7 +317,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P bb94ef64b227839a0ef4156985e2f5a061a78e2c
-R d764f727b04686e2af798ae9ccbcdf15
+P 7780f5e9d504926f11bd0662c03c88c76fb1d416
+R 1a3d1b527330224886b9cff041619a5d
 U drh
-Z 6e4bc42bd67b219bb703d08d5d61a498
+Z f1e5a520d02502b659fb8d9e06e8fb3d
index 1bed2abe7826f57d38bc09e2c14655ed646e44ca..5d4d99edddbe69000e1872a3a0adb7900e4a17c3 100644 (file)
@@ -1 +1 @@
-7780f5e9d504926f11bd0662c03c88c76fb1d416
\ No newline at end of file
+1b6bf4188e8ebf55cf1972b7081f6d31bf525555
\ No newline at end of file
index b19ff059067bae9759a6628ba39aeae4463c2d7f..112fbb7794de954bcb43103ccc71a5f023f5faf9 100644 (file)
@@ -88,6 +88,7 @@ static unsigned int elapse;
 ** is used for testing the I/O recovery logic.
 */
 #ifdef SQLITE_TEST
+int sqlite3_io_error_hit = 0;
 int sqlite3_io_error_pending = 0;
 int sqlite3_diskfull_pending = 0;
 int sqlite3_diskfull = 0;
@@ -95,7 +96,7 @@ int sqlite3_diskfull = 0;
    if( sqlite3_io_error_pending ) \
      if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
 static void local_ioerr(){
-  sqlite3_io_error_pending = 0;  /* Really just a place to set a breakpoint */
+  sqlite3_io_error_hit = 1;  /* Really just a place to set a breakpoint */
 }
 #define SimulateDiskfullError \
    if( sqlite3_diskfull_pending ){ \
index 74b55aa1cf521d7154b46dc34840038005f220d0..cc91672c680ee9ab5a3acdb070c7a659f9a7f808 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.215 2005/09/17 15:20:27 drh Exp $
+** @(#) $Id: pager.c,v 1.216 2005/11/04 22:03:30 drh Exp $
 */
 #ifndef SQLITE_OMIT_DISKIO
 #include "sqliteInt.h"
@@ -1738,6 +1738,34 @@ int sqlite3pager_set_pagesize(Pager *pPager, int pageSize){
   return pPager->pageSize;
 }
 
+/*
+** The following set of routines are used to disable the simulated
+** I/O error mechanism.  These routines are used to avoid simulated
+** errors in places where we do not care about errors.
+**
+** Unless -DSQLITE_TEST=1 is used, these routines are all no-ops
+** and generate no code.
+*/
+#ifdef SQLITE_TEST
+extern int sqlite3_io_error_pending;
+extern int sqlite3_io_error_hit;
+static int saved_cnt;
+void clear_simulated_io_error(){
+  sqlite3_io_error_hit = 0;
+}
+void disable_simulated_io_errors(void){
+  saved_cnt = sqlite3_io_error_pending;
+  sqlite3_io_error_pending = -1;
+}
+void enable_simulated_io_errors(void){
+  sqlite3_io_error_pending = saved_cnt;
+}
+#else
+# define clear_simulated_io_error(X)
+# define disable_simulated_io_errors(X)
+# define enable_simulated_io_errors(X)
+#endif
+
 /*
 ** Read the first N bytes from the beginning of the file into memory
 ** that pDest points to.  No error checking is done.
@@ -1747,6 +1775,7 @@ void sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){
   if( MEMDB==0 ){
     sqlite3OsSeek(&pPager->fd, 0);
     sqlite3OsRead(&pPager->fd, pDest, N);
+    clear_simulated_io_error();
   }
 }
 
@@ -1961,15 +1990,9 @@ int sqlite3pager_close(Pager *pPager){
       ** operation. So disable IO error simulation so that testing
       ** works more easily.
       */
-#if defined(SQLITE_TEST) && (defined(OS_UNIX) || defined(OS_WIN))
-      extern int sqlite3_io_error_pending;
-      int ioerr_cnt = sqlite3_io_error_pending;
-      sqlite3_io_error_pending = -1;
-#endif
+      disable_simulated_io_errors();
       sqlite3pager_rollback(pPager);
-#if defined(SQLITE_TEST) && (defined(OS_UNIX) || defined(OS_WIN))
-      sqlite3_io_error_pending = ioerr_cnt;
-#endif
+      enable_simulated_io_errors();
       if( !MEMDB ){
         sqlite3OsUnlock(&pPager->fd, NO_LOCK);
       }
@@ -2535,6 +2558,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
           sqlite3pager_unref(PGHDR_TO_DATA(pPg));
           return rc;
         }else{
+          clear_simulated_io_error();
           memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
         }
       }else{
index fa4cd329c145c5fea1ff286d73fc5b50eec9f178..1867fc8662c0fbacda7d7b48295b2ba517d607f9 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test2.c,v 1.34 2005/09/16 10:13:42 danielk1977 Exp $
+** $Id: test2.c,v 1.35 2005/11/04 22:03:30 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -560,6 +560,7 @@ static int fake_big_file(
 */
 int Sqlitetest2_Init(Tcl_Interp *interp){
   extern int sqlite3_io_error_pending;
+  extern int sqlite3_io_error_hit;
   extern int sqlite3_diskfull_pending;
   extern int sqlite3_diskfull;
   static struct {
@@ -592,6 +593,8 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
   }
   Tcl_LinkVar(interp, "sqlite_io_error_pending",
      (char*)&sqlite3_io_error_pending, TCL_LINK_INT);
+  Tcl_LinkVar(interp, "sqlite_io_error_hit",
+     (char*)&sqlite3_io_error_hit, TCL_LINK_INT);
   Tcl_LinkVar(interp, "sqlite_diskfull_pending",
      (char*)&sqlite3_diskfull_pending, TCL_LINK_INT);
   Tcl_LinkVar(interp, "sqlite_diskfull",
index 28d45d5d7c9ac20c7bc8424e1dfa36ee1444bcbb..a8af62908f90badd8e02aa1555448d581f006b3d 100644 (file)
@@ -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.46 2005/11/03 02:15:04 drh Exp $
+** $Id: vacuum.c,v 1.47 2005/11/04 22:03:30 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -100,6 +100,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   Btree *pMain;           /* The database being vacuumed */
   Btree *pTemp;
   char *zSql = 0;
+  int rc2;  
   int saved_flags;       /* Saved value of the db->flags */
 
   /* Save the current value of the write-schema flag before setting it. */
@@ -176,7 +177,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
 #endif
 
   /* Begin a transaction */
-  rc = execSql(db, "BEGIN;");
+  rc = execSql(db, "BEGIN EXCLUSIVE;");
   if( rc!=SQLITE_OK ) goto end_of_vacuum;
 
   /* Query the schema of the main database. Create a mirror schema
@@ -247,7 +248,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   ** opened for writing. This way, the SQL transaction used to create the
   ** temporary database never needs to be committed.
   */
-  if( sqlite3BtreeIsInTrans(pTemp) ){
+  if( rc==SQLITE_OK ){
     u32 meta;
     int i;
 
@@ -264,19 +265,21 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
        6, 0,    /* Preserve the user version */
     };
 
-    assert( 0==sqlite3BtreeIsInTrans(pMain) );
-    rc = sqlite3BtreeBeginTrans(pMain, 1);
-    if( rc!=SQLITE_OK ) goto end_of_vacuum;
+    assert( 1==sqlite3BtreeIsInTrans(pTemp) );
+    assert( 1==sqlite3BtreeIsInTrans(pMain) );
 
     /* Copy Btree meta values */
     for(i=0; i<sizeof(aCopy)/sizeof(aCopy[0]); i+=2){
       rc = sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);
       if( rc!=SQLITE_OK ) goto end_of_vacuum;
       rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);
+      if( rc!=SQLITE_OK ) goto end_of_vacuum;
     }
 
     rc = sqlite3BtreeCopyFile(pMain, pTemp);
     if( rc!=SQLITE_OK ) goto end_of_vacuum;
+    rc = sqlite3BtreeCommit(pTemp);
+    if( rc!=SQLITE_OK ) goto end_of_vacuum;
     rc = sqlite3BtreeCommit(pMain);
   }
 
@@ -292,16 +295,15 @@ end_of_vacuum:
   ** is closed by the DETACH.
   */
   db->autoCommit = 1;
+  rc2 = execSql(db, "DETACH vacuum_db;");
   if( rc==SQLITE_OK ){
-    rc = execSql(db, "DETACH vacuum_db;");
-  }else{
-    execSql(db, "DETACH vacuum_db;");
+    rc = rc2;
   }
   if( zTemp ){
     sqlite3OsDelete(zTemp);
     sqliteFree(zTemp);
   }
-  if( zSql ) sqliteFree( zSql );
+  sqliteFree( zSql );
   sqlite3ResetInternalSchema(db, 0);
 #endif
 
index d4b1afc7a36e77e1694dc48e99ae69412df27c7d..adc85d5f6c4bacefe3bd5910c3181a0c2f9b17b7 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements some common TCL routines used for regression
 # testing the SQLite library
 #
-# $Id: tester.tcl,v 1.50 2005/09/17 15:20:28 drh Exp $
+# $Id: tester.tcl,v 1.51 2005/11/04 22:03:30 drh Exp $
 
 # Make sure tclsqlite3 was compiled correctly.  Abort now with an
 # error message if not.
@@ -362,7 +362,7 @@ proc do_ioerr_test {testname args} {
     do_test $testname.$n.3 {
       set r [catch $::ioerrorbody msg]
       set ::go [expr {$::sqlite_io_error_pending<=0}]
-      set s [expr $::sqlite_io_error_pending>0]
+      set s [expr $::sqlite_io_error_hit==0]
       # puts "$::sqlite_io_error_pending $r $msg"
       expr { ($s && !$r) || (!$s && $r) }
       # expr {$::sqlite_io_error_pending>0 || $r!=0}
diff --git a/test/tkt1512.test b/test/tkt1512.test
new file mode 100644 (file)
index 0000000..60c53ec
--- /dev/null
@@ -0,0 +1,45 @@
+# 2005 September 19
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+#
+# This file implements tests to verify that ticket #1512 is
+# fixed.  
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test tkt1512-1.1 {
+  execsql {
+    CREATE TABLE t1(a,b);
+    INSERT INTO t1 VALUES(1,2);
+    INSERT INTO t1 VALUES(3,4);
+    SELECT * FROM t1
+  }
+} {1 2 3 4}
+do_test tkt1512-1.2 {
+  file size test.db
+} {2048}
+do_test tkt1512-1.3 {
+  execsql {
+    DROP TABLE t1;
+  }
+  file size test.db
+} {2048}
+do_test tkt1512-1.4 {
+  execsql {
+    VACUUM;
+  }
+  file size test.db
+} {1024}
+
+
+finish_test
index fe105c7bb28615f49206326955b924f27cd9eebb..b2ed562e950dae3698b018df2f8496723ee2df05 100644 (file)
@@ -13,6 +13,7 @@
 static int pagesize = 1024;
 static int db = -1;
 static int mxPage = 0;
+static int perLine = 32;
 
 static void out_of_memory(void){
   fprintf(stderr,"Out of memory...\n");
@@ -27,12 +28,12 @@ static print_page(int iPg){
   lseek(db, (iPg-1)*pagesize, SEEK_SET);
   read(db, aData, pagesize);
   fprintf(stdout, "Page %d:\n", iPg);
-  for(i=0; i<pagesize; i += 16){
+  for(i=0; i<pagesize; i += perLine){
     fprintf(stdout, " %03x: ",i);
-    for(j=0; j<16; j++){
+    for(j=0; j<perLine; j++){
       fprintf(stdout,"%02x ", aData[i+j]);
     }
-    for(j=0; j<16; j++){
+    for(j=0; j<perLine; j++){
       fprintf(stdout,"%c", isprint(aData[i+j]) ? aData[i+j] : '.');
     }
     fprintf(stdout,"\n");