From eea627da9e35aec681f8f7c54e933668a5f238bc Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 18 Mar 2016 20:12:28 +0000 Subject: [PATCH] Add further tests for sqlite3rbu_bp_progress(). Fix a problem in handling WITHOUT ROWID tables in the same. FossilOrigin-Name: 65e02368e2b6cec349ea71af5a456d6783b0d15e --- ext/rbu/rbuprogress.test | 117 ++++++++++++++++++++++++++++++++++++++- ext/rbu/sqlite3rbu.c | 13 ++++- manifest | 14 ++--- manifest.uuid | 2 +- 4 files changed, 133 insertions(+), 13 deletions(-) diff --git a/ext/rbu/rbuprogress.test b/ext/rbu/rbuprogress.test index 8459bc09e0..6e6c7faf61 100644 --- a/ext/rbu/rbuprogress.test +++ b/ext/rbu/rbuprogress.test @@ -70,12 +70,13 @@ proc do_sp_test {tn bReopen target rbu reslist} { while 1 { if {$bReopen} { sqlite3rbu rbu $target $rbu } set rc [rbu step] - if {[set rc] != "SQLITE_OK"} { error "error 1" } + if {[set rc] != "SQLITE_OK"} { rbu close ; error "error 1" } lappend res [lindex [rbu bp_progress] 0] if {[lindex [set res] end]==10000} break if {$bReopen} { rbu close } } if {[set res] != [list $reslist]} { + rbu close error "1. reslist incorrect (expect=$reslist got=[set res])" } @@ -88,6 +89,7 @@ proc do_sp_test {tn bReopen target rbu reslist} { rbu step set res [rbu bp_progress] if {[set res] != [list 10000 0]} { + rbu close error "2. reslist incorrect (expect=10000 0 got=[set res])" } } @@ -95,6 +97,7 @@ proc do_sp_test {tn bReopen target rbu reslist} { rbu step set res [rbu bp_progress] if {[set res] != [list 10000 0]} { + rbu close error "3. reslist incorrect (expect=10000 0 got=[set res])" } @@ -102,12 +105,14 @@ proc do_sp_test {tn bReopen target rbu reslist} { while {[rbu step]=="SQLITE_OK"} { foreach {a b} [rbu bp_progress] {} if {[set a]!=10000 || [set b]<=0 || [set b]>10000} { + rbu close error "4. reslist incorrect (expect=10000 1..10000 got=[set a] [set b])" } } set res [rbu bp_progress] if {[set res] != [list 10000 10000]} { + rbu close error "5. reslist is incorrect (expect=10000 10000 got=[set res])" } @@ -116,7 +121,6 @@ proc do_sp_test {tn bReopen target rbu reslist} { } foreach {bReopen} { 0 1 } { - reset_db do_test 2.$bReopen.1.0 { execsql { @@ -288,5 +292,114 @@ foreach bReopen {0 1} { } +foreach {bReopen} { 0 1 } { + foreach {tn tbl} { + ipk { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c) } + wr { CREATE TABLE t1(a INT PRIMARY KEY, b, c) WITHOUT ROWID } + pk { CREATE TABLE t1(a INT PRIMARY KEY, b, c) } + } { + + foreach {tn2 rbusql r1 r3} { + 1 { + CREATE TABLE data0_t1(a, b, c, rbu_control); + INSERT INTO data0_t1 VALUES(15, 15, 15, 0); + INSERT INTO data0_t1 VALUES(20, 20, 20, 0); + CREATE TABLE rbu_count(tbl, cnt); + INSERT INTO rbu_count VALUES('data0_t1', 2); + } + {2500 5000 7500 10000} + {1666 3333 5000 6666 8333 10000} + + 2 { + CREATE TABLE data0_t1(a, b, c, rbu_control); + INSERT INTO data0_t1 VALUES(10, 10, 10, 2); + CREATE TABLE rbu_count(tbl, cnt); + INSERT INTO rbu_count VALUES('data0_t1', 1); + } + {3333 6666 10000} + {2000 4000 6000 8000 10000} + + 3 { + CREATE TABLE data0_t1(a, b, c, rbu_control); + INSERT INTO data0_t1 VALUES(7, 7, 7, 2); + INSERT INTO data0_t1 VALUES(10, 10, 10, 2); + CREATE TABLE rbu_count(tbl, cnt); + INSERT INTO rbu_count VALUES('data0_t1', 2); + } + {2500 4000 6000 8000 10000} + {1666 2500 3750 5000 6250 7500 8750 10000} + + } { + + reset_db ; execsql $tbl + do_test 4.$tn.$bReopen.$tn2.0 { + execsql { + CREATE INDEX t1c ON t1(c); + INSERT INTO t1 VALUES(1, 1, 1); + INSERT INTO t1 VALUES(5, 5, 5); + INSERT INTO t1 VALUES(10, 10, 10); + } + create_db_file rbu.db $rbusql + } {} + + set R(ipk) $r1 + set R(wr) $r1 + set R(pk) $r3 + do_sp_test 4.$tn.$bReopen.$tn2.1 $bReopen test.db rbu.db $R($tn) + } + } +} + +foreach {bReopen} { 0 1 } { + foreach {tn tbl} { + nopk { + CREATE TABLE t1(a, b, c); + CREATE INDEX t1c ON t1(c); + } + vtab { + CREATE VIRTUAL TABLE t1 USING fts5(a, b, c); + } + } { + + foreach {tn2 rbusql r1 r2} { + 1 { + CREATE TABLE data0_t1(a, b, c, rbu_rowid, rbu_control); + INSERT INTO data0_t1 VALUES(15, 15, 15, 4, 0); + INSERT INTO data0_t1 VALUES(20, 20, 20, 5, 0); + CREATE TABLE rbu_count(tbl, cnt); + INSERT INTO rbu_count VALUES('data0_t1', 2); + } + {2500 5000 7500 10000} + {5000 10000} + + 2 { + CREATE TABLE data0_t1(rbu_rowid, a, b, c, rbu_control); + INSERT INTO data0_t1 VALUES(0, 7, 7, 7, 2); + INSERT INTO data0_t1 VALUES(2, 10, 10, 10, 2); + CREATE TABLE rbu_count(tbl, cnt); + INSERT INTO rbu_count VALUES('data0_t1', 2); + } + {2500 4000 6000 8000 10000} + {5000 10000} + } { + + reset_db ; execsql $tbl + do_test 5.$tn.$bReopen.$tn2.0 { + execsql { + INSERT INTO t1 VALUES(1, 1, 1); + INSERT INTO t1 VALUES(5, 5, 5); + INSERT INTO t1 VALUES(10, 10, 10); + } + create_db_file rbu.db $rbusql + } {} + + set R(nopk) $r1 + set R(vtab) $r2 + do_sp_test 5.$tn.$bReopen.$tn2.1 $bReopen test.db rbu.db $R($tn) + } + } +} + + finish_test diff --git a/ext/rbu/sqlite3rbu.c b/ext/rbu/sqlite3rbu.c index ab7b983ead..b587d2bb20 100644 --- a/ext/rbu/sqlite3rbu.c +++ b/ext/rbu/sqlite3rbu.c @@ -1202,6 +1202,11 @@ static void rbuObjIterCacheIndexedCols(sqlite3rbu *p, RbuObjIter *pIter){ pIter->nIndex++; } + if( pIter->eType==RBU_PK_WITHOUT_ROWID ){ + /* "PRAGMA index_list" includes the main PK b-tree */ + pIter->nIndex--; + } + rbuFinalize(p, pList); if( bIndex==0 ) pIter->abIndexed = 0; } @@ -1313,6 +1318,7 @@ static int rbuObjIterCacheTableInfo(sqlite3rbu *p, RbuObjIter *pIter){ rbuFinalize(p, pStmt); rbuObjIterCacheIndexedCols(p, pIter); assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 ); + assert( pIter->eType!=RBU_PK_VTAB || pIter->nIndex==0 ); } return p->rc; @@ -3122,14 +3128,15 @@ static void rbuIndexCntFunc( assert( nVal==1 ); rc = prepareFreeAndCollectError(p->dbMain, &pStmt, &zErrmsg, - sqlite3_mprintf("PRAGMA index_list = %Q", sqlite3_value_text(apVal[0])) + sqlite3_mprintf("SELECT count(*) FROM sqlite_master " + "WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0])) ); if( rc!=SQLITE_OK ){ sqlite3_result_error(pCtx, zErrmsg, -1); }else{ int nIndex = 0; - while( SQLITE_ROW==sqlite3_step(pStmt) ){ - nIndex++; + if( SQLITE_ROW==sqlite3_step(pStmt) ){ + nIndex = sqlite3_column_int(pStmt, 0); } rc = sqlite3_finalize(pStmt); if( rc==SQLITE_OK ){ diff --git a/manifest b/manifest index 106d447afa..ec9f64957f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sname\sof\sthe\snew\sAPI\son\sthis\sbranch\sto\s"sqlite3_bp_progress".\sAdd\stests\sand\sdocumentation\sfor\sthe\ssame. -D 2016-03-18T18:56:45.343 +C Add\sfurther\stests\sfor\ssqlite3rbu_bp_progress().\sFix\sa\sproblem\sin\shandling\sWITHOUT\sROWID\stables\sin\sthe\ssame. +D 2016-03-18T20:12:28.661 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -242,9 +242,9 @@ F ext/rbu/rbudiff.test 6cc806dc36389292f2a8f5842d0103721df4a07d F ext/rbu/rbufault.test cc0be8d5d392d98b0c2d6a51be377ea989250a89 F ext/rbu/rbufault2.test 9a7f19edd6ea35c4c9f807d8a3db0a03a5670c06 F ext/rbu/rbufts.test 828cd689da825f0a7b7c53ffc1f6f7fdb6fa5bda -F ext/rbu/rbuprogress.test 77fe3cd10d3c408bef364bc2e529310495ddd07e +F ext/rbu/rbuprogress.test 9d2dfd82fc001f26997e36db256df31f2e19e133 F ext/rbu/rbusave.test 0f43b6686084f426ddd040b878426452fd2c2f48 -F ext/rbu/sqlite3rbu.c 6b7dc899b3980d4236bffa5048218f8dba85ac0a +F ext/rbu/sqlite3rbu.c edeb8f90a1bccc567438036e083123cec1403091 F ext/rbu/sqlite3rbu.h d7cc99350c10134f358fe1a8997d9225b3f712b2 F ext/rbu/test_rbu.c 3505641a78b723589b8780d5f9b2faeeb73e037d F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 @@ -1457,7 +1457,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 bf82321724d3b0feb51e26d9b76090e03cc3964a -R 14faa32cca0db38c921d7bc3da7dea4c +P 1a1b69e87eb7d18f76f5b733e44da75136a686b6 +R 4f2c92bc8e3f772f06e8b5d5663259fa U dan -Z 40a2b2dbafc34d98f3493240ec44ac36 +Z bf41c4bf32ca5beb18733d3a05925431 diff --git a/manifest.uuid b/manifest.uuid index d6c18684be..5b3c08d363 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1a1b69e87eb7d18f76f5b733e44da75136a686b6 \ No newline at end of file +65e02368e2b6cec349ea71af5a456d6783b0d15e \ No newline at end of file