mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Improve coverage of rtree.c some more.
FossilOrigin-Name: bee1959dde19ebec20a7ffcb732aee0c8bb2e67d
This commit is contained in:
@ -2065,6 +2065,11 @@ splitnode_out:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** If node pLeaf is not the root of the r-tree and its pParent
|
||||
** pointer is still NULL, locate the parent node of pLeaf and populate
|
||||
** pLeaf->pParent.
|
||||
*/
|
||||
static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
|
||||
int rc = SQLITE_OK;
|
||||
if( pLeaf->iNode!=1 && pLeaf->pParent==0 ){
|
||||
@ -2442,19 +2447,17 @@ static int rtreeUpdate(
|
||||
** the root node (the operation that Gutman's paper says to perform
|
||||
** in this scenario).
|
||||
*/
|
||||
if( rc==SQLITE_OK && pRtree->iDepth>0 ){
|
||||
if( rc==SQLITE_OK && NCELL(pRoot)==1 ){
|
||||
RtreeNode *pChild;
|
||||
i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
|
||||
rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
pRtree->iDepth--;
|
||||
writeInt16(pRoot->zData, pRtree->iDepth);
|
||||
pRoot->isDirty = 1;
|
||||
}
|
||||
if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
|
||||
RtreeNode *pChild;
|
||||
i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
|
||||
rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
pRtree->iDepth--;
|
||||
writeInt16(pRoot->zData, pRtree->iDepth);
|
||||
pRoot->isDirty = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,8 @@ if {!$MEMDEBUG} {
|
||||
return
|
||||
}
|
||||
|
||||
if 1 {
|
||||
|
||||
do_faultsim_test rtree3-1 -faults oom* -prep {
|
||||
faultsim_delete_and_reopen
|
||||
} -body {
|
||||
@ -94,6 +96,8 @@ do_faultsim_test rtree3-3b -faults oom* -prep {
|
||||
db eval COMMIT
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
do_test rtree3-4.prep {
|
||||
faultsim_delete_and_reopen
|
||||
execsql {
|
||||
@ -108,19 +112,87 @@ do_test rtree3-4.prep {
|
||||
faultsim_save_and_close
|
||||
} {}
|
||||
|
||||
do_faultsim_test rtree3-4a -faults oom-transient -prep {
|
||||
do_faultsim_test rtree3-4a -faults oom-* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
db eval { SELECT count(*) FROM rt }
|
||||
} -test {
|
||||
faultsim_test_result {0 1500}
|
||||
}
|
||||
do_faultsim_test rtree3-4b -faults oom-transient -prep {
|
||||
|
||||
do_faultsim_test rtree3-4b -faults oom-* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
db eval { DELETE FROM rt WHERE ii BETWEEN 880 AND 920 }
|
||||
db eval { DELETE FROM rt WHERE ii BETWEEN 1 AND 100 }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
do_test rtree3-5.prep {
|
||||
faultsim_delete_and_reopen
|
||||
execsql {
|
||||
BEGIN;
|
||||
PRAGMA page_size = 512;
|
||||
CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
|
||||
}
|
||||
for {set i 0} {$i < 100} {incr i} {
|
||||
execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
|
||||
}
|
||||
execsql { COMMIT }
|
||||
faultsim_save_and_close
|
||||
} {}
|
||||
do_faultsim_test rtree3-5 -faults oom-* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
for {set i 100} {$i < 110} {incr i} {
|
||||
execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
do_test rtree3-6.prep {
|
||||
faultsim_delete_and_reopen
|
||||
execsql {
|
||||
BEGIN;
|
||||
PRAGMA page_size = 512;
|
||||
CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
|
||||
}
|
||||
for {set i 0} {$i < 50} {incr i} {
|
||||
execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
|
||||
}
|
||||
execsql { COMMIT }
|
||||
faultsim_save_and_close
|
||||
} {}
|
||||
do_faultsim_test rtree3-6 -faults oom-* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
execsql BEGIN
|
||||
for {set i 0} {$i < 50} {incr i} {
|
||||
execsql { DELETE FROM rt WHERE ii=$i }
|
||||
}
|
||||
execsql COMMIT
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
do_test rtree3-7.prep {
|
||||
faultsim_delete_and_reopen
|
||||
execsql { CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2) }
|
||||
faultsim_save_and_close
|
||||
} {}
|
||||
do_faultsim_test rtree3-7 -faults oom-* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
execsql { ALTER TABLE rt RENAME TO rt2 }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
do_faultsim_test rtree3-8 -faults oom-* -prep {
|
||||
catch { db close }
|
||||
} -body {
|
||||
sqlite3 db test.db
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
@ -126,12 +126,46 @@ do_execsql_test rtree8-2.2.3 {
|
||||
# Test that trying to use the MATCH operator with the r-tree module does
|
||||
# not confuse it.
|
||||
#
|
||||
breakpoint
|
||||
populate_t1 10
|
||||
do_catchsql_test rtree8-3.1 {
|
||||
SELECT * FROM t1 WHERE x1 MATCH '1234'
|
||||
} {1 {unable to use function MATCH in the requested context}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test a couple of invalid arguments to rtreedepth().
|
||||
#
|
||||
do_catchsql_test rtree8-4.1 {
|
||||
SELECT rtreedepth('hello world')
|
||||
} {1 {Invalid argument to rtreedepth()}}
|
||||
do_catchsql_test rtree8-4.2 {
|
||||
SELECT rtreedepth(X'00')
|
||||
} {1 {Invalid argument to rtreedepth()}}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Delete half of a lopsided tree.
|
||||
#
|
||||
do_execsql_test rtree8-5.1 {
|
||||
CREATE VIRTUAL TABLE t2 USING rtree_i32(id, x1, x2)
|
||||
} {}
|
||||
do_test rtree8-5.2 {
|
||||
execsql BEGIN
|
||||
for {set i 0} {$i < 100} {incr i} {
|
||||
execsql { INSERT INTO t2 VALUES($i, 100, 101) }
|
||||
}
|
||||
for {set i 100} {$i < 200} {incr i} {
|
||||
execsql { INSERT INTO t2 VALUES($i, 1000, 1001) }
|
||||
}
|
||||
execsql COMMIT
|
||||
} {}
|
||||
do_test rtree8-5.3 {
|
||||
execsql BEGIN
|
||||
for {set i 0} {$i < 200} {incr i} {
|
||||
execsql { DELETE FROM t2 WHERE id = $i }
|
||||
}
|
||||
execsql COMMIT
|
||||
} {}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
Reference in New Issue
Block a user