mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Add SQL scalar function rtreecheck() to the rtree module. For running checks
to ensure the shadow tables used by an rtree virtual table are internally consistent. FossilOrigin-Name: dde0bb3eab1316c3247b1755594527ca70955aab4ad4907190731f7ec092b327
This commit is contained in:
113
ext/rtree/rtreecheck.test
Normal file
113
ext/rtree/rtreecheck.test
Normal file
@ -0,0 +1,113 @@
|
||||
# 2017 August 17
|
||||
#
|
||||
# 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 rtreecheck
|
||||
|
||||
ifcapable !rtree {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
proc swap_int32 {blob i0 i1} {
|
||||
binary scan $blob I* L
|
||||
|
||||
set a [lindex $L $i0]
|
||||
set b [lindex $L $i1]
|
||||
|
||||
lset L $i0 $b
|
||||
lset L $i1 $a
|
||||
|
||||
binary format I* $L
|
||||
}
|
||||
|
||||
do_catchsql_test 1.0 {
|
||||
SELECT rtreecheck();
|
||||
} {1 {wrong number of arguments to function rtreecheck()}}
|
||||
|
||||
do_catchsql_test 1.1 {
|
||||
SELECT rtreecheck(0,0,0);
|
||||
} {1 {wrong number of arguments to function rtreecheck()}}
|
||||
|
||||
|
||||
proc setup_simple_db {{module rtree}} {
|
||||
reset_db
|
||||
db func swap_int32 swap_int32
|
||||
execsql "
|
||||
CREATE VIRTUAL TABLE r1 USING $module (id, x1, x2, y1, y2);
|
||||
INSERT INTO r1 VALUES(1, 5, 5, 5, 5); -- 3
|
||||
INSERT INTO r1 VALUES(2, 6, 6, 6, 6); -- 9
|
||||
INSERT INTO r1 VALUES(3, 7, 7, 7, 7); -- 15
|
||||
INSERT INTO r1 VALUES(4, 8, 8, 8, 8); -- 21
|
||||
INSERT INTO r1 VALUES(5, 9, 9, 9, 9); -- 27
|
||||
"
|
||||
}
|
||||
|
||||
setup_simple_db
|
||||
do_execsql_test 2.1 {
|
||||
SELECT rtreecheck('r1')
|
||||
} {ok}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
UPDATE r1_node SET data = swap_int32(data, 3, 9);
|
||||
UPDATE r1_node SET data = swap_int32(data, 23, 29);
|
||||
}
|
||||
|
||||
do_execsql_test 2.3 {
|
||||
SELECT rtreecheck('r1')
|
||||
} {{Dimension 0 of cell 0 on node 1 is corrupt
|
||||
Dimension 1 of cell 3 on node 1 is corrupt}}
|
||||
|
||||
setup_simple_db
|
||||
do_execsql_test 2.4 {
|
||||
DELETE FROM r1_rowid WHERE rowid = 3;
|
||||
SELECT rtreecheck('r1')
|
||||
} {{Mapping (3 -> 1) missing from %_rowid table
|
||||
Wrong number of entries in %_rowid table - expected 5, actual 4}}
|
||||
|
||||
setup_simple_db
|
||||
do_execsql_test 2.5 {
|
||||
UPDATE r1_rowid SET nodeno=2 WHERE rowid=3;
|
||||
SELECT rtreecheck('r1')
|
||||
} {{Found (3 -> 2) in %_rowid table, expected (3 -> 1)}}
|
||||
|
||||
################
|
||||
reset_db
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE r1 USING rtree_i32(id, x1, x2);
|
||||
INSERT INTO r1 VALUES(1, 0x7FFFFFFF*-1, 0x7FFFFFFF);
|
||||
INSERT INTO r1 VALUES(2, 0x7FFFFFFF*-1, 5);
|
||||
INSERT INTO r1 VALUES(3, -5, 5);
|
||||
INSERT INTO r1 VALUES(4, 5, 0x11111111);
|
||||
INSERT INTO r1 VALUES(5, 5, 0x00800000);
|
||||
INSERT INTO r1 VALUES(6, 5, 0x00008000);
|
||||
INSERT INTO r1 VALUES(7, 5, 0x00000080);
|
||||
INSERT INTO r1 VALUES(8, 5, 0x40490fdb);
|
||||
INSERT INTO r1 VALUES(9, 0x7f800000, 0x7f900000);
|
||||
SELECT rtreecheck('r1')
|
||||
} {ok}
|
||||
|
||||
breakpoint
|
||||
do_execsql_test 3.1 {
|
||||
CREATE VIRTUAL TABLE r2 USING rtree_i32(id, x1, x2);
|
||||
INSERT INTO r2 VALUES(2, -1*(1<<31), -1*(1<<31)+5);
|
||||
SELECT rtreecheck('r2')
|
||||
} {ok}
|
||||
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user