summaryrefslogtreecommitdiff
path: root/dev-db/sqlite/files/sqlite-3.22.0-full_archive-tests.patch
blob: a253028b7f4b57aacdd54001cb65bee9a0b08928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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}