]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add new test file rtreedoc.test.
authordan <Dan Kennedy>
Mon, 13 Sep 2021 16:36:20 +0000 (16:36 +0000)
committerdan <Dan Kennedy>
Mon, 13 Sep 2021 16:36:20 +0000 (16:36 +0000)
FossilOrigin-Name: 8c4b1482eeb31856bce20eda1ce74959e19da11962f74d406a608747a92fe429

ext/rtree/rtreedoc.test [new file with mode: 0644]
manifest
manifest.uuid

diff --git a/ext/rtree/rtreedoc.test b/ext/rtree/rtreedoc.test
new file mode 100644 (file)
index 0000000..f8aeece
--- /dev/null
@@ -0,0 +1,257 @@
+# 2021 September 13
+#
+# 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.
+#
+#***********************************************************************
+#
+# The focus of this file is testing the r-tree extension.
+#
+
+if {![info exists testdir]} {
+  set testdir [file join [file dirname [info script]] .. .. test]
+}
+source [file join [file dirname [info script]] rtree_util.tcl]
+source $testdir/tester.tcl
+set testprefix rtreedoc
+
+# This command returns the number of columns in table $tbl within the
+# database opened by database handle $db
+proc column_count {db tbl} {
+  set nCol 0
+  $db eval "PRAGMA table_info = $tbl" { incr nCol }
+  return $nCol
+}
+
+#-------------------------------------------------------------------------
+#-------------------------------------------------------------------------
+# Section 3 of documentation.
+#-------------------------------------------------------------------------
+#-------------------------------------------------------------------------
+
+# 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) }
+do_test         1.1.2 { column_count db rt1 } 3
+
+# EVIDENCE-OF: R-19353-19546 A 2-dimensional R*Tree has 5 columns.
+do_execsql_test 1.2.1 { CREATE VIRTUAL TABLE rt2 USING rtree(id,x1,x2, y1,y2) }
+do_test         1.2.2 { column_count db rt2 } 5
+
+# EVIDENCE-OF: R-13615-19528 A 3-dimensional R*Tree has 7 columns.
+do_execsql_test 1.3.1 { 
+  CREATE VIRTUAL TABLE rt3 USING rtree(id, x1,x2, y1,y2, z1,z2) 
+}
+do_test         1.3.2 { column_count db rt3 } 7
+
+# EVIDENCE-OF: R-53479-41922 A 4-dimensional R*Tree has 9 columns.
+do_execsql_test 1.4.1 { 
+  CREATE VIRTUAL TABLE rt4 USING rtree(id, x1,x2, y1,y2, z1,z2, v1,v2) 
+}
+do_test         1.4.2 { column_count db rt4 } 9
+
+# EVIDENCE-OF: R-13981-28768 And a 5-dimensional R*Tree has 11 columns.
+do_execsql_test 1.5.1 { 
+  CREATE VIRTUAL TABLE rt5 USING rtree(id, x1,x2, y1,y2, z1,z2, v1,v2, w1,w2)
+}
+do_test         1.5.2 { column_count db rt5 } 11
+
+
+# Attempt to create r-tree tables with 6 and 7 dimensions.
+#
+# EVIDENCE-OF: R-61533-25862 The SQLite R*Tree implementation does not
+# support R*Trees wider than 5 dimensions.
+do_catchsql_test 2.1.1 { 
+  CREATE VIRTUAL TABLE rt6 USING rtree(
+    id, x1,x2, y1,y2, z1,z2, v1,v2, w1,w2, a1,a2
+  )
+} {1 {Too many columns for an rtree table}}
+do_catchsql_test 2.1.2 { 
+  CREATE VIRTUAL TABLE rt6 USING rtree(
+    id, x1,x2, y1,y2, z1,z2, v1,v2, w1,w2, a1,a2, b1, b2
+  )
+} {1 {Too many columns for an rtree table}}
+
+# Attempt to create r-tree tables with no columns, a single column, or
+# an even number of columns. This and the tests above establish that:
+#
+# EVIDENCE-OF: R-16717-50504 Each R*Tree index is a virtual table with
+# an odd number of columns between 3 and 11.
+foreach {tn cols err} {
+  1 ""                        "Too few columns for an rtree table"
+  2 "x"                       "Too few columns for an rtree table"
+  3 "x,y"                     "Too few columns for an rtree table"
+  4 "a,b,c,d"                 "Wrong number of columns for an rtree table"
+  5 "a,b,c,d,e,f"             "Wrong number of columns for an rtree table"
+  6 "a,b,c,d,e,f,g,h"         "Wrong number of columns for an rtree table"
+  7 "a,b,c,d,e,f,g,h,i,j"     "Wrong number of columns for an rtree table"
+  8 "a,b,c,d,e,f,g,h,i,j,k,l" "Too many columns for an rtree table"
+} {
+  do_catchsql_test 3.$tn "
+    CREATE VIRTUAL TABLE xyz USING rtree($cols)
+  " [list 1 $err]
+}
+
+# EVIDENCE-OF: R-46619-65417 The first column is always a 64-bit signed
+# integer primary key.
+#
+# EVIDENCE-OF: R-46866-24036 It may only store a 64-bit signed integer
+# value.
+#
+# EVIDENCE-OF: R-00250-64843 If an attempt is made to insert any other
+# non-integer value into this column, the r-tree module silently
+# converts it to an integer before writing it into the database.
+#
+do_execsql_test 4.0 { CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2) }
+foreach {tn val res} {
+  1 10    10
+  2 10.6  10
+  3 10.99 10
+  4 '123' 123
+  5 X'313233'  123
+  6 -10   -10
+  7  9223372036854775807 9223372036854775807 
+  8 -9223372036854775808 -9223372036854775808 
+  9  '9223372036854775807' 9223372036854775807
+  10  '-9223372036854775808' -9223372036854775808
+  11  'hello+world' 0
+} {
+  do_execsql_test 4.$tn.1 "
+    DELETE FROM rt;
+    INSERT INTO rt VALUES($val, 10, 20);
+  "
+  do_execsql_test 4.$tn.2 {
+    SELECT typeof(id), id FROM rt
+  } [list integer $res]
+}
+
+# EVIDENCE-OF: R-15544-29079 Inserting a NULL value into this column
+# causes SQLite to automatically generate a new unique primary key
+# value.
+do_execsql_test 5.1 {
+  DELETE FROM rt;
+  INSERT INTO rt VALUES(100, 1, 2);
+  INSERT INTO rt VALUES(NULL, 1, 2);
+}
+do_execsql_test 5.2 { SELECT id FROM rt } {100 101}
+do_execsql_test 5.3 { 
+  INSERT INTO rt VALUES(9223372036854775807, 1, 2);
+  INSERT INTO rt VALUES(NULL, 1, 2);
+}
+do_execsql_test 5.4 {
+  SELECT count(*) FROM rt;
+} 4
+do_execsql_test 5.5 {
+  SELECT id IN(100, 101, 9223372036854775807) FROM rt ORDER BY 1;
+} {0 1 1 1}
+
+
+# EVIDENCE-OF: R-64317-38978 The other columns are pairs, one pair per
+# dimension, containing the minimum and maximum values for that
+# dimension, respectively.
+#
+# Show this by observing that attempts to insert rows with max>min fail.
+#
+do_execsql_test 6.1 {
+  CREATE VIRTUAL TABLE rtF USING rtree(id, x1,x2, y1,y2);
+  CREATE VIRTUAL TABLE rtI USING rtree_i32(id, x1,x2, y1,y2, z1,z2);
+}
+foreach {tn x1 x2 y1 y2 ok} {
+  1   10.3 20.1   30.9 40.2   1
+  2   10.3 20.1   40.2 30.9   0
+  3   10.3 30.9   20.1 40.2   1
+  4   20.1 10.3   30.9 40.2   0
+} {
+  do_test 6.2.$tn {
+    catch { db eval { INSERT INTO rtF VALUES(NULL, $x1, $x2, $y1, $y2) } }
+  } [expr $ok==0]
+}
+foreach {tn x1 x2 y1 y2 z1 z2 ok} {
+  1   10 20   30 40  50 60  1
+  2   10 20   30 40  60 50  0
+  3   10 20   30 50  40 60  1
+  4   10 20   40 30  50 60  0
+  5   10 30   20 40  50 60  1
+  6   20 10   30 40  50 60  0
+} {
+  do_test 6.3.$tn {
+    catch { db eval { INSERT INTO rtI VALUES(NULL,$x1,$x2,$y1,$y2,$z1,$z2) } }
+  } [expr $ok==0]
+}
+
+# EVIDENCE-OF: R-08054-15429 The min/max-value pair columns are stored
+# as 32-bit floating point values for "rtree" virtual tables or as
+# 32-bit signed integers in "rtree_i32" virtual tables.
+#
+# Show this by showing that large values are rounded in ways consistent
+# with those two 32-bit types.
+do_execsql_test 7.1 {
+  DELETE FROM rtI;
+  INSERT INTO rtI VALUES(
+    0, -2000000000, 2000000000, -5000000000, 5000000000,
+    -1000000000000, 10000000000000
+  );
+  SELECT * FROM rtI;
+} {
+  0 -2000000000 2000000000 -705032704 705032704 727379968 1316134912
+}
+do_execsql_test 7.2 {
+  DELETE FROM rtF;
+  INSERT INTO rtF VALUES(
+    0, -2000000000, 2000000000, 
+    -1000000000000, 10000000000000
+  );
+  SELECT * FROM rtF;
+} {
+  0 -2000000000.0 2000000000.0 -1000000126976.0 10000000876544.0
+}
+
+# EVIDENCE-OF: R-47371-54529 Unlike regular SQLite tables which can
+# store data in a variety of datatypes and formats, the R*Tree rigidly
+# enforce these storage types.
+#
+# EVIDENCE-OF: R-39153-14977 If any other type of value is inserted into
+# such a column, the r-tree module silently converts it to the required
+# type before writing the new record to the database.
+do_execsql_test 8.1 {
+  DELETE FROM rtI;
+  INSERT INTO rtI VALUES(
+    1, 'hello world', X'616263', NULL, 44.5, 1000, 9999.9999
+  );
+  SELECT * FROM rtI;
+} {
+  1   0 0    0 44    1000 9999
+}
+
+do_execsql_test 8.2 {
+  SELECT 
+    typeof(x1), typeof(x2), typeof(y1), typeof(y2), typeof(z1), typeof(z2)
+  FROM rtI
+} {integer integer integer integer integer integer}
+
+do_execsql_test 8.3 {
+  DELETE FROM rtF;
+  INSERT INTO rtF VALUES(
+    1, 'hello world', X'616263', NULL, 44
+  );
+  SELECT * FROM rtF;
+} {
+  1   0.0 0.0    0.0 44.0
+}
+do_execsql_test 8.4 {
+  SELECT 
+    typeof(x1), typeof(x2), typeof(y1), typeof(y2)
+  FROM rtF
+} {real real real real}
+
+
+
+
+#-------------------------------------------------------------------------
+
+finish_test
+
+
index 4edb55e3dbe3148b6f6db474a99677c762ffb86c..5fe7aa9aceab86f99400c1182eca9dcf7749c61a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\sincorrect\scomment\sand\spossible\sinteger\soverflow\sin\spager\nresulting\sfrom\scheck-in\s[23ca23894af352ea].\s\sProblem\sreported\sby\n[forum:/forumpost/e2ea1a3f61|forum\spost\se2ea1a3f61].\s\sAlso\schange\nthe\sdatatype\sof\sPager.pageSize\sto\si64\seven\sthough\spage\ssize\snever\nexceeds\s65536,\sin\sorder\sto\shelp\sprevent\sfuture\sproblems\sof\sthis\skind.
-D 2021-09-13T13:53:13.560
+C Add\snew\stest\sfile\srtreedoc.test.
+D 2021-09-13T16:36:20.763
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -418,6 +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/rtreefuzz001.test 0fc793f67897c250c5fde96cefee455a5e2fb92f4feeabde5b85ea02040790ee
 F ext/rtree/sqlite3rtree.h 03c8db3261e435fbddcfc961471795cbf12b24e03001d0015b2636b0f3881373
 F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de
@@ -1922,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 2dd61dd97b0326b59b0bc3c83b4d4b9acf811c5acae4d1003e7525ba7a26daf5
-R 66cc359b5bd82ddca4b6f4fbb9050fa7
-U drh
-Z 3e25a183a096e34ec8d9ba775c31b648
+P f4a552ed9f4ab35520b634954c39748cc7bda535f426280b79da1b99f70599ac
+R f99597bfa8634077950c96867f36ea09
+U dan
+Z 062a262734dac9852988b18115d599fe
index 98e404b1e59f0b459c29cb8d8326d3e285cec9c3..ed943b18a2ba385894185f0706eccb98f2e5d006 100644 (file)
@@ -1 +1 @@
-f4a552ed9f4ab35520b634954c39748cc7bda535f426280b79da1b99f70599ac
\ No newline at end of file
+8c4b1482eeb31856bce20eda1ce74959e19da11962f74d406a608747a92fe429
\ No newline at end of file