diff --git a/manifest b/manifest index 40213f1639..7f3d514ca1 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,5 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -C Fix\sdisabled\simplementation-mark\scomments\sin\sfunc.c. -D 2010-08-03T18:06:25 +C When\sopening\sa\swrite-transaction\son\sa\sdatabase\sfile\sthat\shas\sbeen\sappended\sto\sor\struncated\sby\sa\spre-3.7.0\sclient,\supdate\sthe\sdatabase-size\sfield\sin\sthe\sdatabase\sheader.\sFix\sfor\s[51ae9cad31]. +D 2010-08-04T11:34:31 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -116,7 +113,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 51d83300fe0baee39405c416ceb19a58ed30a8ed F src/bitvec.c 06ad2c36a9c3819c0b9cbffec7b15f58d5d834e0 F src/btmutex.c 96a12f50f7a17475155971a241d85ec5171573ff -F src/btree.c 2b122b7d7dec94670ecaa70f92397406100036aa +F src/btree.c 397093afc0019b973e1c4403480431d13219c2e3 F src/btree.h b4ba2fdf6b64c7c376bdfffa826af6b786b151d9 F src/btreeInt.h b0c87f6725b06a0aa194a6d25d54b16ce9d6e291 F src/build.c 0018d49629fc4807100c988dd191dd95e185bb38 @@ -355,7 +352,7 @@ F test/exclusive2.test fcbb1c9ca9739292a0a22a3763243ad6d868086b F test/exec.test e949714dc127eaa5ecc7d723efec1ec27118fdd7 F test/expr.test 9f521ae22f00e074959f72ce2e55d46b9ed23f68 F test/filectrl.test 97003734290887566e01dded09dc9e99cb937e9e -F test/filefmt.test 5d271bf467e6557fe7499dcc8203069c9dc5825e +F test/filefmt.test f77c92141960b7933bc6691631d2ad62257ef40a F test/fkey1.test 01c7de578e11747e720c2d9aeef27f239853c4da F test/fkey2.test e028cd80aa0bd38541c99214e3ba2dfccadffe6f F test/fkey3.test 42f88d6048d8dc079e2a8cf7baad1cc1483a7620 @@ -543,7 +540,7 @@ F test/null.test a8b09b8ed87852742343b33441a9240022108993 F test/openv2.test af02ed0a9cbc0d2a61b8f35171d4d117e588e4ec F test/pager1.test d8e4b2bc8164c920e6ea0572c9e13576d6e4f3fa F test/pager2.test f5c757c271ce642d36a393ecbfb3aef1c240dcef -F test/pagerfault.test a4c0bb8900b8dbf5fcbe41ee2a96148e22174bcb +F test/pagerfault.test c1d176326ce244db157ce9c3ba128be2a9b172d6 F test/pagerfault2.test 1f79ea40d1133b2683a2f811b00f2399f7ec2401 F test/pageropt.test 8146bf448cf09e87bb1867c2217b921fb5857806 F test/pagesize.test 76aa9f23ecb0741a4ed9d2e16c5fa82671f28efb @@ -622,7 +619,7 @@ F test/tclsqlite.test 8c154101e704170c2be10f137a5499ac2c6da8d3 F test/tempdb.test 800c36623d67a2ad1f58784b9c5644e0405af6e6 F test/temptable.test f42121a0d29a62f00f93274464164177ab1cc24a F test/temptrigger.test b0273db072ce5f37cf19140ceb1f0d524bbe9f05 -F test/tester.tcl bc01480bbf2e948b52da8943fedc4237b0735961 +F test/tester.tcl 36552bcc93adb3a932a487da84da6597cdc5871b F test/thread001.test a3e6a7254d1cb057836cb3145b60c10bf5b7e60f F test/thread002.test afd20095e6e845b405df4f2c920cb93301ca69db F test/thread003.test b824d4f52b870ae39fc5bae4d8070eca73085dca @@ -844,14 +841,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 4e157b774764b8bafc9fabb88decf54f178b5ff5 -R 2ffda3ab686430275e530bf434e41e4c -U drh -Z 636446afbb2581f1ac8c757ae258a4e0 ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.6 (GNU/Linux) - -iD8DBQFMWFqkoxKgR168RlERAoOBAKCD0AqnZ6ZzbybLHgm4lZfoGX3cfgCfa6ef -C79lcWSk6pzbtaW4+fqCLFQ= -=jbsY ------END PGP SIGNATURE----- +P 57c0960038b8ce97f9d6665f15e7f6ec310c681f +R 2302fd10d4e5885f2536eafbb69bad6e +U dan +Z a94bacf2e85499d72182ad0845d48def diff --git a/manifest.uuid b/manifest.uuid index fce696df96..6b50305f08 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -57c0960038b8ce97f9d6665f15e7f6ec310c681f \ No newline at end of file +65b8636ac6e5d3e4502d4f576ddf9350d5df3022 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index c03d3c92b8..70b202692d 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2569,13 +2569,27 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag){ if( p->inTrans>pBt->inTransaction ){ pBt->inTransaction = p->inTrans; } -#ifndef SQLITE_OMIT_SHARED_CACHE if( wrflag ){ + MemPage *pPage1 = pBt->pPage1; +#ifndef SQLITE_OMIT_SHARED_CACHE assert( !pBt->pWriter ); pBt->pWriter = p; pBt->isExclusive = (u8)(wrflag>1); - } #endif + + /* If the db-size header field is incorrect (as it may be if an old + ** client has been writing the database file), update it now. Doing + ** this sooner rather than later means the database size can safely + ** re-read the database size from page 1 if a savepoint or transaction + ** rollback occurs within the transaction. + */ + if( pBt->nPage!=get4byte(&pPage1->aData[28]) ){ + rc = sqlite3PagerWrite(pPage1->pDbPage); + if( rc==SQLITE_OK ){ + put4byte(&pPage1->aData[28], pBt->nPage); + } + } + } } diff --git a/test/filefmt.test b/test/filefmt.test index 28bc5fcc6f..16b459630c 100644 --- a/test/filefmt.test +++ b/test/filefmt.test @@ -117,5 +117,80 @@ ifcapable pager_pragmas { } {1 {file is encrypted or is not a database}} } +#------------------------------------------------------------------------- +# The following block of tests - filefmt-2.* - test that versions 3.7.0 +# and later can read and write databases that have been modified or created +# by 3.6.23.1 and earlier. The difference difference is that 3.7.0 stores +# the size of the database in the database file header, whereas 3.6.23.1 +# always derives this from the size of the file. +# +db close +file delete -force test.db + +set a_string_counter 1 +proc a_string {n} { + incr ::a_string_counter + string range [string repeat "${::a_string_counter}." $n] 1 $n +} +sqlite3 db test.db +db func a_string a_string + +do_execsql_test filefmt-2.1.1 { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(a_string(3000)); + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); +} {} +do_test filefmt-2.1.2 { + hexio_read test.db 28 4 +} {00000009} + +do_test filefmt-2.1.3 { + sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } +} {} + +do_execsql_test filefmt-2.1.4 { INSERT INTO t2 VALUES(2) } {} +integrity_check filefmt-2.1.5 +do_test filefmt-2.1.6 { hexio_read test.db 28 4 } {00000010} + +db close +file delete -force test.db +sqlite3 db test.db +db func a_string a_string + +do_execsql_test filefmt-2.2.1 { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(a_string(3000)); + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); +} {} +do_test filefmt-2.2.2 { + hexio_read test.db 28 4 +} {00000009} + +do_test filefmt-2.2.3 { + sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } +} {} + +do_execsql_test filefmt-2.2.4 { + PRAGMA integrity_check; + BEGIN; + INSERT INTO t2 VALUES(2); + SAVEPOINT a; + INSERT INTO t2 VALUES(3); + ROLLBACK TO a; +} {ok} + +integrity_check filefmt-2.2.5 +do_execsql_test filefmt-2.2.6 { COMMIT } {} +db close +sqlite3 db test.db +integrity_check filefmt-2.2.7 finish_test diff --git a/test/pagerfault.test b/test/pagerfault.test index 89f5a11eb2..f9c82ddb60 100644 --- a/test/pagerfault.test +++ b/test/pagerfault.test @@ -1045,4 +1045,37 @@ ifcapable crashtest { } } + +#------------------------------------------------------------------------- +# When a 3.7.0 client opens a write-transaction on a database file that +# has been appended to or truncated by a pre-370 client, it updates +# the db-size in the file header immediately. This test case provokes +# errors during that operation. +# +do_test pagerfault-22-pre1 { + faultsim_delete_and_reopen + db func a_string a_string + execsql { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(a_string(3000)); + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); + } + db close + sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } + faultsim_save_and_close +} {} +do_faultsim_test pagerfault-22 -prep { + faultsim_restore_and_reopen +} -body { + execsql { INSERT INTO t2 VALUES(2) } + execsql { SELECT * FROM t2 } +} -test { + faultsim_test_result {0 {1 2}} + faultsim_integrity_check +} + finish_test diff --git a/test/tester.tcl b/test/tester.tcl index f485a6de5b..e4193b48f8 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -1230,6 +1230,23 @@ proc slave_test_file {zFile} { show_memstats } +# Open a new connection on database test.db and execute the SQL script +# supplied as an argument. Before returning, close the new conection and +# restore the 4 byte fields starting at header offsets 28, 92 and 96 +# to the values they held before the SQL was executed. This simulates +# a write by a pre-3.7.0 client. +# +proc sql36231 {sql} { + set B [hexio_read test.db 92 8] + set A [hexio_read test.db 28 4] + sqlite3 db36231 test.db + catch { db36231 func a_string a_string } + execsql $sql db36231 + db36231 close + hexio_write test.db 28 $A + hexio_write test.db 92 $B + return "" +} # If the library is compiled with the SQLITE_DEFAULT_AUTOVACUUM macro set # to non-zero, then set the global variable $AUTOVACUUM to 1.