1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Further test coverage improvements for rtree.c.

FossilOrigin-Name: 05f6c1aebbe757dd3b54fd027057b9db7ae3a990
This commit is contained in:
dan
2010-08-25 19:04:38 +00:00
parent 92e01aafe1
commit f836afd44a
5 changed files with 50 additions and 29 deletions

View File

@ -1998,8 +1998,12 @@ static int SplitNode(
goto splitnode_out;
}
/* Ensure both child nodes have node numbers assigned to them. */
if( (0==pRight->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pRight)))
/* Ensure both child nodes have node numbers assigned to them by calling
** nodeWrite(). Node pRight always needs a node number, as it was created
** by nodeNew() above. But node pLeft sometimes already has a node number.
** In this case avoid the all to nodeWrite().
*/
if( SQLITE_OK!=(rc = nodeWrite(pRtree, pRight))
|| (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
){
goto splitnode_out;
@ -2064,14 +2068,19 @@ splitnode_out:
static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
int rc = SQLITE_OK;
if( pLeaf->iNode!=1 && pLeaf->pParent==0 ){
int rc2; /* sqlite3_reset() return code */
sqlite3_bind_int64(pRtree->pReadParent, 1, pLeaf->iNode);
if( sqlite3_step(pRtree->pReadParent)==SQLITE_ROW ){
rc = sqlite3_step(pRtree->pReadParent);
if( rc==SQLITE_ROW ){
i64 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
rc = nodeAcquire(pRtree, iNode, 0, &pLeaf->pParent);
}else{
rc = SQLITE_ERROR;
}else if( rc==SQLITE_DONE ){
rc = SQLITE_CORRUPT;
}
rc2 = sqlite3_reset(pRtree->pReadParent);
if( rc==SQLITE_OK ){
rc = rc2;
}
sqlite3_reset(pRtree->pReadParent);
if( rc==SQLITE_OK ){
rc = fixLeafParent(pRtree, pLeaf->pParent);
}
@ -2881,12 +2890,10 @@ static void rtreedepth(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
** function "rtreenode".
*/
int sqlite3RtreeInit(sqlite3 *db){
int rc = SQLITE_OK;
const int utf8 = SQLITE_UTF8;
int rc;
if( rc==SQLITE_OK ){
int utf8 = SQLITE_UTF8;
rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
}
rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
if( rc==SQLITE_OK ){
int utf8 = SQLITE_UTF8;
rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);

View File

@ -33,8 +33,6 @@ if {!$MEMDEBUG} {
return
}
if 1 {
do_faultsim_test rtree3-1 -faults oom* -prep {
faultsim_delete_and_reopen
} -body {
@ -96,8 +94,6 @@ do_faultsim_test rtree3-3b -faults oom* -prep {
db eval COMMIT
}
}
do_test rtree3-4.prep {
faultsim_delete_and_reopen
execsql {
@ -112,12 +108,19 @@ do_test rtree3-4.prep {
faultsim_save_and_close
} {}
do_faultsim_test rtree3-4 -faults oom-transient -prep {
do_faultsim_test rtree3-4a -faults oom-transient -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 {
faultsim_restore_and_reopen
} -body {
db eval { DELETE FROM rt WHERE ii BETWEEN 880 AND 920 }
} -test {
faultsim_test_result {0 {}}
}
finish_test

View File

@ -104,13 +104,24 @@ do_catchsql_test rtree8-2.1.5 {
} {1 {database disk image is malformed}}
do_execsql_test rtree8-2.1.6 {
DELETE FROM t1_node;
DELETE FROM t1_parent;
DELETE FROM t1_rowid;
DROP TABLE t1;
CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
} {}
populate_t1 50
do_execsql_test rtree8-2.2.1 {
DELETE FROM t1_parent
} {}
do_catchsql_test rtree8-2.2.2 {
DELETE FROM t1 WHERE id=25
} {1 {database disk image is malformed}}
do_execsql_test rtree8-2.2.3 {
DROP TABLE t1;
CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
} {}
#-------------------------------------------------------------------------
# Test that trying to use the MATCH operator with the r-tree module does
# not confuse it.
@ -119,7 +130,7 @@ breakpoint
populate_t1 10
do_catchsql_test rtree8-3.1 {
SELECT * FROM t1 WHERE x1 MATCH '1234'
} {1 {}}
} {1 {unable to use function MATCH in the requested context}}
finish_test