You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
250 lines
7.4 KiB
250 lines
7.4 KiB
https://sqlite.org/src/info/e4766cabdf64d8e9
|
|
https://sqlite.org/src/info/d9e59cfb8476e1ec
|
|
https://sqlite.org/src/info/ba0631de60ca38bf
|
|
https://sqlite.org/src/info/b685d3231097fb90
|
|
|
|
--- /test/fts3rank.test
|
|
+++ /test/fts3rank.test
|
|
@@ -14,7 +14,7 @@
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
-set testprefix fts3expr5
|
|
+set testprefix fts3rank
|
|
|
|
# If SQLITE_ENABLE_FTS3 is defined, omit this file.
|
|
ifcapable !fts3 {
|
|
@@ -56,9 +56,14 @@
|
|
SELECT * FROM t1 ORDER BY rank(x'0000000000000000') DESC, rowid
|
|
} {0 {{one two} one {one two} three {one two} two}}
|
|
|
|
-do_catchsql_test 1.5 {
|
|
- SELECT * FROM t1 ORDER BY rank(x'0100000001000000') DESC, rowid
|
|
-} {1 {invalid matchinfo blob passed to function rank()}}
|
|
+if {$tcl_platform(byteOrder)=="littleEndian"} {
|
|
+ do_catchsql_test 1.5le {
|
|
+ SELECT * FROM t1 ORDER BY rank(x'0100000001000000') DESC, rowid
|
|
+ } {1 {invalid matchinfo blob passed to function rank()}}
|
|
+} else {
|
|
+ do_catchsql_test 1.5be {
|
|
+ SELECT * FROM t1 ORDER BY rank(x'0000000100000001') DESC, rowid
|
|
+ } {1 {invalid matchinfo blob passed to function rank()}}
|
|
+}
|
|
|
|
finish_test
|
|
-
|
|
--- /test/func6.test
|
|
+++ /test/func6.test
|
|
@@ -33,54 +33,125 @@
|
|
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
|
|
--- /test/walro2.test
|
|
+++ /test/walro2.test
|
|
@@ -39,6 +39,18 @@
|
|
}
|
|
}
|
|
|
|
+# Most systems allocate the *-shm file in 32KB trunks. But on UNIX systems
|
|
+# for which the getpagesize() call returns greater than 32K, the *-shm
|
|
+# file is allocated in page-sized units (since you cannot mmap part of
|
|
+# a page). The following code sets variable $MINSHMSZ to the smallest
|
|
+# possible *-shm file (i.e. the greater of 32KB and the system page-size).
|
|
+#
|
|
+do_execsql_test 0.0 {
|
|
+ PRAGMA journal_mode = wal;
|
|
+ CREATE TABLE t1(x);
|
|
+} {wal}
|
|
+set MINSHMSZ [file size test.db-shm]
|
|
+
|
|
foreach bZeroShm {0 1} {
|
|
set TN [expr $bZeroShm+1]
|
|
do_multiclient_test tn {
|
|
@@ -169,7 +181,7 @@
|
|
} {a b c d e f g h 1 2}
|
|
do_test $TN.3.2.2 {
|
|
list [file size test.db-wal] [file size test.db-shm]
|
|
- } {0 32768}
|
|
+ } [list 0 $MINSHMSZ]
|
|
|
|
do_test $TN.3.3.0 {
|
|
code2 { sqlite3 db2 test.db }
|
|
@@ -182,7 +194,7 @@
|
|
code2 { db2 close }
|
|
code1 { db close }
|
|
list [file size test.db-wal] [file size test.db-shm]
|
|
- } [list [wal_file_size 4 1024] 32768]
|
|
+ } [list [wal_file_size 4 1024] $MINSHMSZ]
|
|
do_test $TN.3.3.1 {
|
|
code1 { sqlite3 db file:test.db?readonly_shm=1 }
|
|
sql1 { SELECT * FROM t1 }
|
|
@@ -196,7 +208,7 @@
|
|
}
|
|
code2 { db2 close }
|
|
list [file size test.db-wal] [file size test.db-shm]
|
|
- } [list [wal_file_size 4 1024] 32768]
|
|
+ } [list [wal_file_size 4 1024] $MINSHMSZ]
|
|
do_test $TN.3.3.3 {
|
|
sql1 { SELECT * FROM t1 }
|
|
} {i ii}
|