From cb1b0a693ac7aef2f05c65dba4d4bf5d78d4cf3b Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 2 Mar 2017 14:51:47 +0000 Subject: [PATCH 1/8] When saving the state of an RBU update in the incremental-checkpoint phase, sync the database file. Otherwise, if a power failure occurs and the RBU update resumed following system recovery, the database may become corrupt. FossilOrigin-Name: edee6a80e1cc7e6a2b8c3c7f76dd794fc8ab9a72 --- ext/rbu/rbucrash2.test | 101 +++++++++++++++++++++++++++++++++++++++++ ext/rbu/sqlite3rbu.c | 12 +++++ manifest | 19 ++++---- manifest.uuid | 2 +- src/test6.c | 17 ++++--- test/tester.tcl | 6 ++- 6 files changed, 139 insertions(+), 18 deletions(-) create mode 100644 ext/rbu/rbucrash2.test diff --git a/ext/rbu/rbucrash2.test b/ext/rbu/rbucrash2.test new file mode 100644 index 0000000000..89c2535a93 --- /dev/null +++ b/ext/rbu/rbucrash2.test @@ -0,0 +1,101 @@ +# 2017 March 02 +# +# 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. +# +#*********************************************************************** +# + +if {![info exists testdir]} { + set testdir [file join [file dirname [info script]] .. .. test] +} +source $testdir/tester.tcl +set ::testprefix rbucrash2 + +db close +forcedelete test.db-oal rbu.db +sqlite3_shutdown +sqlite3_config_uri 1 +reset_db + +# Set up a target database and an rbu update database. The target +# db is the usual "test.db", the rbu db is "test.db2". +# +forcedelete test.db2 +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c, PRIMARY KEY(a), UNIQUE(b)); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + INSERT INTO t1 VALUES(7, 8, 9); + + ATTACH 'test.db2' AS rbu; + CREATE TABLE rbu.data_t1(a, b, c, rbu_control); + INSERT INTO data_t1 VALUES('one', randomblob(3500), NULL, 0); + INSERT INTO data_t1 VALUES('two', randomblob(3500), NULL, 0); + INSERT INTO data_t1 VALUES('three', randomblob(3500), NULL, 0); + INSERT INTO data_t1 VALUES('four', randomblob(3500), NULL, 0); + INSERT INTO data_t1 VALUES('five', randomblob(3500), NULL, 0); + INSERT INTO data_t1 VALUES('six', randomblob(3500), NULL, 0); +} +db_save_and_close + +proc do_rbu_crash_test2 {tn script} { + + foreach f {test.db test.db2} { + set bDone 0 + for {set iDelay 1} {$bDone==0} {incr iDelay} { + forcedelete test.db2 test.db2-journal test.db test.db-oal test.db-wal + db_restore + + set res [ + crashsql -file $f -delay $iDelay -tclbody $script -dflt 1 -opendb {} \ + -blocksize 512 {} + ] + + set bDone 1 + if {$res == "1 {child process exited abnormally}"} { + set bDone 0 + } elseif {$res != "0 {}"} { + error "unexected catchsql result: $res" + } + + sqlite3rbu rbu test.db test.db2 + while {[rbu step]=="SQLITE_OK"} {} + rbu close + + sqlite3 db test.db + do_execsql_test $tn.delay=$iDelay.f=$f { + PRAGMA integrity_check; + } {ok} + db close + } + } +} + +for {set x 1} {$x < 10} {incr x} { + do_rbu_crash_test2 1.$x { + sqlite3rbu rbu test.db test.db2 + while {[rbu step]=="SQLITE_OK"} { + rbu savestate + } + rbu close + } +} + +for {set x 1} {$x < 2} {incr x} { + do_rbu_crash_test2 2.$x { + sqlite3rbu rbu test.db test.db2 + while {[rbu step]=="SQLITE_OK"} { + rbu close + sqlite3rbu rbu test.db test.db2 + } + rbu close + } +} + +finish_test + diff --git a/ext/rbu/sqlite3rbu.c b/ext/rbu/sqlite3rbu.c index 48c69115ee..262f96ea3c 100644 --- a/ext/rbu/sqlite3rbu.c +++ b/ext/rbu/sqlite3rbu.c @@ -3718,6 +3718,12 @@ int sqlite3rbu_close(sqlite3rbu *p, char **pzErrmsg){ p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg); } + /* Sync the db file if currently doing an incremental checkpoint */ + if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_CKPT ){ + sqlite3_file *pDb = p->pTargetFd->pReal; + p->rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL); + } + rbuSaveState(p, p->eStage); if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){ @@ -3842,6 +3848,12 @@ int sqlite3rbu_savestate(sqlite3rbu *p){ if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0); } + /* Sync the db file */ + if( rc==SQLITE_OK && p->eStage==RBU_STAGE_CKPT ){ + sqlite3_file *pDb = p->pTargetFd->pReal; + rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL); + } + p->rc = rc; rbuSaveState(p, p->eStage); rc = p->rc; diff --git a/manifest b/manifest index 646adca563..4ab87a35ed 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthe\sVdbe.expmask\svalue\sis\sset\scorrectly\sin\ssqlite3VdbeSwap().\nThis\sfixes\sa\sproblem\sintroduced\sby\s[a8fd7052]. -D 2017-03-02T13:13:30.327 +C When\ssaving\sthe\sstate\sof\san\sRBU\supdate\sin\sthe\sincremental-checkpoint\sphase,\nsync\sthe\sdatabase\sfile.\sOtherwise,\sif\sa\spower\sfailure\soccurs\sand\sthe\sRBU\nupdate\sresumed\sfollowing\ssystem\srecovery,\sthe\sdatabase\smay\sbecome\scorrupt. +D 2017-03-02T14:51:47.379 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -250,6 +250,7 @@ F ext/rbu/rbuB.test c25bc325b8072a766e56bb76c001866b405925c2 F ext/rbu/rbuC.test efe47db508a0269b683cb2a1913a425ffd39a831 F ext/rbu/rbu_common.tcl a38e8e2d4a50fd6aaf151633714c1b1d2fae3ead F ext/rbu/rbucrash.test 8d2ed5d4b05fef6c00c2a6b5f7ead71fa172a695 +F ext/rbu/rbucrash2.test 7f3fe5d6d930be0965f27b49bdcdc8d4a078b73c F ext/rbu/rbudiff.test 3e605cf624d00d04d0fb1316a3acec4fbe3b3ac5 F ext/rbu/rbudor.test 99b05cc0df613e962c2c8085cfb05686a09cf315 F ext/rbu/rbufault.test cc0be8d5d392d98b0c2d6a51be377ea989250a89 @@ -262,7 +263,7 @@ F ext/rbu/rburesume.test 8acb77f4a422ff55acfcfc9cc15a5cb210b1de83 F ext/rbu/rbusave.test 0f43b6686084f426ddd040b878426452fd2c2f48 F ext/rbu/rbuvacuum.test 4a977447c15c2581ab668781d9ef4294382530e0 F ext/rbu/rbuvacuum2.test 2074ab14fe66e1c7e7210c62562650dcd215bbaa -F ext/rbu/sqlite3rbu.c bb0de6cdbdb14a7d55a097238a434b7e99caf318 +F ext/rbu/sqlite3rbu.c 3c2dfd3f27a3ecc5f017ecf82d563b522bbc341a F ext/rbu/sqlite3rbu.h 6fb6294c34a9ca93b5894a33bca530c6f08decba F ext/rbu/test_rbu.c 5aa22616afac6f71ebd3d9bc9bf1006cfabcca88 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 @@ -411,7 +412,7 @@ F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5 F src/test3.c d03f5b5da9a2410b7a91c64b0d3306ed28ab6fee F src/test4.c 18ec393bb4d0ad1de729f0b94da7267270f3d8e6 F src/test5.c 328aae2c010c57a9829d255dc099d6899311672d -F src/test6.c 121060d2e79a4f5047eb12b5135b23a6a7a5af01 +F src/test6.c 004ad42f121f693b8cbe060d1a330678abc61620 F src/test7.c 5612e9aecf934d6df7bba6ce861fdf5ba5456010 F src/test8.c 4f4904721167b32f7a4fa8c7b32a07a673d6cc86 F src/test9.c 12e5ba554d2d1cbe0158f6ab3f7ffcd7a86ee4e5 @@ -1173,7 +1174,7 @@ F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 F test/temptable2.test cd396beb41117a5302fff61767c35fa4270a0d5e F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc -F test/tester.tcl 67835ac17e90055f24a9cf52e5c5bce0dd511c74 +F test/tester.tcl 581f0185434daf7026ccede4c07e8d1479186ec5 F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5 F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -1559,7 +1560,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ac760db0727209db0a816e112ea5f47e54d54dac -R be25bb329cc9311f7d92b42176424b6a -U drh -Z eb983447910676b385a2c6496a637326 +P 29f54b899e5cf22ece98ab41c39c41d75a4b228d +R fd6b0917cff6359266006d6c00dd0a12 +U dan +Z 1a59570e49a3b7cf84dd8025330375c8 diff --git a/manifest.uuid b/manifest.uuid index 9f406e4ffa..f24ae9a62a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -29f54b899e5cf22ece98ab41c39c41d75a4b228d \ No newline at end of file +edee6a80e1cc7e6a2b8c3c7f76dd794fc8ab9a72 \ No newline at end of file diff --git a/src/test6.c b/src/test6.c index a103b9619e..849cdeb3b9 100644 --- a/src/test6.c +++ b/src/test6.c @@ -315,8 +315,9 @@ static int writeListSync(CrashFile *pFile, int isCrash){ assert(pWrite->zBuf); #ifdef TRACE_CRASHTEST - printf("Trashing %d sectors @ %lld (sector %d) (%s)\n", - 1+iLast-iFirst, pWrite->iOffset, iFirst, pWrite->pFile->zName + printf("Trashing %d sectors (%d bytes) @ %lld (sector %d) (%s)\n", + 1+iLast-iFirst, (1+iLast-iFirst)*g.iSectorSize, + pWrite->iOffset, iFirst, pWrite->pFile->zName ); #endif @@ -827,7 +828,7 @@ static int SQLITE_TCLAPI crashNowCmd( } /* -** tclcmd: sqlite_crash_enable ENABLE +** tclcmd: sqlite_crash_enable ENABLE ?DEFAULT? ** ** Parameter ENABLE must be a boolean value. If true, then the "crash" ** vfs is added to the system. If false, it is removed. @@ -839,6 +840,7 @@ static int SQLITE_TCLAPI crashEnableCmd( Tcl_Obj *CONST objv[] ){ int isEnable; + int isDefault = 0; static sqlite3_vfs crashVfs = { 2, /* iVersion */ 0, /* szOsFile */ @@ -862,14 +864,17 @@ static int SQLITE_TCLAPI crashEnableCmd( 0, /* xCurrentTimeInt64 */ }; - if( objc!=2 ){ - Tcl_WrongNumArgs(interp, 1, objv, "ENABLE"); + if( objc!=2 && objc!=3 ){ + Tcl_WrongNumArgs(interp, 1, objv, "ENABLE ?DEFAULT?"); return TCL_ERROR; } if( Tcl_GetBooleanFromObj(interp, objv[1], &isEnable) ){ return TCL_ERROR; } + if( objc==3 && Tcl_GetBooleanFromObj(interp, objv[2], &isDefault) ){ + return TCL_ERROR; + } if( (isEnable && crashVfs.pAppData) || (!isEnable && !crashVfs.pAppData) ){ return TCL_OK; @@ -880,7 +885,7 @@ static int SQLITE_TCLAPI crashEnableCmd( crashVfs.mxPathname = pOriginalVfs->mxPathname; crashVfs.pAppData = (void *)pOriginalVfs; crashVfs.szOsFile = sizeof(CrashFile) + pOriginalVfs->szOsFile; - sqlite3_vfs_register(&crashVfs, 0); + sqlite3_vfs_register(&crashVfs, isDefault); }else{ crashVfs.pAppData = 0; sqlite3_vfs_unregister(&crashVfs); diff --git a/test/tester.tcl b/test/tester.tcl index 1da89fec26..dc6547d033 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -1533,6 +1533,7 @@ proc crashsql {args} { set tclbody {} set crashfile "" set dc "" + set dfltvfs 0 set sql [lindex $args end] for {set ii 0} {$ii < [llength $args]-1} {incr ii 2} { @@ -1546,7 +1547,8 @@ proc crashsql {args} { elseif {$n>1 && [string first $z -file]==0} {set crashfile $z2} \ elseif {$n>1 && [string first $z -tclbody]==0} {set tclbody $z2} \ elseif {$n>1 && [string first $z -blocksize]==0} {set blocksize "-s $z2" } \ - elseif {$n>1 && [string first $z -characteristics]==0} {set dc "-c {$z2}" } \ + elseif {$n>1 && [string first $z -characteristics]==0} {set dc "-c {$z2}" }\ + elseif {$n>1 && [string first $z -dfltvfs]==0} {set dfltvfs $z2 }\ else { error "Unrecognized option: $z" } } @@ -1560,7 +1562,7 @@ proc crashsql {args} { set cfile [string map {\\ \\\\} [file nativename [file join [get_pwd] $crashfile]]] set f [open crash.tcl w] - puts $f "sqlite3_crash_enable 1" + puts $f "sqlite3_crash_enable 1 $dfltvfs" puts $f "sqlite3_crashparams $blocksize $dc $crashdelay $cfile" puts $f "sqlite3_test_control_pending_byte $::sqlite_pending_byte" From 1d62a66230ddf0320d918283141b32bb8a3926ff Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 2 Mar 2017 16:56:48 +0000 Subject: [PATCH 2/8] Fix another RBU case similar to the previous. This one for systems where the sector-size is larger than the page-size. FossilOrigin-Name: 4012bb3aa91927156ba149caa4e5c622b0729d79 --- ext/rbu/rbucrash2.test | 11 ++++++++--- ext/rbu/rbuprogress.test | 2 ++ ext/rbu/sqlite3rbu.c | 34 +++++++++++++++++++++++++++++++--- manifest | 16 ++++++++-------- manifest.uuid | 2 +- 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/ext/rbu/rbucrash2.test b/ext/rbu/rbucrash2.test index 89c2535a93..5f2ba604d1 100644 --- a/ext/rbu/rbucrash2.test +++ b/ext/rbu/rbucrash2.test @@ -45,7 +45,12 @@ db_save_and_close proc do_rbu_crash_test2 {tn script} { - foreach f {test.db test.db2} { + foreach {f blksz} { + test.db 512 + test.db2 512 + test.db 4096 + test.db2 4096 + } { set bDone 0 for {set iDelay 1} {$bDone==0} {incr iDelay} { forcedelete test.db2 test.db2-journal test.db test.db-oal test.db-wal @@ -53,7 +58,7 @@ proc do_rbu_crash_test2 {tn script} { set res [ crashsql -file $f -delay $iDelay -tclbody $script -dflt 1 -opendb {} \ - -blocksize 512 {} + -blocksize $blksz {} ] set bDone 1 @@ -68,7 +73,7 @@ proc do_rbu_crash_test2 {tn script} { rbu close sqlite3 db test.db - do_execsql_test $tn.delay=$iDelay.f=$f { + do_execsql_test $tn.delay=$iDelay.f=$f.blksz=$blksz { PRAGMA integrity_check; } {ok} db close diff --git a/ext/rbu/rbuprogress.test b/ext/rbu/rbuprogress.test index af202829c1..078b3b0d30 100644 --- a/ext/rbu/rbuprogress.test +++ b/ext/rbu/rbuprogress.test @@ -40,6 +40,7 @@ proc create_rbu1 {filename} { do_execsql_test 1.0 { + PRAGMA page_size = 4096; CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); } @@ -266,6 +267,7 @@ foreach bReopen {0 1} { do_test 3.$bReopen.1.0 { reset_db execsql { + PRAGMA page_size = 4096; CREATE TABLE t1(a INTEGER PRIMARY KEY, b); CREATE TABLE t2(a INTEGER PRIMARY KEY, b); CREATE TABLE t3(a INTEGER PRIMARY KEY, b); diff --git a/ext/rbu/sqlite3rbu.c b/ext/rbu/sqlite3rbu.c index 262f96ea3c..163a544259 100644 --- a/ext/rbu/sqlite3rbu.c +++ b/ext/rbu/sqlite3rbu.c @@ -356,6 +356,7 @@ struct sqlite3rbu { RbuObjIter objiter; /* Iterator for skipping through tbl/idx */ const char *zVfsName; /* Name of automatically created rbu vfs */ rbu_file *pTargetFd; /* File handle open on target db */ + int nPagePerSector; /* Pages per sector for pTargetFd */ i64 iOalSz; i64 nPhaseOneStep; @@ -2620,6 +2621,16 @@ static void rbuSetupCheckpoint(sqlite3rbu *p, RbuState *pState){ if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){ p->rc = SQLITE_DONE; p->eStage = RBU_STAGE_DONE; + }else{ + int nSectorSize; + sqlite3_file *pDb = p->pTargetFd->pReal; + assert( p->nPagePerSector==0 ); + nSectorSize = pDb->pMethods->xSectorSize(pDb); + if( nSectorSize>p->pgsz ){ + p->nPagePerSector = nSectorSize / p->pgsz; + }else{ + p->nPagePerSector = 1; + } } } } @@ -3275,9 +3286,26 @@ int sqlite3rbu_step(sqlite3rbu *p){ p->rc = SQLITE_DONE; } }else{ - RbuFrame *pFrame = &p->aFrame[p->nStep]; - rbuCheckpointFrame(p, pFrame); - p->nStep++; + /* At one point the following block copied a single frame from the + ** wal file to the database file. So that one call to sqlite3rbu_step() + ** checkpointed a single frame. + ** + ** However, if the sector-size is larger than the page-size, and the + ** application calls sqlite3rbu_savestate() or close() immediately + ** after this step, then rbu_step() again, then a power failure occurs, + ** then the database page written here may be damaged. Work around + ** this by checkpointing frames until the next page in the aFrame[] + ** lies on a different disk sector to the current one. */ + u32 iSector; + do{ + RbuFrame *pFrame = &p->aFrame[p->nStep]; + iSector = (pFrame->iDbPage-1) / p->nPagePerSector; + rbuCheckpointFrame(p, pFrame); + p->nStep++; + }while( p->nStepnFrame + && iSector==((p->aFrame[p->nStep].iDbPage-1) / p->nPagePerSector) + && p->rc==SQLITE_OK + ); } p->nProgress++; } diff --git a/manifest b/manifest index 4ab87a35ed..ff786aa1dc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\ssaving\sthe\sstate\sof\san\sRBU\supdate\sin\sthe\sincremental-checkpoint\sphase,\nsync\sthe\sdatabase\sfile.\sOtherwise,\sif\sa\spower\sfailure\soccurs\sand\sthe\sRBU\nupdate\sresumed\sfollowing\ssystem\srecovery,\sthe\sdatabase\smay\sbecome\scorrupt. -D 2017-03-02T14:51:47.379 +C Fix\sanother\sRBU\scase\ssimilar\sto\sthe\sprevious.\sThis\sone\sfor\ssystems\swhere\sthe\nsector-size\sis\slarger\sthan\sthe\spage-size. +D 2017-03-02T16:56:48.085 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -250,7 +250,7 @@ F ext/rbu/rbuB.test c25bc325b8072a766e56bb76c001866b405925c2 F ext/rbu/rbuC.test efe47db508a0269b683cb2a1913a425ffd39a831 F ext/rbu/rbu_common.tcl a38e8e2d4a50fd6aaf151633714c1b1d2fae3ead F ext/rbu/rbucrash.test 8d2ed5d4b05fef6c00c2a6b5f7ead71fa172a695 -F ext/rbu/rbucrash2.test 7f3fe5d6d930be0965f27b49bdcdc8d4a078b73c +F ext/rbu/rbucrash2.test b2ecbdd7bb72c88bd217c65bd00dafa07f7f2d4d F ext/rbu/rbudiff.test 3e605cf624d00d04d0fb1316a3acec4fbe3b3ac5 F ext/rbu/rbudor.test 99b05cc0df613e962c2c8085cfb05686a09cf315 F ext/rbu/rbufault.test cc0be8d5d392d98b0c2d6a51be377ea989250a89 @@ -258,12 +258,12 @@ F ext/rbu/rbufault2.test 9a7f19edd6ea35c4c9f807d8a3db0a03a5670c06 F ext/rbu/rbufault3.test 54a399888ac4af44c68f9f58afbed23149428bca F ext/rbu/rbufault4.test 34e70701cbec51571ffbd9fbf9d4e0f2ec495ca7 F ext/rbu/rbufts.test 828cd689da825f0a7b7c53ffc1f6f7fdb6fa5bda -F ext/rbu/rbuprogress.test e3e25fb7622641b8f2df7c6b7a7eb6fddfc46a4b +F ext/rbu/rbuprogress.test 1849d4e0e50616edf5ce75ce7db86622e656b5cf F ext/rbu/rburesume.test 8acb77f4a422ff55acfcfc9cc15a5cb210b1de83 F ext/rbu/rbusave.test 0f43b6686084f426ddd040b878426452fd2c2f48 F ext/rbu/rbuvacuum.test 4a977447c15c2581ab668781d9ef4294382530e0 F ext/rbu/rbuvacuum2.test 2074ab14fe66e1c7e7210c62562650dcd215bbaa -F ext/rbu/sqlite3rbu.c 3c2dfd3f27a3ecc5f017ecf82d563b522bbc341a +F ext/rbu/sqlite3rbu.c cba23db39792175295b94ad0086825894b617921 F ext/rbu/sqlite3rbu.h 6fb6294c34a9ca93b5894a33bca530c6f08decba F ext/rbu/test_rbu.c 5aa22616afac6f71ebd3d9bc9bf1006cfabcca88 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 @@ -1560,7 +1560,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 29f54b899e5cf22ece98ab41c39c41d75a4b228d -R fd6b0917cff6359266006d6c00dd0a12 +P edee6a80e1cc7e6a2b8c3c7f76dd794fc8ab9a72 +R f72d0ed562c179232e2d4d139b6c6946 U dan -Z 1a59570e49a3b7cf84dd8025330375c8 +Z a85a6fd6f15328765626feb0d9a72fd7 diff --git a/manifest.uuid b/manifest.uuid index f24ae9a62a..b44fc2cacb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -edee6a80e1cc7e6a2b8c3c7f76dd794fc8ab9a72 \ No newline at end of file +4012bb3aa91927156ba149caa4e5c622b0729d79 \ No newline at end of file From 9715f7f033887a2c4ec09592e3668d5fc0d737bd Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 2 Mar 2017 23:40:21 +0000 Subject: [PATCH 3/8] Fix a bug in the 'start of ...' date/time modifiers when they follow a julian day number. Fix for ticket [6097cb92745327a1]. FossilOrigin-Name: 081dbcfb6d82528cefecb36c4491fa6e1a790b17 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/date.c | 1 + test/date.test | 10 ++++++++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index ff786aa1dc..8ace7675fd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sanother\sRBU\scase\ssimilar\sto\sthe\sprevious.\sThis\sone\sfor\ssystems\swhere\sthe\nsector-size\sis\slarger\sthan\sthe\spage-size. -D 2017-03-02T16:56:48.085 +C Fix\sa\sbug\sin\sthe\s'start\sof\s...'\sdate/time\smodifiers\swhen\sthey\sfollow\sa\njulian\sday\snumber.\s\sFix\sfor\sticket\s[6097cb92745327a1]. +D 2017-03-02T23:40:21.740 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -347,7 +347,7 @@ F src/build.c 51b473eec465f471d607b54e8dbc00751c3f8a1f F src/callback.c 2e76147783386374bf01b227f752c81ec872d730 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c a9984df73898c042a5cfc8f9d8e7723d02bc35c9 -F src/date.c dc3f1391d9297f8c748132813aaffcb117090d6e +F src/date.c bb4db348be17903f4bbf2ef3cb208add874deab9 F src/dbstat.c 19ee7a4e89979d4df8e44cfac7a8f905ec89b77d F src/delete.c 0d9d5549d42e79ce4d82ff1db1e6c81e36d2f67c F src/expr.c 8a29e9b72d4b642189999c41782cd6c5bc43512f @@ -637,7 +637,7 @@ F test/csv01.test e0ba3caaa57e4c667a0b45977689fb8082f14348 F test/ctime.test ff6c38e822459d6ca743c34901caf57740b08b54 F test/cursorhint.test 7bc346788390475e77a345da2b92270d04d35856 F test/cursorhint2.test 8457e93d97f665f23f97cdbc8477d16e3480331b -F test/date.test a6a5a48b90907bca9fbcc79a30be5a715c1ab2fc +F test/date.test e6da60d8ec399de43c076425fbe2eecbc90a31a4 F test/dbfuzz.c 73047c920d6210e5912c87cdffd9a1c281d4252e F test/dbselftest.c b2e6cfac59066dbcb7334b66304bb15a5508dd42 F test/dbstatus.test 73149851b3aff14fc6db478e58f9083a66422cf5 @@ -1560,7 +1560,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P edee6a80e1cc7e6a2b8c3c7f76dd794fc8ab9a72 -R f72d0ed562c179232e2d4d139b6c6946 -U dan -Z a85a6fd6f15328765626feb0d9a72fd7 +P 4012bb3aa91927156ba149caa4e5c622b0729d79 +R 106d75876c31ad808988639b89376fd6 +U drh +Z d7eafab06f2b8ece511ab9317c8fe2f8 diff --git a/manifest.uuid b/manifest.uuid index b44fc2cacb..9e61a74210 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4012bb3aa91927156ba149caa4e5c622b0729d79 \ No newline at end of file +081dbcfb6d82528cefecb36c4491fa6e1a790b17 \ No newline at end of file diff --git a/src/date.c b/src/date.c index a08248ce2f..6fc66385c5 100644 --- a/src/date.c +++ b/src/date.c @@ -748,6 +748,7 @@ static int parseModifier( p->validHMS = 1; p->h = p->m = 0; p->s = 0.0; + p->rawS = 0; p->validTZ = 0; p->validJD = 0; if( sqlite3_stricmp(z,"month")==0 ){ diff --git a/test/date.test b/test/date.test index 2d336e6c00..a9694f18ca 100644 --- a/test/date.test +++ b/test/date.test @@ -596,5 +596,15 @@ datetest 16.29 {datetime(5373484,'-176546 months')} NULL datetest 16.30 {datetime(5373484,'-14712 years')} {-4713-12-31 12:00:00} datetest 16.31 {datetime(5373484,'-14713 years')} NULL +# 2017-03-02: Wrong 'start of day' computation. +# https://www.sqlite.org/src/info/6097cb92745327a1 +# +datetest 17.1 {datetime(2457754, 'start of day')} {2016-12-31 00:00:00} +datetest 17.2 {datetime(2457828)} {2017-03-15 12:00:00} +datetest 17.3 {datetime(2457828,'start of day')} {2017-03-15 00:00:00} +datetest 17.4 {datetime(2457828,'start of month')} {2017-03-01 00:00:00} +datetest 17.5 {datetime(2457828,'start of year')} {2017-01-01 00:00:00} + + finish_test From 0e9b43ff853afe97b416e4bd3866f0d27ea985d8 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 3 Mar 2017 16:51:46 +0000 Subject: [PATCH 4/8] Before beginning an incremental checkpoint in RBU, sync the directory containing the target database file. This ensures that the new directory entry created by renaming the *-oal file to *-wal is synced to disk. FossilOrigin-Name: 915a9a28783fbb2f4c0794eb4264ce8c0b9d42f7 --- ext/rbu/sqlite3rbu.c | 7 +++++++ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ext/rbu/sqlite3rbu.c b/ext/rbu/sqlite3rbu.c index 163a544259..7dd232b4b5 100644 --- a/ext/rbu/sqlite3rbu.c +++ b/ext/rbu/sqlite3rbu.c @@ -2624,6 +2624,7 @@ static void rbuSetupCheckpoint(sqlite3rbu *p, RbuState *pState){ }else{ int nSectorSize; sqlite3_file *pDb = p->pTargetFd->pReal; + sqlite3_file *pWal = p->pTargetFd->pWalFd->pReal; assert( p->nPagePerSector==0 ); nSectorSize = pDb->pMethods->xSectorSize(pDb); if( nSectorSize>p->pgsz ){ @@ -2631,6 +2632,12 @@ static void rbuSetupCheckpoint(sqlite3rbu *p, RbuState *pState){ }else{ p->nPagePerSector = 1; } + + /* Call xSync() on the wal file. This causes SQLite to sync the + ** directory in which the target database and the wal file reside, in + ** case it has not been synced since the rename() call in + ** rbuMoveOalFile(). */ + p->rc = pWal->pMethods->xSync(pWal, SQLITE_SYNC_NORMAL); } } } diff --git a/manifest b/manifest index 8ace7675fd..b06ed90284 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sbug\sin\sthe\s'start\sof\s...'\sdate/time\smodifiers\swhen\sthey\sfollow\sa\njulian\sday\snumber.\s\sFix\sfor\sticket\s[6097cb92745327a1]. -D 2017-03-02T23:40:21.740 +C Before\sbeginning\san\sincremental\scheckpoint\sin\sRBU,\ssync\sthe\sdirectory\ncontaining\sthe\starget\sdatabase\sfile.\sThis\sensures\sthat\sthe\snew\sdirectory\sentry\ncreated\sby\srenaming\sthe\s*-oal\sfile\sto\s*-wal\sis\ssynced\sto\sdisk. +D 2017-03-03T16:51:46.903 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -263,7 +263,7 @@ F ext/rbu/rburesume.test 8acb77f4a422ff55acfcfc9cc15a5cb210b1de83 F ext/rbu/rbusave.test 0f43b6686084f426ddd040b878426452fd2c2f48 F ext/rbu/rbuvacuum.test 4a977447c15c2581ab668781d9ef4294382530e0 F ext/rbu/rbuvacuum2.test 2074ab14fe66e1c7e7210c62562650dcd215bbaa -F ext/rbu/sqlite3rbu.c cba23db39792175295b94ad0086825894b617921 +F ext/rbu/sqlite3rbu.c 2a89efba9eeba8e6c89a498dc195e8efbdde2694 F ext/rbu/sqlite3rbu.h 6fb6294c34a9ca93b5894a33bca530c6f08decba F ext/rbu/test_rbu.c 5aa22616afac6f71ebd3d9bc9bf1006cfabcca88 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 @@ -1560,7 +1560,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4012bb3aa91927156ba149caa4e5c622b0729d79 -R 106d75876c31ad808988639b89376fd6 -U drh -Z d7eafab06f2b8ece511ab9317c8fe2f8 +P 081dbcfb6d82528cefecb36c4491fa6e1a790b17 +R c49d10bdecee819ceb83b85a5e3f8244 +U dan +Z 0d48f0e17be43a572b386c16c35f7b42 diff --git a/manifest.uuid b/manifest.uuid index 9e61a74210..91442ae413 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -081dbcfb6d82528cefecb36c4491fa6e1a790b17 \ No newline at end of file +915a9a28783fbb2f4c0794eb4264ce8c0b9d42f7 \ No newline at end of file From 30741eb0d3fb13221aab418d6c8c8922308be290 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 3 Mar 2017 20:02:53 +0000 Subject: [PATCH 5/8] Fix a case introduced by [4cd2a967] where a corrupt database could cause a buffer overwrite. FossilOrigin-Name: 5d0455fece514552ad7f283d56526f53d7c688bd --- manifest | 13 +++--- manifest.uuid | 2 +- src/btree.c | 17 ++++++- test/corruptK.test | 113 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 9 deletions(-) create mode 100644 test/corruptK.test diff --git a/manifest b/manifest index b06ed90284..05070243d5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Before\sbeginning\san\sincremental\scheckpoint\sin\sRBU,\ssync\sthe\sdirectory\ncontaining\sthe\starget\sdatabase\sfile.\sThis\sensures\sthat\sthe\snew\sdirectory\sentry\ncreated\sby\srenaming\sthe\s*-oal\sfile\sto\s*-wal\sis\ssynced\sto\sdisk. -D 2017-03-03T16:51:46.903 +C Fix\sa\scase\sintroduced\sby\s[4cd2a967]\swhere\sa\scorrupt\sdatabase\scould\scause\sa\sbuffer\soverwrite. +D 2017-03-03T20:02:53.439 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -340,7 +340,7 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca -F src/btree.c 03149b0f3fec3c1aa3c50a17e997bb442b867632 +F src/btree.c 91baade79832becb44d85cd7c39b5ebe170666d8 F src/btree.h e6d352808956ec163a17f832193a3e198b3fb0ac F src/btreeInt.h cd55d39d9916270837a88c12e701047cba0729b0 F src/build.c 51b473eec465f471d607b54e8dbc00751c3f8a1f @@ -618,6 +618,7 @@ F test/corruptG.test adf79b669cbfd19e28c8191a610d083ae53a6d51 F test/corruptH.test 79801d97ec5c2f9f3c87739aa1ec2eb786f96454 F test/corruptI.test 075fe1d75aa1d84e2949be56b6264376c41502e4 F test/corruptJ.test 4d5ccc4bf959464229a836d60142831ef76a5aa4 +F test/corruptK.test 814a59ec699d8546b4e29005fba3d16e933ef2fe F test/cost.test 1eedbfd868f806f3fa08ff072b04cf270dcf61c8 F test/count.test cb2e0f934c6eb33670044520748d2ecccd46259c F test/coveridxscan.test b629e896b14df2f000a99b8d170d80589c46562c @@ -1560,7 +1561,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 081dbcfb6d82528cefecb36c4491fa6e1a790b17 -R c49d10bdecee819ceb83b85a5e3f8244 +P 915a9a28783fbb2f4c0794eb4264ce8c0b9d42f7 +R 87fee79fc77f11db6d08a83e962c36d1 U dan -Z 0d48f0e17be43a572b386c16c35f7b42 +Z d96b298a9dab6e01e07206495b42117b diff --git a/manifest.uuid b/manifest.uuid index 91442ae413..a7791d4715 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -915a9a28783fbb2f4c0794eb4264ce8c0b9d42f7 \ No newline at end of file +5d0455fece514552ad7f283d56526f53d7c688bd \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index bf65852fe6..e942dbce03 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1355,6 +1355,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ nCell = pPage->nCell; assert( nCell==get2byte(&data[hdr+3]) ); iCellFirst = cellOffset + 2*nCell; + usableSize = pPage->pBt->usableSize; /* This block handles pages with two or fewer free blocks and nMaxFrag ** or fewer fragmented bytes. In this case it is faster to move the @@ -1365,6 +1366,17 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ int iFree = get2byte(&data[hdr+1]); if( iFree ){ int iFree2 = get2byte(&data[iFree]); + + /* pageFindSlot() has already verified that free blocks are sorted + ** in order of offset within the page, and that no block extends + ** past the end of the page. Provided the two free slots do not + ** overlap, this guarantees that the memmove() calls below will not + ** overwrite the usableSize byte buffer, even if the database page + ** is corrupt. */ + assert( iFree2==0 || iFree2>iFree ); + assert( iFree+get2byte(&data[iFree+2]) <= usableSize ); + assert( iFree2==0 || iFree2+get2byte(&data[iFree2+2]) <= usableSize ); + if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){ u8 *pEnd = &data[cellOffset + nCell*2]; u8 *pAddr; @@ -1372,11 +1384,14 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ int sz = get2byte(&data[iFree+2]); int top = get2byte(&data[hdr+5]); if( iFree2 ){ + if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_BKPT; sz2 = get2byte(&data[iFree2+2]); + assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize ); memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz)); sz += sz2; } cbrk = top+sz; + assert( cbrk+(iFree-top) <= usableSize ); memmove(&data[cbrk], &data[top], iFree-top); for(pAddr=&data[cellOffset]; pAddrpBt->usableSize; cbrk = usableSize; iCellLast = usableSize - 4; - for(i=0; i Date: Fri, 3 Mar 2017 20:43:43 +0000 Subject: [PATCH 6/8] Fix another corner-case for the 'start of ...' modifier in the date/time functions. Related to ticket [6097cb92745327a1]. FossilOrigin-Name: 8831f4393dda42b3434e7767968caea84bbca2af --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/date.c | 1 + test/date.test | 2 ++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 05070243d5..30c7196c3f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scase\sintroduced\sby\s[4cd2a967]\swhere\sa\scorrupt\sdatabase\scould\scause\sa\sbuffer\soverwrite. -D 2017-03-03T20:02:53.439 +C Fix\sanother\scorner-case\sfor\sthe\s'start\sof\s...'\smodifier\sin\sthe\sdate/time\nfunctions.\s\sRelated\sto\sticket\s[6097cb92745327a1]. +D 2017-03-03T20:43:43.649 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -347,7 +347,7 @@ F src/build.c 51b473eec465f471d607b54e8dbc00751c3f8a1f F src/callback.c 2e76147783386374bf01b227f752c81ec872d730 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c a9984df73898c042a5cfc8f9d8e7723d02bc35c9 -F src/date.c bb4db348be17903f4bbf2ef3cb208add874deab9 +F src/date.c 499343d9cd97fb0c13ec299dbd1ff3d787b1cdac F src/dbstat.c 19ee7a4e89979d4df8e44cfac7a8f905ec89b77d F src/delete.c 0d9d5549d42e79ce4d82ff1db1e6c81e36d2f67c F src/expr.c 8a29e9b72d4b642189999c41782cd6c5bc43512f @@ -638,7 +638,7 @@ F test/csv01.test e0ba3caaa57e4c667a0b45977689fb8082f14348 F test/ctime.test ff6c38e822459d6ca743c34901caf57740b08b54 F test/cursorhint.test 7bc346788390475e77a345da2b92270d04d35856 F test/cursorhint2.test 8457e93d97f665f23f97cdbc8477d16e3480331b -F test/date.test e6da60d8ec399de43c076425fbe2eecbc90a31a4 +F test/date.test 9b73bbeb1b82d9c1f44dec5cf563bf7da58d2373 F test/dbfuzz.c 73047c920d6210e5912c87cdffd9a1c281d4252e F test/dbselftest.c b2e6cfac59066dbcb7334b66304bb15a5508dd42 F test/dbstatus.test 73149851b3aff14fc6db478e58f9083a66422cf5 @@ -1561,7 +1561,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 915a9a28783fbb2f4c0794eb4264ce8c0b9d42f7 -R 87fee79fc77f11db6d08a83e962c36d1 -U dan -Z d96b298a9dab6e01e07206495b42117b +P 5d0455fece514552ad7f283d56526f53d7c688bd +R 7ede60c220c81f4f24b446e38f3b85e3 +U drh +Z 2f7d593b5303445a6b7dc1a2027118f1 diff --git a/manifest.uuid b/manifest.uuid index a7791d4715..74049a1b57 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d0455fece514552ad7f283d56526f53d7c688bd \ No newline at end of file +8831f4393dda42b3434e7767968caea84bbca2af \ No newline at end of file diff --git a/src/date.c b/src/date.c index 6fc66385c5..c3ce4248c2 100644 --- a/src/date.c +++ b/src/date.c @@ -743,6 +743,7 @@ static int parseModifier( ** or month or year. */ if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break; + if( !p->validJD && !p->validYMD && !p->validHMS ) break; z += 9; computeYMD(p); p->validHMS = 1; diff --git a/test/date.test b/test/date.test index a9694f18ca..f002334d17 100644 --- a/test/date.test +++ b/test/date.test @@ -604,6 +604,8 @@ datetest 17.2 {datetime(2457828)} {2017-03-15 12:00:00} datetest 17.3 {datetime(2457828,'start of day')} {2017-03-15 00:00:00} datetest 17.4 {datetime(2457828,'start of month')} {2017-03-01 00:00:00} datetest 17.5 {datetime(2457828,'start of year')} {2017-01-01 00:00:00} +datetest 17.6 {datetime(37,'start of year')} NULL +datetest 17.7 {datetime(38,'start of year')} {-4712-01-01 00:00:00} From f3f883fcd735b65bdf5f29790512276e5d7746ba Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 3 Mar 2017 21:36:26 +0000 Subject: [PATCH 7/8] Remove an redundant function call from the date/time function implementation. FossilOrigin-Name: 4a04c48a311b19ba5e566877dc5baff543c41aba --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/date.c | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 30c7196c3f..7865de9c71 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sanother\scorner-case\sfor\sthe\s'start\sof\s...'\smodifier\sin\sthe\sdate/time\nfunctions.\s\sRelated\sto\sticket\s[6097cb92745327a1]. -D 2017-03-03T20:43:43.649 +C Remove\san\sredundant\sfunction\scall\sfrom\sthe\sdate/time\sfunction\simplementation. +D 2017-03-03T21:36:26.906 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -347,7 +347,7 @@ F src/build.c 51b473eec465f471d607b54e8dbc00751c3f8a1f F src/callback.c 2e76147783386374bf01b227f752c81ec872d730 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c a9984df73898c042a5cfc8f9d8e7723d02bc35c9 -F src/date.c 499343d9cd97fb0c13ec299dbd1ff3d787b1cdac +F src/date.c ee676e7694dfadbdd2fde1a258a71be8360ba5ae F src/dbstat.c 19ee7a4e89979d4df8e44cfac7a8f905ec89b77d F src/delete.c 0d9d5549d42e79ce4d82ff1db1e6c81e36d2f67c F src/expr.c 8a29e9b72d4b642189999c41782cd6c5bc43512f @@ -1561,7 +1561,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5d0455fece514552ad7f283d56526f53d7c688bd -R 7ede60c220c81f4f24b446e38f3b85e3 +P 8831f4393dda42b3434e7767968caea84bbca2af +R d8b3a18d4fd999381a3209784f6b834e U drh -Z 2f7d593b5303445a6b7dc1a2027118f1 +Z 55613e922149954b91d38c0de9685f66 diff --git a/manifest.uuid b/manifest.uuid index 74049a1b57..637cd06ca0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8831f4393dda42b3434e7767968caea84bbca2af \ No newline at end of file +4a04c48a311b19ba5e566877dc5baff543c41aba \ No newline at end of file diff --git a/src/date.c b/src/date.c index c3ce4248c2..b49d506bc4 100644 --- a/src/date.c +++ b/src/date.c @@ -756,7 +756,6 @@ static int parseModifier( p->D = 1; rc = 0; }else if( sqlite3_stricmp(z,"year")==0 ){ - computeYMD(p); p->M = 1; p->D = 1; rc = 0; From 2996796dcf2a01df4cacf94f3c8efd430db9a82d Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 3 Mar 2017 21:51:40 +0000 Subject: [PATCH 8/8] If a reprepare is needed after binding to a variable with a number larger than 32, set only the high-order bit of the Vdbe.expmask rather than setting all bits. This could potentially result in fewer false-positive reprepares. FossilOrigin-Name: 45797feefe90cb7da53256b0c42fdaa1221d0a27 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeapi.c | 2 +- src/vdbeaux.c | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 7865de9c71..084b50ff08 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sredundant\sfunction\scall\sfrom\sthe\sdate/time\sfunction\simplementation. -D 2017-03-03T21:36:26.906 +C If\sa\sreprepare\sis\sneeded\safter\sbinding\sto\sa\svariable\swith\sa\snumber\slarger\nthan\s32,\sset\sonly\sthe\shigh-order\sbit\sof\sthe\sVdbe.expmask\srather\sthan\ssetting\nall\sbits.\s\sThis\scould\spotentially\sresult\sin\sfewer\sfalse-positive\sreprepares. +D 2017-03-03T21:51:40.099 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2 @@ -467,8 +467,8 @@ F src/vacuum.c 1fe4555cd8c9b263afb85b5b4ee3a4a4181ad569 F src/vdbe.c 83f387d9e6842b1dc99f6e85bb577c5bbc4e397d F src/vdbe.h 59998ffd71d7caa8886bc78dafaf8caeccd4c13c F src/vdbeInt.h 4e4b15b2e1330e1636e4e01974eab2b0b985092f -F src/vdbeapi.c 70aabe108c411e529a59d8800445513965334062 -F src/vdbeaux.c b632f9151a296c5eb22a2cc955c487ebc2347cb6 +F src/vdbeapi.c 5b08d82592bcff4470601fe78aaabebd50837860 +F src/vdbeaux.c 57361f2e761d92a254638bdbfc03fc68ae6aebc6 F src/vdbeblob.c 359891617358deefc85bef7bcf787fa6b77facb9 F src/vdbemem.c 3b5a9a5b375458d3e12a50ae1aaa41eeec2175fd F src/vdbesort.c eda25cb2d1727efca6f7862fea32b8aa33c0face @@ -1561,7 +1561,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8831f4393dda42b3434e7767968caea84bbca2af -R d8b3a18d4fd999381a3209784f6b834e +P 4a04c48a311b19ba5e566877dc5baff543c41aba +R 637ce5713001d3d9ffad62c9c4caff88 U drh -Z 55613e922149954b91d38c0de9685f66 +Z 435b5c3ba7edfd2dba5c4b61417da7dd diff --git a/manifest.uuid b/manifest.uuid index 637cd06ca0..9ee7804d61 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4a04c48a311b19ba5e566877dc5baff543c41aba \ No newline at end of file +45797feefe90cb7da53256b0c42fdaa1221d0a27 \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 3d9bcca99f..1f2699dc4d 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -1260,7 +1260,7 @@ static int vdbeUnbind(Vdbe *p, int i){ ** following any change to the bindings of that parameter. */ assert( p->isPrepareV2 || p->expmask==0 ); - if( p->expmask & ((u32)1 << (i&0x001F)) && (i<32 || p->expmask==0xffffffff) ){ + if( p->expmask!=0 && (p->expmask & (i>=31 ? 0x80000000 : (u32)1<expired = 1; } return SQLITE_OK; diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 8a19c26003..ab4aad7a0f 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4552,8 +4552,8 @@ sqlite3_value *sqlite3VdbeGetBoundValue(Vdbe *v, int iVar, u8 aff){ */ void sqlite3VdbeSetVarmask(Vdbe *v, int iVar){ assert( iVar>0 ); - if( iVar>32 ){ - v->expmask = 0xffffffff; + if( iVar>=32 ){ + v->expmask |= 0x80000000; }else{ v->expmask |= ((u32)1 << (iVar-1)); }