]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a file corruption bug in CREATE INDEX in auto-vacuum databases. (CVS 2368)
authordanielk1977 <danielk1977@noemail.net>
Wed, 9 Mar 2005 13:09:43 +0000 (13:09 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Wed, 9 Mar 2005 13:09:43 +0000 (13:09 +0000)
FossilOrigin-Name: 64c4c717d35c8fce9b4be073196c507f6d471188

manifest
manifest.uuid
src/btree.c
src/pager.c
test/autovacuum.test

index 54518d47b248f9ab7e1e632532904203d5b9987b..0beee47eeea6939ae1bf4f7b955b85405a214c6f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Support\sfor\sa\sfuture\sALTER\sTABLE\scommand\sto\sadd\scolumns\swith\sdefault\svalues.\s(CVS\s2367)
-D 2005-03-09T12:26:51
+C Fix\sa\sfile\scorruption\sbug\sin\sCREATE\sINDEX\sin\sauto-vacuum\sdatabases.\s(CVS\s2368)
+D 2005-03-09T13:09:44
 F Makefile.in 76443a83549d1539105e12d13bd0054a05ab2214
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@@ -30,7 +30,7 @@ F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
 F src/alter.c 6dab3d91aa4bf5c24e874145a2a547070c8c1883
 F src/attach.c f78f76bc6a8e5e487ca53636e21ccba2484a9a61
 F src/auth.c 18c5a0befe20f3a58a41e3ddd78f372faeeefe1f
-F src/btree.c 2a9c2c8a9f5a2762f0c770bc9c3f69c689d79d81
+F src/btree.c 448cd6280f18ef5723a177c4073319b1c65c86ad
 F src/btree.h 2e2cc923224649337d7217df0dd32b06673ca180
 F src/build.c a8792b2f866c1ccc32f4977f4ff61d787d60ddfb
 F src/date.c f3d1f5cd1503dabf426a198f3ebef5afbc122a7f
@@ -52,7 +52,7 @@ F src/os_unix.c 68d3d32937eee90fe1f50d500d1a4ee826cbe790
 F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13
 F src/os_win.c bddeae1c3299be0fbe47077dd4e98b786a067f71
 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c 835028769569971c7dbd63d11d3517392f1cdae0
+F src/pager.c b728c90bfa33994006a067a32971cabd0a852916
 F src/pager.h 70d496f372163abb6340f474288c4bb9ea962cf7
 F src/parse.y 0b6135268a7a29db35335d5b71b5a8791e02f91e
 F src/pragma.c 4b20dbc0f4b97f412dc511853d3d0c2e0d4adedc
@@ -91,7 +91,7 @@ F test/attach2.test 6f3a3a3a7f5be40388dd4d805e0e0712718dca9d
 F test/attach3.test c05c70b933afbde0901dab9da3e66ee842c09f38
 F test/auth.test b24d12de3a6ba49237216429f8dc672a8a52b342
 F test/autoinc.test d619da7d5cb9a3d63e6a7925259fc173f7e2080e
-F test/autovacuum.test 8ba29face873300394f9446ded0e4a142d24e7e4
+F test/autovacuum.test cf2719b17659f7a011202ad05905654cedf26023
 F test/autovacuum_crash.test 05a63b8805b20cfba7ace82856ce4ccdda075a31
 F test/autovacuum_ioerr.test 9cf27275ca47b72e188a47c53b61b6d583a01d24
 F test/autovacuum_ioerr2.test 2f8a3fb31f833fd0ca86ad4ad98913c73e807572
@@ -274,7 +274,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
 F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
 F www/whentouse.tcl 3e522a06ad41992023c80ca29a048ae2331ca5bd
-P 9b96078763949a2723482328e7b90c939ba8d2d8
-R addb8e4a99b565c64d053b41daed1503
+P 9d5abc1ddf6da37563c12d5a0401b89bb4e51c59
+R 7ebd6c17f19c475f5965e55f2c022589
 U danielk1977
-Z 96056e2906d91fc33a19b0bf81dd2822
+Z 9f3ce05c00f0a22bc7d46eacd8760d1e
index dcd0b347fd4b3a6abd281228a5c14da343afce60..eb74301cf6dccdd3b62c350dbdcb337caf8e46dc 100644 (file)
@@ -1 +1 @@
-9d5abc1ddf6da37563c12d5a0401b89bb4e51c59
\ No newline at end of file
+64c4c717d35c8fce9b4be073196c507f6d471188
\ No newline at end of file
index f68766e8d74c39fab1e268ed708ce1dbc48723aa..a9bf67430192e14709525091a4bb65560ea34417 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.249 2005/02/26 17:31:27 drh Exp $
+** $Id: btree.c,v 1.250 2005/03/09 13:09:44 danielk1977 Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -4699,6 +4699,11 @@ int sqlite3BtreeCreateTable(Btree *pBt, int *piTable, int flags){
       }
       assert( eType!=PTRMAP_ROOTPAGE );
       assert( eType!=PTRMAP_FREEPAGE );
+      rc = sqlite3pager_write(pRoot->aData);
+      if( rc!=SQLITE_OK ){
+        releasePage(pRoot);
+        return rc;
+      }
       rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove);
       releasePage(pRoot);
       if( rc!=SQLITE_OK ){
index 4a65af72c17d0b7454f19260bc6f426ca4ce8162..c26d7176d2fb8e37d76557e4bd145a9cf2a17817 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.190 2005/02/15 03:38:06 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.191 2005/03/09 13:09:45 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -3406,8 +3406,10 @@ sync_exit:
 ** meta-data associated with page pData (i.e. data stored in the nExtra bytes
 ** allocated along with the page) is the responsibility of the caller.
 **
-** A transaction must be active when this routine is called, however it is 
-** illegal to call this routine if a statment transaction is active.
+** A transaction must be active when this routine is called. It used to be
+** required that a statement transaction was not active, but this restriction
+** has been removed (CREATE INDEX needs to move a page when a statement
+** transaction is active).
 */
 int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){
   PgHdr *pPg = DATA_TO_PGHDR(pData);
@@ -3415,7 +3417,6 @@ int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){
   int h;
   Pgno needSyncPgno = 0;
 
-  assert( !pPager->stmtInUse );
   assert( pPg->nRef>0 );
 
   TRACE5("MOVE %d page %d (needSync=%d) moves to %d\n", 
index ee6239f79ee6232ab8feca4eb32c1ced61fa17d1..cc2211d788876dc2b189f7840c616f1d7753b50b 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the SELECT statement.
 #
-# $Id: autovacuum.test,v 1.16 2005/01/24 10:26:00 danielk1977 Exp $
+# $Id: autovacuum.test,v 1.17 2005/03/09 13:09:45 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -488,4 +488,37 @@ do_test autovacuum-3.7 {
   file_pages
 } [expr $AUTOVACUUM?1:2]
 
+#-----------------------------------------------------------------------
+# Test that if a statement transaction around a CREATE INDEX statement is
+# rolled back no corruption occurs.
+#
+do_test autovacuum-4.1 {
+  execsql {
+    CREATE TABLE av1(a, b);
+    BEGIN;
+  }
+  for {set i 0} {$i<100} {incr i} {
+    execsql "INSERT INTO av1 VALUES($i, '[string repeat X 200]');"
+  }
+  execsql "INSERT INTO av1 VALUES(99, '[string repeat X 200]');"
+  execsql {
+    SELECT sum(a) FROM av1;
+  }
+} {5049.0}
+do_test autovacuum-4.2 {
+  catchsql {
+    CREATE UNIQUE INDEX av1_i ON av1(a);
+  }
+} {1 {indexed columns are not unique}}
+do_test autovacuum-4.3 {
+  execsql {
+    SELECT sum(a) FROM av1;
+  }
+} {5049.0}
+do_test autovacuum-4.4 {
+  execsql {
+    COMMIT;
+  }
+} {}
+
 finish_test