Add test cases to rtreedoc.test.

FossilOrigin-Name: 4ee99d315487a3aa09911191a74c6a12693784c5359243eb1396d8868566e80a
This commit is contained in:
dan
2021-09-13 18:32:02 +00:00
parent 82456a661d
commit db45212a35
3 changed files with 182 additions and 8 deletions
+174
View File
@@ -27,11 +27,20 @@ proc column_count {db tbl} {
return $nCol
}
proc column_name_list {db tbl} {
set lCol [list]
$db eval "PRAGMA table_info = $tbl" {
lappend lCol $name
}
return $lCol
}
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
# Section 3 of documentation.
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
set testprefix rtreedoc-1
# EVIDENCE-OF: R-15060-13876 A 1-dimensional R*Tree thus has 3 columns.
do_execsql_test 1.1.1 { CREATE VIRTUAL TABLE rt1 USING rtree(id, x1,x2) }
@@ -251,6 +260,171 @@ do_execsql_test 8.4 {
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
# Section 3.1 of documentation.
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
set testprefix rtreedoc-2
reset_db
foreach {tn name clist} {
1 t1 "id x1 x2"
2 t2 "id x1 x2 y1 y2 z1 z2"
} {
# EVIDENCE-OF: R-15142-18077 A new R*Tree index is created as follows:
# CREATE VIRTUAL TABLE <name> USING rtree(<column-names>);
do_execsql_test 1.$tn.1 "
CREATE VIRTUAL TABLE $name USING rtree([join $clist ,])
"
# EVIDENCE-OF: R-51698-09302 The <name> is the name your
# application chooses for the R*Tree index and <column-names> is a
# comma separated list of between 3 and 11 columns.
do_test 1.$tn.2 { column_name_list db $name } [list {*}$clist]
# EVIDENCE-OF: R-50130-53472 The virtual <name> table creates
# three shadow tables to actually store its content.
do_execsql_test 1.$tn.3 {
SELECT count(*) FROM sqlite_schema
} [expr 1+3]
# EVIDENCE-OF: R-45256-35998 The names of these shadow tables are:
# <name>_node <name>_rowid <name>_parent
do_execsql_test 1.$tn.4 {
SELECT name FROM sqlite_schema WHERE rootpage>0 ORDER BY 1
} [list ${name}_node ${name}_parent ${name}_rowid]
do_execsql_test 1.$tn.5 "DROP TABLE $name"
}
# EVIDENCE-OF: R-11241-54478 As an example, consider creating a
# two-dimensional R*Tree index for use in spatial queries: CREATE
# VIRTUAL TABLE demo_index USING rtree( id, -- Integer primary key minX,
# maxX, -- Minimum and maximum X coordinate minY, maxY -- Minimum and
# maximum Y coordinate );
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE demo_index USING rtree(
id, -- Integer primary key
minX, maxX, -- Minimum and maximum X coordinate
minY, maxY -- Minimum and maximum Y coordinate
);
INSERT INTO demo_index VALUES(1,2,3,4,5);
INSERT INTO demo_index VALUES(6,7,8,9,10);
}
# EVIDENCE-OF: R-02287-33529 The shadow tables are ordinary SQLite data
# tables.
#
# Ordinary tables. With ordinary sqlite_schema entries.
do_execsql_test 2.1 {
SELECT * FROM sqlite_schema WHERE sql NOT LIKE '%virtual%'
} {
table demo_index_rowid demo_index_rowid 2
{CREATE TABLE "demo_index_rowid"(rowid INTEGER PRIMARY KEY,nodeno)}
table demo_index_node demo_index_node 3
{CREATE TABLE "demo_index_node"(nodeno INTEGER PRIMARY KEY,data)}
table demo_index_parent demo_index_parent 4
{CREATE TABLE "demo_index_parent"(nodeno INTEGER PRIMARY KEY,parentnode)}
}
# EVIDENCE-OF: R-10863-13089 You can query them directly if you like,
# though this unlikely to reveal anything particularly useful.
#
# Querying:
do_execsql_test 2.2 {
SELECT count(*) FROM demo_index_node;
SELECT count(*) FROM demo_index_rowid;
SELECT count(*) FROM demo_index_parent;
} {1 2 0}
# EVIDENCE-OF: R-05650-46070 And you can UPDATE, DELETE, INSERT or even
# DROP the shadow tables, though doing so will corrupt your R*Tree
# index.
do_execsql_test 2.3 {
DELETE FROM demo_index_rowid;
INSERT INTO demo_index_parent VALUES(2, 3);
UPDATE demo_index_node SET data = 'hello world'
}
do_catchsql_test 2.4 {
SELECT * FROM demo_index WHERE minX>10 AND maxX<30
} {1 {database disk image is malformed}}
do_execsql_test 2.5 {
DROP TABLE demo_index_rowid
}
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
# Section 3.1.1 of documentation.
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
set testprefix rtreedoc-3
reset_db
# EVIDENCE-OF: R-44253-50720 In the argments to "rtree" in the CREATE
# VIRTUAL TABLE statement, the names of the columns are taken from the
# first token of each argument. All subsequent tokens within each
# argument are silently ignored.
#
foreach {tn cols lCol} {
1 {(id TEXT, x1 TEXT, x2 TEXT, y1 TEXT, y2 TEXT)} {id x1 x2 y1 y2}
2 {(id TEXT, x1 UNIQUE, x2 TEXT, y1 NOT NULL, y2 TEXT)} {id x1 x2 y1 y2}
3 {(id, x1 DEFAULT 4, x2 TEXT, y1 NOT NULL, y2 TEXT)} {id x1 x2 y1 y2}
} {
do_execsql_test 1.$tn.1 " CREATE VIRTUAL TABLE abc USING rtree $cols "
do_test 1.$tn.2 { column_name_list db abc } $lCol
# EVIDENCE-OF: R-52032-06717 This means, for example, that if you try to
# give a column a type affinity or add a constraint such as UNIQUE or
# NOT NULL or DEFAULT to a column, those extra tokens are accepted as
# valid, but they do not change the behavior of the rtree.
# Show there are no UNIQUE constraints
do_execsql_test 1.$tn.3 {
INSERT INTO abc VALUES(1, 10.0, 20.0, 10.0, 20.0);
INSERT INTO abc VALUES(2, 10.0, 20.0, 10.0, 20.0);
}
# Show the default values have not been modified
do_execsql_test 1.$tn.4 {
INSERT INTO abc DEFAULT VALUES;
SELECT * FROM abc WHERE rowid NOT IN (1,2)
} {3 0.0 0.0 0.0 0.0}
# Show that there are no NOT NULL constraints
do_execsql_test 1.$tn.5 {
INSERT INTO abc VALUES(NULL, NULL, NULL, NULL, NULL);
SELECT * FROM abc WHERE rowid NOT IN (1,2,3)
} {4 0.0 0.0 0.0 0.0}
# EVIDENCE-OF: R-06893-30579 In an RTREE virtual table, the first column
# always has a type affinity of INTEGER and all other data columns have
# a type affinity of REAL.
do_execsql_test 1.$tn.5 {
INSERT INTO abc VALUES('5', '5', '5', '5', '5');
SELECT * FROM abc WHERE rowid NOT IN (1,2,3,4)
} {5 5.0 5.0 5.0 5.0}
do_execsql_test 1.$tn.6 {
SELECT type FROM pragma_table_info('abc') ORDER BY cid
} {INT REAL REAL REAL REAL}
do_execsql_test 1.$tn.7 " CREATE VIRTUAL TABLE abc2 USING rtree_i32 $cols "
# EVIDENCE-OF: R-06224-52418 In an RTREE_I32 virtual table, all columns
# have type affinity of INTEGER.
do_execsql_test 1.$tn.8 {
INSERT INTO abc2 VALUES('6.0', '6.0', '6.0', '6.0', '6.0');
SELECT * FROM abc2
} {6 6 6 6 6}
do_execsql_test 1.$tn.9 {
SELECT type FROM pragma_table_info('abc2') ORDER BY cid
} {INT INT INT INT INT}
do_execsql_test 1.$tn.10 {
DROP TABLE abc;
DROP TABLE abc2;
}
}
finish_test
+7 -7
View File
@@ -1,5 +1,5 @@
C Add\sassert()\sstatements\sto\srefute\s\n[forum:/forumpost/9f4e7f58fbb66ddd|forum\spost\s9f4e7f58fbb66ddd].
D 2021-09-13T18:16:15.976
C Add\stest\scases\sto\srtreedoc.test.
D 2021-09-13T18:32:02.389
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -418,7 +418,7 @@ F ext/rtree/rtree_util.tcl db734b4c5e75fed6acc56d9701f2235345acfdec750b5fc7b5879
F ext/rtree/rtreecheck.test d67d5b3e9e45bfa8cd90734e8e9302144ac415b8e9176c6f02d4f92892ee8a35
F ext/rtree/rtreecirc.test aec664eb21ae943aeb344191407afff5d392d3ae9d12b9a112ced0d9c5de298e
F ext/rtree/rtreeconnect.test 225ad3fcb483d36cbee423a25052a6bbae762c9576ae9268332360c68c170d3d
F ext/rtree/rtreedoc.test 99e1bac95df108f3bdae6c09cd08c27eca20c20ed70d989a4df73799540305df
F ext/rtree/rtreedoc.test a1e5199edd7ddb1f3ac20b720f908cffe85cbaa28924c50415de09ce01b478b7
F ext/rtree/rtreefuzz001.test 0fc793f67897c250c5fde96cefee455a5e2fb92f4feeabde5b85ea02040790ee
F ext/rtree/sqlite3rtree.h 03c8db3261e435fbddcfc961471795cbf12b24e03001d0015b2636b0f3881373
F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de
@@ -1923,7 +1923,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 8c4b1482eeb31856bce20eda1ce74959e19da11962f74d406a608747a92fe429
R 31122d38ddbc232dcbd8f2a1a089a76e
U drh
Z 2f8fa553907508fe78dd100f7c6194fd
P 83a83475c5064ea62016a03e9173ecd2a1fec7f6296f1ee99896fa0a38b4196a
R a1c3bdb5fd69f05f7096cf73daf4f563
U dan
Z 525d49d8fabd36744cc1fce5e4c65380
+1 -1
View File
@@ -1 +1 @@
83a83475c5064ea62016a03e9173ecd2a1fec7f6296f1ee99896fa0a38b4196a
4ee99d315487a3aa09911191a74c6a12693784c5359243eb1396d8868566e80a