-C Fix\sa\sharmless\scompiler\swarning.
-D 2018-02-09T15:04:51.897
+C Make\sthe\stests\sin\sfunc6.test\smore\srobust\sagainst\simplementation\schanges.
+D 2018-02-09T15:42:40.632
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in 7a3f714b4fcf793108042b7b0a5c720b0b310ec84314d61ba7f3f49f27e550ea
F test/func3.test d202a7606d23f90988a664e88e268aed1087c11c
F test/func4.test 6beacdfcb0e18c358e6c2dcacf1b65d1fa80955f
F test/func5.test cdd224400bc3e48d891827cc913a57051a426fa4
-F test/func6.test a4281c8fcd42b56f7a60f28e8e4d444e8b2256f9e82658b7ab87699f8318f564
+F test/func6.test 612311a51adad23326d15353eea8d90394798acb26dd1f7c7cad59bd8ac982d2
F test/fuzz-oss1.test e58330d01cbbd8215ee636b17a03fe220b37dbfa
F test/fuzz.test 96083052bf5765e4518c1ba686ce2bab785670d1
F test/fuzz2.test 76dc35b32b6d6f965259508508abce75a6c4d7e1
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P ad5d3bdc739a0997786f94fb5789b726b9f53ff883226093924338fe5000922b
-R b0cb95e907260417df10582a6a66e391
-U drh
-Z cf86aa36db1eb294d8bf4ad196d065d9
+P a6c3115483d597fc77ab19fdcfd1d3437cad7e467081ad8c5315fb98c115eed9
+R f6c1b3a83bf1fd9e6dbd920e348c4245
+U dan
+Z baeba07272c3f575c3e3036aa614a6dd
CREATE TABLE t2(x TEXT PRIMARY KEY, y) WITHOUT ROWID;
INSERT INTO t2(x,y) SELECT a, b FROM t1;
}
+
+# Load the contents of $file from disk and return it encoded as a hex
+# string.
+proc loadhex {file} {
+ set fd [open $file]
+ fconfigure $fd -translation binary -encoding binary
+ set data [read $fd]
+ close $fd
+ binary encode hex $data
+}
+
+# Each argument is either an integer between 0 and 65535, a text value, or
+# an empty string representing an SQL NULL. This command builds an SQLite
+# record containing the values passed as arguments and returns it encoded
+# as a hex string.
+proc hexrecord {args} {
+ set hdr ""
+ set body ""
+ foreach x $args {
+ if {$x==""} {
+ append hdr 00
+ } elseif {[string is integer $x]==0} {
+ set n [string length $x]
+ append hdr [format %02x [expr $n*2 + 13]]
+ append body [binary encode hex $x]
+ } elseif {$x == 0} {
+ append hdr 08
+ } elseif {$x == 1} {
+ append hdr 09
+ } elseif {$x <= 127} {
+ append hdr 01
+ append body [format %02x $x]
+ } else {
+ append hdr 02
+ append body [format %04x $x]
+ }
+ }
+ set res [format %02x [expr 1 + [string length $hdr]/2]]
+ append res $hdr
+ append res $body
+}
+
+# Argument $off is an offset into the database image encoded as a hex string
+# in argument $hexdb. This command returns 0 if the offset contains the hex
+# $hexrec, or throws an exception otherwise.
+#
+proc offset_contains_record {off hexdb hexrec} {
+ set n [string length $hexrec]
+ set off [expr $off*2]
+ if { [string compare $hexrec [string range $hexdb $off [expr $off+$n-1]]] } {
+ error "record not found!"
+ }
+ return 0
+}
+
+# This command is the implementation of SQL function "offrec()". The first
+# argument to this is an offset value. The remaining values are used to
+# formulate an SQLite record. If database file test.db does not contain
+# an equivalent record at the specified offset, an exception is thrown.
+# Otherwise, 0 is returned.
+#
+proc offrec {args} {
+ set offset [lindex $args 0]
+ set rec [hexrecord {*}[lrange $args 1 end]]
+ offset_contains_record $offset $::F $rec
+}
+set F [loadhex test.db]
+db func offrec offrec
+
+# Test the sanity of the tests.
+do_execsql_test func6-105 {
+ SELECT sqlite_offset(d) FROM t1 ORDER BY rowid LIMIT 1;
+} {8179}
+do_test func6-106 {
+ set r [hexrecord abc001 1 999 {}]
+ offset_contains_record 8179 $F $r
+} 0
+
+set z100 [string trim [string repeat "0 " 100]]
+
+# Test offsets within table b-tree t1.
do_execsql_test func6-110 {
- SELECT a, sqlite_offset(d)/4096 + 1,
- sqlite_offset(d)%4096 FROM t1
- ORDER BY rowid LIMIT 2;
-} {abc001 2 4084 abc002 2 4069}
+ SELECT offrec(sqlite_offset(d), a, b, c, d) FROM t1 ORDER BY rowid
+} $z100
+
do_execsql_test func6-120 {
SELECT a, typeof(sqlite_offset(+a)) FROM t1
ORDER BY rowid LIMIT 2;
} {abc001 null abc002 null}
+
+# Test offsets within index b-tree t1a.
do_execsql_test func6-130 {
- SELECT a, sqlite_offset(a)/4096+1,
- sqlite_offset(a)%4096
- FROM t1
- ORDER BY a LIMIT 2;
-} {abc001 3 4087 abc002 3 4076}
+ SELECT offrec(sqlite_offset(a), a, rowid) FROM t1 ORDER BY a
+} $z100
+
+# Test offsets within table b-tree t1 with a temp b-tree ORDER BY.
do_execsql_test func6-140 {
- SELECT a, sqlite_offset(d)/4096+1,
- sqlite_offset(d)%4096
- FROM t1
- ORDER BY a LIMIT 2;
-} {abc001 2 4084 abc002 2 4069}
+ SELECT offrec(sqlite_offset(d), a, b, c, d) FROM t1 ORDER BY a
+} $z100
+
+# Test offsets from both index t1a and table t1 in the same query.
do_execsql_test func6-150 {
- SELECT a,
- sqlite_offset(a)/4096+1,
- sqlite_offset(a)%4096,
- sqlite_offset(d)/4096+1,
- sqlite_offset(d)%4096
- FROM t1
- ORDER BY a LIMIT 2;
-} {abc001 3 4087 2 4084 abc002 3 4076 2 4069}
-do_execsql_test func6-160 {
- SELECT b,
- sqlite_offset(b)/4096+1,
- sqlite_offset(b)%4096,
- sqlite_offset(c)/4096+1,
- sqlite_offset(c)%4096,
- sqlite_offset(d)/4096+1,
- sqlite_offset(d)%4096
- FROM t1
- ORDER BY b LIMIT 2;
-} {1 4 4090 4 4090 2 4084 2 4 4081 4 4081 2 4069}
+ SELECT offrec(sqlite_offset(a), a, rowid),
+ offrec(sqlite_offset(d), a, b, c, d)
+ FROM t1 ORDER BY a
+} [concat $z100 $z100]
+# Test offsets from both index t1bc and table t1 in the same query.
+do_execsql_test func6-160 {
+ SELECT offrec(sqlite_offset(b), b, c, rowid),
+ offrec(sqlite_offset(c), b, c, rowid),
+ offrec(sqlite_offset(d), a, b, c, d)
+ FROM t1
+ ORDER BY b
+} [concat $z100 $z100 $z100]
+# Test offsets in WITHOUT ROWID table t2.
do_execsql_test func6-200 {
- SELECT y, sqlite_offset(y)/4096+1,
- sqlite_offset(y)%4096
- FROM t2
- ORDER BY x LIMIT 2;
-} {1 5 4087 2 5 4076}
+ SELECT offrec( sqlite_offset(y), x, y ) FROM t2 ORDER BY x
+} $z100
finish_test