]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
When copying a rollback mode database over a WAL database using the backup API, leave...
authordan <dan@noemail.net>
Tue, 23 Aug 2011 11:47:06 +0000 (11:47 +0000)
committerdan <dan@noemail.net>
Tue, 23 Aug 2011 11:47:06 +0000 (11:47 +0000)
FossilOrigin-Name: 35e6ac18e3d030095da57fff87a288939e9be93f

manifest
manifest.uuid
src/backup.c
src/btree.c
test/walbak.test

index 10f007cf247b4fccf9905c1ad343fb4969eba9df..acc30194f289a1ba4617b972581a62c1c58c94d7 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\sa\sbranch\sthat\sis\salways\strue.
-D 2011-08-23T00:01:58.939
+C When\scopying\sa\srollback\smode\sdatabase\sover\sa\sWAL\sdatabase\susing\sthe\sbackup\sAPI,\sleave\sthe\sdestination\sdatabase\sin\sWAL\smode\s(instead\sof\sswitching\sit\sto\srollback\smode).\sFix\sfor\s[af95b8c609].
+D 2011-08-23T11:47:06.849
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 8c930e7b493d59099ea1304bd0f2aed152eb3315
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -121,10 +121,10 @@ F src/alter.c ac80a0f31189f8b4a524ebf661e47e84536ee7f5
 F src/analyze.c a425d62e8fa9ebcb4359ab84ff0c62c6563d2e2a
 F src/attach.c 12c6957996908edc31c96d7c68d4942c2474405f
 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
-F src/backup.c 986c15232757f2873dff35ee3b35cbf935fc573c
+F src/backup.c 4dfc39043a42cbe47f22b2da47065ae5377f44fd
 F src/bitvec.c af50f1c8c0ff54d6bdb7a80e2fceca5a93670bef
 F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
-F src/btree.c a30bdcc27eedc36a38a3a11e1ba83de9a6729f7e
+F src/btree.c 97cf3ba4ff067e716753b33661035e50853aebba
 F src/btree.h f5d775cd6cfc7ac32a2535b70e8d2af48ef5f2ce
 F src/btreeInt.h 67978c014fa4f7cc874032dd3aacadd8db656bc3
 F src/build.c 6c60478a1e23f7cdd30ae0251b46f9adbe0e98c2
@@ -891,7 +891,7 @@ F test/wal5.test 08e145a352b1223930c7f0a1de82a8747a99c322
 F test/wal6.test 2e3bc767d9c2ce35c47106148d43fcbd072a93b3
 F test/wal7.test 2ae8f427d240099cc4b2dfef63cff44e2a68a1bd
 F test/wal_common.tcl a98f17fba96206122eff624db0ab13ec377be4fe
-F test/walbak.test 53be94bccbc3f592d22a5909588ccc81b319ce83
+F test/walbak.test b9f68e39646375c2b877be906babcc15d38b4877
 F test/walbig.test e882bc1d014afffbfa2b6ba36e0f07d30a633ad0
 F test/walcksum.test f5447800a157c9e2234fbb8e80243f0813941bde
 F test/walcrash.test 4fcb661faf71db91214156d52d43ee327f52bde1
@@ -961,7 +961,7 @@ F tool/symbols.sh caaf6ccc7300fd43353318b44524853e222557d5
 F tool/tostr.awk 11760e1b94a5d3dcd42378f3cc18544c06cfa576
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
 F tool/warnings.sh 2ebae31e1eb352696f3c2f7706a34c084b28c262
-P 6c227cc85378fa6041703d6620031c0e0a2db55f
-R 097c99892539b0af0c0419cec17783c1
-U drh
-Z ba0092ef44967f1382824e5e567024ca
+P a65681926d8acf779ad39be21b74537c21777783
+R 4fa828c7c042de4b81d2337ffc4e400a
+U dan
+Z 6839a6474a17b2a69c514b02de64259d
index 6f5be3c994186513a6188b2ff18e169307ee300b..46d3d766829b93931444c327605da11924663773 100644 (file)
@@ -1 +1 @@
-a65681926d8acf779ad39be21b74537c21777783
\ No newline at end of file
+35e6ac18e3d030095da57fff87a288939e9be93f
\ No newline at end of file
index 4d7ae31834cf6fd06565f342cec047b56ba1f706..83fa74767202e63ff7aff31acf29ae21a3d31172 100644 (file)
@@ -419,6 +419,15 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
         sqlite3ResetInternalSchema(p->pDestDb, -1);
       }
 
+      if( destMode==PAGER_JOURNALMODE_WAL ){
+        /* This call cannot fail. The success of the BtreeUpdateMeta() 
+        ** method above indicates that a write transaction has been opened 
+        ** and page 1 is already dirty. Therefore this always succeeds.
+        */
+        TESTONLY(int rc2 =) sqlite3BtreeSetVersion(p->pDest, 2);
+        assert( rc2==SQLITE_OK );
+      }
+
       /* Set nDestTruncate to the final number of pages in the destination
       ** database. The complication here is that the destination page
       ** size may be different to the source page size. 
index 3e58f68cb53f1eeee5b48b3d099ae90a89f22c6d..547ef83707b84708584533881840dc151d638ed3 100644 (file)
@@ -8149,7 +8149,6 @@ int sqlite3BtreeSetVersion(Btree *pBtree, int iVersion){
   BtShared *pBt = pBtree->pBt;
   int rc;                         /* Return code */
  
-  assert( pBtree->inTrans==TRANS_NONE );
   assert( iVersion==1 || iVersion==2 );
 
   /* If setting the version fields to 1, do not automatically open the
index 4224c5b48d2cdbab9ede8302f7893e76cf5a0646..303a628a84bb9f39e83ae6adb63d3310e43fb360 100644 (file)
@@ -79,6 +79,9 @@ do_test walbak-1.6 {
   execsql { PRAGMA wal_checkpoint }
   list [file size test.db] [file size test.db-wal]
 } [list [expr 3*1024] [wal_file_size 6 1024]]
+do_test walbak-1.6.1 {
+  hexio_read test.db 18 2
+} {0202}
 do_test walbak-1.7 {
   execsql { 
     CREATE TABLE t2(a, b);
@@ -271,9 +274,84 @@ foreach {tn setup} {
     execsql { SELECT * FROM t1 }
   } {1 2 3 4 5 6 7 8}
 
+  # Check that [db] is still in WAL mode.
+  do_test walbak-3.$tn.5 {
+    execsql { PRAGMA journal_mode }
+  } {wal}
+  do_test walbak-3.$tn.6 {
+    execsql { PRAGMA wal_checkpoint }
+    hexio_read test.db 18 2
+  } {0202}
+
+  # If it was not an in-memory database, check that [db2] is still in
+  # rollback mode.
+  if {[file exists test.db2]} {
+    do_test walbak-3.$tn.7 {
+      execsql { PRAGMA journal_mode } db2
+    } {wal}
+    do_test walbak-3.$tn.8 {
+      execsql { PRAGMA wal_checkpoint }
+      hexio_read test.db 18 2
+    } {0202}
+  }
+
   db  close
   db2 close
 }
 
+#-------------------------------------------------------------------------
+# Test that the following holds when a backup operation is run:
+#
+#   Source  |  Destination inital  |  Destination final
+#   ---------------------------------------------------
+#   Rollback   Rollback               Rollback
+#   Rollback   WAL                    WAL
+#   WAL        Rollback               WAL
+#   WAL        WAL                    WAL
+#
+foreach {tn src dest dest_final} {
+  1   delete    delete    delete
+  2   delete    wal       wal
+  3   wal       delete    wal
+  4   wal       wal       wal
+} {
+  catch { db close } 
+  catch { db2 close } 
+  forcedelete test.db test.db2
+
+  do_test walbak-4.$tn.1 {
+    sqlite3 db test.db
+    db eval "PRAGMA journal_mode = $src"
+    db eval {
+      CREATE TABLE t1(a, b);
+      INSERT INTO t1 VALUES('I', 'II');
+      INSERT INTO t1 VALUES('III', 'IV');
+    }
+
+    sqlite3 db2 test.db2
+    db2 eval "PRAGMA journal_mode = $dest"
+    db2 eval {
+      CREATE TABLE t2(x, y);
+      INSERT INTO t2 VALUES('1', '2');
+      INSERT INTO t2 VALUES('3', '4');
+    }
+  } {}
+
+  do_test walbak-4.$tn.2 { execsql { PRAGMA journal_mode } db  } $src
+  do_test walbak-4.$tn.3 { execsql { PRAGMA journal_mode } db2 } $dest
+
+  do_test walbak-4.$tn.4 { db backup test.db2 } {}
+  do_test walbak-4.$tn.5 {
+    execsql { SELECT * FROM t1 } db2
+  } {I II III IV}
+  do_test walbak-4.$tn.5 { execsql { PRAGMA journal_mode } db2 } $dest_final
+
+
+  db2 close
+  do_test walbak-4.$tn.6 { file exists test.db2-wal } 0
+  sqlite3 db2 test.db2
+  do_test walbak-4.$tn.7 { execsql { PRAGMA journal_mode } db2 } $dest_final
+}
+
 
 finish_test