Kitxuuu commited on
Commit
4c7d4df
·
verified ·
1 Parent(s): 7be92e6

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. local-test-sqlite3-delta-03/afc-sqlite3/test/alterfault.test +41 -0
  2. local-test-sqlite3-delta-03/afc-sqlite3/test/altertab.test +1002 -0
  3. local-test-sqlite3-delta-03/afc-sqlite3/test/analyze.test +399 -0
  4. local-test-sqlite3-delta-03/afc-sqlite3/test/auth2.test +160 -0
  5. local-test-sqlite3-delta-03/afc-sqlite3/test/autoindex2.test +232 -0
  6. local-test-sqlite3-delta-03/afc-sqlite3/test/bestindexB.test +87 -0
  7. local-test-sqlite3-delta-03/afc-sqlite3/test/bestindexC.test +352 -0
  8. local-test-sqlite3-delta-03/afc-sqlite3/test/bloom1.test +188 -0
  9. local-test-sqlite3-delta-03/afc-sqlite3/test/boundary1.tcl +289 -0
  10. local-test-sqlite3-delta-03/afc-sqlite3/test/busy.test +139 -0
  11. local-test-sqlite3-delta-03/afc-sqlite3/test/capi2.test +803 -0
  12. local-test-sqlite3-delta-03/afc-sqlite3/test/carray01.test +159 -0
  13. local-test-sqlite3-delta-03/afc-sqlite3/test/coalesce.test +84 -0
  14. local-test-sqlite3-delta-03/afc-sqlite3/test/collateB.test +77 -0
  15. local-test-sqlite3-delta-03/afc-sqlite3/test/corrupt4.test +149 -0
  16. local-test-sqlite3-delta-03/afc-sqlite3/test/crash6.test +118 -0
  17. local-test-sqlite3-delta-03/afc-sqlite3/test/crashM.test +80 -0
  18. local-test-sqlite3-delta-03/afc-sqlite3/test/ctime.test +259 -0
  19. local-test-sqlite3-delta-03/afc-sqlite3/test/date4.test +38 -0
  20. local-test-sqlite3-delta-03/afc-sqlite3/test/dbdata.test +115 -0
  21. local-test-sqlite3-delta-03/afc-sqlite3/test/dbfuzz001.test +397 -0
  22. local-test-sqlite3-delta-03/afc-sqlite3/test/e_blobclose.test +175 -0
  23. local-test-sqlite3-delta-03/afc-sqlite3/test/e_vacuum.test +347 -0
  24. local-test-sqlite3-delta-03/afc-sqlite3/test/e_walauto.test +214 -0
  25. local-test-sqlite3-delta-03/afc-sqlite3/test/enc3.test +107 -0
  26. local-test-sqlite3-delta-03/afc-sqlite3/test/extraquick.test +16 -0
  27. local-test-sqlite3-delta-03/afc-sqlite3/test/fts3auto.test +717 -0
  28. local-test-sqlite3-delta-03/afc-sqlite3/test/fts3cov.test +434 -0
  29. local-test-sqlite3-delta-03/afc-sqlite3/test/fts3e.test +125 -0
  30. local-test-sqlite3-delta-03/afc-sqlite3/test/fts3fault.test +263 -0
  31. local-test-sqlite3-delta-03/afc-sqlite3/test/fts3misc.test +326 -0
  32. local-test-sqlite3-delta-03/afc-sqlite3/test/fts3prefix2.test +61 -0
  33. local-test-sqlite3-delta-03/afc-sqlite3/test/fts3varint.test +121 -0
  34. local-test-sqlite3-delta-03/afc-sqlite3/test/fts4aa.test +256 -0
  35. local-test-sqlite3-delta-03/afc-sqlite3/test/fts4growth.test +441 -0
  36. local-test-sqlite3-delta-03/afc-sqlite3/test/fts4merge5.test +58 -0
  37. local-test-sqlite3-delta-03/afc-sqlite3/test/fuzzer2.test +72 -0
  38. local-test-sqlite3-delta-03/afc-sqlite3/test/incrvacuum.test +892 -0
  39. local-test-sqlite3-delta-03/afc-sqlite3/test/join3.test +62 -0
  40. local-test-sqlite3-delta-03/afc-sqlite3/test/joinD.test +0 -0
  41. local-test-sqlite3-delta-03/afc-sqlite3/test/joinF.test +613 -0
  42. local-test-sqlite3-delta-03/afc-sqlite3/test/lastinsert.test +377 -0
  43. local-test-sqlite3-delta-03/afc-sqlite3/test/laststmtchanges.test +331 -0
  44. local-test-sqlite3-delta-03/afc-sqlite3/test/lock2.test +111 -0
  45. local-test-sqlite3-delta-03/afc-sqlite3/test/malloc3.test +703 -0
  46. local-test-sqlite3-delta-03/afc-sqlite3/test/mallocG.test +73 -0
  47. local-test-sqlite3-delta-03/afc-sqlite3/test/notify3.test +152 -0
  48. local-test-sqlite3-delta-03/afc-sqlite3/test/offset1.test +202 -0
  49. local-test-sqlite3-delta-03/afc-sqlite3/test/pcache.test +182 -0
  50. local-test-sqlite3-delta-03/afc-sqlite3/test/pragma5.test +70 -0
local-test-sqlite3-delta-03/afc-sqlite3/test/alterfault.test ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2021 November 16
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library.
12
+ #
13
+
14
+ set testdir [file dirname $argv0]
15
+ source $testdir/tester.tcl
16
+ set testprefix alterfault
17
+
18
+ # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
19
+ ifcapable !altertable {
20
+ finish_test
21
+ return
22
+ }
23
+
24
+ do_execsql_test 1.0 {
25
+ CREATE TABLE t1(a);
26
+ }
27
+ faultsim_save_and_close
28
+
29
+ do_faultsim_test 1.1 -faults oom* -prep {
30
+ faultsim_restore_and_reopen
31
+ } -body {
32
+ execsql {
33
+ ALTER TABLE t1 ADD COLUMN b CHECK (a!=1)
34
+ }
35
+ } -test {
36
+ faultsim_test_result {0 {}}
37
+ }
38
+
39
+
40
+
41
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/altertab.test ADDED
@@ -0,0 +1,1002 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2018 August 24
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #*************************************************************************
11
+ #
12
+
13
+ set testdir [file dirname $argv0]
14
+ source $testdir/tester.tcl
15
+ set testprefix altertab
16
+
17
+ # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
18
+ ifcapable !altertable {
19
+ finish_test
20
+ return
21
+ }
22
+
23
+ do_execsql_test 1.0 {
24
+ CREATE TABLE t1(a, b, CHECK(t1.a != t1.b));
25
+
26
+ CREATE TABLE t2(a, b);
27
+ CREATE INDEX t2expr ON t2(a) WHERE t2.b>0;
28
+ }
29
+
30
+ do_execsql_test 1.1 {
31
+ SELECT sql FROM sqlite_master
32
+ } {
33
+ {CREATE TABLE t1(a, b, CHECK(t1.a != t1.b))}
34
+ {CREATE TABLE t2(a, b)}
35
+ {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0}
36
+ }
37
+
38
+ do_execsql_test 1.2 {
39
+ ALTER TABLE t1 RENAME TO t1new;
40
+ }
41
+
42
+ do_execsql_test 1.3 {
43
+ CREATE TABLE t3(c, d);
44
+ ALTER TABLE t3 RENAME TO t3new;
45
+ DROP TABLE t3new;
46
+ }
47
+
48
+ do_execsql_test 1.4 {
49
+ SELECT sql FROM sqlite_master
50
+ } {
51
+ {CREATE TABLE "t1new"(a, b, CHECK("t1new".a != "t1new".b))}
52
+ {CREATE TABLE t2(a, b)}
53
+ {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0}
54
+ }
55
+
56
+
57
+ do_execsql_test 1.3 {
58
+ ALTER TABLE t2 RENAME TO t2new;
59
+ }
60
+ do_execsql_test 1.4 {
61
+ SELECT sql FROM sqlite_master
62
+ } {
63
+ {CREATE TABLE "t1new"(a, b, CHECK("t1new".a != "t1new".b))}
64
+ {CREATE TABLE "t2new"(a, b)}
65
+ {CREATE INDEX t2expr ON "t2new"(a) WHERE "t2new".b>0}
66
+ }
67
+
68
+
69
+ #-------------------------------------------------------------------------
70
+ reset_db
71
+ ifcapable vtab {
72
+ register_echo_module db
73
+
74
+ do_execsql_test 2.0 {
75
+ CREATE TABLE abc(a, b, c);
76
+ INSERT INTO abc VALUES(1, 2, 3);
77
+ CREATE VIRTUAL TABLE eee USING echo('abc');
78
+ SELECT * FROM eee;
79
+ } {1 2 3}
80
+
81
+ do_execsql_test 2.1 {
82
+ ALTER TABLE eee RENAME TO fff;
83
+ SELECT * FROM fff;
84
+ } {1 2 3}
85
+
86
+ db close
87
+ sqlite3 db test.db
88
+
89
+ do_catchsql_test 2.2 {
90
+ ALTER TABLE fff RENAME TO ggg;
91
+ } {1 {no such module: echo}}
92
+ }
93
+
94
+ #-------------------------------------------------------------------------
95
+ reset_db
96
+
97
+ do_execsql_test 3.0 {
98
+ CREATE TABLE txx(a, b, c);
99
+ INSERT INTO txx VALUES(1, 2, 3);
100
+ CREATE VIEW vvv AS SELECT main.txx.a, txx.b, c FROM txx;
101
+ CREATE VIEW uuu AS SELECT main.one.a, one.b, c FROM txx AS one;
102
+ CREATE VIEW temp.ttt AS SELECT main.txx.a, txx.b, one.b, main.one.a FROM txx AS one, txx;
103
+ }
104
+
105
+ do_execsql_test 3.1.1 {
106
+ SELECT * FROM vvv;
107
+ } {1 2 3}
108
+ do_execsql_test 3.1.2 {
109
+ ALTER TABLE txx RENAME TO "t xx";
110
+ SELECT * FROM vvv;
111
+ } {1 2 3}
112
+ do_execsql_test 3.1.3 {
113
+ SELECT sql FROM sqlite_master WHERE name='vvv';
114
+ } {{CREATE VIEW vvv AS SELECT main."t xx".a, "t xx".b, c FROM "t xx"}}
115
+
116
+
117
+ do_execsql_test 3.2.1 {
118
+ SELECT * FROM uuu;
119
+ } {1 2 3}
120
+ do_execsql_test 3.2.2 {
121
+ SELECT sql FROM sqlite_master WHERE name='uuu';;
122
+ } {{CREATE VIEW uuu AS SELECT main.one.a, one.b, c FROM "t xx" AS one}}
123
+
124
+ do_execsql_test 3.3.1 {
125
+ SELECT * FROM ttt;
126
+ } {1 2 2 1}
127
+ do_execsql_test 3.3.2 {
128
+ SELECT sql FROM sqlite_temp_master WHERE name='ttt';
129
+ } {{CREATE VIEW ttt AS SELECT main."t xx".a, "t xx".b, one.b, main.one.a FROM "t xx" AS one, "t xx"}}
130
+
131
+ #-------------------------------------------------------------------------
132
+ reset_db
133
+ do_execsql_test 4.0 {
134
+ CREATE table t1(x, y);
135
+ CREATE table t2(a, b);
136
+
137
+ CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
138
+ SELECT t1.x, * FROM t1, t2;
139
+ INSERT INTO t2 VALUES(new.x, new.y);
140
+ END;
141
+ }
142
+
143
+ do_execsql_test 4.1 {
144
+ INSERT INTO t1 VALUES(1, 1);
145
+ ALTER TABLE t1 RENAME TO t11;
146
+ INSERT INTO t11 VALUES(2, 2);
147
+ ALTER TABLE t2 RENAME TO t22;
148
+ INSERT INTO t11 VALUES(3, 3);
149
+ }
150
+
151
+ proc squish {a} {
152
+ string trim [regsub -all {[[:space:]][[:space:]]*} $a { }]
153
+ }
154
+ db func squish squish
155
+ do_test 4.2 {
156
+ execsql { SELECT squish(sql) FROM sqlite_master WHERE name = 'tr1' }
157
+ } [list [squish {
158
+ CREATE TRIGGER tr1 AFTER INSERT ON "t11" BEGIN
159
+ SELECT "t11".x, * FROM "t11", "t22";
160
+ INSERT INTO "t22" VALUES(new.x, new.y);
161
+ END
162
+ }]]
163
+
164
+ #-------------------------------------------------------------------------
165
+ reset_db
166
+ do_execsql_test 5.0 {
167
+ CREATE TABLE t9(a, b, c);
168
+ CREATE TABLE t10(a, b, c);
169
+ CREATE TEMP TABLE t9(a, b, c);
170
+
171
+ CREATE TRIGGER temp.t9t AFTER INSERT ON temp.t9 BEGIN
172
+ INSERT INTO t10 VALUES(new.a, new.b, new.c);
173
+ END;
174
+
175
+ INSERT INTO temp.t9 VALUES(1, 2, 3);
176
+ SELECT * FROM t10;
177
+ } {1 2 3}
178
+
179
+ do_execsql_test 5.1 {
180
+ ALTER TABLE temp.t9 RENAME TO 't1234567890'
181
+ }
182
+
183
+ do_execsql_test 5.2 {
184
+ CREATE TABLE t1(a, b);
185
+ CREATE TABLE t2(a, b);
186
+ INSERT INTO t1 VALUES(1, 2);
187
+ INSERT INTO t2 VALUES(3, 4);
188
+ CREATE VIEW v AS SELECT one.a, one.b, t2.a, t2.b FROM t1 AS one, t2;
189
+ SELECT * FROM v;
190
+ } {1 2 3 4}
191
+
192
+ do_catchsql_test 5.3 {
193
+ ALTER TABLE t2 RENAME TO one;
194
+ } {1 {error in view v after rename: ambiguous column name: one.a}}
195
+
196
+ do_execsql_test 5.4 {
197
+ SELECT * FROM v
198
+ } {1 2 3 4}
199
+
200
+ do_execsql_test 5.5 {
201
+ DROP VIEW v;
202
+ CREATE VIEW temp.vv AS SELECT one.a, one.b, t2.a, t2.b FROM t1 AS one, t2;
203
+ SELECT * FROM vv;
204
+ } {1 2 3 4}
205
+
206
+ do_catchsql_test 5.6 {
207
+ ALTER TABLE t2 RENAME TO one;
208
+ } {1 {error in view vv after rename: ambiguous column name: one.a}}
209
+
210
+ #-------------------------------------------------------------------------
211
+
212
+ ifcapable vtab {
213
+ register_tcl_module db
214
+ proc tcl_command {method args} {
215
+ switch -- $method {
216
+ xConnect {
217
+ return "CREATE TABLE t1(a, b, c)"
218
+ }
219
+ }
220
+ return {}
221
+ }
222
+
223
+ do_execsql_test 6.0 {
224
+ CREATE VIRTUAL TABLE x1 USING tcl(tcl_command);
225
+ }
226
+
227
+ do_execsql_test 6.1 {
228
+ ALTER TABLE x1 RENAME TO x2;
229
+ SELECT sql FROM sqlite_master WHERE name = 'x2'
230
+ } {{CREATE VIRTUAL TABLE "x2" USING tcl(tcl_command)}}
231
+
232
+ do_execsql_test 7.1 {
233
+ CREATE TABLE ddd(db, sql, zOld, zNew, bTemp);
234
+ INSERT INTO ddd VALUES(
235
+ 'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', 'ddd', NULL, 0
236
+ ), (
237
+ 'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', NULL, 'eee', 0
238
+ ), (
239
+ 'main', NULL, 'ddd', 'eee', 0
240
+ );
241
+ } {}
242
+
243
+ sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db
244
+ do_execsql_test 7.2 {
245
+ SELECT
246
+ sqlite_rename_table(db, 0, 0, sql, zOld, zNew, bTemp)
247
+ FROM ddd;
248
+ } {{} {} {}}
249
+ sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db
250
+ }
251
+
252
+ #-------------------------------------------------------------------------
253
+ #
254
+ reset_db
255
+ forcedelete test.db2
256
+ do_execsql_test 8.1 {
257
+ ATTACH 'test.db2' AS aux;
258
+ PRAGMA foreign_keys = on;
259
+ CREATE TABLE aux.p1(a INTEGER PRIMARY KEY, b);
260
+ CREATE TABLE aux.c1(x INTEGER PRIMARY KEY, y REFERENCES p1(a));
261
+ INSERT INTO aux.p1 VALUES(1, 1);
262
+ INSERT INTO aux.p1 VALUES(2, 2);
263
+ INSERT INTO aux.c1 VALUES(NULL, 2);
264
+ CREATE TABLE aux.c2(x INTEGER PRIMARY KEY, y REFERENCES c1(a));
265
+ }
266
+
267
+ do_execsql_test 8.2 {
268
+ ALTER TABLE aux.p1 RENAME TO ppp;
269
+ }
270
+
271
+ do_execsql_test 8.2 {
272
+ INSERT INTO aux.c1 VALUES(NULL, 1);
273
+ SELECT sql FROM aux.sqlite_master WHERE name = 'c1';
274
+ } {{CREATE TABLE c1(x INTEGER PRIMARY KEY, y REFERENCES "ppp"(a))}}
275
+
276
+ reset_db
277
+ do_execsql_test 9.0 {
278
+ CREATE TABLE t1(a, b, c);
279
+ CREATE VIEW v1 AS SELECT * FROM t2;
280
+ }
281
+ do_catchsql_test 9.1 {
282
+ ALTER TABLE t1 RENAME TO t3;
283
+ } {1 {error in view v1: no such table: main.t2}}
284
+ do_execsql_test 9.2 {
285
+ DROP VIEW v1;
286
+ CREATE TRIGGER tr AFTER INSERT ON t1 BEGIN
287
+ INSERT INTO t2 VALUES(new.a);
288
+ END;
289
+ }
290
+ do_catchsql_test 9.3 {
291
+ ALTER TABLE t1 RENAME TO t3;
292
+ } {1 {error in trigger tr: no such table: main.t2}}
293
+
294
+ forcedelete test.db2
295
+ do_execsql_test 9.4 {
296
+ DROP TRIGGER tr;
297
+
298
+ ATTACH 'test.db2' AS aux;
299
+ CREATE TRIGGER tr AFTER INSERT ON t1 WHEN new.a IS NULL BEGIN SELECT 1, 2, 3; END;
300
+
301
+ CREATE TABLE aux.t1(x);
302
+ CREATE TEMP TRIGGER tr AFTER INSERT ON aux.t1 BEGIN SELECT 1, 2, 3; END;
303
+ }
304
+ do_execsql_test 9.5 {
305
+ ALTER TABLE main.t1 RENAME TO t3;
306
+ }
307
+ do_execsql_test 9.6 {
308
+ SELECT sql FROM sqlite_temp_master;
309
+ SELECT sql FROM sqlite_master WHERE type='trigger';
310
+ } {
311
+ {CREATE TRIGGER tr AFTER INSERT ON aux.t1 BEGIN SELECT 1, 2, 3; END}
312
+ {CREATE TRIGGER tr AFTER INSERT ON "t3" WHEN new.a IS NULL BEGIN SELECT 1, 2, 3; END}
313
+ }
314
+
315
+ #-------------------------------------------------------------------------
316
+ reset_db
317
+ ifcapable fts5 {
318
+ do_execsql_test 10.0 {
319
+ CREATE VIRTUAL TABLE fff USING fts5(x, y, z);
320
+ }
321
+
322
+ do_execsql_test 10.1 {
323
+ BEGIN;
324
+ INSERT INTO fff VALUES('a', 'b', 'c');
325
+ ALTER TABLE fff RENAME TO ggg;
326
+ COMMIT;
327
+ }
328
+
329
+ do_execsql_test 10.2 {
330
+ SELECT * FROM ggg;
331
+ } {a b c}
332
+ }
333
+
334
+ #-------------------------------------------------------------------------
335
+ reset_db
336
+ forcedelete test.db2
337
+ db func trigger trigger
338
+ set ::trigger [list]
339
+ proc trigger {args} {
340
+ lappend ::trigger $args
341
+ }
342
+ do_execsql_test 11.0 {
343
+ ATTACH 'test.db2' AS aux;
344
+ CREATE TABLE aux.t1(a, b, c);
345
+ CREATE TABLE main.t1(a, b, c);
346
+ CREATE TEMP TRIGGER tr AFTER INSERT ON aux.t1 BEGIN
347
+ SELECT trigger(new.a, new.b, new.c);
348
+ END;
349
+ }
350
+
351
+ do_execsql_test 11.1 {
352
+ INSERT INTO main.t1 VALUES(1, 2, 3);
353
+ INSERT INTO aux.t1 VALUES(4, 5, 6);
354
+ }
355
+ do_test 11.2 { set ::trigger } {{4 5 6}}
356
+
357
+ do_execsql_test 11.3 {
358
+ SELECT name, tbl_name FROM sqlite_temp_master;
359
+ } {tr t1}
360
+
361
+ do_execsql_test 11.4 {
362
+ ALTER TABLE main.t1 RENAME TO t2;
363
+ SELECT name, tbl_name FROM sqlite_temp_master;
364
+ } {tr t1}
365
+
366
+ do_execsql_test 11.5 {
367
+ ALTER TABLE aux.t1 RENAME TO t2;
368
+ SELECT name, tbl_name FROM sqlite_temp_master;
369
+ } {tr t2}
370
+
371
+ do_execsql_test 11.6 {
372
+ INSERT INTO aux.t2 VALUES(7, 8, 9);
373
+ }
374
+ do_test 11.7 { set ::trigger } {{4 5 6} {7 8 9}}
375
+
376
+ #-------------------------------------------------------------------------
377
+ reset_db
378
+ do_execsql_test 12.0 {
379
+ CREATE TABLE t1(a);
380
+ CREATE TABLE t2(w);
381
+ CREATE TRIGGER temp.r1 AFTER INSERT ON main.t2 BEGIN
382
+ INSERT INTO t1(a) VALUES(new.w);
383
+ END;
384
+ CREATE TEMP TABLE t2(x);
385
+ }
386
+
387
+ do_execsql_test 12.1 {
388
+ ALTER TABLE main.t2 RENAME TO t3;
389
+ }
390
+
391
+ do_execsql_test 12.2 {
392
+ INSERT INTO t3 VALUES('WWW');
393
+ SELECT * FROM t1;
394
+ } {WWW}
395
+
396
+
397
+ #-------------------------------------------------------------------------
398
+ reset_db
399
+ do_execsql_test 13.0 {
400
+ CREATE TABLE t1(x, y);
401
+ CREATE TABLE t2(a, b);
402
+ CREATE TABLE log(c);
403
+ CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
404
+ INSERT INTO log SELECT y FROM t1, t2;
405
+ END;
406
+ }
407
+
408
+ do_execsql_test 13.1 {
409
+ INSERT INTO t1 VALUES(1, 2);
410
+ }
411
+
412
+ do_catchsql_test 13.2 {
413
+ ALTER TABLE t2 RENAME b TO y;
414
+ } {1 {error in trigger tr1 after rename: ambiguous column name: y}}
415
+
416
+ #-------------------------------------------------------------------------
417
+ reset_db
418
+
419
+ ifcapable rtree {
420
+ do_execsql_test 14.0 {
421
+ CREATE VIRTUAL TABLE rt USING rtree(id, minx, maxx, miny, maxy);
422
+
423
+ CREATE TABLE "mytable" ( "fid" INTEGER PRIMARY KEY, "geom" BLOB);
424
+
425
+ CREATE TRIGGER tr1 AFTER UPDATE OF "geom" ON "mytable"
426
+ WHEN OLD."fid" = NEW."fid" AND NEW."geom" IS NULL BEGIN
427
+ DELETE FROM rt WHERE id = OLD."fid";
428
+ END;
429
+
430
+ INSERT INTO mytable VALUES(1, X'abcd');
431
+ }
432
+
433
+ do_execsql_test 14.1 {
434
+ UPDATE mytable SET geom = X'1234'
435
+ }
436
+
437
+ do_execsql_test 14.2 {
438
+ ALTER TABLE mytable RENAME TO mytable_renamed;
439
+ }
440
+
441
+ do_execsql_test 14.3 {
442
+ CREATE TRIGGER tr2 AFTER INSERT ON mytable_renamed BEGIN
443
+ DELETE FROM rt WHERE id=(SELECT min(id) FROM rt);
444
+ END;
445
+ }
446
+
447
+ do_execsql_test 14.4 {
448
+ ALTER TABLE mytable_renamed RENAME TO mytable2;
449
+ }
450
+ }
451
+
452
+ reset_db
453
+ do_execsql_test 14.5 {
454
+ CREATE TABLE t1(a, b, c);
455
+ CREATE VIEW v1 AS SELECT * FROM t1;
456
+ CREATE TRIGGER xyz AFTER INSERT ON t1 BEGIN
457
+ SELECT a, b FROM v1;
458
+ END;
459
+ }
460
+ do_execsql_test 14.6 {
461
+ ALTER TABLE t1 RENAME TO tt1;
462
+ }
463
+
464
+ #-------------------------------------------------------------------------
465
+ reset_db
466
+ do_execsql_test 15.0 {
467
+ CREATE TABLE t1(a integer NOT NULL PRIMARY KEY);
468
+ CREATE VIEW v1 AS SELECT a FROM t1;
469
+ CREATE TRIGGER tr1 INSTEAD OF INSERT ON v1 BEGIN
470
+ UPDATE t1 SET a = NEW.a;
471
+ END;
472
+ CREATE TRIGGER tr2 INSTEAD OF INSERT ON v1 BEGIN
473
+ SELECT new.a;
474
+ END;
475
+ CREATE TABLE t2 (b);
476
+ }
477
+
478
+ do_execsql_test 15.1 {
479
+ INSERT INTO v1 VALUES(1);
480
+ ALTER TABLE t2 RENAME TO t3;
481
+ }
482
+
483
+ do_execsql_test 15.2 {
484
+ CREATE TABLE x(f1 integer NOT NULL);
485
+ CREATE VIEW y AS SELECT f1 AS f1 FROM x;
486
+ CREATE TRIGGER t INSTEAD OF UPDATE OF f1 ON y BEGIN
487
+ UPDATE x SET f1 = NEW.f1;
488
+ END;
489
+ CREATE TABLE z (f1 integer NOT NULL PRIMARY KEY);
490
+ ALTER TABLE z RENAME TO z2;
491
+ }
492
+
493
+ do_execsql_test 15.3 {
494
+ INSERT INTO x VALUES(1), (2), (3);
495
+ ALTER TABLE x RENAME f1 TO f2;
496
+ SELECT * FROM x;
497
+ } {1 2 3}
498
+
499
+ do_execsql_test 15.4 {
500
+ UPDATE y SET f1 = 'x' WHERE f1 = 1;
501
+ SELECT * FROM x;
502
+ } {x x x}
503
+
504
+ do_execsql_test 15.5 {
505
+ SELECT sql FROM sqlite_master WHERE name = 'y';
506
+ } {{CREATE VIEW y AS SELECT f2 AS f1 FROM x}}
507
+
508
+ #-------------------------------------------------------------------------
509
+ # Test that it is not possible to rename a shadow table in DEFENSIVE mode.
510
+ #
511
+ ifcapable fts3 {
512
+ proc vtab_command {method args} {
513
+ switch -- $method {
514
+ xConnect {
515
+ if {[info exists ::vtab_connect_sql]} {
516
+ execsql $::vtab_connect_sql
517
+ }
518
+ return "CREATE TABLE t1(a, b, c)"
519
+ }
520
+
521
+ xBestIndex {
522
+ set clist [lindex $args 0]
523
+ if {[llength $clist]!=1} { error "unexpected constraint list" }
524
+ catch { array unset C }
525
+ array set C [lindex $clist 0]
526
+ if {$C(usable)} {
527
+ return "omit 0 cost 0 rows 1 idxnum 555 idxstr eq!"
528
+ } else {
529
+ return "cost 1000000 rows 0 idxnum 0 idxstr scan..."
530
+ }
531
+ }
532
+ }
533
+
534
+ return {}
535
+ }
536
+
537
+ register_tcl_module db
538
+
539
+ sqlite3_db_config db DEFENSIVE 1
540
+
541
+ do_execsql_test 16.0 {
542
+ CREATE VIRTUAL TABLE y1 USING fts3;
543
+ VACUUM;
544
+ }
545
+
546
+ do_catchsql_test 16.10 {
547
+ INSERT INTO y1_segments VALUES(1, X'1234567890');
548
+ } {1 {table y1_segments may not be modified}}
549
+
550
+ do_catchsql_test 16.20 {
551
+ DROP TABLE y1_segments;
552
+ } {1 {table y1_segments may not be dropped}}
553
+
554
+ do_catchsql_test 16.20 {
555
+ ALTER TABLE y1_segments RENAME TO abc;
556
+ } {1 {table y1_segments may not be altered}}
557
+ sqlite3_db_config db DEFENSIVE 0
558
+ do_catchsql_test 16.22 {
559
+ ALTER TABLE y1_segments RENAME TO abc;
560
+ } {0 {}}
561
+ sqlite3_db_config db DEFENSIVE 1
562
+ do_catchsql_test 16.23 {
563
+ CREATE TABLE y1_segments AS SELECT * FROM abc;
564
+ } {1 {object name reserved for internal use: y1_segments}}
565
+ do_catchsql_test 16.24 {
566
+ CREATE VIEW y1_segments AS SELECT * FROM abc;
567
+ } {1 {object name reserved for internal use: y1_segments}}
568
+ sqlite3_db_config db DEFENSIVE 0
569
+ do_catchsql_test 16.25 {
570
+ ALTER TABLE abc RENAME TO y1_segments;
571
+ } {0 {}}
572
+ sqlite3_db_config db DEFENSIVE 1
573
+
574
+ do_execsql_test 16.30 {
575
+ ALTER TABLE y1 RENAME TO z1;
576
+ }
577
+
578
+ do_execsql_test 16.40 {
579
+ SELECT * FROM z1_segments;
580
+ }
581
+ }
582
+
583
+ #-------------------------------------------------------------------------
584
+ reset_db
585
+ do_execsql_test 17.0 {
586
+ CREATE TABLE sqlite1234 (id integer);
587
+ ALTER TABLE sqlite1234 RENAME TO User;
588
+ SELECT name, sql FROM sqlite_master WHERE sql IS NOT NULL;
589
+ } {
590
+ User {CREATE TABLE "User" (id integer)}
591
+ }
592
+
593
+ #-------------------------------------------------------------------------
594
+ reset_db
595
+ do_execsql_test 18.1.0 {
596
+ CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0)) WITHOUT ROWID;
597
+ }
598
+ do_execsql_test 18.1.1 {
599
+ ALTER TABLE t0 RENAME COLUMN c0 TO c1;
600
+ }
601
+ do_execsql_test 18.1.2 {
602
+ SELECT sql FROM sqlite_master;
603
+ } {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1)) WITHOUT ROWID}}
604
+
605
+ reset_db
606
+ do_execsql_test 18.2.0 {
607
+ CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0));
608
+ }
609
+ do_execsql_test 18.2.1 {
610
+ ALTER TABLE t0 RENAME COLUMN c0 TO c1;
611
+ }
612
+ do_execsql_test 18.2.2 {
613
+ SELECT sql FROM sqlite_master;
614
+ } {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1))}}
615
+
616
+ # 2020-02-23 ticket f50af3e8a565776b
617
+ reset_db
618
+ do_execsql_test 19.100 {
619
+ CREATE TABLE t1(x);
620
+ CREATE VIEW t2 AS SELECT 1 FROM t1, (t1 AS a0, t1);
621
+ ALTER TABLE t1 RENAME TO t3;
622
+ SELECT sql FROM sqlite_master;
623
+ } {{CREATE TABLE "t3"(x)} {CREATE VIEW t2 AS SELECT 1 FROM "t3", ("t3" AS a0, "t3")}}
624
+ do_execsql_test 19.110 {
625
+ INSERT INTO t3(x) VALUES(123);
626
+ SELECT * FROM t2;
627
+ } {1}
628
+ do_execsql_test 19.120 {
629
+ INSERT INTO t3(x) VALUES('xyz');
630
+ SELECT * FROM t2;
631
+ } {1 1 1 1 1 1 1 1}
632
+
633
+ # Ticket 4722bdab08cb14
634
+ reset_db
635
+ do_execsql_test 20.0 {
636
+ CREATE TABLE a(a);
637
+ CREATE VIEW b AS SELECT(SELECT *FROM c JOIN a USING(d, a, a, a) JOIN a) IN();
638
+ }
639
+ do_execsql_test 20.1 {
640
+ ALTER TABLE a RENAME a TO e;
641
+ } {}
642
+
643
+ reset_db
644
+ do_execsql_test 21.0 {
645
+ CREATE TABLE a(b);
646
+ CREATE VIEW c AS
647
+ SELECT NULL INTERSECT
648
+ SELECT NULL ORDER BY
649
+ likelihood(NULL, (d, (SELECT c)));
650
+ } {}
651
+ do_catchsql_test 21.1 {
652
+ SELECT likelihood(NULL, (d, (SELECT c)));
653
+ } {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
654
+ do_catchsql_test 21.2 {
655
+ SELECT * FROM c;
656
+ } {1 {1st ORDER BY term does not match any column in the result set}}
657
+
658
+ do_catchsql_test 21.3 {
659
+ ALTER TABLE a RENAME TO e;
660
+ } {1 {error in view c: 1st ORDER BY term does not match any column in the result set}}
661
+
662
+ # After forum thread https://sqlite.org/forum/forumpost/ddbe1c7efa
663
+ # Ensure that PRAGMA schema_version=N causes a full schema reload.
664
+ #
665
+ reset_db
666
+ do_execsql_test 22.0 {
667
+ CREATE TABLE t1(a INT, b TEXT NOT NULL);
668
+ INSERT INTO t1 VALUES(1,2),('a','b');
669
+ BEGIN;
670
+ PRAGMA writable_schema=ON;
671
+ UPDATE sqlite_schema SET sql='CREATE TABLE t1(a INT, b TEXT)' WHERE name LIKE 't1';
672
+ PRAGMA schema_version=1234;
673
+ COMMIT;
674
+ PRAGMA integrity_check;
675
+ } {ok}
676
+ do_execsql_test 22.1 {
677
+ ALTER TABLE t1 ADD COLUMN c INT DEFAULT 78;
678
+ SELECT * FROM t1;
679
+ } {1 2 78 a b 78}
680
+
681
+ #-------------------------------------------------------------------------
682
+ reset_db
683
+ db collate compare64 compare64
684
+
685
+ do_execsql_test 23.1 {
686
+ CREATE TABLE gigo(a text);
687
+ CREATE TABLE idx(x text COLLATE compare64);
688
+ CREATE VIEW v1 AS SELECT * FROM idx WHERE x='abc';
689
+ }
690
+ db close
691
+ sqlite3 db test.db
692
+
693
+ do_execsql_test 23.2 {
694
+ alter table gigo rename to ggiiggoo;
695
+ alter table idx rename to idx2;
696
+ }
697
+
698
+ do_execsql_test 23.3 {
699
+ SELECT sql FROM sqlite_master;
700
+ } {
701
+ {CREATE TABLE "ggiiggoo"(a text)}
702
+ {CREATE TABLE "idx2"(x text COLLATE compare64)}
703
+ {CREATE VIEW v1 AS SELECT * FROM "idx2" WHERE x='abc'}
704
+ }
705
+
706
+ do_execsql_test 23.4 {
707
+ ALTER TABLE idx2 RENAME x TO y;
708
+ SELECT sql FROM sqlite_master;
709
+ } {
710
+ {CREATE TABLE "ggiiggoo"(a text)}
711
+ {CREATE TABLE "idx2"(y text COLLATE compare64)}
712
+ {CREATE VIEW v1 AS SELECT * FROM "idx2" WHERE y='abc'}
713
+ }
714
+
715
+ #-------------------------------------------------------------------------
716
+ #
717
+ reset_db
718
+ do_execsql_test 24.1.0 {
719
+ CREATE TABLE t1(a, b);
720
+ CREATE TRIGGER AFTER INSERT ON t1 BEGIN
721
+ INSERT INTO nosuchtable VALUES(new.a) ON CONFLICT(a) DO NOTHING;
722
+ END;
723
+ }
724
+ do_catchsql_test 24.1.1 {
725
+ ALTER TABLE t1 RENAME TO t2;
726
+ } {1 {error in trigger AFTER: no such table: main.nosuchtable}}
727
+
728
+ reset_db
729
+ do_execsql_test 24.2.0 {
730
+ CREATE TABLE t1(a, b);
731
+ CREATE TRIGGER AFTER INSERT ON t1 BEGIN
732
+ INSERT INTO v1 VALUES(new.a) ON CONFLICT(a) DO NOTHING;
733
+ END;
734
+ CREATE VIEW v1 AS SELECT * FROM nosuchtable;
735
+ }
736
+ do_catchsql_test 24.2.1 {
737
+ ALTER TABLE t1 RENAME TO t2;
738
+ } {1 {error in trigger AFTER: no such table: main.nosuchtable}}
739
+
740
+ #--------------------------------------------------------------------------
741
+ #
742
+ reset_db
743
+ do_execsql_test 25.1 {
744
+ CREATE TABLE xx(x);
745
+ CREATE VIEW v3(b) AS WITH b AS (SELECT b FROM (SELECT * FROM t2)) VALUES(1);
746
+ }
747
+
748
+ ifcapable json1&&vtab {
749
+ do_catchsql_test 25.2 {
750
+ ALTER TABLE json_each RENAME TO t4;
751
+ } {1 {table json_each may not be altered}}
752
+ }
753
+
754
+ # 2021-05-01 dbsqlfuzz bc17a306a09329bba0ecc61547077f6178bcf321
755
+ # Remove a NEVER() inserted on 2019-12-09 that is reachable after all.
756
+ #
757
+ reset_db
758
+ do_execsql_test 26.1 {
759
+ CREATE TABLE t1(k,v);
760
+ CREATE TABLE t2_a(k,v);
761
+ CREATE VIEW t2 AS SELECT * FROM t2_a;
762
+ CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN
763
+ UPDATE t1
764
+ SET (k,v)=((WITH cte1(a) AS (SELECT 1 FROM t2) SELECT t2.k FROM t2, cte1),1);
765
+ END;
766
+ ALTER TABLE t1 RENAME TO t1x;
767
+ INSERT INTO t2_a VALUES(2,3);
768
+ INSERT INTO t1x VALUES(98,99);
769
+ SELECT * FROM t1x;
770
+ } {2 1}
771
+
772
+ #-------------------------------------------------------------------------
773
+ reset_db
774
+
775
+ do_execsql_test 27.1 {
776
+
777
+ create table t_sa (
778
+ c_muyat INTEGER NOT NULL,
779
+ c_d4u TEXT
780
+ );
781
+
782
+ create table t2 ( abc );
783
+
784
+ CREATE TRIGGER trig AFTER DELETE ON t_sa
785
+ BEGIN
786
+ DELETE FROM t_sa WHERE (
787
+ SELECT 123 FROM t2
788
+ WINDOW oamat7fzf AS ( PARTITION BY t_sa.c_d4u )
789
+ );
790
+ END;
791
+ }
792
+
793
+ do_execsql_test 27.2 {
794
+ alter table t_sa rename column c_muyat to c_dg;
795
+ }
796
+
797
+ #-------------------------------------------------------------------------
798
+ reset_db
799
+ do_execsql_test 29.1 {
800
+ CREATE TABLE t1(a, b, c);
801
+ INSERT INTO t1 VALUES('a', 'b', 'c');
802
+
803
+ CREATE VIEW v0 AS
804
+ WITH p AS ( SELECT 1 FROM t1 ),
805
+ g AS ( SELECT 1 FROM p, t1 )
806
+ SELECT 1 FROM g;
807
+ }
808
+
809
+ do_execsql_test 29.2 {
810
+ SELECT * FROM v0
811
+ } 1
812
+
813
+ do_execsql_test 29.2 {
814
+ ALTER TABLE t1 RENAME TO t2
815
+ }
816
+
817
+ do_execsql_test 29.3 {
818
+ SELECT sql FROM sqlite_schema WHERE name='v0'
819
+ } {{CREATE VIEW v0 AS
820
+ WITH p AS ( SELECT 1 FROM "t2" ),
821
+ g AS ( SELECT 1 FROM p, "t2" )
822
+ SELECT 1 FROM g}}
823
+
824
+ do_execsql_test 29.4 {
825
+ CREATE VIEW v2 AS
826
+ WITH p AS ( SELECT 1 FROM t2 ),
827
+ g AS ( SELECT 1 FROM (
828
+ WITH i AS (SELECT 1 FROM p, t2)
829
+ SELECT * FROM i
830
+ )
831
+ )
832
+ SELECT 1 FROM g;
833
+ }
834
+
835
+ do_execsql_test 29.4 {
836
+ SELECT * FROM v2;
837
+ } 1
838
+
839
+ do_execsql_test 29.5 {
840
+ ALTER TABLE t2 RENAME TO t3;
841
+ }
842
+
843
+ do_execsql_test 29.5 {
844
+ SELECT sql FROM sqlite_schema WHERE name='v2'
845
+ } {{CREATE VIEW v2 AS
846
+ WITH p AS ( SELECT 1 FROM "t3" ),
847
+ g AS ( SELECT 1 FROM (
848
+ WITH i AS (SELECT 1 FROM p, "t3")
849
+ SELECT * FROM i
850
+ )
851
+ )
852
+ SELECT 1 FROM g}}
853
+
854
+
855
+ #-------------------------------------------------------------------------
856
+ reset_db
857
+ do_execsql_test 28.1 {
858
+ CREATE TABLE t1(a);
859
+ CREATE TABLE t2(b,c);
860
+ CREATE TABLE t4(b,c);
861
+ INSERT INTO t2 VALUES(1,2),(1,3),(2,5);
862
+ INSERT INTO t4 VALUES(1,2),(1,3),(2,5);
863
+
864
+ CREATE VIEW v3 AS
865
+ WITH RECURSIVE t3(x,y,z) AS (
866
+ SELECT b,c,NULL FROM t4
867
+ UNION
868
+ SELECT x,y,NULL FROM t3, t2
869
+ )
870
+ SELECT * FROM t3 AS xyz;
871
+ }
872
+
873
+ do_execsql_test 28.2 {
874
+ SELECT * FROM v3
875
+ } {
876
+ 1 2 {} 1 3 {} 2 5 {}
877
+ }
878
+
879
+ do_execsql_test 28.3 {
880
+ ALTER TABLE t1 RENAME a TO a2; -- fails in v3
881
+ }
882
+
883
+ do_execsql_test 28.4 {
884
+ ALTER TABLE t2 RENAME TO t5;
885
+ }
886
+
887
+ do_execsql_test 28.5 {
888
+ SELECT sql FROM sqlite_schema WHERE name='v3'
889
+ } {{CREATE VIEW v3 AS
890
+ WITH RECURSIVE t3(x,y,z) AS (
891
+ SELECT b,c,NULL FROM t4
892
+ UNION
893
+ SELECT x,y,NULL FROM t3, "t5"
894
+ )
895
+ SELECT * FROM t3 AS xyz}}
896
+
897
+ #-------------------------------------------------------------------------
898
+ reset_db
899
+ do_execsql_test 30.0 {
900
+ CREATE TABLE t1(a,b,c,d,e,f);
901
+ CREATE TABLE t2(a,b,c);
902
+ CREATE INDEX t1abc ON t1(a,b,c+d+e);
903
+ CREATE VIEW v1(x,y) AS
904
+ SELECT t1.b,t2.b FROM t1,t2 WHERE t1.a=t2.a
905
+ GROUP BY 1 HAVING t2.c NOT NULL LIMIT 10;
906
+ CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN 'no' NOT NULL BEGIN
907
+ INSERT INTO t2(a,a,b,c) VALUES(new.b,new.a,new.c-7);
908
+ WITH c1(x) AS (
909
+ VALUES(0)
910
+ UNION ALL
911
+ SELECT current_time+x FROM c1 WHERE x
912
+ UNION ALL
913
+ SELECT 1+x FROM c1 WHERE x<1
914
+ ), c2(x) AS (VALUES(0),(1))
915
+ SELECT * FROM c1 AS x1, c2 AS x2, (
916
+ SELECT x+1 FROM c1 WHERE x IS NOT TRUE
917
+ UNION ALL
918
+ SELECT 1+x FROM c1 WHERE 1<x
919
+ ) AS x3, c2 x5;
920
+ END;
921
+ }
922
+
923
+ do_execsql_test 30.1 {
924
+ ALTER TABLE t1 RENAME TO t1x;
925
+ }
926
+
927
+ do_execsql_test 30.2 {
928
+ SELECT sql FROM sqlite_schema ORDER BY rowid
929
+ } {
930
+ {CREATE TABLE "t1x"(a,b,c,d,e,f)}
931
+ {CREATE TABLE t2(a,b,c)}
932
+ {CREATE INDEX t1abc ON "t1x"(a,b,c+d+e)}
933
+ {CREATE VIEW v1(x,y) AS
934
+ SELECT "t1x".b,t2.b FROM "t1x",t2 WHERE "t1x".a=t2.a
935
+ GROUP BY 1 HAVING t2.c NOT NULL LIMIT 10}
936
+ {CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN 'no' NOT NULL BEGIN
937
+ INSERT INTO t2(a,a,b,c) VALUES(new.b,new.a,new.c-7);
938
+ WITH c1(x) AS (
939
+ VALUES(0)
940
+ UNION ALL
941
+ SELECT current_time+x FROM c1 WHERE x
942
+ UNION ALL
943
+ SELECT 1+x FROM c1 WHERE x<1
944
+ ), c2(x) AS (VALUES(0),(1))
945
+ SELECT * FROM c1 AS x1, c2 AS x2, (
946
+ SELECT x+1 FROM c1 WHERE x IS NOT TRUE
947
+ UNION ALL
948
+ SELECT 1+x FROM c1 WHERE 1<x
949
+ ) AS x3, c2 x5;
950
+ END}
951
+ }
952
+
953
+ #-------------------------------------------------------------------------
954
+ reset_db
955
+ do_execsql_test 31.0 {
956
+ CREATE TABLE t1(q);
957
+ CREATE VIEW vvv AS WITH x AS (WITH y AS (SELECT * FROM x) SELECT 1) SELECT 1;
958
+ }
959
+
960
+ do_execsql_test 31.1 {
961
+ SELECT * FROM vvv;
962
+ } {1}
963
+
964
+ do_execsql_test 31.2 {
965
+ ALTER TABLE t1 RENAME TO t1x;
966
+ }
967
+
968
+ do_execsql_test 31.3 {
969
+ ALTER TABLE t1x RENAME q TO x;
970
+ }
971
+
972
+ # 2021-07-02 OSSFuzz https://oss-fuzz.com/testcase-detail/5517690440646656
973
+ # Bad assert() statement
974
+ #
975
+ reset_db
976
+ do_catchsql_test 32.0 {
977
+ CREATE TABLE t1(x);
978
+ CREATE TRIGGER r1 BEFORE INSERT ON t1 BEGIN
979
+ UPDATE t1 SET x=x FROM (SELECT*);
980
+ END;
981
+ ALTER TABLE t1 RENAME TO x;
982
+ } {1 {error in trigger r1: no tables specified}}
983
+
984
+ # 2023-04-13 https://sqlite.org/forum/forumpost/ff3840145a
985
+ #
986
+ reset_db
987
+ do_execsql_test 33.0 {
988
+ CREATE TABLE t1(a TEXT);
989
+ INSERT INTO t1(a) VALUES('abc'),('def'),(NULL);
990
+ CREATE TABLE t2(b TEXT);
991
+ CREATE TRIGGER r3 AFTER INSERT ON t1 BEGIN
992
+ UPDATE t2 SET (b,a)=(SELECT 1) FROM t1 JOIN t2 ON (SELECT * FROM (SELECT a));
993
+ END;
994
+ }
995
+ do_catchsql_test 33.1 {
996
+ ALTER TABLE t1 RENAME COLUMN a TO b;
997
+ } {1 {error in trigger r3 after rename: no such column: a}}
998
+ do_execsql_test 33.2 {
999
+ SELECT quote(a) FROM t1 ORDER BY +a;
1000
+ } {NULL 'abc' 'def'}
1001
+
1002
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/analyze.test ADDED
@@ -0,0 +1,399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2005 July 22
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library.
12
+ # This file implements tests for the ANALYZE command.
13
+ #
14
+ # $Id: analyze.test,v 1.9 2008/08/11 18:44:58 drh Exp $
15
+
16
+ set testdir [file dirname $argv0]
17
+ source $testdir/tester.tcl
18
+
19
+ # There is nothing to test if ANALYZE is disable for this build.
20
+ #
21
+ ifcapable {!analyze} {
22
+ finish_test
23
+ return
24
+ }
25
+
26
+ # Basic sanity checks.
27
+ #
28
+ do_test analyze-1.1 {
29
+ catchsql {
30
+ ANALYZE no_such_table
31
+ }
32
+ } {1 {no such table: no_such_table}}
33
+ do_test analyze-1.2 {
34
+ execsql {
35
+ SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1'
36
+ }
37
+ } {0}
38
+ do_test analyze-1.3 {
39
+ catchsql {
40
+ ANALYZE no_such_db.no_such_table
41
+ }
42
+ } {1 {unknown database no_such_db}}
43
+ do_test analyze-1.4 {
44
+ execsql {
45
+ SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1'
46
+ }
47
+ } {0}
48
+ do_test analyze-1.5.1 {
49
+ catchsql {
50
+ ANALYZE
51
+ }
52
+ } {0 {}}
53
+ do_test analyze-1.5.2 {
54
+ catchsql {
55
+ PRAGMA empty_result_callbacks=1;
56
+ ANALYZE
57
+ }
58
+ } {0 {}}
59
+ do_test analyze-1.6 {
60
+ execsql {
61
+ SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1'
62
+ }
63
+ } {1}
64
+ do_test analyze-1.6.2 {
65
+ catchsql {
66
+ CREATE INDEX stat1idx ON sqlite_stat1(idx);
67
+ }
68
+ } {1 {table sqlite_stat1 may not be indexed}}
69
+ do_test analyze-1.6.3 {
70
+ catchsql {
71
+ CREATE INDEX main.stat1idx ON SQLite_stat1(idx);
72
+ }
73
+ } {1 {table sqlite_stat1 may not be indexed}}
74
+ do_test analyze-1.7 {
75
+ execsql {
76
+ SELECT * FROM sqlite_stat1 WHERE idx NOT NULL
77
+ }
78
+ } {}
79
+ do_test analyze-1.8 {
80
+ catchsql {
81
+ ANALYZE main
82
+ }
83
+ } {0 {}}
84
+ do_test analyze-1.9 {
85
+ execsql {
86
+ SELECT * FROM sqlite_stat1 WHERE idx NOT NULL
87
+ }
88
+ } {}
89
+ do_test analyze-1.10 {
90
+ catchsql {
91
+ CREATE TABLE t1(a,b);
92
+ ANALYZE main.t1;
93
+ }
94
+ } {0 {}}
95
+ do_test analyze-1.11 {
96
+ execsql {
97
+ SELECT * FROM sqlite_stat1
98
+ }
99
+ } {}
100
+ do_test analyze-1.12 {
101
+ catchsql {
102
+ ANALYZE t1;
103
+ }
104
+ } {0 {}}
105
+ do_test analyze-1.13 {
106
+ execsql {
107
+ SELECT * FROM sqlite_stat1
108
+ }
109
+ } {}
110
+
111
+ # Create some indices that can be analyzed. But do not yet add
112
+ # data. Without data in the tables, no analysis is done.
113
+ #
114
+ do_test analyze-2.1 {
115
+ execsql {
116
+ CREATE INDEX t1i1 ON t1(a);
117
+ ANALYZE main.t1;
118
+ SELECT * FROM sqlite_stat1 ORDER BY idx;
119
+ }
120
+ } {}
121
+ do_test analyze-2.2 {
122
+ execsql {
123
+ CREATE INDEX t1i2 ON t1(b);
124
+ ANALYZE t1;
125
+ SELECT * FROM sqlite_stat1 ORDER BY idx;
126
+ }
127
+ } {}
128
+ do_test analyze-2.3 {
129
+ execsql {
130
+ CREATE INDEX t1i3 ON t1(a,b);
131
+ ANALYZE main;
132
+ SELECT * FROM sqlite_stat1 ORDER BY idx;
133
+ }
134
+ } {}
135
+
136
+ # Start adding data to the table. Verify that the analysis
137
+ # is done correctly.
138
+ #
139
+ do_test analyze-3.1 {
140
+ execsql {
141
+ INSERT INTO t1 VALUES(1,2);
142
+ INSERT INTO t1 VALUES(1,3);
143
+ ANALYZE main.t1;
144
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
145
+ }
146
+ } {t1i1 {2 2} t1i2 {2 1} t1i3 {2 2 1}}
147
+ do_test analyze-3.2 {
148
+ execsql {
149
+ INSERT INTO t1 VALUES(1,4);
150
+ INSERT INTO t1 VALUES(1,5);
151
+ ANALYZE t1;
152
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
153
+ }
154
+ } {t1i1 {4 4} t1i2 {4 1} t1i3 {4 4 1}}
155
+ do_test analyze-3.3 {
156
+ execsql {
157
+ INSERT INTO t1 VALUES(2,5);
158
+ ANALYZE main;
159
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
160
+ }
161
+ } {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1}}
162
+ do_test analyze-3.4 {
163
+ execsql {
164
+ CREATE TABLE t2 AS SELECT * FROM t1;
165
+ CREATE INDEX t2i1 ON t2(a);
166
+ CREATE INDEX t2i2 ON t2(b);
167
+ CREATE INDEX t2i3 ON t2(a,b);
168
+ ANALYZE;
169
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
170
+ }
171
+ } {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2} t2i3 {5 3 1}}
172
+ do_test analyze-3.5 {
173
+ execsql {
174
+ DROP INDEX t2i3;
175
+ ANALYZE t1;
176
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
177
+ }
178
+ } {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2}}
179
+ do_test analyze-3.6 {
180
+ execsql {
181
+ ANALYZE t2;
182
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
183
+ }
184
+ } {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2}}
185
+ do_test analyze-3.7 {
186
+ execsql {
187
+ DROP INDEX t2i2;
188
+ ANALYZE t2;
189
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
190
+ }
191
+ } {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3}}
192
+ do_test analyze-3.8 {
193
+ execsql {
194
+ CREATE TABLE t3 AS SELECT a, b, rowid AS c, 'hi' AS d FROM t1;
195
+ CREATE INDEX t3i1 ON t3(a);
196
+ CREATE INDEX t3i2 ON t3(a,b,c,d);
197
+ CREATE INDEX t3i3 ON t3(d,b,c,a);
198
+ DROP TABLE t1;
199
+ DROP TABLE t2;
200
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
201
+ }
202
+ } {}
203
+ do_test analyze-3.9 {
204
+ execsql {
205
+ ANALYZE;
206
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
207
+ }
208
+ } {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}}
209
+
210
+ do_test analyze-3.10 {
211
+ execsql {
212
+ CREATE TABLE [silly " name](a, b, c);
213
+ CREATE INDEX 'foolish '' name' ON [silly " name](a, b);
214
+ CREATE INDEX 'another foolish '' name' ON [silly " name](c);
215
+ INSERT INTO [silly " name] VALUES(1, 2, 3);
216
+ INSERT INTO [silly " name] VALUES(4, 5, 6);
217
+ ANALYZE;
218
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
219
+ }
220
+ } {{another foolish ' name} {2 1} {foolish ' name} {2 1 1} t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}}
221
+ do_test analyze-3.11 {
222
+ execsql {
223
+ DROP INDEX "foolish ' name";
224
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
225
+ }
226
+ } {{another foolish ' name} {2 1} t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}}
227
+ do_test analyze-3.11 {
228
+ execsql {
229
+ DROP TABLE "silly "" name";
230
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
231
+ }
232
+ } {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}}
233
+
234
+ # Try corrupting the sqlite_stat1 table and make sure the
235
+ # database is still able to function.
236
+ #
237
+ do_test analyze-4.0 {
238
+ sqlite3 db2 test.db
239
+ db2 eval {
240
+ CREATE TABLE t4(x,y,z);
241
+ CREATE INDEX t4i1 ON t4(x);
242
+ CREATE INDEX t4i2 ON t4(y);
243
+ INSERT INTO t4 SELECT a,b,c FROM t3;
244
+ }
245
+ db2 close
246
+ db close
247
+ sqlite3 db test.db
248
+ execsql {
249
+ ANALYZE;
250
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
251
+ }
252
+ } {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1} t4i1 {5 3} t4i2 {5 2}}
253
+ do_test analyze-4.1 {
254
+ execsql {
255
+ PRAGMA writable_schema=on;
256
+ INSERT INTO sqlite_stat1 VALUES(null,null,null);
257
+ PRAGMA writable_schema=off;
258
+ }
259
+ db close
260
+ sqlite3 db test.db
261
+ execsql {
262
+ SELECT * FROM t4 WHERE x=1234;
263
+ }
264
+ } {}
265
+ do_test analyze-4.2 {
266
+ execsql {
267
+ PRAGMA writable_schema=on;
268
+ DELETE FROM sqlite_stat1;
269
+ INSERT INTO sqlite_stat1 VALUES('t4','t4i1','nonsense');
270
+ INSERT INTO sqlite_stat1 VALUES('t4','t4i2','120897349817238741092873198273409187234918720394817209384710928374109827172901827349871928741910');
271
+ PRAGMA writable_schema=off;
272
+ }
273
+ db close
274
+ sqlite3 db test.db
275
+ execsql {
276
+ SELECT * FROM t4 WHERE x=1234;
277
+ }
278
+ } {}
279
+ do_test analyze-4.3 {
280
+ execsql {
281
+ INSERT INTO sqlite_stat1 VALUES('t4','xyzzy','0 1 2 3');
282
+ }
283
+ db close
284
+ sqlite3 db test.db
285
+ execsql {
286
+ SELECT * FROM t4 WHERE x=1234;
287
+ }
288
+ } {}
289
+
290
+ # Verify that DROP TABLE and DROP INDEX remove entries from the
291
+ # sqlite_stat1 and sqlite_stat4 tables.
292
+ #
293
+ do_test analyze-5.0 {
294
+ execsql {
295
+ DELETE FROM t3;
296
+ DELETE FROM t4;
297
+ INSERT INTO t3 VALUES(1,2,3,4);
298
+ INSERT INTO t3 VALUES(5,6,7,8);
299
+ INSERT INTO t3 SELECT a+8, b+8, c+8, d+8 FROM t3;
300
+ INSERT INTO t3 SELECT a+16, b+16, c+16, d+16 FROM t3;
301
+ INSERT INTO t3 SELECT a+32, b+32, c+32, d+32 FROM t3;
302
+ INSERT INTO t3 SELECT a+64, b+64, c+64, d+64 FROM t3;
303
+ INSERT INTO t4 SELECT a, b, c FROM t3;
304
+ ANALYZE;
305
+ SELECT DISTINCT idx FROM sqlite_stat1 ORDER BY 1;
306
+ SELECT DISTINCT tbl FROM sqlite_stat1 ORDER BY 1;
307
+ }
308
+ } {t3i1 t3i2 t3i3 t4i1 t4i2 t3 t4}
309
+ ifcapable stat4 {
310
+ do_test analyze-5.1 {
311
+ execsql {
312
+ SELECT DISTINCT idx FROM sqlite_stat4 ORDER BY 1;
313
+ SELECT DISTINCT tbl FROM sqlite_stat4 ORDER BY 1;
314
+ }
315
+ } {t3i1 t3i2 t3i3 t4i1 t4i2 t3 t4}
316
+ }
317
+ do_test analyze-5.2 {
318
+ execsql {
319
+ DROP INDEX t3i2;
320
+ SELECT DISTINCT idx FROM sqlite_stat1 ORDER BY 1;
321
+ SELECT DISTINCT tbl FROM sqlite_stat1 ORDER BY 1;
322
+ }
323
+ } {t3i1 t3i3 t4i1 t4i2 t3 t4}
324
+ ifcapable stat4 {
325
+ do_test analyze-5.3 {
326
+ execsql {
327
+ SELECT DISTINCT idx FROM sqlite_stat4 ORDER BY 1;
328
+ SELECT DISTINCT tbl FROM sqlite_stat4 ORDER BY 1;
329
+ }
330
+ } {t3i1 t3i3 t4i1 t4i2 t3 t4}
331
+ }
332
+ do_test analyze-5.4 {
333
+ execsql {
334
+ DROP TABLE t3;
335
+ SELECT DISTINCT idx FROM sqlite_stat1 ORDER BY 1;
336
+ SELECT DISTINCT tbl FROM sqlite_stat1 ORDER BY 1;
337
+ }
338
+ } {t4i1 t4i2 t4}
339
+ ifcapable stat4 {
340
+ do_test analyze-5.5 {
341
+ execsql {
342
+ SELECT DISTINCT idx FROM sqlite_stat4 ORDER BY 1;
343
+ SELECT DISTINCT tbl FROM sqlite_stat4 ORDER BY 1;
344
+ }
345
+ } {t4i1 t4i2 t4}
346
+ }
347
+
348
+ # This test corrupts the database file so it must be the last test
349
+ # in the series.
350
+ #
351
+ do_test analyze-5.99 {
352
+ sqlite3_db_config db DEFENSIVE 0
353
+ execsql {
354
+ PRAGMA writable_schema=on;
355
+ UPDATE sqlite_master SET sql='nonsense' WHERE name='sqlite_stat1';
356
+ }
357
+ db close
358
+ catch { sqlite3 db test.db }
359
+ catchsql {
360
+ ANALYZE
361
+ }
362
+ } {1 {malformed database schema (sqlite_stat1)}}
363
+
364
+ # Verify that tables whose names begin with "sqlite" but not
365
+ # "sqlite_" are analyzed.
366
+ #
367
+ db close
368
+ sqlite3 db :memory:
369
+ do_execsql_test analyze-6.1 {
370
+ CREATE TABLE sqliteDemo(a);
371
+ INSERT INTO sqliteDemo(a) VALUES(1),(2),(3),(4),(5);
372
+ CREATE TABLE SQLiteDemo2(a INTEGER PRIMARY KEY AUTOINCREMENT);
373
+ INSERT INTO SQLiteDemo2 SELECT * FROM sqliteDemo;
374
+ CREATE TABLE t1(b);
375
+ INSERT INTO t1(b) SELECT a FROM sqliteDemo;
376
+ ANALYZE;
377
+ SELECT tbl FROM sqlite_stat1 WHERE idx IS NULL ORDER BY tbl;
378
+ } {SQLiteDemo2 sqliteDemo t1}
379
+
380
+ # The following caused a small buffer overread in STAT4 processing prior
381
+ # to check-in [b99135288b157044].
382
+ #
383
+ ifcapable stat4 {
384
+ reset_db
385
+ database_may_be_corrupt
386
+ do_execsql_test analyze-7.1 {
387
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER);
388
+ INSERT INTO t1 VALUES(1, 7223372036854775);
389
+ INSERT INTO t1 VALUES(2, 7223372036854776);
390
+ INSERT INTO t1 VALUES(3, 7223372036854777);
391
+ CREATE INDEX i1 ON t1(b);
392
+ ANALYZE;
393
+ UPDATE sqlite_stat4 SET sample = substr(sample, 0, 4);
394
+ ANALYZE sqlite_schema;
395
+ SELECT * FROM t1 WHERE b>7223372036854775
396
+ } {2 7223372036854776 3 7223372036854777}
397
+ }
398
+
399
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/auth2.test ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2006 Aug 24
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this script is testing the sqlite3_set_authorizer() API
13
+ # and related functionality.
14
+ #
15
+ # $Id: auth2.test,v 1.3 2008/07/02 13:13:53 danielk1977 Exp $
16
+ #
17
+
18
+ set testdir [file dirname $argv0]
19
+ source $testdir/tester.tcl
20
+
21
+ # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
22
+ # defined during compilation.
23
+ if {[catch {db auth {}} msg]} {
24
+ finish_test
25
+ return
26
+ }
27
+
28
+ do_test auth2-1.1 {
29
+ execsql {
30
+ CREATE TABLE t1(a,b,c);
31
+ INSERT INTO t1 VALUES(1,2,3);
32
+ }
33
+ set ::flist {}
34
+ proc auth {code arg1 arg2 arg3 arg4 args} {
35
+ if {$code=="SQLITE_FUNCTION"} {
36
+ lappend ::flist $arg2
37
+ if {$arg2=="max"} {
38
+ return SQLITE_DENY
39
+ } elseif {$arg2=="min"} {
40
+ return SQLITE_IGNORE
41
+ } else {
42
+ return SQLITE_OK
43
+ }
44
+ }
45
+ return SQLITE_OK
46
+ }
47
+ db authorizer ::auth
48
+ catchsql {SELECT max(a,b,c) FROM t1}
49
+ } {1 {not authorized to use function: max}}
50
+ do_test auth2-1.2 {
51
+ set ::flist
52
+ } max
53
+ do_test auth2-1.3 {
54
+ set ::flist {}
55
+ catchsql {SELECT min(a,b,c) FROM t1}
56
+ } {0 {{}}}
57
+ do_test auth2-1.4 {
58
+ set ::flist
59
+ } min
60
+ do_test auth2-1.5 {
61
+ set ::flist {}
62
+ catchsql {SELECT coalesce(min(a,b,c),999) FROM t1}
63
+ } {0 999}
64
+ do_test auth2-1.6 {
65
+ set ::flist
66
+ } {coalesce min}
67
+ do_test auth2-1.7 {
68
+ set ::flist {}
69
+ catchsql {SELECT coalesce(a,b,c) FROM t1}
70
+ } {0 1}
71
+ do_test auth2-1.8 {
72
+ set ::flist
73
+ } coalesce
74
+
75
+ # Make sure the authorizer is not called when parsing the schema
76
+ # and when computing the result set of a view.
77
+ #
78
+ db close
79
+ sqlite3 db test.db
80
+ sqlite3 db2 test.db
81
+ proc auth {args} {
82
+ global authargs
83
+ append authargs [lrange $args 0 4]\n
84
+ return SQLITE_OK
85
+ }
86
+ db auth auth
87
+ do_test auth2-2.1 {
88
+ set ::authargs {}
89
+ db eval {
90
+ CREATE TABLE t2(x,y,z);
91
+ }
92
+ set ::authargs
93
+ } {SQLITE_INSERT sqlite_master {} main {}
94
+ SQLITE_CREATE_TABLE t2 {} main {}
95
+ SQLITE_UPDATE sqlite_master type main {}
96
+ SQLITE_UPDATE sqlite_master name main {}
97
+ SQLITE_UPDATE sqlite_master tbl_name main {}
98
+ SQLITE_UPDATE sqlite_master rootpage main {}
99
+ SQLITE_UPDATE sqlite_master sql main {}
100
+ SQLITE_READ sqlite_master ROWID main {}
101
+ }
102
+ do_test auth2-2.2 {
103
+ set ::authargs {}
104
+ db eval {
105
+ CREATE VIEW v2 AS SELECT x+y AS a, y+z AS b from t2;
106
+ }
107
+ set ::authargs
108
+ } {SQLITE_INSERT sqlite_master {} main {}
109
+ SQLITE_CREATE_VIEW v2 {} main {}
110
+ SQLITE_UPDATE sqlite_master type main {}
111
+ SQLITE_UPDATE sqlite_master name main {}
112
+ SQLITE_UPDATE sqlite_master tbl_name main {}
113
+ SQLITE_UPDATE sqlite_master rootpage main {}
114
+ SQLITE_UPDATE sqlite_master sql main {}
115
+ SQLITE_READ sqlite_master ROWID main {}
116
+ }
117
+ do_test auth2-2.3 {
118
+ set ::authargs {}
119
+ db eval {
120
+ SELECT a, b FROM v2;
121
+ }
122
+ set ::authargs
123
+ } {SQLITE_SELECT {} {} {} {}
124
+ SQLITE_READ t2 x main v2
125
+ SQLITE_READ t2 y main v2
126
+ SQLITE_READ t2 y main v2
127
+ SQLITE_READ t2 z main v2
128
+ SQLITE_READ v2 a main {}
129
+ SQLITE_READ v2 b main {}
130
+ SQLITE_SELECT {} {} {} v2
131
+ }
132
+ do_test auth2-2.4 {
133
+ db2 eval {
134
+ CREATE TABLE t3(p,q,r);
135
+ }
136
+ set ::authargs {}
137
+ db eval {
138
+ SELECT b, a FROM v2;
139
+ }
140
+ set ::authargs
141
+ } {SQLITE_SELECT {} {} {} {}
142
+ SQLITE_READ t2 x main v2
143
+ SQLITE_READ t2 y main v2
144
+ SQLITE_READ t2 y main v2
145
+ SQLITE_READ t2 z main v2
146
+ SQLITE_READ v2 b main {}
147
+ SQLITE_READ v2 a main {}
148
+ SQLITE_SELECT {} {} {} v2
149
+ SQLITE_SELECT {} {} {} {}
150
+ SQLITE_READ t2 x main v2
151
+ SQLITE_READ t2 y main v2
152
+ SQLITE_READ t2 y main v2
153
+ SQLITE_READ t2 z main v2
154
+ SQLITE_READ v2 b main {}
155
+ SQLITE_READ v2 a main {}
156
+ SQLITE_SELECT {} {} {} v2
157
+ }
158
+ db2 close
159
+
160
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/autoindex2.test ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2014-06-17
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #*************************************************************************
11
+ #
12
+ # This file implements regression tests for SQLite library. The
13
+ # focus of this script is testing automatic index creation logic.
14
+ #
15
+ # This file contains a single real-world test case that was giving
16
+ # suboptimal performance because of over-use of automatic indexes.
17
+ #
18
+
19
+ set testdir [file dirname $argv0]
20
+ source $testdir/tester.tcl
21
+
22
+
23
+ do_execsql_test autoindex2-100 {
24
+ CREATE TABLE t1(
25
+ t1_id largeint,
26
+ did char(9),
27
+ ptime largeint,
28
+ exbyte char(4),
29
+ pe_id int,
30
+ field_id int,
31
+ mass float,
32
+ param10 float,
33
+ param11 float,
34
+ exmass float,
35
+ deviation float,
36
+ trange float,
37
+ vstatus int,
38
+ commit_status int,
39
+ formula char(329),
40
+ tier int DEFAULT 2,
41
+ ssid int DEFAULT 0,
42
+ last_operation largeint DEFAULT 0,
43
+ admin_uuid int DEFAULT 0,
44
+ previous_value float,
45
+ job_id largeint,
46
+ last_t1 largeint DEFAULT 0,
47
+ data_t1 int,
48
+ previous_date largeint DEFAULT 0,
49
+ flg8 int DEFAULT 1,
50
+ failed_fields char(100)
51
+ );
52
+ CREATE INDEX t1x0 on t1 (t1_id);
53
+ CREATE INDEX t1x1 on t1 (ptime, vstatus);
54
+ CREATE INDEX t1x2 on t1 (did, ssid, ptime, vstatus, exbyte, t1_id);
55
+ CREATE INDEX t1x3 on t1 (job_id);
56
+
57
+ CREATE TABLE t2(
58
+ did char(9),
59
+ client_did char(30),
60
+ description char(49),
61
+ uid int,
62
+ tzid int,
63
+ privilege int,
64
+ param2 int,
65
+ type char(30),
66
+ subtype char(32),
67
+ dparam1 char(7) DEFAULT '',
68
+ param5 char(3) DEFAULT '',
69
+ notional float DEFAULT 0.000000,
70
+ create_time largeint,
71
+ sample_time largeint DEFAULT 0,
72
+ param6 largeint,
73
+ frequency int,
74
+ expiration largeint,
75
+ uw_status int,
76
+ next_sample largeint,
77
+ last_sample largeint,
78
+ reserve1 char(29) DEFAULT '',
79
+ reserve2 char(29) DEFAULT '',
80
+ reserve3 char(29) DEFAULT '',
81
+ bxcdr char(19) DEFAULT 'XY',
82
+ ssid int DEFAULT 1,
83
+ last_t1_id largeint,
84
+ reserve4 char(29) DEFAULT '',
85
+ reserve5 char(29) DEFAULT '',
86
+ param12 int DEFAULT 0,
87
+ long_did char(100) DEFAULT '',
88
+ gr_code int DEFAULT 0,
89
+ drx char(100) DEFAULT '',
90
+ parent_id char(9) DEFAULT '',
91
+ param13 int DEFAULT 0,
92
+ position float DEFAULT 1.000000,
93
+ client_did3 char(100) DEFAULT '',
94
+ client_did4 char(100) DEFAULT '',
95
+ dlib_id char(9) DEFAULT ''
96
+ );
97
+ CREATE INDEX t2x0 on t2 (did);
98
+ CREATE INDEX t2x1 on t2 (client_did);
99
+ CREATE INDEX t2x2 on t2 (long_did);
100
+ CREATE INDEX t2x3 on t2 (uid);
101
+ CREATE INDEX t2x4 on t2 (param2);
102
+ CREATE INDEX t2x5 on t2 (type);
103
+ CREATE INDEX t2x6 on t2 (subtype);
104
+ CREATE INDEX t2x7 on t2 (last_sample);
105
+ CREATE INDEX t2x8 on t2 (param6);
106
+ CREATE INDEX t2x9 on t2 (frequency);
107
+ CREATE INDEX t2x10 on t2 (privilege);
108
+ CREATE INDEX t2x11 on t2 (sample_time);
109
+ CREATE INDEX t2x12 on t2 (notional);
110
+ CREATE INDEX t2x13 on t2 (tzid);
111
+ CREATE INDEX t2x14 on t2 (gr_code);
112
+ CREATE INDEX t2x15 on t2 (parent_id);
113
+
114
+ CREATE TABLE t3(
115
+ uid int,
116
+ param3 int,
117
+ uuid int,
118
+ acc_id int,
119
+ cust_num int,
120
+ numerix_id int,
121
+ pfy char(29),
122
+ param4 char(29),
123
+ param15 int DEFAULT 0,
124
+ flg7 int DEFAULT 0,
125
+ param21 int DEFAULT 0,
126
+ bxcdr char(2) DEFAULT 'PC',
127
+ c31 int DEFAULT 0,
128
+ c33 int DEFAULT 0,
129
+ c35 int DEFAULT 0,
130
+ c37 int,
131
+ mgr_uuid int,
132
+ back_up_uuid int,
133
+ priv_mars int DEFAULT 0,
134
+ is_qc int DEFAULT 0,
135
+ c41 int DEFAULT 0,
136
+ deleted int DEFAULT 0,
137
+ c47 int DEFAULT 1
138
+ );
139
+ CREATE INDEX t3x0 on t3 (uid);
140
+ CREATE INDEX t3x1 on t3 (param3);
141
+ CREATE INDEX t3x2 on t3 (uuid);
142
+ CREATE INDEX t3x3 on t3 (acc_id);
143
+ CREATE INDEX t3x4 on t3 (param4);
144
+ CREATE INDEX t3x5 on t3 (pfy);
145
+ CREATE INDEX t3x6 on t3 (is_qc);
146
+ SELECT count(*) FROM sqlite_master;
147
+ } {30}
148
+ do_execsql_test autoindex2-110 {
149
+ ANALYZE sqlite_master;
150
+ INSERT INTO sqlite_stat1 VALUES('t1','t1x3','10747267 260');
151
+ INSERT INTO sqlite_stat1 VALUES('t1','t1x2','10747267 121 113 2 2 2 1');
152
+ INSERT INTO sqlite_stat1 VALUES('t1','t1x1','10747267 50 40');
153
+ INSERT INTO sqlite_stat1 VALUES('t1','t1x0','10747267 1');
154
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x15','39667 253');
155
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x14','39667 19834');
156
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x13','39667 13223');
157
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x12','39667 7');
158
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x11','39667 17');
159
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x10','39667 19834');
160
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x9','39667 7934');
161
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x8','39667 11');
162
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x7','39667 5');
163
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x6','39667 242');
164
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x5','39667 1984');
165
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x4','39667 4408');
166
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x3','39667 81');
167
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x2','39667 551');
168
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x1','39667 2');
169
+ INSERT INTO sqlite_stat1 VALUES('t2','t2x0','39667 1');
170
+ INSERT INTO sqlite_stat1 VALUES('t3','t3x6','569 285');
171
+ INSERT INTO sqlite_stat1 VALUES('t3','t3x5','569 2');
172
+ INSERT INTO sqlite_stat1 VALUES('t3','t3x4','569 2');
173
+ INSERT INTO sqlite_stat1 VALUES('t3','t3x3','569 5');
174
+ INSERT INTO sqlite_stat1 VALUES('t3','t3x2','569 3');
175
+ INSERT INTO sqlite_stat1 VALUES('t3','t3x1','569 6');
176
+ INSERT INTO sqlite_stat1 VALUES('t3','t3x0','569 1');
177
+ ANALYZE sqlite_master;
178
+ } {}
179
+ do_execsql_test autoindex2-120 {
180
+ EXPLAIN QUERY PLAN
181
+ SELECT
182
+ t1_id,
183
+ t1.did,
184
+ param2,
185
+ param3,
186
+ t1.ptime,
187
+ t1.trange,
188
+ t1.exmass,
189
+ t1.mass,
190
+ t1.vstatus,
191
+ type,
192
+ subtype,
193
+ t1.deviation,
194
+ t1.formula,
195
+ dparam1,
196
+ reserve1,
197
+ reserve2,
198
+ param4,
199
+ t1.last_operation,
200
+ t1.admin_uuid,
201
+ t1.previous_value,
202
+ t1.job_id,
203
+ client_did,
204
+ t1.last_t1,
205
+ t1.data_t1,
206
+ t1.previous_date,
207
+ param5,
208
+ param6,
209
+ mgr_uuid
210
+ FROM
211
+ t1,
212
+ t2,
213
+ t3
214
+ WHERE
215
+ t1.ptime > 1393520400
216
+ AND param3<>9001
217
+ AND t3.flg7 = 1
218
+ AND t1.did = t2.did
219
+ AND t2.uid = t3.uid
220
+ ORDER BY t1.ptime desc LIMIT 500;
221
+ } {~/AUTO/}
222
+ #
223
+ # ^^^--- Before being fixed, the above was using an automatic covering
224
+ # on t3 and reordering the tables so that t3 was in the outer loop and
225
+ # implementing the ORDER BY clause using a B-Tree.
226
+ #
227
+ # This test is sanitized data received from a user. The original unsanitized
228
+ # data and STAT4 data is found in the th3private test repository. See one of
229
+ # the th3private check-ins on 2016-02-25. The test is much more accurate when
230
+ # STAT4 data is used.
231
+
232
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/bestindexB.test ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2023-10-26
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ #
13
+
14
+ set testdir [file dirname $argv0]
15
+ source $testdir/tester.tcl
16
+ set testprefix bestindexB
17
+
18
+ ifcapable !vtab {
19
+ finish_test
20
+ return
21
+ }
22
+
23
+ register_tcl_module db
24
+
25
+ proc vtab_command {method args} {
26
+ switch -- $method {
27
+ xConnect {
28
+ return "CREATE TABLE t1(a, b, c)"
29
+ }
30
+
31
+ xBestIndex {
32
+ set hdl [lindex $args 0]
33
+ set clist [$hdl constraints]
34
+ set orderby [$hdl orderby]
35
+
36
+ if {[info exists ::xbestindex_sql]} {
37
+ explain_i $::xbestindex_sql
38
+ set ::xbestindex_res [ execsql $::xbestindex_sql ]
39
+ }
40
+
41
+ return "cost 1000000 rows 1000000 idxnum 0 idxstr hello"
42
+ }
43
+
44
+ xFilter {
45
+ return "sql {SELECT 0, 1, 2, 3}"
46
+ }
47
+ }
48
+
49
+ return {}
50
+ }
51
+
52
+ do_execsql_test 1.0 {
53
+ CREATE VIRTUAL TABLE x1 USING tcl(vtab_command);
54
+ CREATE TABLE y1(a, b);
55
+ CREATE TABLE y2(a, b);
56
+ } {}
57
+
58
+ do_execsql_test 1.1 {
59
+ SELECT * FROM x1
60
+ } {1 2 3}
61
+
62
+ do_execsql_test 1.2 {
63
+ INSERT INTO y1 VALUES(1, 2) RETURNING rowid;
64
+ } {1}
65
+
66
+ do_execsql_test 1.3 {
67
+ CREATE TRIGGER y1tr BEFORE INSERT ON y1 BEGIN
68
+ SELECT * FROM x1;
69
+ END;
70
+ INSERT INTO y1 VALUES(3, 4) RETURNING rowid;
71
+ } {2}
72
+
73
+
74
+ # This time, rig the xBestIndex() method of the vtab to invoke an SQL
75
+ # statement that uses RETURNING.
76
+ set ::xbestindex_sql {
77
+ INSERT INTO y2 VALUES(NULL, NULL) RETURNING rowid;
78
+ }
79
+ do_execsql_test 1.4 {
80
+ INSERT INTO y1 VALUES(5, 6) RETURNING rowid;
81
+ } {3}
82
+
83
+ do_test 1.5 {
84
+ set ::xbestindex_res
85
+ } {1}
86
+
87
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/bestindexC.test ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2024-04-26
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ #
13
+
14
+ set testdir [file dirname $argv0]
15
+ source $testdir/tester.tcl
16
+ set testprefix bestindexC
17
+
18
+ ifcapable !vtab {
19
+ finish_test
20
+ return
21
+ }
22
+
23
+ register_tcl_module db
24
+
25
+ proc vtab_command {lVal method args} {
26
+ switch -- $method {
27
+ xConnect {
28
+ return "CREATE TABLE t1(a)"
29
+ }
30
+
31
+ xBestIndex {
32
+ set hdl [lindex $args 0]
33
+ set clist [$hdl constraints]
34
+ set orderby [$hdl orderby]
35
+
36
+ set idxstr [list]
37
+ set res [list]
38
+
39
+ set idx 0
40
+ foreach c $clist {
41
+ array set a $c
42
+ if {$a(usable)==0} continue
43
+ if {$a(op)=="limit" && ![info exists ::do_not_use_limit]} {
44
+ lappend idxstr limit
45
+ lappend res omit $idx
46
+ }
47
+ if {$a(op)=="offset" && ![info exists ::do_not_use_offset]} {
48
+ lappend idxstr offset
49
+ lappend res omit $idx
50
+ }
51
+ incr idx
52
+ }
53
+
54
+ return "cost 1000000 rows 1000000 idxnum 0 idxstr {$idxstr} $res"
55
+ }
56
+
57
+ xFilter {
58
+ set idxstr [lindex $args 1]
59
+ set LIMIT ""
60
+ foreach a $idxstr b [lindex $args 2] {
61
+ set x($a) $b
62
+ }
63
+
64
+ if {![info exists x(limit)]} { set x(limit) -1 }
65
+ if {![info exists x(offset)]} { set x(offset) -1 }
66
+ set LIMIT " LIMIT $x(limit) OFFSET $x(offset)"
67
+
68
+ set idx 1
69
+ foreach v $lVal {
70
+ lappend lRow "($idx, '$v')"
71
+ incr idx
72
+ }
73
+
74
+ return [list sql "
75
+ SELECT * FROM ( VALUES [join $lRow ,]) $LIMIT
76
+ "]
77
+ }
78
+ }
79
+
80
+ return {}
81
+ }
82
+
83
+ do_execsql_test 1.0 {
84
+ CREATE VIRTUAL TABLE x1 USING tcl(vtab_command "a b c d e f");
85
+ CREATE VIRTUAL TABLE x2 USING tcl(vtab_command "A B C D E F a b");
86
+ } {}
87
+
88
+ do_execsql_test 1.1 {
89
+ CREATE TEMP TABLE t_unionall AS
90
+ SELECT * FROM x1 UNION ALL SELECT * FROM x2;
91
+
92
+ CREATE TEMP TABLE t_intersect AS
93
+ SELECT * FROM x1 INTERSECT SELECT * FROM x2;
94
+
95
+ CREATE TEMP TABLE t_union AS
96
+ SELECT * FROM x1 UNION SELECT * FROM x2;
97
+
98
+ CREATE TEMP TABLE t_except AS
99
+ SELECT * FROM x1 EXCEPT SELECT * FROM x2;
100
+ }
101
+
102
+ foreach {tn limit} {
103
+ 1 "LIMIT 8"
104
+ 2 "LIMIT 4"
105
+ 3 "LIMIT 4 OFFSET 2"
106
+ 4 "LIMIT 8 OFFSET 4"
107
+ } {
108
+
109
+ foreach {op tbl} {
110
+ "UNION ALL" t_unionall
111
+ "UNION" t_union
112
+ "INTERSECT" t_intersect
113
+ "EXCEPT" t_except
114
+ } {
115
+
116
+ set expect [execsql "SELECT * FROM $tbl $limit"]
117
+ do_execsql_test 1.2.$tbl.$tn "SELECT * FROM (
118
+ SELECT * FROM x1 $op SELECT * FROM x2
119
+ ) $limit" $expect
120
+
121
+ }
122
+
123
+ }
124
+
125
+ #-------------------------------------------------------------------------
126
+ reset_db
127
+ register_tcl_module db
128
+
129
+ do_execsql_test 2.0 {
130
+ CREATE VIRTUAL TABLE x1 USING tcl(vtab_command "a b c d e f");
131
+ CREATE VIRTUAL TABLE x2 USING tcl(vtab_command "a b e f");
132
+ } {}
133
+
134
+ do_execsql_test 2.1 {
135
+ SELECT * FROM x1
136
+ EXCEPT
137
+ SELECT * FROM x2
138
+ LIMIT 3
139
+ } {c d}
140
+
141
+ #-------------------------------------------------------------------------
142
+ reset_db
143
+ register_tcl_module db
144
+ do_execsql_test 3.0 {
145
+ CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "1 2 3 4 5 6 7 8 9 10");
146
+ } {}
147
+
148
+ do_execsql_test 3.1 {
149
+ SELECT * FROM y1 WHERE a = COALESCE('8', a) LIMIT 3
150
+ } {8}
151
+
152
+ do_execsql_test 3.2 {
153
+ SELECT * FROM y1 WHERE a = '2' LIMIT 3
154
+ } {2}
155
+
156
+ load_static_extension db series
157
+ do_execsql_test 3.3 {
158
+ SELECT * FROM generate_series(1, 5) WHERE value = (value & 14) LIMIT 3
159
+ } {2 4}
160
+
161
+ do_execsql_test 3.4 {
162
+ SELECT value FROM generate_series(1,10) WHERE value>2 LIMIT 4 OFFSET 1;
163
+ } {4 5 6 7}
164
+
165
+ set ::do_not_use_limit 1
166
+ do_execsql_test 3.5 {
167
+ SELECT * FROM y1 LIMIT 5 OFFSET 3
168
+ } {4 5 6 7 8}
169
+ unset ::do_not_use_limit
170
+ set ::do_not_use_offset 1
171
+ do_execsql_test 3.6 {
172
+ SELECT * FROM y1 LIMIT 5 OFFSET 3
173
+ } {4 5 6 7 8}
174
+ unset ::do_not_use_offset
175
+
176
+ #-------------------------------------------------------------------------
177
+ reset_db
178
+ proc vtab_command {lVal method args} {
179
+ switch -- $method {
180
+ xConnect { error "not happy!" }
181
+ }
182
+
183
+ return {}
184
+ }
185
+
186
+ register_tcl_module db
187
+ do_catchsql_test 4.0 {
188
+ CREATE VIRTUAL TABLE y1 USING tcl(vtab_command 1);
189
+ } {1 {not happy!}}
190
+ do_test 4.1 {
191
+ sqlite3_errcode db
192
+ } SQLITE_ERROR
193
+
194
+ proc vtab_command {lVal method args} {
195
+ switch -- $method {
196
+ xConnect {
197
+ return $lVal
198
+ }
199
+ }
200
+ return {}
201
+ }
202
+
203
+ do_catchsql_test 4.2 {
204
+ CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "PRAGMA page_size=1024");
205
+ } {1 {declare_vtab: syntax error}}
206
+ do_catchsql_test 4.3 {
207
+ CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "CREATE TABLE x1(");
208
+ } {1 {declare_vtab: incomplete input}}
209
+ do_catchsql_test 4.4 {
210
+ CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "CREATE TABLE x1(insert)");
211
+ } {1 {declare_vtab: near "insert": syntax error}}
212
+
213
+ #-------------------------------------------------------------------------
214
+ reset_db
215
+ register_tcl_module db
216
+
217
+ proc quote {str} {
218
+ return "'[string map {' ''} $str]'"
219
+ }
220
+
221
+ proc vtab_command {lVal method args} {
222
+ switch -- $method {
223
+ xConnect {
224
+ return "CREATE TABLE t1(a, b, c, d)"
225
+ }
226
+
227
+ xBestIndex {
228
+ set hdl [lindex $args 0]
229
+ set clist [$hdl constraints]
230
+
231
+ set res [list]
232
+ set idx 0
233
+ set idxnum 0
234
+
235
+ set cols(0) a
236
+ set cols(1) b
237
+ set cols(2) c
238
+
239
+ set lCons [list]
240
+
241
+ foreach c $clist {
242
+ array set a $c
243
+ if {$a(usable)==0} continue
244
+
245
+ if {($a(op)=="eq" || $a(op)=="is") && [info exists cols($a(column))]} {
246
+ lappend res omit $idx
247
+ set coll [$hdl collation $idx]
248
+ lappend lCons "$cols($a(column)) = %[llength $lCons]% COLLATE $coll"
249
+
250
+ set idxnum [expr {$idx + (1 << $a(column))}]
251
+ catch { unset cols($a(column)) }
252
+ }
253
+
254
+ incr idx
255
+ }
256
+
257
+ if {[llength [array names cols]]>0} {
258
+ set missing [list]
259
+ for {set i 0} {$i < 3} {incr i} {
260
+ catch { lappend missing $cols($i) }
261
+ }
262
+ set msg "missing required constraints: [join $missing ,]"
263
+ return [list constraint $msg]
264
+ }
265
+
266
+ set idxstr [join $lCons " AND "]
267
+ return "cost 1000 rows 1000 idxnum $idxnum $res idxstr {$idxstr}"
268
+ }
269
+
270
+ xFilter {
271
+ foreach {idxnum idxstr lArg} $args {}
272
+ set i 0
273
+ set where $idxstr
274
+ foreach a $lArg {
275
+ set where [string map [list %$i% [quote $a]] $where]
276
+ incr i
277
+ }
278
+ # puts $where
279
+ return [list sql "SELECT rowid, * FROM $lVal WHERE $where"]
280
+ }
281
+ }
282
+
283
+ return {}
284
+ }
285
+
286
+ do_execsql_test 5.1 {
287
+ CREATE VIRTUAL TABLE x1 USING tcl(vtab_command t1);
288
+ CREATE TABLE t1(a, b, c, d);
289
+ }
290
+
291
+ foreach {tn where ok} {
292
+ 0 "WHERE a=? AND b=? AND c=? AND c=?" 1
293
+ 1 "WHERE a=? AND b=? AND c=?" 1
294
+ 2 "WHERE a=? AND b=? AND (c=? OR c=?)" 1
295
+ 3 "WHERE a=? AND b=? AND (c=? OR c=? OR c=?)" 1
296
+ 4 "WHERE a=? AND b=? AND (c IS ? OR c IS ?)" 1
297
+ 5 "WHERE a=? AND ((b=? AND c=?) OR (c=? AND b=?))" 1
298
+ 6 "WHERE a=? AND ((b=? AND c=?) OR (c=?))" 0
299
+ } {
300
+ do_test 5.2.$tn {
301
+ catch { execsql "SELECT * FROM x1 $::where" } msg
302
+ # if {$tn==0 || $tn==2 || $tn==3} { puts "MSG: $msg" }
303
+ } [expr !$ok]
304
+ }
305
+
306
+ do_execsql_test 5.3 {
307
+ SELECT * FROM x1 WHERE (a, b, c) = (?, ?, ?);
308
+ }
309
+
310
+ do_execsql_test 5.4 {
311
+ INSERT INTO t1(rowid, a, b, c, d) VALUES(1, 'x', 'y', 'z', 'one');
312
+ INSERT INTO t1(rowid, a, b, c, d) VALUES(2, 'X', 'Y', 'Z', 'two');
313
+ SELECT * FROM x1 WHERE (a, b, c) = ('X', 'Y', 'Z');
314
+ } {X Y Z two}
315
+ do_execsql_test 5.5 {
316
+ SELECT * FROM x1 WHERE a='x' AND b='y' AND c='z';
317
+ } {x y z one}
318
+ do_execsql_test 5.6 {
319
+ SELECT * FROM x1
320
+ WHERE a='x' COLLATE nocase AND b='y' COLLATE nocase AND c='z'COLLATE nocase;
321
+ } {x y z one X Y Z two}
322
+
323
+ do_execsql_test 5.7 {
324
+ DELETE FROM t1;
325
+
326
+ INSERT INTO t1(rowid, a, b, c, d) VALUES(0, 'x', 'y', 'z', 'zero');
327
+ INSERT INTO t1(rowid, a, b, c, d) VALUES(1, 'x', 'y', 'Z', 'one');
328
+ INSERT INTO t1(rowid, a, b, c, d) VALUES(2, 'x', 'Y', 'z', 'two');
329
+ INSERT INTO t1(rowid, a, b, c, d) VALUES(3, 'x', 'Y', 'Z', 'three');
330
+ INSERT INTO t1(rowid, a, b, c, d) VALUES(4, 'X', 'y', 'z', 'four');
331
+ INSERT INTO t1(rowid, a, b, c, d) VALUES(5, 'X', 'y', 'Z', 'five');
332
+ INSERT INTO t1(rowid, a, b, c, d) VALUES(6, 'X', 'Y', 'z', 'six');
333
+ INSERT INTO t1(rowid, a, b, c, d) VALUES(7, 'X', 'Y', 'z', 'seven');
334
+ }
335
+
336
+ do_execsql_test 5.8 {
337
+ SELECT d FROM x1
338
+ WHERE a='x' AND ((b='y' AND c='z') OR (b='Y' AND c='z' COLLATE nocase))
339
+ } {
340
+ zero two three
341
+ }
342
+
343
+ do_execsql_test 5.9 {
344
+ SELECT d FROM x1
345
+ WHERE a='x' COLLATE nocase
346
+ AND ((b='y' AND c='z') OR (b='Y' AND c='z' COLLATE nocase))
347
+ } {
348
+ zero four two
349
+ three six seven
350
+ }
351
+
352
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/bloom1.test ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2022 October 06
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # Tests for queries that use bloom filters
13
+
14
+ set testdir [file dirname $argv0]
15
+ source $testdir/tester.tcl
16
+ source $testdir/lock_common.tcl
17
+ source $testdir/malloc_common.tcl
18
+
19
+ set testprefix bloom1
20
+
21
+ # Tests 1.* verify that the bloom filter code correctly handles the
22
+ # case where the RHS of an (<ipk-column> = ?) expression must be coerced
23
+ # to an integer before the comparison made.
24
+ #
25
+ do_execsql_test 1.0 {
26
+ CREATE TABLE t1(a, b);
27
+ CREATE TABLE t2(c INTEGER PRIMARY KEY, d);
28
+ }
29
+
30
+ do_execsql_test 1.1 {
31
+ INSERT INTO t1 VALUES('hello', 'world');
32
+ INSERT INTO t2 VALUES(14, 'fourteen');
33
+ }
34
+
35
+ do_execsql_test 1.2 {
36
+ ANALYZE sqlite_schema;
37
+ INSERT INTO sqlite_stat1 VALUES('t2','idx1','6 6');
38
+ ANALYZE sqlite_schema;
39
+ }
40
+
41
+ do_execsql_test 1.3 {
42
+ SELECT 'affinity!' FROM t1 CROSS JOIN t2 WHERE t2.c = '14';
43
+ } {affinity!}
44
+
45
+
46
+ reset_db
47
+ do_execsql_test 1.4 {
48
+ CREATE TABLE t1(a, b TEXT);
49
+ CREATE TABLE t2(c INTEGER PRIMARY KEY, d);
50
+ CREATE TABLE t3(e INTEGER PRIMARY KEY, f);
51
+
52
+ ANALYZE sqlite_schema;
53
+ INSERT INTO sqlite_stat1 VALUES('t1','idx1','600 6');
54
+ INSERT INTO sqlite_stat1 VALUES('t2','idx1','6 6');
55
+ INSERT INTO sqlite_stat1 VALUES('t3','idx2','6 6');
56
+ ANALYZE sqlite_schema;
57
+
58
+ INSERT INTO t1 VALUES(1, '123');
59
+ INSERT INTO t2 VALUES(123, 'one');
60
+ INSERT INTO t3 VALUES(123, 'two');
61
+ }
62
+
63
+ do_execsql_test 1.5 {
64
+ SELECT 'result' FROM t1, t2, t3
65
+ WHERE t2.c=t1.b AND t2.d!='silly'
66
+ AND t3.e=t1.b AND t3.f!='silly'
67
+ } {result}
68
+
69
+ # 2023-02-05
70
+ # https://sqlite.org/forum/forumpost/56de336385
71
+ #
72
+ # Do not employ a Bloom filter if the table being filtered or any table
73
+ # wo the left of the table being filtered lacks STAT1 data, since we
74
+ # cannot make a good Bloom filter usefulness determination without STAT1
75
+ # data.
76
+ #
77
+ reset_db
78
+ do_execsql_test 2.0 {
79
+ CREATE TABLE objs(c INTEGER, s INTEGER, p INTEGER, o INTEGER);
80
+ CREATE UNIQUE INDEX objs_cspo ON objs(o,p,c,s);
81
+ ANALYZE;
82
+ DELETE FROM sqlite_stat1;
83
+ INSERT INTO sqlite_stat1 VALUES('objs','objs_cspo','520138 21 20 19 1');
84
+ ANALYZE sqlite_schema;
85
+ }
86
+ do_eqp_test 2.1 {
87
+ WITH RECURSIVE transit(x) AS (
88
+ SELECT s FROM objs WHERE p=9 AND o=32805
89
+ UNION
90
+ SELECT objs.s FROM objs, transit WHERE objs.p=9 AND objs.o=transit.x
91
+ )
92
+ SELECT x FROM transit;
93
+ } {
94
+ QUERY PLAN
95
+ |--CO-ROUTINE transit
96
+ | |--SETUP
97
+ | | `--SEARCH objs USING COVERING INDEX objs_cspo (o=? AND p=?)
98
+ | `--RECURSIVE STEP
99
+ | |--SCAN transit
100
+ | `--SEARCH objs USING COVERING INDEX objs_cspo (o=? AND p=?)
101
+ `--SCAN transit
102
+ }
103
+
104
+ # 2023-02-28
105
+ # https://sqlite.org/forum/forumpost/0846211821
106
+ #
107
+ # Bloom filter gives an incorrect result if the collating sequence is
108
+ # anything other than binary.
109
+ #
110
+ reset_db
111
+ do_execsql_test 3.1 {
112
+ CREATE TABLE t0(x TEXT COLLATE rtrim);
113
+ INSERT INTO t0(x) VALUES ('a'), ('b'), ('c');
114
+ CREATE VIEW v0(y) AS SELECT DISTINCT x FROM t0;
115
+ SELECT count(*) FROM t0, v0 WHERE x='b ';
116
+ } 3
117
+ do_eqp_test 3.2 {
118
+ SELECT count(*) FROM t0, v0 WHERE x='b ';
119
+ } {
120
+ QUERY PLAN
121
+ |--CO-ROUTINE v0
122
+ | |--SCAN t0
123
+ | `--USE TEMP B-TREE FOR DISTINCT
124
+ |--SCAN v0
125
+ `--SEARCH t0 USING AUTOMATIC PARTIAL COVERING INDEX (x=?)
126
+ }
127
+ # ^^^^^--- The key feature in the previous result is that no Bloom filter
128
+ # is used. In the following, a Bloom filter is used because the data type
129
+ # is INT instead of TEXT.
130
+ do_execsql_test 3.3 {
131
+ CREATE TABLE t1(x INT COLLATE rtrim);
132
+ INSERT INTO t1(x) VALUES ('a'), ('b'), ('c');
133
+ CREATE VIEW v1(y) AS SELECT DISTINCT x FROM t1;
134
+ SELECT count(*) FROM t1, v1 WHERE x='b ';
135
+ } 3
136
+ do_eqp_test 3.4 {
137
+ SELECT count(*) FROM t1, v1 WHERE x='b ';
138
+ } {
139
+ QUERY PLAN
140
+ |--CO-ROUTINE v1
141
+ | |--SCAN t1
142
+ | `--USE TEMP B-TREE FOR DISTINCT
143
+ |--SCAN v1
144
+ |--BLOOM FILTER ON t1 (x=?)
145
+ `--SEARCH t1 USING AUTOMATIC PARTIAL COVERING INDEX (x=?)
146
+ }
147
+
148
+ # 2023-03-14
149
+ # https://sqlite.org/forum/forumpost/d47a0e8e3a
150
+ # https://sqlite.org/forum/forumpost/2e427099d5
151
+ #
152
+ # Both reports are for the same problem - using a Bloom filter on an
153
+ # expression index can cause issues.
154
+ #
155
+ reset_db
156
+ do_execsql_test 4.1 {
157
+ CREATE TABLE t1(x TEXT, y INT, z TEXT);
158
+ INSERT INTO t1(rowid,x,y,z) VALUES(12,'aa','bb','aa');
159
+ CREATE INDEX i1x ON t1(1 IS true,z);
160
+ CREATE TABLE t0(x TEXT);
161
+ INSERT INTO t0(rowid,x) VALUES(4,'aa');
162
+ ANALYZE sqlite_schema;
163
+ INSERT INTO sqlite_stat1 VALUES('t0',NULL,'20');
164
+ INSERT INTO sqlite_stat1 VALUES('t1','i1x','18 18 2');
165
+ ANALYZE sqlite_schema;
166
+ }
167
+ do_execsql_test 4.2 {
168
+ SELECT * FROM t0 NATURAL JOIN t1 WHERE z=t1.x;
169
+ } {aa bb aa}
170
+ do_execsql_test 4.3 {
171
+ DROP TABLE t0;
172
+ CREATE TABLE t0(a TEXT);
173
+ INSERT INTO t0 VALUES ('xyz');
174
+ CREATE INDEX t0x ON t0(a IS FALSE) WHERE false;
175
+ DROP TABLE t1;
176
+ CREATE TABLE t1(b INT);
177
+ INSERT INTO t1 VALUES('aaa'),('bbb'),('ccc'),('ddd'),(NULL);
178
+ CREATE TABLE t2(c REAL);
179
+ INSERT INTO t2 VALUES(7);
180
+ ANALYZE;
181
+ CREATE INDEX t2x ON t2(true IN ());
182
+ }
183
+ do_execsql_test 4.4 {
184
+ SELECT * FROM t0 LEFT JOIN t1 LEFT JOIN t2 ON (b NOTNULL)==(c IN ()) WHERE c;
185
+ } {xyz {} 7.0}
186
+
187
+
188
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/boundary1.tcl ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ puts {# 2008 December 11
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library.
12
+ #
13
+ # This file is automatically generated from a separate TCL script.
14
+ # This file seeks to exercise integer boundary values.
15
+ #
16
+ # $Id: boundary1.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $
17
+
18
+ set testdir [file dirname $argv0]
19
+ source $testdir/tester.tcl
20
+
21
+ # Many of the boundary tests depend on a working 64-bit implementation.
22
+ if {![working_64bit_int]} { finish_test; return }
23
+ }
24
+
25
+ expr srand(0)
26
+
27
+ # Generate interesting boundary numbers
28
+ #
29
+ foreach x {
30
+ 0
31
+ 1
32
+ 0x7f
33
+ 0x7fff
34
+ 0x7fffff
35
+ 0x7fffffff
36
+ 0x7fffffffff
37
+ 0x7fffffffffff
38
+ 0x7fffffffffffff
39
+ 0x7fffffffffffffff
40
+ } {
41
+ set x [expr {wide($x)}]
42
+ set boundarynum($x) 1
43
+ set boundarynum([expr {$x+1}]) 1
44
+ set boundarynum([expr {-($x+1)}]) 1
45
+ set boundarynum([expr {-($x+2)}]) 1
46
+ set boundarynum([expr {$x+$x+1}]) 1
47
+ set boundarynum([expr {$x+$x+2}]) 1
48
+ }
49
+ set x [expr {wide(127)}]
50
+ for {set i 1} {$i<=9} {incr i} {
51
+ set boundarynum($x) 1
52
+ set boundarynum([expr {$x+1}]) 1
53
+ set x [expr {wide($x*128 + 127)}]
54
+ }
55
+
56
+ # Scramble the $inlist into a random order.
57
+ #
58
+ proc scramble {inlist} {
59
+ set y {}
60
+ foreach x $inlist {
61
+ lappend y [list [expr {rand()}] $x]
62
+ }
63
+ set y [lsort $y]
64
+ set outlist {}
65
+ foreach x $y {
66
+ lappend outlist [lindex $x 1]
67
+ }
68
+ return $outlist
69
+ }
70
+
71
+ # A simple selection sort. Not trying to be efficient.
72
+ #
73
+ proc sort {inlist} {
74
+ set outlist {}
75
+ set mn [lindex $inlist 0]
76
+ foreach x $inlist {
77
+ if {$x<$mn} {set mn $x}
78
+ }
79
+ set outlist $mn
80
+ set mx $mn
81
+ while {1} {
82
+ set valid 0
83
+ foreach x $inlist {
84
+ if {$x>$mx && (!$valid || $mn>$x)} {
85
+ set mn $x
86
+ set valid 1
87
+ }
88
+ }
89
+ if {!$valid} break
90
+ lappend outlist $mn
91
+ set mx $mn
92
+ }
93
+ return $outlist
94
+ }
95
+
96
+ # Reverse the order of a list
97
+ #
98
+ proc reverse {inlist} {
99
+ set i [llength $inlist]
100
+ set outlist {}
101
+ for {incr i -1} {$i>=0} {incr i -1} {
102
+ lappend outlist [lindex $inlist $i]
103
+ }
104
+ return $outlist
105
+ }
106
+
107
+ set nums1 [scramble [array names boundarynum]]
108
+ set nums2 [scramble [array names boundarynum]]
109
+
110
+ set tname boundary1
111
+ puts "do_test $tname-1.1 \173"
112
+ puts " db eval \173"
113
+ puts " CREATE TABLE t1(a,x);"
114
+ set a 0
115
+ foreach r $nums1 {
116
+ incr a
117
+ set t1ra($r) $a
118
+ set t1ar($a) $r
119
+ set x [format %08x%08x [expr {wide($r)>>32}] $r]
120
+ set t1rx($r) $x
121
+ set t1xr($x) $r
122
+ puts " INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');"
123
+ }
124
+ puts " CREATE INDEX t1i1 ON t1(a);"
125
+ puts " CREATE INDEX t1i2 ON t1(x);"
126
+ puts " \175"
127
+ puts "\175 {}"
128
+
129
+ puts "do_test $tname-1.2 \173"
130
+ puts " db eval \173"
131
+ puts " SELECT count(*) FROM t1"
132
+ puts " \175"
133
+ puts "\175 {64}"
134
+
135
+ set nums3 $nums2
136
+ lappend nums3 9.22337303685477580800e+18
137
+ lappend nums3 -9.22337303685477580800e+18
138
+
139
+ set i 0
140
+ foreach r $nums3 {
141
+ incr i
142
+
143
+ if {abs($r)<9.22337203685477580800e+18} {
144
+ set x $t1rx($r)
145
+ set a $t1ra($r)
146
+ set r5 $r.5
147
+ set r0 $r.0
148
+ puts "do_test $tname-2.$i.1 \173"
149
+ puts " db eval \173"
150
+ puts " SELECT * FROM t1 WHERE rowid=$r"
151
+ puts " \175"
152
+ puts "\175 {$a $x}"
153
+ puts "do_test $tname-2.$i.2 \173"
154
+ puts " db eval \173"
155
+ puts " SELECT rowid, a FROM t1 WHERE x='$x'"
156
+ puts " \175"
157
+ puts "\175 {$r $a}"
158
+ puts "do_test $tname-2.$i.3 \173"
159
+ puts " db eval \173"
160
+ puts " SELECT rowid, x FROM t1 WHERE a=$a"
161
+ puts " \175"
162
+ puts "\175 {$r $x}"
163
+ }
164
+
165
+ foreach op {> >= < <=} subno {gt ge lt le} {
166
+
167
+ ################################################################ 2.x.y.1
168
+ set rset {}
169
+ set aset {}
170
+ foreach rx $nums2 {
171
+ if "\$rx $op \$r" {
172
+ lappend rset $rx
173
+ lappend aset $t1ra($rx)
174
+ }
175
+ }
176
+ puts "do_test $tname-2.$i.$subno.1 \173"
177
+ puts " db eval \173"
178
+ puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY a"
179
+ puts " \175"
180
+ puts "\175 {[sort $aset]}"
181
+
182
+ ################################################################ 2.x.y.2
183
+ puts "do_test $tname-2.$i.$subno.2 \173"
184
+ puts " db eval \173"
185
+ puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY a DESC"
186
+ puts " \175"
187
+ puts "\175 {[reverse [sort $aset]]}"
188
+
189
+ ################################################################ 2.x.y.3
190
+ set aset {}
191
+ foreach rx [sort $rset] {
192
+ lappend aset $t1ra($rx)
193
+ }
194
+ puts "do_test $tname-2.$i.$subno.3 \173"
195
+ puts " db eval \173"
196
+ puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY rowid"
197
+ puts " \175"
198
+ puts "\175 {$aset}"
199
+
200
+ ################################################################ 2.x.y.4
201
+ set aset {}
202
+ foreach rx [reverse [sort $rset]] {
203
+ lappend aset $t1ra($rx)
204
+ }
205
+ puts "do_test $tname-2.$i.$subno.4 \173"
206
+ puts " db eval \173"
207
+ puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY rowid DESC"
208
+ puts " \175"
209
+ puts "\175 {$aset}"
210
+
211
+ ################################################################ 2.x.y.5
212
+ set aset {}
213
+ set xset {}
214
+ foreach rx $rset {
215
+ lappend xset $t1rx($rx)
216
+ }
217
+ foreach x [sort $xset] {
218
+ set rx $t1xr($x)
219
+ lappend aset $t1ra($rx)
220
+ }
221
+ puts "do_test $tname-2.$i.$subno.5 \173"
222
+ puts " db eval \173"
223
+ puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY x"
224
+ puts " \175"
225
+ puts "\175 {$aset}"
226
+
227
+ ################################################################ 2.x.y.10
228
+ if {abs($r)>9223372036854775808 || [string length $r5]>15} continue
229
+ set rset {}
230
+ set aset {}
231
+ foreach rx $nums2 {
232
+ if "\$rx $op \$r0" {
233
+ lappend rset $rx
234
+ }
235
+ }
236
+ foreach rx [sort $rset] {
237
+ lappend aset $t1ra($rx)
238
+ }
239
+ puts "do_test $tname-2.$i.$subno.10 \173"
240
+ puts " db eval \173"
241
+ puts " SELECT a FROM t1 WHERE rowid $op $r0 ORDER BY rowid"
242
+ puts " \175"
243
+ puts "\175 {$aset}"
244
+
245
+ ################################################################ 2.x.y.11
246
+ set aset {}
247
+ foreach rx [reverse [sort $rset]] {
248
+ lappend aset $t1ra($rx)
249
+ }
250
+ puts "do_test $tname-2.$i.$subno.11 \173"
251
+ puts " db eval \173"
252
+ puts " SELECT a FROM t1 WHERE rowid $op $r0 ORDER BY rowid DESC"
253
+ puts " \175"
254
+ puts "\175 {$aset}"
255
+
256
+
257
+ ################################################################ 2.x.y.12
258
+ set rset {}
259
+ set aset {}
260
+ foreach rx $nums2 {
261
+ if "\$rx $op \$r5" {
262
+ lappend rset $rx
263
+ }
264
+ }
265
+ foreach rx [sort $rset] {
266
+ lappend aset $t1ra($rx)
267
+ }
268
+ puts "do_test $tname-2.$i.$subno.12 \173"
269
+ puts " db eval \173"
270
+ puts " SELECT a FROM t1 WHERE rowid $op $r5 ORDER BY rowid"
271
+ puts " \175"
272
+ puts "\175 {$aset}"
273
+
274
+ ################################################################ 2.x.y.13
275
+ set aset {}
276
+ foreach rx [reverse [sort $rset]] {
277
+ lappend aset $t1ra($rx)
278
+ }
279
+ puts "do_test $tname-2.$i.$subno.13 \173"
280
+ puts " db eval \173"
281
+ puts " SELECT a FROM t1 WHERE rowid $op $r5 ORDER BY rowid DESC"
282
+ puts " \175"
283
+ puts "\175 {$aset}"
284
+ }
285
+
286
+ }
287
+
288
+
289
+ puts {finish_test}
local-test-sqlite3-delta-03/afc-sqlite3/test/busy.test ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2005 july 8
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file test the busy handler
12
+ #
13
+
14
+
15
+ set testdir [file dirname $argv0]
16
+ source $testdir/tester.tcl
17
+ set testprefix busy
18
+
19
+ do_test busy-1.1 {
20
+ sqlite3 db2 test.db
21
+ execsql {
22
+ CREATE TABLE t1(x);
23
+ INSERT INTO t1 VALUES(1);
24
+ SELECT * FROM t1
25
+ }
26
+ } 1
27
+ proc busy x {
28
+ lappend ::busyargs $x
29
+ if {$x>2} {return 1}
30
+ return 0
31
+ }
32
+ set busyargs {}
33
+ do_test busy-1.2 {
34
+ db busy busy
35
+ db2 eval {BEGIN EXCLUSIVE}
36
+ catchsql {BEGIN IMMEDIATE}
37
+ } {1 {database is locked}}
38
+ do_test busy-1.3 {
39
+ set busyargs
40
+ } {0 1 2 3}
41
+ do_test busy-1.4 {
42
+ set busyargs {}
43
+ catchsql {BEGIN IMMEDIATE}
44
+ set busyargs
45
+ } {0 1 2 3}
46
+
47
+ do_test busy-2.1 {
48
+ db2 eval {COMMIT}
49
+ db eval {BEGIN; INSERT INTO t1 VALUES(5)}
50
+ db2 eval {BEGIN; SELECT * FROM t1}
51
+ set busyargs {}
52
+ catchsql COMMIT
53
+ } {1 {database is locked}}
54
+ do_test busy-2.2 {
55
+ set busyargs
56
+ } {0 1 2 3}
57
+
58
+ db2 close
59
+
60
+ #-------------------------------------------------------------------------
61
+ # Test that the busy-handler is invoked correctly for "PRAGMA optimize"
62
+ # and ANALYZE commnds.
63
+ ifcapable pragma&&analyze&&!stat4 {
64
+
65
+ reset_db
66
+
67
+ do_execsql_test 3.1 {
68
+ CREATE TABLE t1(x);
69
+ CREATE TABLE t2(y);
70
+ CREATE TABLE t3(z);
71
+
72
+ CREATE INDEX i1 ON t1(x);
73
+ CREATE INDEX i2 ON t2(y);
74
+
75
+ INSERT INTO t1 VALUES(1);
76
+ INSERT INTO t2 VALUES(1);
77
+ ANALYZE;
78
+
79
+ SELECT * FROM t1 WHERE x=1;
80
+ SELECT * FROM t2 WHERE y=1;
81
+ } {1 1}
82
+
83
+ do_test 3.2 {
84
+ sqlite3 db2 test.db
85
+ execsql { BEGIN EXCLUSIVE } db2
86
+ catchsql { PRAGMA optimize }
87
+ } {1 {database is locked}}
88
+
89
+ proc busy_handler {n} {
90
+ if {$n>1000} { execsql { COMMIT } db2 }
91
+ return 0
92
+ }
93
+ db busy busy_handler
94
+
95
+ do_test 3.3 {
96
+ catchsql { PRAGMA optimize }
97
+ } {0 {}}
98
+
99
+ do_test 3.4 {
100
+ execsql {
101
+ BEGIN;
102
+ SELECT count(*) FROM sqlite_master;
103
+ } db2
104
+ } {6}
105
+
106
+ proc busy_handler {n} { return 1 }
107
+ do_test 3.5 {
108
+ catchsql { PRAGMA optimize }
109
+ } {1 {database is locked}}
110
+
111
+ do_test 3.6 {
112
+ execsql { COMMIT } db2
113
+ execsql {
114
+ WITH s(i) AS (
115
+ SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
116
+ )
117
+ INSERT INTO t1 SELECT i FROM s;
118
+ }
119
+ execsql {
120
+ BEGIN;
121
+ SELECT count(*) FROM sqlite_master;
122
+ } db2
123
+ } {6}
124
+
125
+ do_test 3.7 {
126
+ catchsql { PRAGMA optimize }
127
+ } {1 {database is locked}}
128
+
129
+ proc busy_handler {n} {
130
+ if {$n>1000} { execsql { COMMIT } db2 }
131
+ return 0
132
+ }
133
+ do_test 3.8 {
134
+ catchsql { PRAGMA optimize }
135
+ } {0 {}}
136
+
137
+ }
138
+
139
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/capi2.test ADDED
@@ -0,0 +1,803 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2003 January 29
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this script testing the callback-free C/C++ API.
13
+ #
14
+ # $Id: capi2.test,v 1.37 2008/12/30 17:55:00 drh Exp $
15
+ #
16
+
17
+ set testdir [file dirname $argv0]
18
+ source $testdir/tester.tcl
19
+
20
+ # Return the text values from the current row pointed at by STMT as a list.
21
+ proc get_row_values {STMT} {
22
+ set VALUES [list]
23
+ for {set i 0} {$i < [sqlite3_data_count $STMT]} {incr i} {
24
+ lappend VALUES [sqlite3_column_text $STMT $i]
25
+ }
26
+ return $VALUES
27
+ }
28
+
29
+ # Return the column names followed by declaration types for the result set
30
+ # of the SQL statement STMT.
31
+ #
32
+ # i.e. for:
33
+ # CREATE TABLE abc(a text, b integer);
34
+ # SELECT * FROM abc;
35
+ #
36
+ # The result is {a b text integer}
37
+ proc get_column_names {STMT} {
38
+ set VALUES [list]
39
+ for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} {
40
+ lappend VALUES [sqlite3_column_name $STMT $i]
41
+ }
42
+ for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} {
43
+ lappend VALUES [sqlite3_column_decltype $STMT $i]
44
+ }
45
+ return $VALUES
46
+ }
47
+
48
+ # Check basic functionality
49
+ #
50
+ do_test capi2-1.1 {
51
+ set DB [sqlite3_connection_pointer db]
52
+ execsql {CREATE TABLE t1(a,b,c)}
53
+ set VM [sqlite3_prepare $DB {SELECT name, rowid FROM sqlite_master} -1 TAIL]
54
+ set TAIL
55
+ } {}
56
+ do_test capi2-1.2 {
57
+ sqlite3_step $VM
58
+ } {SQLITE_ROW}
59
+ do_test capi2-1.3 {
60
+ sqlite3_data_count $VM
61
+ } {2}
62
+ do_test capi2-1.4 {
63
+ get_row_values $VM
64
+ } {t1 1}
65
+ do_test capi2-1.5 {
66
+ get_column_names $VM
67
+ } {name rowid TEXT INTEGER}
68
+ do_test capi2-1.6 {
69
+ sqlite3_step $VM
70
+ } {SQLITE_DONE}
71
+ do_test capi2-1.7 {
72
+ list [sqlite3_column_count $VM] [get_row_values $VM] [get_column_names $VM]
73
+ } {2 {} {name rowid TEXT INTEGER}}
74
+
75
+ # This used to be SQLITE_MISUSE. But now we automatically reset prepared
76
+ # statements.
77
+ ifcapable autoreset {
78
+ do_test capi2-1.8 {
79
+ sqlite3_step $VM
80
+ } {SQLITE_ROW}
81
+ } else {
82
+ do_test capi2-1.8 {
83
+ sqlite3_step $VM
84
+ } {SQLITE_MISUSE}
85
+ }
86
+
87
+ # Update: In v2, once SQLITE_MISUSE is returned the statement handle cannot
88
+ # be interrogated for more information. However in v3, since the column
89
+ # count, names and types are determined at compile time, these are still
90
+ # accessible after an SQLITE_MISUSE error.
91
+ do_test capi2-1.9 {
92
+ sqlite3_reset $VM
93
+ list [sqlite3_column_count $VM] [get_row_values $VM] [get_column_names $VM]
94
+ } {2 {} {name rowid TEXT INTEGER}}
95
+ do_test capi2-1.10 {
96
+ sqlite3_data_count $VM
97
+ } {0}
98
+
99
+ do_test capi2-1.11 {
100
+ sqlite3_finalize $VM
101
+ } {SQLITE_OK}
102
+
103
+ # Check to make sure that the "tail" of a multi-statement SQL script
104
+ # is returned by sqlite3_prepare.
105
+ #
106
+ do_test capi2-2.1 {
107
+ set SQL {
108
+ SELECT name, rowid FROM sqlite_master;
109
+ SELECT name, rowid FROM sqlite_master WHERE 0;
110
+ -- A comment at the end
111
+ }
112
+ set VM [sqlite3_prepare $DB $SQL -1 SQL]
113
+ set SQL
114
+ } {
115
+ SELECT name, rowid FROM sqlite_master WHERE 0;
116
+ -- A comment at the end
117
+ }
118
+ do_test capi2-2.2 {
119
+ set r [sqlite3_step $VM]
120
+ lappend r [sqlite3_column_count $VM] \
121
+ [get_row_values $VM] \
122
+ [get_column_names $VM]
123
+ } {SQLITE_ROW 2 {t1 1} {name rowid TEXT INTEGER}}
124
+ do_test capi2-2.3 {
125
+ set r [sqlite3_step $VM]
126
+ lappend r [sqlite3_column_count $VM] \
127
+ [get_row_values $VM] \
128
+ [get_column_names $VM]
129
+ } {SQLITE_DONE 2 {} {name rowid TEXT INTEGER}}
130
+ do_test capi2-2.4 {
131
+ sqlite3_finalize $VM
132
+ } {SQLITE_OK}
133
+ do_test capi2-2.5 {
134
+ set VM [sqlite3_prepare $DB $SQL -1 SQL]
135
+ set SQL
136
+ } {
137
+ -- A comment at the end
138
+ }
139
+ do_test capi2-2.6 {
140
+ set r [sqlite3_step $VM]
141
+ lappend r [sqlite3_column_count $VM] \
142
+ [get_row_values $VM] \
143
+ [get_column_names $VM]
144
+ } {SQLITE_DONE 2 {} {name rowid TEXT INTEGER}}
145
+ do_test capi2-2.7 {
146
+ sqlite3_finalize $VM
147
+ } {SQLITE_OK}
148
+ do_test capi2-2.8 {
149
+ set VM [sqlite3_prepare $DB $SQL -1 SQL]
150
+ list $SQL $VM
151
+ } {{} {}}
152
+
153
+ # Check the error handling.
154
+ #
155
+ do_test capi2-3.1 {
156
+ set rc [catch {
157
+ sqlite3_prepare $DB {select bogus from sqlite_master} -1 TAIL
158
+ } msg]
159
+ lappend rc $msg $TAIL
160
+ } {1 {(1) no such column: bogus} {}}
161
+ do_test capi2-3.2 {
162
+ set rc [catch {
163
+ sqlite3_prepare $DB {select bogus from } -1 TAIL
164
+ } msg]
165
+ lappend rc $msg $TAIL
166
+ } {1 {(1) incomplete input} {}}
167
+ do_test capi2-3.3 {
168
+ set rc [catch {
169
+ sqlite3_prepare $DB {;;;;select bogus from sqlite_master} -1 TAIL
170
+ } msg]
171
+ lappend rc $msg $TAIL
172
+ } {1 {(1) no such column: bogus} {}}
173
+ do_test capi2-3.4 {
174
+ set rc [catch {
175
+ sqlite3_prepare $DB {select bogus from sqlite_master;x;} -1 TAIL
176
+ } msg]
177
+ lappend rc $msg $TAIL
178
+ } {1 {(1) no such column: bogus} {x;}}
179
+ do_test capi2-3.5 {
180
+ set rc [catch {
181
+ sqlite3_prepare $DB {select bogus from sqlite_master;;;x;} -1 TAIL
182
+ } msg]
183
+ lappend rc $msg $TAIL
184
+ } {1 {(1) no such column: bogus} {;;x;}}
185
+ do_test capi2-3.6 {
186
+ set rc [catch {
187
+ sqlite3_prepare $DB {select 5/0;} -1 TAIL
188
+ } VM]
189
+ lappend rc $TAIL
190
+ } {0 {}}
191
+ do_test capi2-3.7 {
192
+ list [sqlite3_step $VM] \
193
+ [sqlite3_column_count $VM] \
194
+ [get_row_values $VM] \
195
+ [get_column_names $VM]
196
+ } {SQLITE_ROW 1 {{}} {5/0 {}}}
197
+ do_test capi2-3.8 {
198
+ sqlite3_finalize $VM
199
+ } {SQLITE_OK}
200
+ do_test capi2-3.9 {
201
+ execsql {CREATE UNIQUE INDEX i1 ON t1(a)}
202
+ set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,2,3)} -1 TAIL]
203
+ set TAIL
204
+ } {}
205
+ do_test capi2-3.9b {db changes} {0}
206
+ do_test capi2-3.10 {
207
+ list [sqlite3_step $VM] \
208
+ [sqlite3_column_count $VM] \
209
+ [get_row_values $VM] \
210
+ [get_column_names $VM]
211
+ } {SQLITE_DONE 0 {} {}}
212
+
213
+ # Update for v3 - the change has not actually happened until the query is
214
+ # finalized. Is this going to cause trouble for anyone? Lee Nelson maybe?
215
+ # (Later:) The change now happens just before SQLITE_DONE is returned.
216
+ do_test capi2-3.10b {db changes} {1}
217
+ do_test capi2-3.11 {
218
+ sqlite3_finalize $VM
219
+ } {SQLITE_OK}
220
+ do_test capi2-3.11b {db changes} {1}
221
+ #do_test capi2-3.12-misuse {
222
+ # sqlite3_finalize $VM
223
+ #} {SQLITE_MISUSE}
224
+ do_test capi2-3.13 {
225
+ set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,3,4)} -1 TAIL]
226
+ list [sqlite3_step $VM] \
227
+ [sqlite3_column_count $VM] \
228
+ [get_row_values $VM] \
229
+ [get_column_names $VM]
230
+ } {SQLITE_ERROR 0 {} {}}
231
+
232
+ # Update for v3: Preparing a statement does not affect the change counter.
233
+ # (Test result changes from 0 to 1). (Later:) change counter updates occur
234
+ # when sqlite3_step returns, not at finalize time.
235
+ do_test capi2-3.13b {db changes} {0}
236
+
237
+ do_test capi2-3.14 {
238
+ list [sqlite3_finalize $VM] [sqlite3_errmsg $DB] \
239
+ [sqlite3_extended_errcode $DB]
240
+ } {SQLITE_CONSTRAINT {UNIQUE constraint failed: t1.a} SQLITE_CONSTRAINT_UNIQUE}
241
+ do_test capi2-3.15 {
242
+ set VM [sqlite3_prepare $DB {CREATE TABLE t2(a NOT NULL, b)} -1 TAIL]
243
+ set TAIL
244
+ } {}
245
+ do_test capi2-3.16 {
246
+ list [sqlite3_step $VM] \
247
+ [sqlite3_column_count $VM] \
248
+ [get_row_values $VM] \
249
+ [get_column_names $VM]
250
+ } {SQLITE_DONE 0 {} {}}
251
+ do_test capi2-3.17 {
252
+ list [sqlite3_finalize $VM] [sqlite3_errmsg $DB]
253
+ } {SQLITE_OK {not an error}}
254
+ do_test capi2-3.18 {
255
+ set VM [sqlite3_prepare $DB {INSERT INTO t2 VALUES(NULL,2)} -1 TAIL]
256
+ list [sqlite3_step $VM] \
257
+ [sqlite3_column_count $VM] \
258
+ [get_row_values $VM] \
259
+ [get_column_names $VM]
260
+ } {SQLITE_ERROR 0 {} {}}
261
+ do_test capi2-3.19 {
262
+ list [sqlite3_finalize $VM] [sqlite3_errmsg $DB] \
263
+ [sqlite3_extended_errcode $DB]
264
+ } {SQLITE_CONSTRAINT {NOT NULL constraint failed: t2.a} SQLITE_CONSTRAINT_NOTNULL}
265
+
266
+ do_test capi2-3.20 {
267
+ execsql {
268
+ CREATE TABLE a1(message_id, name , UNIQUE(message_id, name) );
269
+ INSERT INTO a1 VALUES(1, 1);
270
+ }
271
+ } {}
272
+ do_test capi2-3.21 {
273
+ set VM [sqlite3_prepare $DB {INSERT INTO a1 VALUES(1, 1)} -1 TAIL]
274
+ sqlite3_step $VM
275
+ } {SQLITE_ERROR}
276
+ do_test capi2-3.22 {
277
+ sqlite3_errcode $DB
278
+ } {SQLITE_ERROR}
279
+ do_test capi2-3.23 {
280
+ sqlite3_finalize $VM
281
+ } {SQLITE_CONSTRAINT}
282
+ do_test capi2-3.24 {
283
+ list [sqlite3_errcode $DB] [sqlite3_extended_errcode $DB]
284
+ } {SQLITE_CONSTRAINT SQLITE_CONSTRAINT_UNIQUE}
285
+
286
+ # Two or more virtual machines exists at the same time.
287
+ #
288
+ do_test capi2-4.1 {
289
+ set VM1 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(1,2)} -1 TAIL]
290
+ set TAIL
291
+ } {}
292
+ do_test capi2-4.2 {
293
+ set VM2 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(2,3)} -1 TAIL]
294
+ set TAIL
295
+ } {}
296
+ do_test capi2-4.3 {
297
+ set VM3 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(3,4)} -1 TAIL]
298
+ set TAIL
299
+ } {}
300
+ do_test capi2-4.4 {
301
+ list [sqlite3_step $VM2] \
302
+ [sqlite3_column_count $VM2] \
303
+ [get_row_values $VM2] \
304
+ [get_column_names $VM2]
305
+ } {SQLITE_DONE 0 {} {}}
306
+ do_test capi2-4.5 {
307
+ execsql {SELECT * FROM t2 ORDER BY a}
308
+ } {2 3}
309
+ do_test capi2-4.6 {
310
+ sqlite3_finalize $VM2
311
+ } {SQLITE_OK}
312
+ do_test capi2-4.7 {
313
+ list [sqlite3_step $VM3] \
314
+ [sqlite3_column_count $VM3] \
315
+ [get_row_values $VM3] \
316
+ [get_column_names $VM3]
317
+ } {SQLITE_DONE 0 {} {}}
318
+ do_test capi2-4.8 {
319
+ execsql {SELECT * FROM t2 ORDER BY a}
320
+ } {2 3 3 4}
321
+ do_test capi2-4.9 {
322
+ sqlite3_finalize $VM3
323
+ } {SQLITE_OK}
324
+ do_test capi2-4.10 {
325
+ list [sqlite3_step $VM1] \
326
+ [sqlite3_column_count $VM1] \
327
+ [get_row_values $VM1] \
328
+ [get_column_names $VM1]
329
+ } {SQLITE_DONE 0 {} {}}
330
+ do_test capi2-4.11 {
331
+ execsql {SELECT * FROM t2 ORDER BY a}
332
+ } {1 2 2 3 3 4}
333
+ do_test capi2-4.12 {
334
+ sqlite3_finalize $VM1
335
+ } {SQLITE_OK}
336
+
337
+ # Interleaved SELECTs
338
+ #
339
+ do_test capi2-5.1 {
340
+ set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
341
+ set VM2 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
342
+ set VM3 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
343
+ list [sqlite3_step $VM1] \
344
+ [sqlite3_column_count $VM1] \
345
+ [get_row_values $VM1] \
346
+ [get_column_names $VM1]
347
+ } {SQLITE_ROW 2 {2 3} {a b {} {}}}
348
+ do_test capi2-5.2 {
349
+ list [sqlite3_step $VM2] \
350
+ [sqlite3_column_count $VM2] \
351
+ [get_row_values $VM2] \
352
+ [get_column_names $VM2]
353
+ } {SQLITE_ROW 2 {2 3} {a b {} {}}}
354
+ do_test capi2-5.3 {
355
+ list [sqlite3_step $VM1] \
356
+ [sqlite3_column_count $VM1] \
357
+ [get_row_values $VM1] \
358
+ [get_column_names $VM1]
359
+ } {SQLITE_ROW 2 {3 4} {a b {} {}}}
360
+ do_test capi2-5.4 {
361
+ list [sqlite3_step $VM3] \
362
+ [sqlite3_column_count $VM3] \
363
+ [get_row_values $VM3] \
364
+ [get_column_names $VM3]
365
+ } {SQLITE_ROW 2 {2 3} {a b {} {}}}
366
+ do_test capi2-5.5 {
367
+ list [sqlite3_step $VM3] \
368
+ [sqlite3_column_count $VM3] \
369
+ [get_row_values $VM3] \
370
+ [get_column_names $VM3]
371
+ } {SQLITE_ROW 2 {3 4} {a b {} {}}}
372
+ do_test capi2-5.6 {
373
+ list [sqlite3_step $VM3] \
374
+ [sqlite3_column_count $VM3] \
375
+ [get_row_values $VM3] \
376
+ [get_column_names $VM3]
377
+ } {SQLITE_ROW 2 {1 2} {a b {} {}}}
378
+ do_test capi2-5.7 {
379
+ list [sqlite3_step $VM3] \
380
+ [sqlite3_column_count $VM3] \
381
+ [get_row_values $VM3] \
382
+ [get_column_names $VM3]
383
+ } {SQLITE_DONE 2 {} {a b {} {}}}
384
+ do_test capi2-5.8 {
385
+ sqlite3_finalize $VM3
386
+ } {SQLITE_OK}
387
+ do_test capi2-5.9 {
388
+ list [sqlite3_step $VM1] \
389
+ [sqlite3_column_count $VM1] \
390
+ [get_row_values $VM1] \
391
+ [get_column_names $VM1]
392
+ } {SQLITE_ROW 2 {1 2} {a b {} {}}}
393
+ do_test capi2-5.10 {
394
+ sqlite3_finalize $VM1
395
+ } {SQLITE_OK}
396
+ do_test capi2-5.11 {
397
+ list [sqlite3_step $VM2] \
398
+ [sqlite3_column_count $VM2] \
399
+ [get_row_values $VM2] \
400
+ [get_column_names $VM2]
401
+ } {SQLITE_ROW 2 {3 4} {a b {} {}}}
402
+ do_test capi2-5.12 {
403
+ list [sqlite3_step $VM2] \
404
+ [sqlite3_column_count $VM2] \
405
+ [get_row_values $VM2] \
406
+ [get_column_names $VM2]
407
+ } {SQLITE_ROW 2 {1 2} {a b {} {}}}
408
+ do_test capi2-5.11 {
409
+ sqlite3_finalize $VM2
410
+ } {SQLITE_OK}
411
+
412
+ # Check for proper SQLITE_BUSY returns.
413
+ #
414
+ do_test capi2-6.1 {
415
+ execsql {
416
+ BEGIN;
417
+ CREATE TABLE t3(x counter);
418
+ INSERT INTO t3 VALUES(1);
419
+ INSERT INTO t3 VALUES(2);
420
+ INSERT INTO t3 SELECT x+2 FROM t3;
421
+ INSERT INTO t3 SELECT x+4 FROM t3;
422
+ INSERT INTO t3 SELECT x+8 FROM t3;
423
+ COMMIT;
424
+ }
425
+ set VM1 [sqlite3_prepare $DB {SELECT * FROM t3} -1 TAIL]
426
+ sqlite3 db2 test.db
427
+ execsql {BEGIN} db2
428
+ } {}
429
+ # Update for v3: BEGIN doesn't write-lock the database. It is quite
430
+ # difficult to get v3 to write-lock the database, which causes a few
431
+ # problems for test scripts.
432
+ #
433
+ # do_test capi2-6.2 {
434
+ # list [sqlite3_step $VM1] \
435
+ # [sqlite3_column_count $VM1] \
436
+ # [get_row_values $VM1] \
437
+ # [get_column_names $VM1]
438
+ # } {SQLITE_BUSY 0 {} {}}
439
+ do_test capi2-6.3 {
440
+ execsql {COMMIT} db2
441
+ } {}
442
+ do_test capi2-6.4 {
443
+ list [sqlite3_step $VM1] \
444
+ [sqlite3_column_count $VM1] \
445
+ [get_row_values $VM1] \
446
+ [get_column_names $VM1]
447
+ } {SQLITE_ROW 1 1 {x counter}}
448
+ do_test capi2-6.5 {
449
+ catchsql {INSERT INTO t3 VALUES(10);} db2
450
+ } {1 {database is locked}}
451
+ do_test capi2-6.6 {
452
+ list [sqlite3_step $VM1] \
453
+ [sqlite3_column_count $VM1] \
454
+ [get_row_values $VM1] \
455
+ [get_column_names $VM1]
456
+ } {SQLITE_ROW 1 2 {x counter}}
457
+ do_test capi2-6.7 {
458
+ execsql {SELECT * FROM t2} db2
459
+ } {2 3 3 4 1 2}
460
+ do_test capi2-6.8 {
461
+ list [sqlite3_step $VM1] \
462
+ [sqlite3_column_count $VM1] \
463
+ [get_row_values $VM1] \
464
+ [get_column_names $VM1]
465
+ } {SQLITE_ROW 1 3 {x counter}}
466
+ do_test capi2-6.9 {
467
+ execsql {SELECT * FROM t2}
468
+ } {2 3 3 4 1 2}
469
+ do_test capi2-6.10 {
470
+ list [sqlite3_step $VM1] \
471
+ [sqlite3_column_count $VM1] \
472
+ [get_row_values $VM1] \
473
+ [get_column_names $VM1]
474
+ } {SQLITE_ROW 1 4 {x counter}}
475
+ do_test capi2-6.11 {
476
+ execsql {BEGIN}
477
+ } {}
478
+ do_test capi2-6.12 {
479
+ list [sqlite3_step $VM1] \
480
+ [sqlite3_column_count $VM1] \
481
+ [get_row_values $VM1] \
482
+ [get_column_names $VM1]
483
+ } {SQLITE_ROW 1 5 {x counter}}
484
+
485
+ # A read no longer blocks a write in the same connection.
486
+ #do_test capi2-6.13 {
487
+ # catchsql {UPDATE t3 SET x=x+1}
488
+ #} {1 {database table is locked}}
489
+
490
+ do_test capi2-6.14 {
491
+ list [sqlite3_step $VM1] \
492
+ [sqlite3_column_count $VM1] \
493
+ [get_row_values $VM1] \
494
+ [get_column_names $VM1]
495
+ } {SQLITE_ROW 1 6 {x counter}}
496
+ do_test capi2-6.15 {
497
+ execsql {SELECT * FROM t1}
498
+ } {1 2 3}
499
+ do_test capi2-6.16 {
500
+ list [sqlite3_step $VM1] \
501
+ [sqlite3_column_count $VM1] \
502
+ [get_row_values $VM1] \
503
+ [get_column_names $VM1]
504
+ } {SQLITE_ROW 1 7 {x counter}}
505
+ do_test capi2-6.17 {
506
+ catchsql {UPDATE t1 SET b=b+1}
507
+ } {0 {}}
508
+ do_test capi2-6.18 {
509
+ list [sqlite3_step $VM1] \
510
+ [sqlite3_column_count $VM1] \
511
+ [get_row_values $VM1] \
512
+ [get_column_names $VM1]
513
+ } {SQLITE_ROW 1 8 {x counter}}
514
+ do_test capi2-6.19 {
515
+ execsql {SELECT * FROM t1}
516
+ } {1 3 3}
517
+ do_test capi2-6.20 {
518
+ list [sqlite3_step $VM1] \
519
+ [sqlite3_column_count $VM1] \
520
+ [get_row_values $VM1] \
521
+ [get_column_names $VM1]
522
+ } {SQLITE_ROW 1 9 {x counter}}
523
+ #do_test capi2-6.21 {
524
+ # execsql {ROLLBACK; SELECT * FROM t1}
525
+ #} {1 2 3}
526
+ do_test capi2-6.22 {
527
+ list [sqlite3_step $VM1] \
528
+ [sqlite3_column_count $VM1] \
529
+ [get_row_values $VM1] \
530
+ [get_column_names $VM1]
531
+ } {SQLITE_ROW 1 10 {x counter}}
532
+ #do_test capi2-6.23 {
533
+ # execsql {BEGIN TRANSACTION;}
534
+ #} {}
535
+ do_test capi2-6.24 {
536
+ list [sqlite3_step $VM1] \
537
+ [sqlite3_column_count $VM1] \
538
+ [get_row_values $VM1] \
539
+ [get_column_names $VM1]
540
+ } {SQLITE_ROW 1 11 {x counter}}
541
+ do_test capi2-6.25 {
542
+ execsql {
543
+ INSERT INTO t1 VALUES(2,3,4);
544
+ SELECT * FROM t1;
545
+ }
546
+ } {1 3 3 2 3 4}
547
+ do_test capi2-6.26 {
548
+ list [sqlite3_step $VM1] \
549
+ [sqlite3_column_count $VM1] \
550
+ [get_row_values $VM1] \
551
+ [get_column_names $VM1]
552
+ } {SQLITE_ROW 1 12 {x counter}}
553
+ do_test capi2-6.27 {
554
+ catchsql {
555
+ INSERT INTO t1 VALUES(2,4,5);
556
+ SELECT * FROM t1;
557
+ }
558
+ } {1 {UNIQUE constraint failed: t1.a}}
559
+ do_test capi2-6.28 {
560
+ list [sqlite3_step $VM1] \
561
+ [sqlite3_column_count $VM1] \
562
+ [get_row_values $VM1] \
563
+ [get_column_names $VM1]
564
+ } {SQLITE_ROW 1 13 {x counter}}
565
+ do_test capi2-6.99 {
566
+ sqlite3_finalize $VM1
567
+ } {SQLITE_OK}
568
+ catchsql {ROLLBACK}
569
+
570
+ do_test capi2-7.1 {
571
+ stepsql $DB {
572
+ SELECT * FROM t1
573
+ }
574
+ } {0 1 2 3}
575
+ do_test capi2-7.2 {
576
+ stepsql $DB {
577
+ PRAGMA count_changes=on
578
+ }
579
+ } {0}
580
+ do_test capi2-7.3 {
581
+ stepsql $DB {
582
+ UPDATE t1 SET a=a+10;
583
+ }
584
+ } {0 1}
585
+ do_test capi2-7.4 {
586
+ stepsql $DB {
587
+ INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1;
588
+ }
589
+ } {0 1}
590
+ do_test capi2-7.4b {sqlite3_changes $DB} {1}
591
+ do_test capi2-7.5 {
592
+ stepsql $DB {
593
+ UPDATE t1 SET a=a+10;
594
+ }
595
+ } {0 2}
596
+ do_test capi2-7.5b {sqlite3_changes $DB} {2}
597
+ do_test capi2-7.6 {
598
+ stepsql $DB {
599
+ SELECT * FROM t1;
600
+ }
601
+ } {0 21 2 3 22 3 4}
602
+ do_test capi2-7.7 {
603
+ stepsql $DB {
604
+ INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1;
605
+ }
606
+ } {0 2}
607
+ do_test capi2-7.8 {
608
+ sqlite3_changes $DB
609
+ } {2}
610
+ do_test capi2-7.9 {
611
+ stepsql $DB {
612
+ SELECT * FROM t1;
613
+ }
614
+ } {0 21 2 3 22 3 4 23 4 5 24 5 6}
615
+ do_test capi2-7.10 {
616
+ stepsql $DB {
617
+ UPDATE t1 SET a=a-20;
618
+ SELECT * FROM t1;
619
+ }
620
+ } {0 4 1 2 3 2 3 4 3 4 5 4 5 6}
621
+
622
+ # Update for version 3: A SELECT statement no longer resets the change
623
+ # counter (Test result changes from 0 to 4).
624
+ do_test capi2-7.11 {
625
+ sqlite3_changes $DB
626
+ } {4}
627
+ do_test capi2-7.11a {
628
+ execsql {SELECT count(*) FROM t1}
629
+ } {4}
630
+
631
+ ifcapable {explain} {
632
+ do_test capi2-7.12 {
633
+ set x [stepsql $DB {EXPLAIN SELECT * FROM t1}]
634
+ lindex $x 0
635
+ } {0}
636
+ }
637
+
638
+ # Ticket #261 - make sure we can finalize before the end of a query.
639
+ #
640
+ do_test capi2-8.1 {
641
+ set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
642
+ sqlite3_finalize $VM1
643
+ } {SQLITE_OK}
644
+
645
+ # Tickets #384 and #385 - make sure the TAIL argument to sqlite3_prepare
646
+ # and all of the return pointers in sqlite_step can be null.
647
+ #
648
+ do_test capi2-9.1 {
649
+ set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 DUMMY]
650
+ sqlite3_step $VM1
651
+ sqlite3_finalize $VM1
652
+ } {SQLITE_OK}
653
+
654
+ # Test that passing a NULL pointer to sqlite3_finalize() or sqlite3_reset
655
+ # does not cause an error.
656
+ do_test capi2-10.1 {
657
+ sqlite3_finalize 0
658
+ } {SQLITE_OK}
659
+ do_test capi2-10.2 {
660
+ sqlite3_reset 0
661
+ } {SQLITE_OK}
662
+
663
+ #---------------------------------------------------------------------------
664
+ # The following tests - capi2-11.* - test the "column origin" APIs.
665
+ #
666
+ # sqlite3_column_origin_name()
667
+ # sqlite3_column_database_name()
668
+ # sqlite3_column_table_name()
669
+ #
670
+
671
+ ifcapable columnmetadata {
672
+
673
+ # This proc uses the database handle $::DB to compile the SQL statement passed
674
+ # as a parameter. The return value of this procedure is a list with one
675
+ # element for each column returned by the compiled statement. Each element of
676
+ # this list is itself a list of length three, consisting of the origin
677
+ # database, table and column for the corresponding returned column.
678
+ proc check_origins {sql} {
679
+ set ret [list]
680
+ set ::STMT [sqlite3_prepare $::DB $sql -1 dummy]
681
+ for {set i 0} {$i < [sqlite3_column_count $::STMT]} {incr i} {
682
+ lappend ret [list \
683
+ [sqlite3_column_database_name $::STMT $i] \
684
+ [sqlite3_column_table_name $::STMT $i] \
685
+ [sqlite3_column_origin_name $::STMT $i] \
686
+ ]
687
+ }
688
+ sqlite3_finalize $::STMT
689
+ return $ret
690
+ }
691
+ do_test capi2-11.1 {
692
+ execsql {
693
+ CREATE TABLE tab1(col1, col2);
694
+ }
695
+ } {}
696
+ do_test capi2-11.2 {
697
+ check_origins {SELECT col2, col1 FROM tab1}
698
+ } [list {main tab1 col2} {main tab1 col1}]
699
+ do_test capi2-11.3 {
700
+ check_origins {SELECT col2 AS hello, col1 AS world FROM tab1}
701
+ } [list {main tab1 col2} {main tab1 col1}]
702
+
703
+ ifcapable subquery {
704
+ do_test capi2-11.4 {
705
+ check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM tab1)}
706
+ } [list {main tab1 col2} {main tab1 col1}]
707
+ do_test capi2-11.5 {
708
+ check_origins {SELECT (SELECT col2 FROM tab1), (SELECT col1 FROM tab1)}
709
+ } [list {main tab1 col2} {main tab1 col1}]
710
+ do_test capi2-11.6 {
711
+ check_origins {SELECT (SELECT col2), (SELECT col1) FROM tab1}
712
+ } [list {main tab1 col2} {main tab1 col1}]
713
+ do_test capi2-11.7 {
714
+ check_origins {SELECT * FROM tab1}
715
+ } [list {main tab1 col1} {main tab1 col2}]
716
+ do_test capi2-11.8 {
717
+ check_origins {SELECT * FROM (SELECT * FROM tab1)}
718
+ } [list {main tab1 col1} {main tab1 col2}]
719
+ }
720
+
721
+ ifcapable view&&subquery {
722
+ do_test capi2-12.1 {
723
+ execsql {
724
+ CREATE VIEW view1 AS SELECT * FROM tab1;
725
+ }
726
+ } {}
727
+ do_test capi2-12.2 {
728
+ check_origins {SELECT col2, col1 FROM view1}
729
+ } [list {main tab1 col2} {main tab1 col1}]
730
+ do_test capi2-12.3 {
731
+ check_origins {SELECT col2 AS hello, col1 AS world FROM view1}
732
+ } [list {main tab1 col2} {main tab1 col1}]
733
+ do_test capi2-12.4 {
734
+ check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM view1)}
735
+ } [list {main tab1 col2} {main tab1 col1}]
736
+ do_test capi2-12.5 {
737
+ check_origins {SELECT (SELECT col2 FROM view1), (SELECT col1 FROM view1)}
738
+ } [list {main tab1 col2} {main tab1 col1}]
739
+ do_test capi2-12.6 {
740
+ check_origins {SELECT (SELECT col2), (SELECT col1) FROM view1}
741
+ } [list {main tab1 col2} {main tab1 col1}]
742
+ do_test capi2-12.7 {
743
+ check_origins {SELECT * FROM view1}
744
+ } [list {main tab1 col1} {main tab1 col2}]
745
+ do_test capi2-12.8 {
746
+ check_origins {select * from (select * from view1)}
747
+ } [list {main tab1 col1} {main tab1 col2}]
748
+ do_test capi2-12.9 {
749
+ check_origins {select * from (select * from (select * from view1))}
750
+ } [list {main tab1 col1} {main tab1 col2}]
751
+ do_test capi2-12.10 {
752
+ db close
753
+ sqlite3 db test.db
754
+ set ::DB [sqlite3_connection_pointer db]
755
+ check_origins {select * from (select * from (select * from view1))}
756
+ } [list {main tab1 col1} {main tab1 col2}]
757
+
758
+ # This view will thwart the flattening optimization.
759
+ do_test capi2-13.1 {
760
+ execsql {
761
+ CREATE VIEW view2 AS SELECT * FROM tab1 limit 10 offset 10;
762
+ }
763
+ } {}
764
+ do_test capi2-13.2 {
765
+ check_origins {SELECT col2, col1 FROM view2}
766
+ } [list {main tab1 col2} {main tab1 col1}]
767
+ do_test capi2-13.3 {
768
+ check_origins {SELECT col2 AS hello, col1 AS world FROM view2}
769
+ } [list {main tab1 col2} {main tab1 col1}]
770
+ do_test capi2-13.4 {
771
+ check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM view2)}
772
+ } [list {main tab1 col2} {main tab1 col1}]
773
+ do_test capi2-13.5 {
774
+ check_origins {SELECT (SELECT col2 FROM view2), (SELECT col1 FROM view2)}
775
+ } [list {main tab1 col2} {main tab1 col1}]
776
+ do_test capi2-13.6 {
777
+ check_origins {SELECT (SELECT col2), (SELECT col1) FROM view2}
778
+ } [list {main tab1 col2} {main tab1 col1}]
779
+ do_test capi2-13.7 {
780
+ check_origins {SELECT * FROM view2}
781
+ } [list {main tab1 col1} {main tab1 col2}]
782
+ do_test capi2-13.8 {
783
+ check_origins {select * from (select * from view2)}
784
+ } [list {main tab1 col1} {main tab1 col2}]
785
+ do_test capi2-13.9 {
786
+ check_origins {select * from (select * from (select * from view2))}
787
+ } [list {main tab1 col1} {main tab1 col2}]
788
+ do_test capi2-13.10 {
789
+ db close
790
+ sqlite3 db test.db
791
+ set ::DB [sqlite3_connection_pointer db]
792
+ check_origins {select * from (select * from (select * from view2))}
793
+ } [list {main tab1 col1} {main tab1 col2}]
794
+ do_test capi2-13.11 {
795
+ check_origins {select * from (select * from tab1 limit 10 offset 10)}
796
+ } [list {main tab1 col1} {main tab1 col2}]
797
+ }
798
+
799
+
800
+ } ;# ifcapable columnmetadata
801
+
802
+ db2 close
803
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/carray01.test ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2020-11-17
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # This file implements tests for CARRAY extension
13
+ #
14
+
15
+ set testdir [file dirname $argv0]
16
+ source $testdir/tester.tcl
17
+ set testprefix carray01
18
+
19
+ ifcapable !vtab {
20
+ finish_test
21
+ return
22
+ }
23
+ load_static_extension db carray
24
+
25
+ # Parameter $stmt must be a prepared statement created using
26
+ # the sqlite3_prepare_v2 command and with parameters fully bound.
27
+ # This routine simply runs the statement, gathers the result, and
28
+ # returns a list containing the result.
29
+ #
30
+ # If the optional second argument is true, then the stmt is finalized
31
+ # after it is run.
32
+ #
33
+ proc run_stmt {stmt} {
34
+ set r {}
35
+ while {[sqlite3_step $stmt]=="SQLITE_ROW"} {
36
+ for {set i 0} {$i<[sqlite3_data_count $stmt]} {incr i} {
37
+ lappend r [sqlite3_column_text $stmt $i]
38
+ }
39
+ }
40
+ sqlite3_reset $stmt
41
+ return $r
42
+ }
43
+
44
+ do_test 100 {
45
+ set STMT [sqlite3_prepare_v2 db {SELECT 5 IN carray(?3)} -1]
46
+ sqlite3_carray_bind $STMT 3 1 2 3 4 5 6 7
47
+ run_stmt $STMT
48
+ } {1}
49
+ do_test 101 {
50
+ sqlite3_carray_bind -static $STMT 3 1 2 3 4 5 6 7
51
+ run_stmt $STMT
52
+ } {1}
53
+ do_test 102 {
54
+ set STMT2 [sqlite3_prepare_v2 db {
55
+ SELECT DISTINCT typeof(value) FROM carray(?3)} -1]
56
+ sqlite3_carray_bind $STMT2 3 1 2 3 4 5 6 7
57
+ run_stmt $STMT2
58
+ } {integer}
59
+ do_test 110 {
60
+ sqlite3_carray_bind $STMT 3 1 2 3 4 6 7
61
+ run_stmt $STMT
62
+ } {0}
63
+ do_test 120 {
64
+ sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 5 6 7
65
+ run_stmt $STMT
66
+ } {1}
67
+ do_test 120b {
68
+ sqlite3_carray_bind -int64 $STMT2 3 1 2 3 4 5 6 7
69
+ run_stmt $STMT2
70
+ } {integer}
71
+ do_test 121 {
72
+ sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 5 6 7
73
+ run_stmt $STMT
74
+ } {1}
75
+ do_test 122 {
76
+ sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 5 6 7
77
+ run_stmt $STMT
78
+ } {1}
79
+ do_test 123 {
80
+ sqlite3_carray_bind -int32 -transient $STMT 3 1 2 3 4 5 6 7
81
+ run_stmt $STMT
82
+ } {1}
83
+ do_test 124 {
84
+ sqlite3_carray_bind -int32 -static $STMT 3 1 2 3 4 5 6 7
85
+ run_stmt $STMT
86
+ } {1}
87
+ do_test 125 {
88
+ sqlite3_carray_bind -int32 $STMT 3 1 2 3 4 5 6 7
89
+ run_stmt $STMT
90
+ } {1}
91
+ do_test 130 {
92
+ sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 6 7
93
+ run_stmt $STMT
94
+ } {0}
95
+ do_test 131 {
96
+ sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 6 7
97
+ run_stmt $STMT
98
+ } {0}
99
+ do_test 131 {
100
+ sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 6 7
101
+ run_stmt $STMT
102
+ } {0}
103
+ do_test 140 {
104
+ sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7
105
+ run_stmt $STMT
106
+ } {1}
107
+ do_test 141 {
108
+ sqlite3_carray_bind -double -transient $STMT 3 1 2 3 4 5 6 7
109
+ run_stmt $STMT
110
+ } {1}
111
+ do_test 142 {
112
+ sqlite3_carray_bind -double -static $STMT 3 1 2 3 4 5 6 7
113
+ run_stmt $STMT
114
+ } {1}
115
+ do_test 143 {
116
+ sqlite3_carray_bind -double $STMT2 3 1 2 3 4 5 6 7
117
+ run_stmt $STMT2
118
+ } {real}
119
+ do_test 150 {
120
+ sqlite3_carray_bind -double $STMT 3 1 2 3 4 6 7
121
+ run_stmt $STMT
122
+ } {0}
123
+ do_test 160 {
124
+ sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7
125
+ run_stmt $STMT
126
+ } {1}
127
+ do_test 170 {
128
+ sqlite3_carray_bind -text -static $STMT 3 1 2 3 4 6 7
129
+ run_stmt $STMT
130
+ } {0}
131
+ do_test 171 {
132
+ sqlite3_carray_bind -text -static $STMT2 3 1 2 3 4 6 7
133
+ run_stmt $STMT2
134
+ } {text}
135
+ do_test 180 {
136
+ sqlite3_carray_bind -text -transient $STMT 3 1 2 3 4 5 6 7
137
+ run_stmt $STMT
138
+ } {0}
139
+ do_test 190 {
140
+ sqlite3_carray_bind -blob -static $STMT 3 1 2 3 4 5 6 7
141
+ run_stmt $STMT
142
+ } {0}
143
+ do_test 191 {
144
+ sqlite3_carray_bind -blob -static $STMT2 3 1 2 3 4 5 6 7
145
+ run_stmt $STMT2
146
+ } {blob}
147
+ do_test 200 {
148
+ sqlite3_carray_bind -blob -transient $STMT 3 1 2 3 4 5 6 7
149
+ run_stmt $STMT
150
+ } {0}
151
+ do_test 300 {
152
+ sqlite3_carray_bind $STMT 3
153
+ run_stmt $STMT
154
+ } {0}
155
+
156
+ sqlite3_finalize $STMT
157
+ sqlite3_finalize $STMT2
158
+
159
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/coalesce.test ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2009 November 10
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # Additional test cases for the COALESCE() and IFNULL() functions.
12
+ #
13
+
14
+ set testdir [file dirname $argv0]
15
+ source $testdir/tester.tcl
16
+
17
+
18
+ do_test coalesce-1.0 {
19
+ db eval {
20
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d);
21
+ INSERT INTO t1 VALUES(1, null, null, null);
22
+ INSERT INTO t1 VALUES(2, 2, 99, 99);
23
+ INSERT INTO t1 VALUES(3, null, 3, 99);
24
+ INSERT INTO t1 VALUES(4, null, null, 4);
25
+ INSERT INTO t1 VALUES(5, null, null, null);
26
+ INSERT INTO t1 VALUES(6, 22, 99, 99);
27
+ INSERT INTO t1 VALUES(7, null, 33, 99);
28
+ INSERT INTO t1 VALUES(8, null, null, 44);
29
+
30
+ SELECT coalesce(b,c,d) FROM t1 ORDER BY a;
31
+ }
32
+ } {{} 2 3 4 {} 22 33 44}
33
+ do_test coalesce-1.1 {
34
+ db eval {
35
+ SELECT coalesce(d+c+b,d+c,d) FROM t1 ORDER BY a;
36
+ }
37
+ } {{} 200 102 4 {} 220 132 44}
38
+ do_test coalesce-1.2 {
39
+ db eval {
40
+ SELECT ifnull(d+c+b,ifnull(d+c,d)) FROM t1 ORDER BY a;
41
+ }
42
+ } {{} 200 102 4 {} 220 132 44}
43
+ do_test coalesce-1.3 {
44
+ db eval {
45
+ SELECT ifnull(ifnull(d+c+b,d+c),d) FROM t1 ORDER BY a;
46
+ }
47
+ } {{} 200 102 4 {} 220 132 44}
48
+ do_test coalesce-1.4 {
49
+ db eval {
50
+ SELECT ifnull(ifnull(b,c),d) FROM t1 ORDER BY a;
51
+ }
52
+ } {{} 2 3 4 {} 22 33 44}
53
+ do_test coalesce-1.5 {
54
+ db eval {
55
+ SELECT ifnull(b,ifnull(c,d)) FROM t1 ORDER BY a;
56
+ }
57
+ } {{} 2 3 4 {} 22 33 44}
58
+ do_test coalesce-1.6 {
59
+ db eval {
60
+ SELECT coalesce(b,NOT b,-b,abs(b),lower(b),length(b),min(b,5),b*123,c)
61
+ FROM t1 ORDER BY a;
62
+ }
63
+ } {{} 2 3 {} {} 22 33 {}}
64
+ do_test coalesce-1.7 {
65
+ db eval {
66
+ SELECT ifnull(nullif(a,4),99)
67
+ FROM t1 ORDER BY a;
68
+ }
69
+ } {1 2 3 99 5 6 7 8}
70
+ do_test coalesce-1.8 {
71
+ db eval {
72
+ pragma vdbe_listing=on;
73
+ SELECT coalesce(
74
+ CASE WHEN b=2 THEN 123 END,
75
+ CASE WHEN b=3 THEN 234 END,
76
+ CASE WHEN c=3 THEN 345 WHEN c=33 THEN 456 END,
77
+ d
78
+ )
79
+ FROM t1 ORDER BY a;
80
+ }
81
+ } {{} 123 345 4 {} 99 456 44}
82
+
83
+
84
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/collateB.test ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2016-07-01
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # Test cases for a crash bug.
12
+ #
13
+
14
+ set testdir [file dirname $argv0]
15
+ source $testdir/tester.tcl
16
+ set testprefix collateB
17
+
18
+ do_execsql_test collateB-1.1 {
19
+ CREATE TABLE t1(a INTEGER PRIMARY KEY);
20
+ CREATE TABLE t2(b INTEGER PRIMARY KEY, x1 INT COLLATE NOCASE);
21
+ CREATE TABLE t3(x2 INT);
22
+ SELECT * FROM t3, t2, t1 WHERE x2=b AND x1=a AND a=1;
23
+ } {}
24
+ do_execsql_test collateB-1.2 {
25
+ INSERT INTO t1(a) VALUES(1),(2),(3);
26
+ INSERT INTO t2(b,x1) VALUES(11,1),(22,2),(33,3);
27
+ INSERT INTO t3(x2) VALUES(11),(22),(33);
28
+ SELECT *,'|' FROM t3, t2, t1 WHERE x2=b AND x1=a AND a=1;
29
+ } {11 11 1 1 |}
30
+ do_execsql_test collateB-1.3 {
31
+ SELECT *,'|' FROM t3, t1, t2 WHERE x2=b AND x1=a AND a=1;
32
+ } {11 1 11 1 |}
33
+ do_execsql_test collateB-1.4 {
34
+ SELECT *,'|' FROM t2, t3, t1 WHERE x2=b AND x1=a AND a=1;
35
+ } {11 1 11 1 |}
36
+ do_execsql_test collateB-1.5 {
37
+ SELECT *,'|' FROM t2, t1, t3 WHERE x2=b AND x1=a AND a=1;
38
+ } {11 1 1 11 |}
39
+ do_execsql_test collateB-1.6 {
40
+ SELECT *,'|' FROM t1, t2, t3 WHERE x2=b AND x1=a AND a=1;
41
+ } {1 11 1 11 |}
42
+ do_execsql_test collateB-1.7 {
43
+ SELECT *,'|' FROM t1, t2, t3 WHERE x2=b AND x1=a AND a=1;
44
+ } {1 11 1 11 |}
45
+ do_execsql_test collateB-1.12 {
46
+ SELECT *,'|' FROM t3, t2, t1 WHERE b=x2 AND a=x1 AND 1=a;
47
+ } {11 11 1 1 |}
48
+ do_execsql_test collateB-1.13 {
49
+ SELECT *,'|' FROM t3, t1, t2 WHERE b=x2 AND a=x1 AND 1=a;
50
+ } {11 1 11 1 |}
51
+ do_execsql_test collateB-1.14 {
52
+ SELECT *,'|' FROM t2, t3, t1 WHERE b=x2 AND a=x1 AND 1=a;
53
+ } {11 1 11 1 |}
54
+ do_execsql_test collateB-1.15 {
55
+ SELECT *,'|' FROM t2, t1, t3 WHERE b=x2 AND a=x1 AND 1=a;
56
+ } {11 1 1 11 |}
57
+ do_execsql_test collateB-1.16 {
58
+ SELECT *,'|' FROM t1, t2, t3 WHERE b=x2 AND a=x1 AND 1=a;
59
+ } {1 11 1 11 |}
60
+ do_execsql_test collateB-1.17 {
61
+ SELECT *,'|' FROM t1, t2, t3 WHERE b=x2 AND a=x1 AND 1=a;
62
+ } {1 11 1 11 |}
63
+
64
+ #-------------------------------------------------------------------------
65
+ # Test an assert() failure that was occuring if an index were created
66
+ # on a column explicitly declared "COLLATE binary".
67
+ reset_db
68
+ do_execsql_test 2.1 {
69
+ CREATE TABLE t4(a COLLATE binary);
70
+ CREATE INDEX i4 ON t4(a);
71
+ INSERT INTO t4 VALUES('one'), ('two'), ('three');
72
+ VACUUM;
73
+ }
74
+
75
+ integrity_check 2.2
76
+
77
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/corrupt4.test ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2007 Sept 7
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library.
12
+ #
13
+ # This file implements tests to make sure SQLite does not crash or
14
+ # segfault if it sees a corrupt database file.
15
+ #
16
+
17
+ set testdir [file dirname $argv0]
18
+ source $testdir/tester.tcl
19
+ set testprefix corrupt4
20
+
21
+ # This module uses hard-coded offsets which do not work if the reserved_bytes
22
+ # value is nonzero.
23
+ if {[nonzero_reserved_bytes]} {finish_test; return;}
24
+
25
+ # These tests deal with corrupt database files
26
+ #
27
+ database_may_be_corrupt
28
+
29
+ # We must have the page_size pragma for these tests to work.
30
+ #
31
+ ifcapable !pager_pragmas {
32
+ finish_test
33
+ return
34
+ }
35
+
36
+ # Create a database with a freelist containing at least two pages.
37
+ #
38
+ do_test corrupt4-1.1 {
39
+ set bigstring [string repeat 0123456789 200]
40
+ execsql {
41
+ PRAGMA auto_vacuum=OFF;
42
+ PRAGMA page_size=1024;
43
+ CREATE TABLE t1(x);
44
+ INSERT INTO t1 VALUES($bigstring);
45
+ CREATE TABLE t2(y);
46
+ INSERT INTO t2 VALUES(1);
47
+ DROP TABLE t1;
48
+ }
49
+ file size test.db
50
+ } [expr {1024*4}]
51
+
52
+ # Verify that there are two pages on the freelist.
53
+ #
54
+ do_test corrupt4-1.2 {
55
+ execsql {PRAGMA freelist_count}
56
+ } {2}
57
+
58
+ # Get the page number for the trunk of the freelist.
59
+ #
60
+ set trunkpgno [hexio_get_int [hexio_read test.db 32 4]]
61
+ set baseaddr [expr {($trunkpgno-1)*1024}]
62
+
63
+ # Verify that the trunk of the freelist has exactly one
64
+ # leaf.
65
+ #
66
+ do_test corrupt4-1.3 {
67
+ hexio_get_int [hexio_read test.db [expr {$::baseaddr+4}] 4]
68
+ } {1}
69
+
70
+ # Insert a negative number as the number of leaves on the trunk.
71
+ # Then try to add a new element to the freelist.
72
+ #
73
+ do_test corrupt4-1.4 {
74
+ hexio_write test.db [expr {$::baseaddr+4}] [hexio_render_int32 -100000000]
75
+ db close
76
+ sqlite3 db test.db
77
+ catchsql {
78
+ DROP TABLE t2
79
+ }
80
+ } {1 {database disk image is malformed}}
81
+
82
+ #-------------------------------------------------------------------------
83
+
84
+ reset_db
85
+ do_execsql_test 2.0 {
86
+ PRAGMA page_size = 512;
87
+ CREATE TABLE t1(a, b, c);
88
+ }
89
+
90
+ # Create a database with a schema so large that the root of the
91
+ # sqlite_schema table is the grandparent of its leaves.
92
+ #
93
+ set nView 1000
94
+ do_test 2.1 {
95
+ execsql BEGIN
96
+ for {set ii 0} {$ii<$nView} {incr ii} {
97
+ execsql " CREATE VIEW v$ii AS SELECT a, b, c FROM t1 "
98
+ }
99
+ execsql COMMIT
100
+ } {}
101
+ db close
102
+
103
+ proc get2byte {fd offset} {
104
+ seek $fd $offset
105
+ set bin [read $fd 2]
106
+ binary scan $bin S val
107
+ set val
108
+ }
109
+ proc get4byte {fd offset} {
110
+ seek $fd $offset
111
+ set bin [read $fd 4]
112
+ binary scan $bin I val
113
+ set val
114
+ }
115
+ proc put4byte {fd offset val} {
116
+ seek $fd $offset
117
+ set bin [binary format I $val]
118
+ puts -nonewline $fd $bin
119
+ }
120
+
121
+ # Page 1 is now the grandparent of its leaves. Corrupt the database by setting
122
+ # the second rightmost child page number of page 1 to 1.
123
+ #
124
+ set fd [open test.db r+]
125
+ fconfigure $fd -translation binary
126
+ set nChild [get2byte $fd 103]
127
+ set offChild [get2byte $fd [expr 100+12+($nChild-2)*2]]
128
+ set pgnoChild [get4byte $fd $offChild]
129
+ put4byte $fd $offChild 1
130
+ close $fd
131
+
132
+ if {![info exists ::G(perm:presql)]} {
133
+ sqlite3 db test.db
134
+
135
+ do_catchsql_test 2.2 {
136
+ PRAGMA writable_schema = 1;
137
+ SELECT * FROM sqlite_schema;
138
+ } {1 {database disk image is malformed}}
139
+
140
+ do_test 2.3 {
141
+ list [catch {
142
+ for {set ii $nView} {$ii<$nView*2} {incr ii} {
143
+ execsql "INSERT INTO sqlite_master VALUES(1, 2, 3, 4, 5)"
144
+ }
145
+ } msg] $msg
146
+ } {1 {database disk image is malformed}}
147
+ }
148
+
149
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/crash6.test ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2001 September 15
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file tests that rollback journals for databases that use a
12
+ # page-size other than the default page-size can be rolled back Ok.
13
+ #
14
+ # $Id: crash6.test,v 1.2 2008/04/14 15:27:19 drh Exp $
15
+
16
+ set testdir [file dirname $argv0]
17
+ source $testdir/tester.tcl
18
+
19
+ ifcapable !crashtest {
20
+ finish_test
21
+ return
22
+ }
23
+
24
+ for {set ii 0} {$ii < 10} {incr ii} {
25
+ catch {db close}
26
+ forcedelete test.db test.db-journal
27
+ crashsql -delay 2 -file test.db {
28
+ PRAGMA auto_vacuum=OFF;
29
+ PRAGMA page_size=4096;
30
+ BEGIN;
31
+ CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
32
+ COMMIT;
33
+ BEGIN;
34
+ CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f;
35
+ COMMIT;
36
+ }
37
+ sqlite3 db test.db
38
+ integrity_check crash6-1.$ii
39
+ }
40
+
41
+ for {set ii 0} {$ii < 10} {incr ii} {
42
+ catch {db close}
43
+ forcedelete test.db test.db-journal
44
+ sqlite3 db test.db
45
+ execsql {
46
+ PRAGMA auto_vacuum=OFF;
47
+ PRAGMA page_size=2048;
48
+ BEGIN;
49
+ CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
50
+ COMMIT;
51
+ }
52
+ db close
53
+ crashsql -delay 1 -file test.db {
54
+ INSERT INTO abc VALUES(5, 6, 7);
55
+ }
56
+ sqlite3 db test.db
57
+ integrity_check crash6-2.$ii
58
+ }
59
+
60
+ proc signature {} {
61
+ return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
62
+ }
63
+
64
+ # Test case for crashing during database sync with page-size values
65
+ # from 1024 to 8192.
66
+ #
67
+ for {set ii 0} {$ii < 30} {incr ii} {
68
+ db close
69
+ forcedelete test.db
70
+ sqlite3 db test.db
71
+
72
+ set pagesize [expr 1024 << ($ii % 4)]
73
+ if {$pagesize>$::SQLITE_MAX_PAGE_SIZE} {
74
+ set pagesize $::SQLITE_MAX_PAGE_SIZE
75
+ }
76
+ do_test crash6-3.$ii.0 {
77
+ execsql "pragma page_size = $pagesize"
78
+ execsql "pragma page_size"
79
+ } $pagesize
80
+
81
+ do_test crash6-3.$ii.1 {
82
+
83
+ execsql BEGIN
84
+ execsql {CREATE TABLE abc(a, b, c)}
85
+ for {set n 0} {$n < 1000} {incr n} {
86
+ execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])"
87
+ }
88
+ execsql {
89
+ INSERT INTO abc SELECT * FROM abc;
90
+ INSERT INTO abc SELECT * FROM abc;
91
+ INSERT INTO abc SELECT * FROM abc;
92
+ INSERT INTO abc SELECT * FROM abc;
93
+ INSERT INTO abc SELECT * FROM abc;
94
+ }
95
+ execsql COMMIT
96
+ expr ([file size test.db] / 1024) > 450
97
+ } {1}
98
+
99
+ set sig [signature]
100
+ db close
101
+
102
+ do_test crash6-3.$ii.2 {
103
+ crashsql -file test.db "
104
+ BEGIN;
105
+ SELECT random() FROM abc LIMIT $ii;
106
+ INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
107
+ DELETE FROM abc WHERE random()%2!=0;
108
+ COMMIT;
109
+ "
110
+ } {1 {child process exited abnormally}}
111
+
112
+ do_test crash6-3.$ii.3 {
113
+ sqlite3 db test.db
114
+ signature
115
+ } $sig
116
+ }
117
+
118
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/crashM.test ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2015 Mar 13
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # Crash tests for the multiplex module with 8.3 filenames enabled.
13
+ #
14
+
15
+ set testdir [file dirname $argv0]
16
+ source $testdir/tester.tcl
17
+ set testprefix crashM
18
+
19
+ ifcapable !crashtest||!8_3_names {
20
+ finish_test
21
+ return
22
+ }
23
+
24
+ db close
25
+ sqlite3_shutdown
26
+ sqlite3_config_uri 1
27
+
28
+ foreach f [glob -nocomplain test1.* test2.*] { forcedelete $f }
29
+ sqlite3_multiplex_initialize "" 1
30
+ sqlite3 db file:test1.db?8_3_names=1
31
+ sqlite3_multiplex_control db main chunk_size [expr 64*1024]
32
+
33
+ do_execsql_test 1.0 {
34
+ ATTACH 'file:test2.db?8_3_names=1' AS aux;
35
+
36
+ CREATE TABLE t1(x, y);
37
+ CREATE INDEX t1x ON t1(x);
38
+ CREATE INDEX t1y ON t1(y);
39
+
40
+ CREATE TABLE aux.t2(x, y);
41
+ CREATE INDEX aux.t2x ON t2(x);
42
+ CREATE INDEX aux.t2y ON t2(y);
43
+
44
+ WITH s(a) AS (
45
+ SELECT 1 UNION ALL SELECT a+1 FROM s WHERE a<1000
46
+ )
47
+ INSERT INTO t1 SELECT a, randomblob(500) FROM s;
48
+
49
+ WITH s(a) AS (
50
+ SELECT 1 UNION ALL SELECT a+1 FROM s WHERE a<1000
51
+ )
52
+ INSERT INTO t2 SELECT a, randomblob(500) FROM s;
53
+ } {}
54
+
55
+ for {set i 0} {$i < 20} {incr i} {
56
+ do_test 2.$i.1 {
57
+ crashsql -delay 1 -file test1.db -opendb {
58
+ sqlite3_shutdown
59
+ sqlite3_config_uri 1
60
+ sqlite3_multiplex_initialize crash 1
61
+ sqlite3 db file:test1.db?8_3_names=1
62
+ sqlite3_multiplex_control db main chunk_size [expr 64*1024]
63
+ } {
64
+ ATTACH 'file:test2.db?8_3_names=1' AS aux;
65
+ BEGIN;
66
+ UPDATE t1 SET y = randomblob(500) WHERE (x%10)==0;
67
+ UPDATE t2 SET y = randomblob(500) WHERE (x%10)==0;
68
+ COMMIT;
69
+ }
70
+ } {1 {child process exited abnormally}}
71
+
72
+ do_execsql_test 2.$i.2 {
73
+ PRAGMA main.integrity_check;
74
+ PRAGMA aux.integrity_check;
75
+ } {ok ok}
76
+ }
77
+
78
+ catch { db close }
79
+ sqlite3_multiplex_shutdown
80
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/ctime.test ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2009 February 24
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library.
12
+ #
13
+ # This file implements tests for the compile time diagnostic
14
+ # functions.
15
+ #
16
+
17
+ set testdir [file dirname $argv0]
18
+ source $testdir/tester.tcl
19
+
20
+ # Test organization:
21
+ #
22
+ # ctime-1.*: Test pragma support.
23
+ # ctime-2.*: Test function support.
24
+ #
25
+
26
+ ifcapable !pragma||!compileoption_diags {
27
+ finish_test
28
+ return
29
+ }
30
+
31
+ #####################
32
+ # ctime-1.*: Test pragma support.
33
+
34
+ do_test ctime-1.1.1 {
35
+ catchsql {
36
+ PRAGMA compile_options();
37
+ }
38
+ } {1 {near ")": syntax error}}
39
+ do_test ctime-1.1.2 {
40
+ catchsql {
41
+ PRAGMA compile_options(NULL);
42
+ }
43
+ } {1 {near "NULL": syntax error}}
44
+ do_test ctime-1.1.3 {
45
+ catchsql {
46
+ PRAGMA compile_options *;
47
+ }
48
+ } {1 {near "*": syntax error}}
49
+
50
+ do_test ctime-1.2.1 {
51
+ set ans [ catchsql {
52
+ PRAGMA compile_options;
53
+ } ]
54
+ list [ lindex $ans 0 ]
55
+ } {0}
56
+ # the results should be in sorted order already
57
+ do_test ctime-1.2.2 {
58
+ set ans [ catchsql {
59
+ PRAGMA compile_options;
60
+ } ]
61
+ list [ lindex $ans 0 ] [ expr { [lsort [lindex $ans 1]]==[lindex $ans 1] } ]
62
+ } {0 1}
63
+
64
+ # Check the THREADSAFE option for SQLITE_THREADSAFE=2 builds (there are
65
+ # a couple of these configurations in releasetest.tcl).
66
+ #
67
+ ifcapable threadsafe2 {
68
+ foreach {tn opt res} {
69
+ 1 SQLITE_THREADSAFE 1
70
+ 2 THREADSAFE 1
71
+ 3 THREADSAFE=0 0
72
+ 4 THREADSAFE=1 0
73
+ 5 THREADSAFE=2 1
74
+ 6 THREADSAFE= 0
75
+ } {
76
+ do_execsql_test ctime-1.3.$tn {
77
+ SELECT sqlite_compileoption_used($opt)
78
+ } $res
79
+ }
80
+ }
81
+
82
+ # SQLITE_THREADSAFE should pretty much always be defined
83
+ # one way or the other, and it must have a value of 0 or 1.
84
+ sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1
85
+ do_test ctime-1.4.1 {
86
+ catchsql {
87
+ SELECT sqlite_compileoption_used('SQLITE_THREADSAFE');
88
+ }
89
+ } {0 1}
90
+ do_test ctime-1.4.2 {
91
+ catchsql {
92
+ SELECT sqlite_compileoption_used('THREADSAFE');
93
+ }
94
+ } {0 1}
95
+ do_test ctime-1.4.3 {
96
+ catchsql {
97
+ SELECT sqlite_compileoption_used("THREADSAFE");
98
+ }
99
+ } {0 1}
100
+
101
+ do_test ctime-1.5 {
102
+ set ans1 [ catchsql {
103
+ SELECT sqlite_compileoption_used('THREADSAFE=0');
104
+ } ]
105
+ set ans2 [ catchsql {
106
+ SELECT sqlite_compileoption_used('THREADSAFE=1');
107
+ } ]
108
+ set ans3 [ catchsql {
109
+ SELECT sqlite_compileoption_used('THREADSAFE=2');
110
+ } ]
111
+ lsort [ list $ans1 $ans2 $ans3 ]
112
+ } {{0 0} {0 0} {0 1}}
113
+
114
+ do_test ctime-1.6 {
115
+ execsql {
116
+ SELECT sqlite_compileoption_used('THREADSAFE=');
117
+ }
118
+ } {0}
119
+
120
+ do_test ctime-1.7.1 {
121
+ execsql {
122
+ SELECT sqlite_compileoption_used('SQLITE_OMIT_COMPILEOPTION_DIAGS');
123
+ }
124
+ } {0}
125
+ do_test ctime-1.7.2 {
126
+ execsql {
127
+ SELECT sqlite_compileoption_used('OMIT_COMPILEOPTION_DIAGS');
128
+ }
129
+ } {0}
130
+
131
+ #####################
132
+ # ctime-2.*: Test function support.
133
+
134
+ do_test ctime-2.1.1 {
135
+ catchsql {
136
+ SELECT sqlite_compileoption_used();
137
+ }
138
+ } {1 {wrong number of arguments to function sqlite_compileoption_used()}}
139
+ do_test ctime-2.1.2 {
140
+ catchsql {
141
+ SELECT sqlite_compileoption_used(NULL);
142
+ }
143
+ } {0 {{}}}
144
+ do_test ctime-2.1.3 {
145
+ catchsql {
146
+ SELECT sqlite_compileoption_used("");
147
+ }
148
+ } {0 0}
149
+ do_test ctime-2.1.4 {
150
+ catchsql {
151
+ SELECT sqlite_compileoption_used('');
152
+ }
153
+ } {0 0}
154
+ do_test ctime-2.1.5 {
155
+ catchsql {
156
+ SELECT sqlite_compileoption_used(foo);
157
+ }
158
+ } {1 {no such column: foo}}
159
+ do_test ctime-2.1.6 {
160
+ catchsql {
161
+ SELECT sqlite_compileoption_used('THREADSAFE', 0);
162
+ }
163
+ } {1 {wrong number of arguments to function sqlite_compileoption_used()}}
164
+ do_test ctime-2.1.7 {
165
+ catchsql {
166
+ SELECT sqlite_compileoption_used(0);
167
+ }
168
+ } {0 0}
169
+ do_test ctime-2.1.8 {
170
+ catchsql {
171
+ SELECT sqlite_compileoption_used('0');
172
+ }
173
+ } {0 0}
174
+ do_test ctime-2.1.9 {
175
+ catchsql {
176
+ SELECT sqlite_compileoption_used(1.0);
177
+ }
178
+ } {0 0}
179
+
180
+ do_test ctime-2.2.1 {
181
+ catchsql {
182
+ SELECT sqlite_compileoption_get();
183
+ }
184
+ } {1 {wrong number of arguments to function sqlite_compileoption_get()}}
185
+ do_test ctime-2.2.2 {
186
+ catchsql {
187
+ SELECT sqlite_compileoption_get(0, 0);
188
+ }
189
+ } {1 {wrong number of arguments to function sqlite_compileoption_get()}}
190
+
191
+ # This assumes there is at least 1 compile time option
192
+ # (see SQLITE_THREADSAFE above).
193
+ do_test ctime-2.3 {
194
+ catchsql {
195
+ SELECT sqlite_compileoption_used(sqlite_compileoption_get(0));
196
+ }
197
+ } {0 1}
198
+
199
+ # This assumes there is at least 1 compile time option
200
+ # (see SQLITE_THREADSAFE above).
201
+ do_test ctime-2.4 {
202
+ set ans [ catchsql {
203
+ SELECT sqlite_compileoption_get(0);
204
+ } ]
205
+ list [lindex $ans 0]
206
+ } {0}
207
+
208
+ # Get the list of defines using the pragma,
209
+ # then try querying each one with the functions.
210
+ set ans [ catchsql {
211
+ PRAGMA compile_options;
212
+ } ]
213
+ set opts [ lindex $ans 1 ]
214
+ set tc 1
215
+ foreach opt $opts {
216
+ do_test ctime-2.5.$tc {
217
+ set N [ expr {$tc-1} ]
218
+ set ans1 [catch {db one {
219
+ SELECT sqlite_compileoption_get($N);
220
+ }} msg]
221
+ lappend ans1 $msg
222
+ set ans2 [ catchsql {
223
+ SELECT sqlite_compileoption_used($opt);
224
+ } ]
225
+ list [ lindex $ans1 0 ] [ expr { [lindex $ans1 1]==$opt } ] \
226
+ [ expr { $ans2 } ]
227
+ } {0 1 {0 1}}
228
+ incr tc 1
229
+ }
230
+ # test 1 past array bounds
231
+ do_test ctime-2.5.$tc {
232
+ set N [ expr {$tc-1} ]
233
+ set ans [ catchsql {
234
+ SELECT sqlite_compileoption_get($N);
235
+ } ]
236
+ } {0 {{}}}
237
+ incr tc 1
238
+ # test 1 before array bounds (N=-1)
239
+ do_test ctime-2.5.$tc {
240
+ set N -1
241
+ set ans [ catchsql {
242
+ SELECT sqlite_compileoption_get($N);
243
+ } ]
244
+ } {0 {{}}}
245
+
246
+ #--------------------------------------------------------------------------
247
+ # Test that SQLITE_DIRECT_OVERFLOW_READ is reflected in the output of
248
+ # "PRAGMA compile_options".
249
+ #
250
+ ifcapable direct_read {
251
+ set res 1
252
+ } else {
253
+ set res 0
254
+ }
255
+ do_test ctime-3.0.1 {
256
+ expr [lsearch [db eval {PRAGMA compile_options}] DIRECT_OVERFLOW_READ]>=0
257
+ } $res
258
+
259
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/date4.test ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2023-08-29
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # Test cases for the strftime() SQL function. Comparisons against the
13
+ # C-library strftime() function.
14
+
15
+ set testdir [file dirname $argv0]
16
+ source $testdir/tester.tcl
17
+
18
+ # Skip this whole file if date and time functions are omitted
19
+ # at compile-time
20
+ #
21
+ ifcapable {!datetime} {
22
+ finish_test
23
+ return
24
+ }
25
+
26
+ if {$tcl_platform(os)=="Linux"} {
27
+ set FMT {%d,%e,%F,%H,%k,%I,%l,%j,%m,%M,%u,%w,%W,%Y,%%,%P,%p,%U,%V,%G,%g}
28
+ } else {
29
+ set FMT {%d,%e,%F,%H,%I,%j,%p,%R,%u,%w,%W,%%}
30
+ }
31
+ for {set i 0} {$i<=24858} {incr i} {
32
+ set TS [expr {$i*86390}]
33
+ do_execsql_test date4-$i {
34
+ SELECT strftime($::FMT,$::TS,'unixepoch');
35
+ } [list [strftime $FMT $TS]]
36
+ }
37
+
38
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/dbdata.test ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2019-04-11
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this file is testing the sqlite_dbpage virtual table.
13
+ #
14
+
15
+ set testdir [file dirname $argv0]
16
+ source $testdir/tester.tcl
17
+ set testprefix dbdata
18
+
19
+ ifcapable !vtab||!compound {
20
+ finish_test
21
+ return
22
+ }
23
+ if { [catch { db enable_load_extension 1 }]
24
+ || [catch { db eval { SELECT load_extension('../dbdata') } }]
25
+ } {
26
+ finish_test
27
+ return
28
+ }
29
+
30
+ do_execsql_test 1.0 {
31
+ CREATE TABLE T1(a, b);
32
+ INSERT INTO t1(rowid, a ,b) VALUES(5, 'v', 'five');
33
+ INSERT INTO t1(rowid, a, b) VALUES(10, 'x', 'ten');
34
+ }
35
+
36
+ do_execsql_test 1.1 {
37
+ SELECT pgno, cell, field, quote(value) FROM sqlite_dbdata WHERE pgno=2;
38
+ } {
39
+ 2 0 -1 5
40
+ 2 0 0 'v'
41
+ 2 0 1 'five'
42
+ 2 1 -1 10
43
+ 2 1 0 'x'
44
+ 2 1 1 'ten'
45
+ }
46
+
47
+ breakpoint
48
+ do_execsql_test 1.2 {
49
+ SELECT pgno, cell, field, quote(value) FROM sqlite_dbdata;
50
+ } {
51
+ 1 0 -1 1
52
+ 1 0 0 'table'
53
+ 1 0 1 'T1'
54
+ 1 0 2 'T1'
55
+ 1 0 3 2
56
+ 1 0 4 {'CREATE TABLE T1(a, b)'}
57
+ 2 0 -1 5
58
+ 2 0 0 'v'
59
+ 2 0 1 'five'
60
+ 2 1 -1 10
61
+ 2 1 0 'x'
62
+ 2 1 1 'ten'
63
+ }
64
+
65
+ set big [string repeat big 2000]
66
+ do_execsql_test 1.3 {
67
+ INSERT INTO t1 VALUES(NULL, $big);
68
+ SELECT value FROM sqlite_dbdata WHERE pgno=2 AND cell=2 AND field=1;
69
+ } $big
70
+
71
+ do_execsql_test 1.4 {
72
+ DELETE FROM t1;
73
+ INSERT INTO t1 VALUES(NULL, randomblob(5050));
74
+ }
75
+ do_test 1.5 {
76
+ execsql {
77
+ SELECT quote(value) FROM sqlite_dbdata WHERE pgno=2 AND cell=0 AND field=1;
78
+ }
79
+ } [db one {SELECT quote(b) FROM t1}]
80
+
81
+ #-------------------------------------------------------------------------
82
+ reset_db
83
+ db enable_load_extension 1
84
+ db eval { SELECT load_extension('../dbdata') }
85
+
86
+ do_execsql_test 2.0 {
87
+ CREATE TABLE t1(a);
88
+ CREATE INDEX i1 ON t1(a);
89
+ WITH s(i) AS (
90
+ SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10
91
+ )
92
+ INSERT INTO t1 SELECT randomblob(900) FROM s;
93
+ }
94
+
95
+ do_execsql_test 2.1 {
96
+ SELECT * FROM sqlite_dbptr WHERE pgno=2;
97
+ } {
98
+ 2 25 2 6 2 7 2 9 2 11 2 13 2 15 2 17 2 19 2 21
99
+ }
100
+
101
+ do_execsql_test 2.2 {
102
+ SELECT * FROM sqlite_dbptr WHERE pgno=3;
103
+ } {
104
+ 3 24 3 23
105
+ }
106
+
107
+ do_execsql_test 2.3 {
108
+ SELECT * FROM sqlite_dbptr
109
+ } {
110
+ 2 25 2 6 2 7 2 9 2 11 2 13 2 15 2 17 2 19 2 21
111
+ 3 24 3 23
112
+ }
113
+
114
+
115
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/dbfuzz001.test ADDED
@@ -0,0 +1,397 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2012-12-13
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # Test cases for corrupt database files.
13
+
14
+ set testdir [file dirname $argv0]
15
+ source $testdir/tester.tcl
16
+
17
+ ifcapable !deserialize {
18
+ finish_test
19
+ return
20
+ }
21
+ database_may_be_corrupt
22
+
23
+ # In the following database file, there is 384 bytes of free space
24
+ # on page 8 that does not appear on the freeblock list.
25
+ #
26
+ do_test dbfuzz001-100 {
27
+ sqlite3 db {}
28
+ db deserialize [decode_hexdb {
29
+ | size 5632 pagesize 512 filename c4.db
30
+ | page 1 offset 0
31
+ | 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
32
+ | 16: 02 00 01 01 00 40 20 20 00 00 00 02 00 00 00 0b .....@ ........
33
+ | 32: 00 00 00 06 00 00 00 01 00 00 00 28 00 00 00 04 ...........(....
34
+ | 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
35
+ | 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 ................
36
+ | 96: 00 2e 30 38 0d 00 00 00 06 01 06 00 01 da 01 b0 ..08............
37
+ | 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*..........
38
+ | 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 ......"......1ta
39
+ | 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T
40
+ | 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*.....
41
+ | 304: 01 3f 69 6e 64 65 78 00 00 00 00 00 00 00 00 00 .?index.........
42
+ | 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein
43
+ | 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE
44
+ | 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t
45
+ | 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta
46
+ | 400: 62 6c 65 74 33 74 33 04 43 52 45 41 54 45 20 54 blet3t3.CREATE T
47
+ | 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f)
48
+ | 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t
49
+ | 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t
50
+ | 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$.....
51
+ | 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA
52
+ | 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b)
53
+ | page 2 offset 512
54
+ | 0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................
55
+ | page 3 offset 1024
56
+ | 0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................
57
+ | page 4 offset 1536
58
+ | 0: 05 00 00 00 03 01 f1 00 00 00 00 0b 01 fb 01 f6 ................
59
+ | 16: 01 f1 00 16 00 00 09 06 05 01 01 01 01 04 04 03 ................
60
+ | 32: 03 07 05 05 01 01 09 09 02 02 19 04 05 17 17 17 ................
61
+ | 48: 17 73 65 76 65 6e 65 69 67 68 74 65 69 67 68 74 .seveneighteight
62
+ | 64: 73 65 76 65 6e 25 03 05 07 07 07 07 40 14 00 00 seven%......@...
63
+ | 80: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@...
64
+ | 96: 00 00 00 00 40 14 00 00 00 00 00 00 09 02 05 01 ....@...........
65
+ | 112: 01 01 01 03 04 04 03 07 01 05 09 01 01 09 02 02 ................
66
+ | 352: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a ................
67
+ | 496: 00 00 00 00 0a 3e 00 00 00 09 21 00 00 00 08 06 .....>....!.....
68
+ | page 5 offset 2048
69
+ | 0: 0a 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................
70
+ | page 7 offset 3072
71
+ | 0: 0d 00 00 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec ................
72
+ | 16: 01 e0 01 d4 01 cb 01 c2 00 00 00 00 00 00 00 00 ................
73
+ | 96: 00 00 00 00 13 00 00 00 00 00 00 00 00 00 00 00 ................
74
+ | 224: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 ................
75
+ | 288: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................
76
+ | 448: 00 00 07 08 02 17 65 69 67 68 74 07 07 02 17 65 ......eight....e
77
+ | 464: 69 67 68 74 0a 06 02 07 40 18 00 00 00 00 00 00 ight....@.......
78
+ | 480: 0a 05 02 07 40 18 00 00 00 00 00 00 03 04 02 01 ....@...........
79
+ | 496: 04 03 03 02 01 04 03 02 02 01 02 03 01 02 01 02 ................
80
+ | page 8 offset 3584
81
+ | 0: 0d 00 21 00 01 00 16 00 00 16 00 16 00 16 00 16 ..!.............
82
+ | 16: 00 16 00 16 00 00 09 06 05 01 01 01 01 04 04 03 ................
83
+ | 32: 03 00 00 00 5f 01 09 09 02 02 00 00 00 56 17 17 ...._........V..
84
+ | 48: 17 73 65 76 65 6e 65 69 67 68 74 65 69 67 68 74 .seveneighteight
85
+ | 64: 73 65 76 65 6e 00 00 00 3b 07 07 07 40 14 00 00 seven...;...@...
86
+ | 80: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@...
87
+ | 96: 00 00 00 00 40 14 00 00 00 00 00 00 00 00 00 14 ....@...........
88
+ | 112: 01 01 01 03 04 04 03 00 00 00 09 01 01 09 02 02 ................
89
+ | 352: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a ................
90
+ | page 9 offset 4096
91
+ | 0: 0d 00 00 00 1b 00 47 00 01 d9 01 be 01 af 01 a0 ......G.........
92
+ | 16: 01 91 01 82 01 73 01 64 01 55 01 46 01 37 01 28 .....s.d.U.F.7.(
93
+ | 32: 01 19 01 0a 00 fb 00 ec 00 dd 00 ce 00 bf 00 b0 ................
94
+ | 48: 00 a1 00 92 00 83 00 74 00 65 00 56 00 47 00 00 .......t.e.V.G..
95
+ | 64: 00 00 00 00 00 00 00 0d 21 00 00 48 01 54 00 01 ........!..H.T..
96
+ | 80: f7 01 ec 01 c5 01 0d 20 00 00 48 01 54 00 01 f7 ....... ..H.T...
97
+ | 96: 01 ec 01 c5 01 0d 1f 00 00 48 01 54 00 01 f7 01 .........H.T....
98
+ | 112: ec 01 c5 01 0d 1e 00 00 48 01 54 00 01 f7 01 ec ........H.T.....
99
+ | 128: 01 c5 01 0d 1d 00 00 48 01 54 00 01 f7 01 ec 01 .......H.T......
100
+ | 144: c5 01 0d 1c 00 00 48 01 54 00 01 f7 01 ec 01 c5 ......H.T.......
101
+ | 160: 01 0d 1b 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 .....H.T........
102
+ | 176: 0d 1a 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d ....H.T.........
103
+ | 192: 19 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 18 ...H.T..........
104
+ | 208: 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 17 00 ..H.T...........
105
+ | 224: 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 16 00 00 .H.T............
106
+ | 240: 48 01 54 00 01 f7 01 ec 01 c5 01 0d 15 00 00 48 H.T............H
107
+ | 256: 01 54 00 01 f7 01 ec 01 c5 01 0d 14 00 00 48 01 .T............H.
108
+ | 272: 54 00 01 f7 01 ec 01 c5 01 0d 13 00 00 48 01 54 T............H.T
109
+ | 288: 00 01 f7 01 ec 01 c5 01 0d 12 00 00 48 01 54 00 ............H.T.
110
+ | 304: 01 f7 01 ec 01 c5 01 0d 11 00 00 48 01 54 00 01 ...........H.T..
111
+ | 320: f7 01 ec 01 c5 01 0d 10 00 00 48 01 54 00 01 f7 ..........H.T...
112
+ | 336: 01 ec 01 c5 01 0d 0f 00 00 48 01 54 00 01 f7 01 .........H.T....
113
+ | 352: ec 01 c5 01 0d 0e 00 00 48 01 54 00 01 f7 01 ec ........H.T.....
114
+ | 368: 01 c5 01 0d 0d 00 00 48 01 54 00 01 f7 01 ec 01 .......H.T......
115
+ | 384: c5 01 0d 0c 00 00 48 01 54 00 01 f7 01 ec 01 c5 ......H.T.......
116
+ | 400: 01 0d 0b 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 .....H.T........
117
+ | 416: 0d 0a 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d ....H.T.........
118
+ | 432: 09 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 19 08 ...H.T..........
119
+ | 448: 05 17 17 17 17 65 69 67 68 74 65 69 67 68 74 73 .....eighteights
120
+ | 464: 65 76 65 6e 73 65 76 65 6e 25 07 05 07 07 07 07 evenseven%......
121
+ | 480: 40 18 00 00 00 00 00 00 40 18 00 00 00 00 00 00 @.......@.......
122
+ | 496: 40 14 00 00 00 00 00 00 40 14 00 00 00 00 00 00 @.......@.......
123
+ | page 10 offset 4608
124
+ | 0: 0d 00 00 00 1d 00 4d 00 01 f1 01 e2 01 d3 01 c4 ......M.........
125
+ | 16: 01 b5 01 a6 01 97 01 88 01 79 01 6a 01 5b 01 4c .........y.j.[.L
126
+ | 32: 01 3d 01 2e 01 1f 01 10 01 01 00 f2 00 e3 00 d4 .=..............
127
+ | 48: 00 c5 00 b6 00 a7 00 98 00 89 00 7a 00 6b 00 5c ...........z.k.\
128
+ | 64: 00 4d 00 00 00 00 00 00 00 00 00 00 00 0d 3e 00 .M............>.
129
+ | 80: 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 3d 00 00 .H.T.........=..
130
+ | 96: 48 01 54 00 01 f7 01 ec 01 c5 01 0d 3c 00 00 48 H.T.........<..H
131
+ | 112: 01 54 00 01 f7 01 ec 01 c5 01 0d 3b 00 00 48 01 .T.........;..H.
132
+ | 128: 54 00 01 f7 01 ec 01 c5 01 0d 3a 00 00 48 01 54 T.........:..H.T
133
+ | 144: 00 01 f7 01 ec 01 c5 01 0d 39 00 00 48 01 54 00 .........9..H.T.
134
+ | 160: 01 f7 01 ec 01 c5 01 0d 38 00 00 48 01 54 00 01 ........8..H.T..
135
+ | 176: f7 01 ec 01 c5 01 0d 37 00 00 48 01 54 00 01 f7 .......7..H.T...
136
+ | 192: 01 ec 01 c5 01 0d 36 00 00 48 01 54 00 01 f7 01 ......6..H.T....
137
+ | 208: ec 01 c5 01 0d 35 00 00 48 01 54 00 01 f7 01 ec .....5..H.T.....
138
+ | 224: 01 c5 01 0d 34 00 00 48 01 54 00 01 f7 01 ec 01 ....4..H.T......
139
+ | 240: c5 01 0d 33 00 00 48 01 54 00 01 f7 01 ec 01 c5 ...3..H.T.......
140
+ | 256: 01 0d 32 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 ..2..H.T........
141
+ | 272: 0d 31 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d .1..H.T.........
142
+ | 288: 30 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2f 0..H.T........./
143
+ | 304: 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2e 00 ..H.T...........
144
+ | 320: 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2d 00 00 .H.T.........-..
145
+ | 336: 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2c 00 00 48 H.T.........,..H
146
+ | 352: 01 54 00 01 f7 01 ec 01 c5 01 0d 2b 00 00 48 01 .T.........+..H.
147
+ | 368: 54 00 01 f7 01 ec 01 c5 01 0d 2a 00 00 48 01 54 T.........*..H.T
148
+ | 384: 00 01 f7 01 ec 01 c5 01 0d 29 00 00 48 01 54 00 .........)..H.T.
149
+ | 400: 01 f7 01 ec 01 c5 01 0d 28 00 00 48 01 54 00 01 ........(..H.T..
150
+ | 416: f7 01 ec 01 c5 01 0d 27 00 00 48 01 54 00 01 f7 .......'..H.T...
151
+ | 432: 01 ec 01 c5 01 0d 26 00 00 48 01 54 00 01 f7 01 ......&..H.T....
152
+ | 448: ec 01 c5 01 0d 25 00 00 48 01 54 00 01 f7 01 ec .....%..H.T.....
153
+ | 464: 01 c5 01 0d 24 00 00 48 01 54 00 01 f7 01 ec 01 ....$..H.T......
154
+ | 480: c5 01 0d 23 00 00 48 01 54 00 01 f7 01 ec 01 c5 ...#..H.T.......
155
+ | 496: 01 0d 22 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 .."..H.T........
156
+ | page 11 offset 5120
157
+ | 0: 0d 00 00 00 0a 01 6a 00 01 f1 01 e2 01 d3 01 c4 ......j.........
158
+ | 16: 01 b5 01 a6 01 97 01 88 01 79 01 6a 00 00 00 00 .........y.j....
159
+ | 352: 00 00 00 00 00 00 00 00 00 00 0d 48 00 00 48 01 ...........H..H.
160
+ | 368: 54 00 01 f7 01 ec 01 c5 01 0d 47 00 00 48 01 54 T.........G..H.T
161
+ | 384: 00 01 f7 01 ec 01 c5 01 0d 46 00 00 48 01 54 00 .........F..H.T.
162
+ | 400: 01 f7 01 ec 01 c5 01 0d 45 00 00 48 01 54 00 01 ........E..H.T..
163
+ | 416: f7 01 ec 01 c5 01 0d 44 00 00 48 01 54 00 01 f7 .......D..H.T...
164
+ | 432: 01 ec 01 c5 01 0d 43 00 00 48 01 54 00 01 f7 01 ......C..H.T....
165
+ | 448: ec 01 c5 01 0d 42 00 00 48 01 54 00 01 f7 01 ec .....B..H.T.....
166
+ | 464: 01 c5 01 0d 41 00 00 48 01 54 00 01 f7 01 ec 01 ....A..H.T......
167
+ | 480: c5 01 0d 40 00 00 48 01 54 00 01 f7 01 ec 01 c5 ...@..H.T.......
168
+ | 496: 01 0d 3f 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 ..?..H.T........
169
+ | end c4.db
170
+ }]
171
+ } {}
172
+
173
+ ifcapable !oversize_cell_check {
174
+ # Non SQLITE_ENABLE_OVERSIZE_CELL_CHECK builds:
175
+ do_test dbfuzz001-101a {
176
+ db eval {PRAGMA writable_schema=on; PRAGMA integrity_check}
177
+ } {/Fragmentation of 384 bytes reported as 0 on page 8/}
178
+ } else {
179
+ # SQLITE_ENABLE_OVERSIZE_CELL_CHECK builds:
180
+ do_catchsql_test dbfuzz001-101b {
181
+ PRAGMA writable_schema=on;
182
+ PRAGMA integrity_check;
183
+ } {1 {database disk image is malformed}}
184
+ }
185
+
186
+ # The DELETE query below deletes the very last cell from page 8.
187
+ # Prior to a certain fix to sqlite3BtreeDelete() and because of the
188
+ # corruption to the freeblock list on page 8, this would fail to
189
+ # cause a rebalance operation, which would leave the btree in a weird
190
+ # state that would lead to segfaults and or assertion faults.
191
+ #
192
+ do_execsql_test dbfuzz001-110 {
193
+ DELETE FROM t3 WHERE x IS NOT NULL AND +rowid=6;
194
+ } {}
195
+
196
+ # This is a dbfuzz2-generate test case that can cause a page with
197
+ # pPage->nCell==0 to enter the balancer.
198
+ #
199
+ do_test dbfuzz001-200 {
200
+ db deserialize [decode_hexdb {
201
+ | size 3076 pagesize 512 filename c03.db
202
+ | page 1 offset 0
203
+ | 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
204
+ | 16: 02 00 01 01 00 40 20 20 00 00 00 0c 00 00 00 07 .....@ ........
205
+ | 32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04 ................
206
+ | 48: 00 00 00 00 00 00 00 03 e8 00 00 01 00 00 00 00 ................
207
+ | 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c ................
208
+ | 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............
209
+ | 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*..........
210
+ | 128: 00 00 00 00 00 00 00 00 ef 00 00 00 00 00 00 00 ................
211
+ | 192: 00 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
212
+ | 224: 00 00 00 00 00 00 00 00 00 00 00 00 00 ff e9 00 ................
213
+ | 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 ......"......1ta
214
+ | 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T
215
+ | 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*.....
216
+ | 304: 01 3f 69 6e 64 65 78 74 33 78 74 33 06 43 52 45 .?indext3xt3.CRE
217
+ | 320: 41 54 45 20 49 4e 44 45 58 20 74 33 64 20 4f 4e ATE INDEX t3d ON
218
+ | 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein
219
+ | 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE
220
+ | 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t
221
+ | 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta
222
+ | 400: 62 6c 65 74 33 74 33 04 43 52 45 41 54 45 20 54 blet3t3.CREATE T
223
+ | 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f)
224
+ | 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t
225
+ | 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t
226
+ | 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$.....
227
+ | 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA
228
+ | 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b)
229
+ | page 2 offset 512
230
+ | 0: 0d 00 00 00 04 01 cf 00 01 fa 01 f3 01 de 01 cf ................
231
+ | 176: 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
232
+ | 256: 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
233
+ | 368: 00 00 00 00 00 00 00 00 00 00 00 00 1e 00 00 00 ................
234
+ | 416: 00 00 00 1b 00 00 00 00 04 00 00 00 00 00 00 00 ................
235
+ | 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d ................
236
+ | 464: 04 03 17 17 73 65 76 65 6e 65 69 67 68 74 13 03 ....seveneight..
237
+ | 480: 03 07 07 40 14 00 00 00 00 00 00 40 18 00 00 00 ...@.......@....
238
+ | 496: 00 00 00 05 02 03 01 01 03 04 04 01 03 09 01 02 ................
239
+ | page 3 offset 1024
240
+ | 0: 0d 00 00 00 08 01 54 00 01 f7 01 ec 01 c5 01 aa ......T.........
241
+ | 16: 01 a1 01 96 01 6f 01 54 00 00 00 00 00 00 00 00 .....o.T........
242
+ | 32: 00 00 00 00 00 00 00 03 e8 00 00 00 00 00 00 00 ................
243
+ | 336: 00 00 00 00 19 08 05 16 17 17 17 65 69 67 68 74 ...........eight
244
+ | 352: 65 69 67 68 74 73 65 76 65 6e 73 65 76 ff ff ff eightsevensev...
245
+ | 368: 0e 05 07 07 07 07 40 18 00 00 00 00 00 00 40 18 ......@.......@.
246
+ | 384: 00 00 00 00 00 00 40 14 00 00 00 00 00 00 40 14 ......@.......@.
247
+ | 400: 00 00 00 00 00 00 09 06 05 01 01 01 01 04 04 03 ................
248
+ | 416: 03 07 05 05 01 01 09 09 02 02 19 04 05 17 17 17 ................
249
+ | 432: 17 73 65 6f 65 6e 65 69 67 68 74 65 69 67 68 74 .seoeneighteight
250
+ | 448: 73 65 76 65 6e 25 03 05 07 07 07 07 40 14 00 00 seven%......@...
251
+ | 464: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@...
252
+ | 480: 00 00 00 00 40 14 00 00 00 00 00 00 09 02 05 01 ....@...........
253
+ | 496: 01 01 01 03 04 04 03 07 01 05 09 01 01 09 02 02 ................
254
+ | page 4 offset 1536
255
+ | 0: 0d 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 ................
256
+ | 160: 00 00 00 ea 00 00 00 00 00 00 00 00 00 00 00 00 ................
257
+ | 336: 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 ............ ...
258
+ | page 5 offset 2048
259
+ | 0: 0a 00 00 00 08 01 96 00 01 fa 01 c4 01 f2 01 bc ................
260
+ | 16: 01 dc 01 a6 01 96 01 cc 00 00 00 00 00 00 00 00 ................
261
+ | 48: 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 ................
262
+ | 288: 00 00 00 00 00 00 00 00 00 64 00 00 00 2b 00 00 .........d...+..
263
+ | 400: 00 00 00 00 00 00 0f 04 17 17 01 65 69 67 68 74 ...........eight
264
+ | 416: 65 69 6f 68 74 08 15 04 07 07 01 40 18 00 00 00 eioht......@....
265
+ | 432: 00 00 00 40 18 00 00 00 00 00 00 07 07 04 01 01 ...@............
266
+ | 448: 01 04 04 06 07 04 01 01 01 02 02 05 0f 04 17 17 ................
267
+ | 464: 01 73 65 76 65 6e 65 69 67 68 74 04 15 04 07 07 .seveneight.....
268
+ | 480: 01 40 14 00 00 00 00 00 00 40 18 00 00 00 00 00 .@.......@......
269
+ | 496: 00 03 07 04 01 01 01 03 04 02 05 04 09 01 09 02 ................
270
+ | page 6 offset 2560
271
+ | 0: 0a 00 00 00 00 02 00 00 00 00 00 00 00 0d 00 00 ................
272
+ | 16: 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec 01 e0 01 ................
273
+ | 32: d4 01 cb 01 c2 00 00 00 00 00 00 00 00 00 00 00 ................
274
+ | 160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 ................
275
+ | 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 ................
276
+ | 464: 08 02 17 65 69 67 68 74 07 07 02 17 65 69 67 68 ...eight....eigh
277
+ | 480: 74 0a 06 02 07 40 18 00 00 00 00 00 00 0a 05 02 t....@..........
278
+ | 496: 07 40 18 00 04 02 01 04 03 03 02 01 04 03 02 02 .@..............
279
+ | end x/c03.db
280
+ }]
281
+ catchsql {INSERT INTO t3 SELECT * FROM t2;}
282
+ } {1 {database disk image is malformed}}
283
+
284
+
285
+ do_test dbfuzz001-310 {
286
+ sqlite3 db {}
287
+ db deserialize [decode_hexdb {
288
+ | size 3584 pagesize 512 filename x/c02.db
289
+ | page 1 offset 0
290
+ | 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
291
+ | 16: 02 00 01 01 00 40 20 20 00 00 00 0c 00 00 00 07 .....@ ........
292
+ | 32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04 ................
293
+ | 48: 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 00 ................
294
+ | 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c ................
295
+ | 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............
296
+ | 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*..........
297
+ | 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 ......"......1ta
298
+ | 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T
299
+ | 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*.....
300
+ | 304: 01 3f 69 6e 64 65 78 74 33 78 74 33 05 43 52 45 .?indext3xt3.CRE
301
+ | 320: 41 54 45 20 49 4e 44 45 58 20 74 33 78 20 4f 4e ATE INDEX t3x ON
302
+ | 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein
303
+ | 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE
304
+ | 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t
305
+ | 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta
306
+ | 400: 62 6c 65 74 33 74 33 07 43 52 45 41 54 45 20 54 blet3t3.CREATE T
307
+ | 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f)
308
+ | 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t
309
+ | 448: 32 32 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 22CREATE TABLE t
310
+ | 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$.....
311
+ | 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA
312
+ | 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b)
313
+ | page 2 offset 512
314
+ | 0: 0d 00 00 00 04 01 cf 00 01 fa 01 f3 01 de 01 cf ................
315
+ | 160: 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 .. .............
316
+ | 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d ................
317
+ | 464: 04 03 17 17 73 65 76 65 6e 65 69 67 68 74 13 03 ....seveneight..
318
+ | 480: 03 07 07 40 14 00 00 00 00 00 00 40 18 00 00 00 ...@.......@....
319
+ | 496: 00 00 00 05 02 03 01 01 03 04 04 01 03 09 01 02 ................
320
+ | page 3 offset 1024
321
+ | 0: 0d 00 00 00 08 01 54 00 01 f7 01 ec 01 c5 01 aa ......T.........
322
+ | 16: 01 a1 01 96 01 6f 01 54 00 00 00 00 00 00 00 00 .....o.T........
323
+ | 112: 00 00 dd 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
324
+ | 336: 00 00 00 00 19 08 05 17 17 17 17 65 69 67 68 74 ...........eight
325
+ | 352: 65 69 67 68 74 73 65 76 65 6e 73 65 76 65 6e 25 eightsevenseven%
326
+ | 368: 07 05 07 07 07 07 40 18 00 00 00 00 00 00 40 18 ......@.......@.
327
+ | 384: 00 00 00 00 00 00 40 14 00 00 00 00 00 00 40 14 ......@.......@.
328
+ | 400: 00 00 00 00 00 00 09 06 05 01 01 01 01 04 04 03 ................
329
+ | 416: 03 07 05 05 01 01 09 09 02 02 19 04 05 17 17 17 ................
330
+ | 432: 17 73 65 76 65 6e 65 69 67 68 74 65 69 67 68 74 .seveneighteight
331
+ | 448: 73 65 76 65 6e 25 03 05 07 07 07 07 40 14 00 00 seven%......@...
332
+ | 464: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@...
333
+ | 480: 00 00 00 00 40 14 00 00 00 00 00 00 09 02 05 01 ....@...........
334
+ | 496: 01 01 01 03 04 04 03 07 01 05 09 01 01 09 02 02 ................
335
+ | page 4 offset 1536
336
+ | 0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................
337
+ | 192: 00 00 00 00 00 00 7f 00 00 00 00 00 00 00 00 00 ................
338
+ | 208: 00 e5 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
339
+ | page 5 offset 2048
340
+ | 0: 0a 00 00 00 08 01 96 00 01 fa 01 c4 01 f2 01 bc ................
341
+ | 16: 01 dc 01 a6 01 96 01 cc 00 00 00 00 00 00 00 00 ................
342
+ | 240: 00 00 00 00 00 00 00 00 00 00 00 00 00 0e 00 00 ................
343
+ | 400: 00 00 00 00 00 00 0f 04 17 07 01 65 69 67 68 74 ...........eight
344
+ | 416: 65 69 67 68 74 08 15 04 07 07 01 40 18 00 00 00 eight......@....
345
+ | 432: 00 00 00 40 18 00 00 00 00 00 00 07 07 04 01 01 ...@............
346
+ | 448: 01 04 04 06 07 04 01 01 01 02 02 05 0f 04 17 17 ................
347
+ | 464: 01 73 65 76 65 6e 65 69 67 68 74 04 15 04 07 07 .seveneight.....
348
+ | 480: 01 40 14 00 00 00 00 00 00 40 18 00 00 00 00 00 .@.......@......
349
+ | 496: 00 03 07 04 01 01 01 03 04 02 05 04 09 01 09 02 ................
350
+ | page 6 offset 2560
351
+ | 0: 0a 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................
352
+ | 464: 00 00 00 00 00 00 00 00 00 00 7f 00 00 00 00 00 ................
353
+ | page 7 offset 3072
354
+ | 0: 0d 00 00 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec ................
355
+ | 16: 01 e0 01 d4 01 cb 01 c2 00 00 00 00 00 00 00 00 ................
356
+ | 448: 00 00 07 08 02 17 65 69 67 68 74 07 07 02 17 65 ......eight....e
357
+ | 464: 69 67 68 74 0a 06 02 07 40 18 00 00 00 00 00 00 ight....@.......
358
+ | 480: 0a 05 02 07 40 18 00 00 00 00 00 00 03 04 02 01 ....@...........
359
+ | 496: 04 03 03 02 01 04 03 02 02 01 02 03 01 02 01 02 ................
360
+ | end x/c02.db
361
+ }]
362
+ } {}
363
+
364
+ extra_schema_checks 0
365
+ do_catchsql_test dbfuzz001-320 {
366
+ PRAGMA integrity_check;
367
+ } {1 {database disk image is malformed}}
368
+
369
+ do_catchsql_test dbfuzz001-330 {
370
+ DELETE FROM t3 WHERE x IN (SELECT x FROM t4);
371
+ } {1 {database disk image is malformed}}
372
+ extra_schema_checks 1
373
+
374
+ #-------------------------------------------------------------------------
375
+ reset_db
376
+
377
+ do_execsql_test dbfuzz001-430 {
378
+ CREATE TABLE t1(a INTEGER, b INT, c DEFAULT 0);
379
+ }
380
+
381
+ do_execsql_test dbfuzz001-420 {
382
+ PRAGMA locking_mode=EXCLUSIVE;
383
+ PRAGMA journal_mode = memory;
384
+ INSERT INTO t1 VALUES(1,2,3);
385
+ PRAGMA journal_mode=PERSIST;
386
+ } {exclusive memory persist}
387
+
388
+ do_execsql_test dbfuzz001-430 {
389
+ INSERT INTO t1 VALUES(4, 5, 6);
390
+ }
391
+
392
+ do_execsql_test dbfuzz001-440 {
393
+ PRAGMA journal_mode=MEMORY;
394
+ INSERT INTO t1 VALUES(7, 8, 9);
395
+ } {memory}
396
+
397
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/e_blobclose.test ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2014 October 30
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+
13
+ set testdir [file dirname $argv0]
14
+ source $testdir/tester.tcl
15
+ set testprefix e_blobclose
16
+
17
+ ifcapable !incrblob {
18
+ finish_test
19
+ return
20
+ }
21
+
22
+ set dots [string repeat . 40]
23
+ do_execsql_test 1.0 {
24
+ CREATE TABLE x1(a INTEGER PRIMARY KEY, b DOTS);
25
+ INSERT INTO x1 VALUES(-1, $dots);
26
+ INSERT INTO x1 VALUES(-10, $dots);
27
+ INSERT INTO x1 VALUES(-100, $dots);
28
+ INSERT INTO x1 VALUES(-1000, $dots);
29
+ INSERT INTO x1 VALUES(-10000, $dots);
30
+ }
31
+
32
+ # EVIDENCE-OF: R-03145-46390 This function closes an open BLOB handle.
33
+ #
34
+ # It's not clear how to test that a blob handle really is closed.
35
+ # Attempting to use a closed blob handle will likely crash the process.
36
+ # Assume here that if the SHARED lock on the db file is released,
37
+ # the blob handle has been closed.
38
+ #
39
+ do_execsql_test 1.1 { PRAGMA lock_status } {main unlocked temp closed}
40
+ sqlite3_blob_open db main x1 b -1 0 B
41
+ do_execsql_test 1.2 { PRAGMA lock_status } {main shared temp closed}
42
+ sqlite3_blob_close $B
43
+ do_execsql_test 1.3 { PRAGMA lock_status } {main unlocked temp closed}
44
+
45
+
46
+ # EVIDENCE-OF: R-34027-00617 If the blob handle being closed was opened
47
+ # for read-write access, and if the database is in auto-commit mode and
48
+ # there are no other open read-write blob handles or active write
49
+ # statements, the current transaction is committed.
50
+ #
51
+ # 2.1.*: Transaction is not committed if there are other open
52
+ # read-write blob handles.
53
+ #
54
+ # 2.2.*: Transaction is not committed if not in auto-commit mode.
55
+ #
56
+ # 2.3.*: Active write statements.
57
+ #
58
+ do_test 2.1.1 {
59
+ sqlite3_blob_open db main x1 b -100 1 B1
60
+ sqlite3_blob_open db main x1 b -1000 1 B2
61
+ sqlite3_blob_open db main x1 b -10000 1 B3
62
+ sqlite3_blob_open db main x1 b -10000 0 B4 ;# B4 is read-only!
63
+ execsql { PRAGMA lock_status }
64
+ } {main reserved temp closed}
65
+ do_test 2.1.2 {
66
+ sqlite3_blob_close $B1
67
+ execsql { PRAGMA lock_status }
68
+ } {main reserved temp closed}
69
+ do_test 2.1.3 {
70
+ sqlite3_blob_close $B2
71
+ execsql { PRAGMA lock_status }
72
+ } {main reserved temp closed}
73
+ do_test 2.1.4 {
74
+ sqlite3_blob_close $B3
75
+ execsql { PRAGMA lock_status }
76
+ } {main shared temp closed}
77
+ do_test 2.1.5 {
78
+ sqlite3_blob_close $B4
79
+ execsql { PRAGMA lock_status }
80
+ } {main unlocked temp closed}
81
+
82
+ do_test 2.2.1 {
83
+ sqlite3_blob_open db main x1 b -100 1 B1
84
+ execsql { PRAGMA lock_status }
85
+ } {main reserved temp closed}
86
+ do_test 2.2.2 {
87
+ execsql { BEGIN }
88
+ sqlite3_blob_close $B1
89
+ execsql { PRAGMA lock_status }
90
+ } {main reserved temp closed}
91
+ do_test 2.2.3 {
92
+ execsql { COMMIT }
93
+ execsql { PRAGMA lock_status }
94
+ } {main unlocked temp closed}
95
+
96
+ proc val {} {
97
+ sqlite3_blob_close $::B
98
+ db eval { PRAGMA lock_status }
99
+ }
100
+ db func val val
101
+ do_test 2.3.1 {
102
+ sqlite3_blob_open db main x1 b -100 1 B
103
+ execsql { PRAGMA lock_status }
104
+ } {main reserved temp closed}
105
+ do_test 2.3.2 {
106
+ execsql { INSERT INTO x1 VALUES(15, val()) }
107
+ execsql { PRAGMA lock_status }
108
+ } {main unlocked temp closed}
109
+ do_test 2.3.3 {
110
+ execsql { SELECT * FROM x1 WHERE a = 15 }
111
+ } {15 {main reserved temp closed}}
112
+
113
+ # A reader does not inhibit commit.
114
+ do_test 2.3.4 {
115
+ sqlite3_blob_open db main x1 b -100 1 B
116
+ execsql { PRAGMA lock_status }
117
+ } {main reserved temp closed}
118
+ do_test 2.3.5 {
119
+ execsql { SELECT a, val() FROM x1 LIMIT 1 }
120
+ } {-10000 {main shared temp closed}}
121
+
122
+
123
+ do_test 3.1 {
124
+ sqlite3_blob_open db main x1 b -10 1 B
125
+ execsql {
126
+ INSERT INTO x1 VALUES(1, 'abc');
127
+ SELECT * FROM x1 WHERE a=1;
128
+ }
129
+ } {1 abc}
130
+ do_test 3.2 {
131
+ sqlite3_blob_write $B 0 "abcdefghij" 10
132
+ execsql { SELECT * FROM x1 WHERE a=-10 }
133
+ } {-10 abcdefghij..............................}
134
+
135
+ do_test 3.3 {
136
+ sqlite3 db2 test.db
137
+ execsql { BEGIN ; SELECT * FROM x1 } db2
138
+ sqlite3_blob_close $B
139
+ } {SQLITE_BUSY}
140
+
141
+ # EVIDENCE-OF: R-41959-38737 Otherwise, if this function is passed a
142
+ # valid open blob handle, the values returned by the sqlite3_errcode()
143
+ # and sqlite3_errmsg() functions are set before returning.
144
+ #
145
+ do_test 3.4 {
146
+ list [sqlite3_errcode db] [sqlite3_errmsg db]
147
+ } {SQLITE_BUSY {database is locked}}
148
+
149
+ # EVIDENCE-OF: R-37801-37633 The BLOB handle is closed unconditionally.
150
+ # Even if this routine returns an error code, the handle is still
151
+ # closed.
152
+ #
153
+ # Test that the lock has been released. Assume this means the handle
154
+ # is closed, even though blob_close() returned SQLITE_BUSY.
155
+ #
156
+ do_execsql_test 3.4 { PRAGMA lock_status } {main unlocked temp closed}
157
+
158
+ # EVIDENCE-OF: R-35111-05628 If an error occurs while committing the
159
+ # transaction, an error code is returned and the transaction rolled
160
+ # back.
161
+ #
162
+ # Row 1 is removed (it was inserted this transaction) and row -10
163
+ # is restored to its original state. Transaction has been rolled back.
164
+ #
165
+ do_execsql_test 3.5 {
166
+ SELECT * FROM x1 WHERE a IN (1, -10);
167
+ } {-10 ........................................}
168
+
169
+ # EVIDENCE-OF: R-25894-51060 Calling this routine with a null pointer
170
+ # (such as would be returned by a failed call to sqlite3_blob_open()) is
171
+ # a harmless no-op.
172
+ #
173
+ do_test 4.0 { sqlite3_blob_close 0 } {}
174
+
175
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/e_vacuum.test ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2010 September 24
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # This file implements tests to verify that the "testable statements" in
13
+ # the lang_vacuum.html document are correct.
14
+ #
15
+
16
+ set testdir [file dirname $argv0]
17
+ source $testdir/tester.tcl
18
+
19
+ sqlite3_test_control_pending_byte 0x1000000
20
+
21
+ proc create_db {{sql ""}} {
22
+ catch { db close }
23
+ forcedelete test.db
24
+ sqlite3 db test.db
25
+
26
+ db transaction {
27
+ execsql { PRAGMA page_size = 1024; }
28
+ execsql $sql
29
+ execsql {
30
+ CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
31
+ INSERT INTO t1 VALUES(1, randomblob(400));
32
+ INSERT INTO t1 SELECT a+1, randomblob(400) FROM t1;
33
+ INSERT INTO t1 SELECT a+2, randomblob(400) FROM t1;
34
+ INSERT INTO t1 SELECT a+4, randomblob(400) FROM t1;
35
+ INSERT INTO t1 SELECT a+8, randomblob(400) FROM t1;
36
+ INSERT INTO t1 SELECT a+16, randomblob(400) FROM t1;
37
+ INSERT INTO t1 SELECT a+32, randomblob(400) FROM t1;
38
+ INSERT INTO t1 SELECT a+64, randomblob(400) FROM t1;
39
+
40
+ CREATE TABLE t2(a PRIMARY KEY, b UNIQUE);
41
+ INSERT INTO t2 SELECT * FROM t1;
42
+ }
43
+ }
44
+
45
+ return [expr {[file size test.db] / 1024}]
46
+ }
47
+
48
+ # This proc returns the number of contiguous blocks of pages that make up
49
+ # the table or index named by the only argument. For example, if the table
50
+ # occupies database pages 3, 4, 8 and 9, then this command returns 2 (there
51
+ # are 2 fragments - one consisting of pages 3 and 4, the other of fragments
52
+ # 8 and 9).
53
+ #
54
+ proc fragment_count {name} {
55
+ execsql { CREATE VIRTUAL TABLE temp.stat USING dbstat }
56
+ set nFrag 1
57
+ db eval {SELECT pageno FROM stat WHERE name = 't1' ORDER BY pageno} {
58
+ if {[info exists prevpageno] && $prevpageno != $pageno-1} {
59
+ incr nFrag
60
+ }
61
+ set prevpageno $pageno
62
+ }
63
+ execsql { DROP TABLE temp.stat }
64
+ set nFrag
65
+ }
66
+
67
+
68
+ # -- syntax diagram vacuum-stmt
69
+ #
70
+ do_execsql_test e_vacuum-0.1 { VACUUM } {}
71
+
72
+ # EVIDENCE-OF: R-51469-36013 Unless SQLite is running in
73
+ # "auto_vacuum=FULL" mode, when a large amount of data is deleted from
74
+ # the database file it leaves behind empty space, or "free" database
75
+ # pages.
76
+ #
77
+ # EVIDENCE-OF: R-60541-63059 Running VACUUM to rebuild the database
78
+ # reclaims this space and reduces the size of the database file.
79
+ #
80
+ foreach {tn avmode sz} {
81
+ 1 none 7
82
+ 2 full 8
83
+ 3 incremental 8
84
+ } {
85
+ set nPage [create_db "PRAGMA auto_vacuum = $avmode"]
86
+
87
+ do_execsql_test e_vacuum-1.1.$tn.1 {
88
+ DELETE FROM t1;
89
+ DELETE FROM t2;
90
+ } {}
91
+
92
+ if {$avmode == "full"} {
93
+ # This branch tests the "unless ... auto_vacuum=FULL" in the requirement
94
+ # above. If auto_vacuum is set to FULL, then no empty space is left in
95
+ # the database file.
96
+ do_execsql_test e_vacuum-1.1.$tn.2 {PRAGMA freelist_count} 0
97
+ } else {
98
+ set freelist [expr {$nPage - $sz}]
99
+ if {$avmode == "incremental"} {
100
+ # The page size is 1024 bytes. Therefore, assuming the database contains
101
+ # somewhere between 207 and 411 pages (it does), there are 2 pointer-map
102
+ # pages.
103
+ incr freelist -2
104
+ }
105
+ do_execsql_test e_vacuum-1.1.$tn.3 {PRAGMA freelist_count} $freelist
106
+ do_execsql_test e_vacuum-1.1.$tn.4 {VACUUM} {}
107
+ }
108
+
109
+ do_test e_vacuum-1.1.$tn.5 { expr {[file size test.db] / 1024} } $sz
110
+ }
111
+
112
+ # EVIDENCE-OF: R-50943-18433 Frequent inserts, updates, and deletes can
113
+ # cause the database file to become fragmented - where data for a single
114
+ # table or index is scattered around the database file.
115
+ #
116
+ # EVIDENCE-OF: R-05791-54928 Running VACUUM ensures that each table and
117
+ # index is largely stored contiguously within the database file.
118
+ #
119
+ # e_vacuum-1.2.1 - Perform many INSERT, UPDATE and DELETE ops on table t1.
120
+ # e_vacuum-1.2.2 - Verify that t1 and its indexes are now quite fragmented.
121
+ # e_vacuum-1.2.3 - Run VACUUM.
122
+ # e_vacuum-1.2.4 - Verify that t1 and its indexes are now much
123
+ # less fragmented.
124
+ #
125
+ ifcapable vtab&&compound {
126
+ create_db
127
+ register_dbstat_vtab db
128
+ do_execsql_test e_vacuum-1.2.1 {
129
+ DELETE FROM t1 WHERE a%2;
130
+ INSERT INTO t1 SELECT b, a FROM t2 WHERE a%2;
131
+ UPDATE t1 SET b=randomblob(600) WHERE (a%2)==0;
132
+ } {}
133
+
134
+ do_test e_vacuum-1.2.2.1 { expr [fragment_count t1]>100 } 1
135
+ do_test e_vacuum-1.2.2.2 { expr [fragment_count sqlite_autoindex_t1_1]>100 } 1
136
+ do_test e_vacuum-1.2.2.3 { expr [fragment_count sqlite_autoindex_t1_2]>100 } 1
137
+
138
+ do_execsql_test e_vacuum-1.2.3 { VACUUM } {}
139
+
140
+ # In practice, the tables and indexes each end up stored as two fragments -
141
+ # one containing the root page and another containing all other pages.
142
+ #
143
+ do_test e_vacuum-1.2.4.1 { fragment_count t1 } 2
144
+ do_test e_vacuum-1.2.4.2 { fragment_count sqlite_autoindex_t1_1 } 2
145
+ do_test e_vacuum-1.2.4.3 { fragment_count sqlite_autoindex_t1_2 } 2
146
+ }
147
+
148
+ # EVIDENCE-OF: R-20474-44465 Normally, the database page_size and
149
+ # whether or not the database supports auto_vacuum must be configured
150
+ # before the database file is actually created.
151
+ #
152
+ do_test e_vacuum-1.3.1.1 {
153
+ create_db "PRAGMA page_size = 1024 ; PRAGMA auto_vacuum = FULL"
154
+ execsql { PRAGMA page_size ; PRAGMA auto_vacuum }
155
+ } {1024 1}
156
+ do_test e_vacuum-1.3.1.2 {
157
+ execsql { PRAGMA page_size = 2048 }
158
+ execsql { PRAGMA auto_vacuum = NONE }
159
+ execsql { PRAGMA page_size ; PRAGMA auto_vacuum }
160
+ } {1024 1}
161
+
162
+ if {![nonzero_reserved_bytes]} {
163
+ # EVIDENCE-OF: R-08570-19916 However, when not in write-ahead log mode,
164
+ # the page_size and/or auto_vacuum properties of an existing database
165
+ # may be changed by using the page_size and/or pragma auto_vacuum
166
+ # pragmas and then immediately VACUUMing the database.
167
+ #
168
+ do_test e_vacuum-1.3.2.1 {
169
+ execsql { PRAGMA journal_mode = delete }
170
+ execsql { PRAGMA page_size = 2048 }
171
+ execsql { PRAGMA auto_vacuum = NONE }
172
+ execsql VACUUM
173
+ execsql { PRAGMA page_size ; PRAGMA auto_vacuum }
174
+ } {2048 0}
175
+
176
+ # EVIDENCE-OF: R-48521-51450 When in write-ahead log mode, only the
177
+ # auto_vacuum support property can be changed using VACUUM.
178
+ #
179
+ if {[wal_is_capable]} {
180
+ do_test e_vacuum-1.3.3.1 {
181
+ execsql { PRAGMA journal_mode = wal }
182
+ execsql { PRAGMA page_size ; PRAGMA auto_vacuum }
183
+ } {2048 0}
184
+ do_test e_vacuum-1.3.3.2 {
185
+ execsql { PRAGMA page_size = 1024 }
186
+ execsql { PRAGMA auto_vacuum = FULL }
187
+ execsql VACUUM
188
+ execsql { PRAGMA page_size ; PRAGMA auto_vacuum }
189
+ } {2048 1}
190
+ }
191
+ }
192
+
193
+ # EVIDENCE-OF: R-40347-36128 By default, VACUUM operates on the main
194
+ # database.
195
+ forcedelete test.db2
196
+ create_db { PRAGMA auto_vacuum = NONE }
197
+ do_execsql_test e_vacuum-2.1.1 {
198
+ ATTACH 'test.db2' AS aux;
199
+ PRAGMA aux.page_size = 1024;
200
+ CREATE TABLE aux.t3 AS SELECT * FROM t1;
201
+ DELETE FROM t3;
202
+ } {}
203
+ set original_size [file size test.db2]
204
+
205
+ # Vacuuming the main database does not affect aux
206
+ do_execsql_test e_vacuum-2.1.3 { VACUUM } {}
207
+ do_test e_vacuum-2.1.6 { expr {[file size test.db2]==$::original_size} } 1
208
+
209
+ # EVIDENCE-OF: R-36598-60500 Attached databases can be vacuumed by
210
+ # appending the appropriate schema-name to the VACUUM statement.
211
+ do_execsql_test e_vacuum-2.1.7 { VACUUM aux; } {}
212
+ do_test e_vacuum-2.1.8 { expr {[file size test.db2]<$::original_size} } 1
213
+
214
+ # EVIDENCE-OF: R-17495-17419 The VACUUM command may change the ROWIDs of
215
+ # entries in any tables that do not have an explicit INTEGER PRIMARY
216
+ # KEY.
217
+ #
218
+ # Tests e_vacuum-3.1.1 - 3.1.2 demonstrate that rowids can change when
219
+ # a database is VACUUMed. Tests e_vacuum-3.1.3 - 3.1.4 show that adding
220
+ # an INTEGER PRIMARY KEY column to a table stops this from happening.
221
+ #
222
+ # Update 2019-01-07: Rowids are now preserved by VACUUM.
223
+ #
224
+ do_execsql_test e_vacuum-3.1.1 {
225
+ CREATE TABLE t4(x);
226
+ INSERT INTO t4(x) VALUES('x');
227
+ INSERT INTO t4(x) VALUES('y');
228
+ INSERT INTO t4(x) VALUES('z');
229
+ DELETE FROM t4 WHERE x = 'y';
230
+ SELECT rowid, x FROM t4;
231
+ } {1 x 3 z}
232
+ do_execsql_test e_vacuum-3.1.2 {
233
+ VACUUM;
234
+ SELECT rowid, x FROM t4;
235
+ } {1 x 2 z}
236
+
237
+ # Rowids are preserved if an INTEGER PRIMARY KEY is used
238
+ do_execsql_test e_vacuum-3.1.3 {
239
+ CREATE TABLE t5(x, y INTEGER PRIMARY KEY);
240
+ INSERT INTO t5(x) VALUES('x');
241
+ INSERT INTO t5(x) VALUES('y');
242
+ INSERT INTO t5(x) VALUES('z');
243
+ DELETE FROM t5 WHERE x = 'y';
244
+ SELECT rowid, x FROM t5;
245
+ } {1 x 3 z}
246
+ do_execsql_test e_vacuum-3.1.4 {
247
+ VACUUM;
248
+ SELECT rowid, x FROM t5;
249
+ } {1 x 3 z}
250
+
251
+ # Rowid is preserved for VACUUM INTO
252
+ do_execsql_test e_vacuum-3.1.5 {
253
+ DROP TABLE t5;
254
+ CREATE TABLE t5(x);
255
+ INSERT INTO t5(x) VALUES('x');
256
+ INSERT INTO t5(x) VALUES('y');
257
+ INSERT INTO t5(x) VALUES('z');
258
+ DELETE FROM t5 WHERE x = 'y';
259
+ SELECT rowid, x FROM t5;
260
+ } {1 x 3 z}
261
+ forcedelete test2.db
262
+ do_execsql_test e_vacuum-3.1.6 {
263
+ VACUUM INTO 'test2.db';
264
+ ATTACH 'test2.db' AS aux1;
265
+ SELECT rowid, x FROM aux1.t5;
266
+ DETACH aux1;
267
+ } {1 x 3 z}
268
+
269
+ # Rowids are not renumbered if the table being vacuumed
270
+ # has indexes.
271
+ do_execsql_test e_vacuum-3.1.7 {
272
+ DROP TABLE t5;
273
+ CREATE TABLE t5(x,y,z);
274
+ INSERT INTO t5(x) VALUES('x');
275
+ INSERT INTO t5(x) VALUES('y');
276
+ INSERT INTO t5(x) VALUES('z');
277
+ UPDATE t5 SET y=x, z=random();
278
+ DELETE FROM t5 WHERE x = 'y';
279
+ CREATE INDEX t5x ON t5(x);
280
+ CREATE UNIQUE INDEX t5y ON t5(y);
281
+ CREATE INDEX t5zxy ON t5(z,x,y);
282
+ SELECT rowid, x FROM t5;
283
+ } {1 x 3 z}
284
+ do_execsql_test e_vacuum-3.1.8 {
285
+ VACUUM;
286
+ SELECT rowid, x FROM t5;
287
+ } {1 x 3 z}
288
+
289
+ # EVIDENCE-OF: R-12218-18073 A VACUUM will fail if there is an open
290
+ # transaction on the database connection that is attempting to run the
291
+ # VACUUM.
292
+ #
293
+ do_execsql_test e_vacuum-3.2.1.1 { BEGIN } {}
294
+ do_catchsql_test e_vacuum-3.2.1.2 {
295
+ VACUUM
296
+ } {1 {cannot VACUUM from within a transaction}}
297
+ do_execsql_test e_vacuum-3.2.1.3 { COMMIT } {}
298
+ do_execsql_test e_vacuum-3.2.1.4 { VACUUM } {}
299
+ do_execsql_test e_vacuum-3.2.1.5 { SAVEPOINT x } {}
300
+ do_catchsql_test e_vacuum-3.2.1.6 {
301
+ VACUUM
302
+ } {1 {cannot VACUUM from within a transaction}}
303
+ do_execsql_test e_vacuum-3.2.1.7 { COMMIT } {}
304
+ do_execsql_test e_vacuum-3.2.1.8 { VACUUM } {}
305
+
306
+ create_db
307
+ do_test e_vacuum-3.2.2.1 {
308
+ set res ""
309
+ db eval { SELECT a FROM t1 } {
310
+ if {$a == 10} { set res [catchsql VACUUM] }
311
+ }
312
+ set res
313
+ } {1 {cannot VACUUM - SQL statements in progress}}
314
+
315
+
316
+ # EVIDENCE-OF: R-55138-13241 An alternative to using the VACUUM command
317
+ # to reclaim space after data has been deleted is auto-vacuum mode,
318
+ # enabled using the auto_vacuum pragma.
319
+ #
320
+ do_test e_vacuum-3.3.1 {
321
+ create_db { PRAGMA auto_vacuum = FULL }
322
+ execsql { PRAGMA auto_vacuum }
323
+ } {1}
324
+
325
+ # EVIDENCE-OF: R-64844-34873 When auto_vacuum is enabled for a database
326
+ # free pages may be reclaimed after deleting data, causing the file to
327
+ # shrink, without rebuilding the entire database using VACUUM.
328
+ #
329
+ do_test e_vacuum-3.3.2.1 {
330
+ create_db { PRAGMA auto_vacuum = FULL }
331
+ execsql {
332
+ DELETE FROM t1;
333
+ DELETE FROM t2;
334
+ }
335
+ expr {[file size test.db] / 1024}
336
+ } {8}
337
+ do_test e_vacuum-3.3.2.2 {
338
+ create_db { PRAGMA auto_vacuum = INCREMENTAL }
339
+ execsql {
340
+ DELETE FROM t1;
341
+ DELETE FROM t2;
342
+ PRAGMA incremental_vacuum;
343
+ }
344
+ expr {[file size test.db] / 1024}
345
+ } {8}
346
+
347
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/e_walauto.test ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2014 December 04
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+
13
+ set testdir [file dirname $argv0]
14
+ source $testdir/tester.tcl
15
+ source $testdir/wal_common.tcl
16
+ set testprefix e_walauto
17
+
18
+ # Do not run this test on OpenBSD, as it depends on read() and mmap both
19
+ # accessing the same coherent view of the "test.db-shm" file. This doesn't
20
+ # work on OpenBSD.
21
+ #
22
+ if {$tcl_platform(os) == "OpenBSD"} {
23
+ finish_test
24
+ return
25
+ }
26
+
27
+ # This module uses hard-coded offsets which do not work if the reserved_bytes
28
+ # value is nonzero.
29
+ if {[nonzero_reserved_bytes]} {finish_test; return;}
30
+
31
+
32
+ proc read_nbackfill {} {
33
+ seek $::shmfd 96
34
+ binary scan [read $::shmfd 4] n nBackfill
35
+ set nBackfill
36
+ }
37
+ proc read_mxframe {} {
38
+ seek $::shmfd 16
39
+ binary scan [read $::shmfd 4] n mxFrame
40
+ set mxFrame
41
+ }
42
+
43
+ # Assuming that the main db for database handle
44
+ #
45
+ proc do_autocommit_threshold_test {tn value} {
46
+
47
+ set nBackfillSaved [read_nbackfill]
48
+ while {1} {
49
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
50
+ if {[read_mxframe] >= $value} break
51
+ }
52
+
53
+ set nBackfillNew [read_nbackfill]
54
+ uplevel [list do_test $tn "expr $nBackfillNew > $nBackfillSaved" 1]
55
+ }
56
+
57
+ # EVIDENCE-OF: R-30135-06439 The wal_autocheckpoint pragma can be used
58
+ # to invoke this interface from SQL.
59
+ #
60
+ # All tests in this file are run twice - once using the
61
+ # sqlite3_wal_autocheckpoint() API, and once using "PRAGMA
62
+ # wal_autocheckpoint".
63
+ #
64
+ foreach {tn code} {
65
+ 1 {
66
+ proc autocheckpoint {db value} {
67
+ uplevel [list $db eval "PRAGMA wal_autocheckpoint = $value"]
68
+ }
69
+ }
70
+
71
+ 2 {
72
+ proc autocheckpoint {db value} {
73
+ uplevel [list sqlite3_wal_autocheckpoint $db $value]
74
+ return $value
75
+ }
76
+ }
77
+ } {
78
+
79
+ eval $code
80
+
81
+ reset_db
82
+ execsql { PRAGMA auto_vacuum = 0 }
83
+ do_execsql_test 1.$tn.0 { PRAGMA journal_mode = WAL } {wal}
84
+ do_execsql_test 1.$tn.1 { CREATE TABLE t1(a, b) }
85
+ set shmfd [open "test.db-shm" rb]
86
+
87
+ # EVIDENCE-OF: R-41531-51083 Every new database connection defaults to
88
+ # having the auto-checkpoint enabled with a threshold of 1000 or
89
+ # SQLITE_DEFAULT_WAL_AUTOCHECKPOINT pages.
90
+ #
91
+ do_autocommit_threshold_test 1.$tn.2 1000
92
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
93
+ do_autocommit_threshold_test 1.$tn.3 1000
94
+
95
+ # EVIDENCE-OF: R-38128-34102 The sqlite3_wal_autocheckpoint(D,N) is a
96
+ # wrapper around sqlite3_wal_hook() that causes any database on database
97
+ # connection D to automatically checkpoint after committing a
98
+ # transaction if there are N or more frames in the write-ahead log file.
99
+ #
100
+ do_test 1.$tn.4 {
101
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
102
+ autocheckpoint db 100
103
+ } {100}
104
+ do_autocommit_threshold_test 1.$tn.5 100
105
+
106
+ do_test 1.$tn.6 {
107
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
108
+ autocheckpoint db 500
109
+ } {500}
110
+ do_autocommit_threshold_test 1.$tn.7 500
111
+
112
+ # EVIDENCE-OF: R-26993-43540 Passing zero or a negative value as the
113
+ # nFrame parameter disables automatic checkpoints entirely.
114
+ #
115
+ do_test 1.$tn.7 {
116
+ autocheckpoint db 0 ;# Set to zero
117
+ for {set i 0} {$i < 10000} {incr i} {
118
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
119
+ }
120
+ expr {[file size test.db-wal] > (5 * 1024 * 1024)}
121
+ } 1
122
+ do_test 1.$tn.8 {
123
+ sqlite3_wal_checkpoint_v2 db truncate
124
+ file size test.db-wal
125
+ } 0
126
+ do_test 1.$tn.9 {
127
+ autocheckpoint db -4 ;# Set to a negative value
128
+ for {set i 0} {$i < 10000} {incr i} {
129
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
130
+ }
131
+ expr {[file size test.db-wal] > (5 * 1024 * 1024)}
132
+ } 1
133
+
134
+ # EVIDENCE-OF: R-10203-42688 The callback registered by this function
135
+ # replaces any existing callback registered using sqlite3_wal_hook().
136
+ #
137
+ set ::wal_hook_callback 0
138
+ proc wal_hook_callback {args} { incr ::wal_hook_callback ; return 0 }
139
+ do_test 1.$tn.10.1 {
140
+ db wal_hook wal_hook_callback
141
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
142
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
143
+ set ::wal_hook_callback
144
+ } 2
145
+ do_test 1.$tn.10.2 {
146
+ autocheckpoint db 100
147
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
148
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
149
+ set ::wal_hook_callback
150
+ } 2
151
+
152
+ # EVIDENCE-OF: R-17497-43474 Likewise, registering a callback using
153
+ # sqlite3_wal_hook() disables the automatic checkpoint mechanism
154
+ # configured by this function.
155
+ do_test 1.$tn.11.1 {
156
+ sqlite3_wal_checkpoint_v2 db truncate
157
+ file size test.db-wal
158
+ } 0
159
+ do_test 1.$tn.11.2 {
160
+ autocheckpoint db 100
161
+ for {set i 0} {$i < 1000} {incr i} {
162
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
163
+ }
164
+ expr {[file size test.db-wal] < (1 * 1024 * 1024)}
165
+ } 1
166
+ do_test 1.$tn.11.3 {
167
+ db wal_hook wal_hook_callback
168
+ for {set i 0} {$i < 1000} {incr i} {
169
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
170
+ }
171
+ expr {[file size test.db-wal] < (1 * 1024 * 1024)}
172
+ } 0
173
+
174
+ # EVIDENCE-OF: R-33080-59193 Checkpoints initiated by this mechanism
175
+ # are PASSIVE.
176
+ #
177
+ set ::busy_callback_count 0
178
+ proc busy_callback {args} {
179
+ incr ::busy_callback_count
180
+ return 0
181
+ }
182
+ do_test 1.$tn.12.1 {
183
+ sqlite3_wal_checkpoint_v2 db truncate
184
+ autocheckpoint db 100
185
+ db busy busy_callback
186
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
187
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
188
+ } {}
189
+ do_test 1.$tn.12.2 {
190
+ sqlite3 db2 test.db
191
+ db2 eval { BEGIN; SELECT * FROM t1 LIMIT 10; }
192
+ read_nbackfill
193
+ } {0}
194
+ do_test 1.$tn.12.3 {
195
+ for {set i 0} {$i < 1000} {incr i} {
196
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
197
+ }
198
+ read_nbackfill
199
+ } {2}
200
+ do_test 1.$tn.12.4 {
201
+ set ::busy_callback_count
202
+ } {0}
203
+ db2 close
204
+
205
+ do_test 1.$tn.12.5 {
206
+ db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }
207
+ read_nbackfill
208
+ } {1559}
209
+
210
+ db close
211
+ close $shmfd
212
+ }
213
+
214
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/enc3.test ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2002 May 24
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library.
12
+ #
13
+ # The focus of this file is testing of the proper handling of conversions
14
+ # to the native text representation.
15
+ #
16
+
17
+ set testdir [file dirname $argv0]
18
+ source $testdir/tester.tcl
19
+
20
+ ifcapable {utf16} {
21
+ do_test enc3-1.1 {
22
+ execsql {
23
+ PRAGMA encoding=utf16le;
24
+ PRAGMA encoding;
25
+ }
26
+ } {UTF-16le}
27
+ }
28
+ do_test enc3-1.2 {
29
+ execsql {
30
+ CREATE TABLE t1(x,y);
31
+ INSERT INTO t1 VALUES('abc''123',5);
32
+ SELECT * FROM t1
33
+ }
34
+ } {abc'123 5}
35
+ do_test enc3-1.3 {
36
+ execsql {
37
+ SELECT quote(x) || ' ' || quote(y) FROM t1
38
+ }
39
+ } {{'abc''123' 5}}
40
+ ifcapable {bloblit} {
41
+ do_test enc3-1.4 {
42
+ execsql {
43
+ DELETE FROM t1;
44
+ INSERT INTO t1 VALUES(x'616263646566',NULL);
45
+ SELECT * FROM t1
46
+ }
47
+ } {abcdef {}}
48
+ do_test enc3-1.5 {
49
+ execsql {
50
+ SELECT quote(x) || ' ' || quote(y) FROM t1
51
+ }
52
+ } {{X'616263646566' NULL}}
53
+ }
54
+ ifcapable {bloblit && utf16} {
55
+ do_test enc3-2.1 {
56
+ execsql {
57
+ PRAGMA encoding
58
+ }
59
+ } {UTF-16le}
60
+ do_test enc3-2.2 {
61
+ execsql {
62
+ CREATE TABLE t2(a);
63
+ INSERT INTO t2 VALUES(x'61006200630064006500');
64
+ SELECT CAST(a AS text) FROM t2 WHERE CAST(a AS text) LIKE 'abc%';
65
+ }
66
+ } {abcde}
67
+ do_test enc3-2.3 {
68
+ execsql {
69
+ SELECT CAST(x'61006200630064006500' AS text);
70
+ }
71
+ } {abcde}
72
+ do_test enc3-2.4 {
73
+ execsql {
74
+ SELECT rowid FROM t2
75
+ WHERE CAST(a AS text) LIKE CAST(x'610062002500' AS text);
76
+ }
77
+ } {1}
78
+ }
79
+
80
+ # Try to attach a database with a different encoding.
81
+ #
82
+ ifcapable {utf16 && shared_cache} {
83
+ db close
84
+ forcedelete test8.db test8.db-journal
85
+ set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
86
+ sqlite3 dbaux test8.db
87
+ sqlite3 db test.db
88
+ db eval {SELECT 1 FROM sqlite_master LIMIT 1}
89
+ do_test enc3-3.1 {
90
+ dbaux eval {
91
+ PRAGMA encoding='utf8';
92
+ CREATE TABLE t1(x);
93
+ PRAGMA encoding
94
+ }
95
+ } {UTF-8}
96
+ do_test enc3-3.2 {
97
+ catchsql {
98
+ ATTACH 'test.db' AS utf16;
99
+ SELECT 1 FROM utf16.sqlite_master LIMIT 1;
100
+ } dbaux
101
+ } {1 {attached databases must use the same text encoding as main database}}
102
+ dbaux close
103
+ forcedelete test8.db test8.db-journal
104
+ sqlite3_enable_shared_cache $::enable_shared_cache
105
+ }
106
+
107
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/extraquick.test ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # May you do good and not evil.
3
+ # May you find forgiveness for yourself and forgive others.
4
+ # May you share freely, never taking more than you give.
5
+ #
6
+ #***********************************************************************
7
+ # This file runs most of the tests run by veryquick.test except for those
8
+ # that take a long time.
9
+ #
10
+
11
+ set testdir [file dirname $argv0]
12
+ source $testdir/permutations.test
13
+
14
+ run_test_suite extraquick
15
+
16
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fts3auto.test ADDED
@@ -0,0 +1,717 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2011 June 10
2
+ #
3
+ # May you do good and not evil.
4
+ # May you find forgiveness for yourself and forgive others.
5
+ # May you share freely, never taking more than you give.
6
+ #
7
+ #***********************************************************************
8
+ #
9
+
10
+ set testdir [file dirname $argv0]
11
+ source $testdir/tester.tcl
12
+
13
+ # If this build does not include FTS3, skip the tests in this file.
14
+ #
15
+ ifcapable !fts3 { finish_test ; return }
16
+ source $testdir/fts3_common.tcl
17
+ source $testdir/malloc_common.tcl
18
+
19
+ set testprefix fts3auto
20
+ set sfep $sqlite_fts3_enable_parentheses
21
+ set sqlite_fts3_enable_parentheses 1
22
+
23
+ #--------------------------------------------------------------------------
24
+ # Start of Tcl infrastructure used by tests. The entry points are:
25
+ #
26
+ # do_fts3query_test
27
+ # fts3_make_deferrable
28
+ # fts3_zero_long_segments
29
+ #
30
+
31
+ #
32
+ # do_fts3query_test TESTNAME ?OPTIONS? TABLE MATCHEXPR
33
+ #
34
+ # This proc runs several test cases on FTS3/4 table $TABLE using match
35
+ # expression $MATCHEXPR. All documents in $TABLE must be formatted so that
36
+ # they can be "tokenized" using the Tcl list commands (llength, lindex etc.).
37
+ # The name and column names used by $TABLE must not require any quoting or
38
+ # escaping when used in SQL statements.
39
+ #
40
+ # $MATCHINFO may be any expression accepted by the FTS4 MATCH operator,
41
+ # except that the "<column-name>:token" syntax is not supported. Tcl list
42
+ # commands are used to tokenize the expression. Any parenthesis must appear
43
+ # either as separate list elements, or as the first (for opening) or last
44
+ # (for closing) character of a list element. i.e. the expression "(a OR b)c"
45
+ # will not be parsed correctly, but "( a OR b) c" will.
46
+ #
47
+ # Available OPTIONS are:
48
+ #
49
+ # -deferred TOKENLIST
50
+ #
51
+ # If the "deferred" option is supplied, it is passed a list of tokens that
52
+ # are deferred by FTS and result in the relevant matchinfo() stats being an
53
+ # approximation.
54
+ #
55
+ set sqlite_fts3_enable_parentheses 1
56
+ proc do_fts3query_test {tn args} {
57
+
58
+ set nArg [llength $args]
59
+ if {$nArg < 2 || ($nArg % 2)} {
60
+ set cmd do_fts3query_test
61
+ error "wrong # args: should be \"$cmd ?-deferred LIST? TABLE MATCHEXPR\""
62
+ }
63
+ set tbl [lindex $args [expr $nArg-2]]
64
+ set match [lindex $args [expr $nArg-1]]
65
+ set deferred [list]
66
+
67
+ foreach {k v} [lrange $args 0 [expr $nArg-3]] {
68
+ switch -- $k {
69
+ -deferred {
70
+ ifcapable fts4_deferred { set deferred $v }
71
+ }
72
+ default {
73
+ error "bad option \"$k\": must be -deferred"
74
+ }
75
+ }
76
+ }
77
+
78
+ get_near_results $tbl $match $deferred aHit
79
+ get_near_results $tbl [string map {AND OR} $match] $deferred aMatchinfo
80
+
81
+ set matchinfo_asc [list]
82
+ foreach docid [lsort -integer -incr [array names aHit]] {
83
+ lappend matchinfo_asc $docid $aMatchinfo($docid)
84
+ }
85
+ set matchinfo_desc [list]
86
+ foreach docid [lsort -integer -decr [array names aHit]] {
87
+ lappend matchinfo_desc $docid $aMatchinfo($docid)
88
+ }
89
+
90
+ set title "(\"$match\" -> [llength [array names aHit]] rows)"
91
+
92
+ do_execsql_test $tn$title.1 "
93
+ SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid ASC
94
+ " [lsort -integer -incr [array names aHit]]
95
+
96
+ do_execsql_test $tn$title.2 "
97
+ SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid DESC
98
+ " [lsort -integer -decr [array names aHit]]
99
+
100
+ do_execsql_test $tn$title.3 "
101
+ SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl
102
+ WHERE $tbl MATCH '$match' ORDER BY docid DESC
103
+ " $matchinfo_desc
104
+
105
+ do_execsql_test $tn$title.4 "
106
+ SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl
107
+ WHERE $tbl MATCH '$match' ORDER BY docid ASC
108
+ " $matchinfo_asc
109
+ }
110
+
111
+ # fts3_make_deferrable TABLE TOKEN ?NROW?
112
+ #
113
+ proc fts3_make_deferrable {tbl token {nRow 0}} {
114
+
115
+ set stmt [sqlite3_prepare db "SELECT * FROM $tbl" -1 dummy]
116
+ set name [sqlite3_column_name $stmt 0]
117
+ sqlite3_finalize $stmt
118
+
119
+ if {$nRow==0} {
120
+ set nRow [db one "SELECT count(*) FROM $tbl"]
121
+ }
122
+ set pgsz [db one "PRAGMA page_size"]
123
+ execsql BEGIN
124
+ for {set i 0} {$i < ($nRow * $pgsz * 1.2)/100} {incr i} {
125
+ set doc [string repeat "$token " 100]
126
+ execsql "INSERT INTO $tbl ($name) VALUES(\$doc)"
127
+ }
128
+ execsql "INSERT INTO $tbl ($name) VALUES('aaaaaaa ${token}aaaaa')"
129
+ execsql COMMIT
130
+
131
+ return [expr $nRow*$pgsz]
132
+ }
133
+
134
+ # fts3_zero_long_segments TABLE ?LIMIT?
135
+ #
136
+ proc fts3_zero_long_segments {tbl limit} {
137
+ sqlite3_db_config db DEFENSIVE 0
138
+ execsql "
139
+ UPDATE ${tbl}_segments
140
+ SET block = zeroblob(length(block))
141
+ WHERE length(block)>$limit
142
+ "
143
+ return [db changes]
144
+ }
145
+
146
+
147
+ proc mit {blob} {
148
+ set scan(littleEndian) i*
149
+ set scan(bigEndian) I*
150
+ binary scan $blob $scan($::tcl_platform(byteOrder)) r
151
+ return $r
152
+ }
153
+ db func mit mit
154
+
155
+ proc fix_phrase_expr {cols expr colfiltervar} {
156
+ upvar $colfiltervar iColFilter
157
+
158
+ set out [list]
159
+ foreach t $expr {
160
+ if {[string match *:* $t]} {
161
+ set col [lindex [split $t :] 0]
162
+ set t [lindex [split $t :] 1]
163
+ set iCol [lsearch $cols $col]
164
+ if {$iCol<0} { error "unknown column: $col" }
165
+ if {$iColFilter < 0} {
166
+ set iColFilter $iCol
167
+ } elseif {$iColFilter != $iCol} {
168
+ set iColFilter [llength $cols]
169
+ }
170
+ }
171
+ lappend out $t
172
+ }
173
+
174
+ return $out
175
+ }
176
+
177
+ proc fix_near_expr {cols expr colfiltervar} {
178
+ upvar $colfiltervar iColFilter
179
+
180
+ set iColFilter -1
181
+
182
+ set out [list]
183
+ lappend out [fix_phrase_expr $cols [lindex $expr 0] iColFilter]
184
+ foreach {a b} [lrange $expr 1 end] {
185
+ if {[string match -nocase near $a]} { set a 10 }
186
+ if {[string match -nocase near/* $a]} { set a [string range $a 5 end] }
187
+ lappend out $a
188
+ lappend out [fix_phrase_expr $cols $b iColFilter]
189
+ }
190
+ return $out
191
+ }
192
+
193
+ proc get_single_near_results {tbl expr deferred arrayvar nullvar} {
194
+ upvar $arrayvar aMatchinfo
195
+ upvar $nullvar nullentry
196
+ catch {array unset aMatchinfo}
197
+
198
+ set cols [list]
199
+ set miss [list]
200
+ db eval "PRAGMA table_info($tbl)" A { lappend cols $A(name) ; lappend miss 0 }
201
+ set expr [fix_near_expr $cols $expr iColFilter]
202
+
203
+ # Calculate the expected results using [fts3_near_match]. The following
204
+ # loop populates the "hits" and "counts" arrays as follows:
205
+ #
206
+ # 1. For each document in the table that matches the NEAR expression,
207
+ # hits($docid) is set to 1. The set of docids that match the expression
208
+ # can therefore be found using [array names hits].
209
+ #
210
+ # 2. For each column of each document in the table, counts($docid,$iCol)
211
+ # is set to the -phrasecountvar output.
212
+ #
213
+ set res [list]
214
+ catch { array unset hits }
215
+ db eval "SELECT docid, * FROM $tbl" d {
216
+ set iCol 0
217
+ foreach col [lrange $d(*) 1 end] {
218
+ set docid $d(docid)
219
+ if {$iColFilter<0 || $iCol==$iColFilter} {
220
+ set hit [fts3_near_match $d($col) $expr -p counts($docid,$iCol)]
221
+ if {$hit} { set hits($docid) 1 }
222
+ } else {
223
+ set counts($docid,$iCol) $miss
224
+ }
225
+ incr iCol
226
+ }
227
+ }
228
+ set nPhrase [expr ([llength $expr]+1)/2]
229
+ set nCol $iCol
230
+
231
+ # This block populates the nHit and nDoc arrays. For each phrase/column
232
+ # in the query/table, array elements are set as follows:
233
+ #
234
+ # nHit($iPhrase,$iCol) - Total number of hits for phrase $iPhrase in
235
+ # column $iCol.
236
+ #
237
+ # nDoc($iPhrase,$iCol) - Number of documents with at least one hit for
238
+ # phrase $iPhrase in column $iCol.
239
+ #
240
+ for {set iPhrase 0} {$iPhrase < $nPhrase} {incr iPhrase} {
241
+ for {set iCol 0} {$iCol < $nCol} {incr iCol} {
242
+ set nHit($iPhrase,$iCol) 0
243
+ set nDoc($iPhrase,$iCol) 0
244
+ }
245
+ }
246
+ foreach key [array names counts] {
247
+ set iCol [lindex [split $key ,] 1]
248
+ set iPhrase 0
249
+ foreach c $counts($key) {
250
+ if {$c>0} { incr nDoc($iPhrase,$iCol) 1 }
251
+ incr nHit($iPhrase,$iCol) $c
252
+ incr iPhrase
253
+ }
254
+ }
255
+
256
+ if {[llength $deferred] && [llength $expr]==1} {
257
+ set phrase [lindex $expr 0]
258
+ set rewritten [list]
259
+ set partial 0
260
+ foreach tok $phrase {
261
+ if {[lsearch $deferred $tok]>=0} {
262
+ lappend rewritten *
263
+ } else {
264
+ lappend rewritten $tok
265
+ set partial 1
266
+ }
267
+ }
268
+ if {$partial==0} {
269
+ set tblsize [db one "SELECT count(*) FROM $tbl"]
270
+ for {set iCol 0} {$iCol < $nCol} {incr iCol} {
271
+ set nHit(0,$iCol) $tblsize
272
+ set nDoc(0,$iCol) $tblsize
273
+ }
274
+ } elseif {$rewritten != $phrase} {
275
+ while {[lindex $rewritten end] == "*"} {
276
+ set rewritten [lrange $rewritten 0 end-1]
277
+ }
278
+ while {[lindex $rewritten 0] == "*"} {
279
+ set rewritten [lrange $rewritten 1 end]
280
+ }
281
+ get_single_near_results $tbl [list $rewritten] {} aRewrite nullentry
282
+ foreach docid [array names hits] {
283
+ set aMatchinfo($docid) $aRewrite($docid)
284
+ }
285
+ return
286
+ }
287
+ }
288
+
289
+ # Set up the aMatchinfo array. For each document, set aMatchinfo($docid) to
290
+ # contain the output of matchinfo('x') for the document.
291
+ #
292
+ foreach docid [array names hits] {
293
+ set mi [list]
294
+ for {set iPhrase 0} {$iPhrase<$nPhrase} {incr iPhrase} {
295
+ for {set iCol 0} {$iCol<$nCol} {incr iCol} {
296
+ lappend mi [lindex $counts($docid,$iCol) $iPhrase]
297
+ lappend mi $nHit($iPhrase,$iCol)
298
+ lappend mi $nDoc($iPhrase,$iCol)
299
+ }
300
+ }
301
+ set aMatchinfo($docid) $mi
302
+ }
303
+
304
+ # Set up the nullentry output.
305
+ #
306
+ set nullentry [list]
307
+ for {set iPhrase 0} {$iPhrase<$nPhrase} {incr iPhrase} {
308
+ for {set iCol 0} {$iCol<$nCol} {incr iCol} {
309
+ lappend nullentry 0 $nHit($iPhrase,$iCol) $nDoc($iPhrase,$iCol)
310
+ }
311
+ }
312
+ }
313
+
314
+
315
+ proc matching_brackets {expr} {
316
+ if {[string range $expr 0 0]!="(" || [string range $expr end end] !=")"} {
317
+ return 0
318
+ }
319
+
320
+ set iBracket 1
321
+ set nExpr [string length $expr]
322
+ for {set i 1} {$iBracket && $i < $nExpr} {incr i} {
323
+ set c [string range $expr $i $i]
324
+ if {$c == "("} {incr iBracket}
325
+ if {$c == ")"} {incr iBracket -1}
326
+ }
327
+
328
+ return [expr ($iBracket==0 && $i==$nExpr)]
329
+ }
330
+
331
+ proc get_near_results {tbl expr deferred arrayvar {nullvar ""}} {
332
+ upvar $arrayvar aMatchinfo
333
+ if {$nullvar != ""} { upvar $nullvar nullentry }
334
+
335
+ set expr [string trim $expr]
336
+ while { [matching_brackets $expr] } {
337
+ set expr [string trim [string range $expr 1 end-1]]
338
+ }
339
+
340
+ set prec(NOT) 1
341
+ set prec(AND) 2
342
+ set prec(OR) 3
343
+
344
+ set currentprec 0
345
+ set iBracket 0
346
+ set expr_length [llength $expr]
347
+ for {set i 0} {$i < $expr_length} {incr i} {
348
+ set op [lindex $expr $i]
349
+ if {$iBracket==0 && [info exists prec($op)] && $prec($op)>=$currentprec } {
350
+ set opidx $i
351
+ set currentprec $prec($op)
352
+ } else {
353
+ for {set j 0} {$j < [string length $op]} {incr j} {
354
+ set c [string range $op $j $j]
355
+ if {$c == "("} { incr iBracket +1 }
356
+ if {$c == ")"} { incr iBracket -1 }
357
+ }
358
+ }
359
+ }
360
+ if {$iBracket!=0} { error "mismatched brackets in: $expr" }
361
+
362
+ if {[info exists opidx]==0} {
363
+ get_single_near_results $tbl $expr $deferred aMatchinfo nullentry
364
+ } else {
365
+ set eLeft [lrange $expr 0 [expr $opidx-1]]
366
+ set eRight [lrange $expr [expr $opidx+1] end]
367
+
368
+ get_near_results $tbl $eLeft $deferred aLeft nullleft
369
+ get_near_results $tbl $eRight $deferred aRight nullright
370
+
371
+ switch -- [lindex $expr $opidx] {
372
+ "NOT" {
373
+ foreach hit [array names aLeft] {
374
+ if {0==[info exists aRight($hit)]} {
375
+ set aMatchinfo($hit) $aLeft($hit)
376
+ }
377
+ }
378
+ set nullentry $nullleft
379
+ }
380
+
381
+ "AND" {
382
+ foreach hit [array names aLeft] {
383
+ if {[info exists aRight($hit)]} {
384
+ set aMatchinfo($hit) [concat $aLeft($hit) $aRight($hit)]
385
+ }
386
+ }
387
+ set nullentry [concat $nullleft $nullright]
388
+ }
389
+
390
+ "OR" {
391
+ foreach hit [array names aLeft] {
392
+ if {[info exists aRight($hit)]} {
393
+ set aMatchinfo($hit) [concat $aLeft($hit) $aRight($hit)]
394
+ unset aRight($hit)
395
+ } else {
396
+ set aMatchinfo($hit) [concat $aLeft($hit) $nullright]
397
+ }
398
+ }
399
+ foreach hit [array names aRight] {
400
+ set aMatchinfo($hit) [concat $nullleft $aRight($hit)]
401
+ }
402
+
403
+ set nullentry [concat $nullleft $nullright]
404
+ }
405
+ }
406
+ }
407
+ }
408
+
409
+
410
+ # End of test procs. Actual tests are below this line.
411
+ #--------------------------------------------------------------------------
412
+
413
+ #--------------------------------------------------------------------------
414
+ # The following test cases - fts3auto-1.* - focus on testing the Tcl
415
+ # command [fts3_near_match], which is used by other tests in this file.
416
+ #
417
+ proc test_fts3_near_match {tn doc expr res} {
418
+ fts3_near_match $doc $expr -phrasecountvar p
419
+ uplevel do_test [list $tn] [list [list set {} $p]] [list $res]
420
+ }
421
+
422
+ test_fts3_near_match 1.1.1 {a b c a b} a {2}
423
+ test_fts3_near_match 1.1.2 {a b c a b} {a 5 b 6 c} {2 2 1}
424
+ test_fts3_near_match 1.1.3 {a b c a b} {"a b"} {2}
425
+ test_fts3_near_match 1.1.4 {a b c a b} {"b c"} {1}
426
+ test_fts3_near_match 1.1.5 {a b c a b} {"c c"} {0}
427
+
428
+ test_fts3_near_match 1.2.1 "a b c d e f g" {b 2 f} {0 0}
429
+ test_fts3_near_match 1.2.2 "a b c d e f g" {b 3 f} {1 1}
430
+ test_fts3_near_match 1.2.3 "a b c d e f g" {f 2 b} {0 0}
431
+ test_fts3_near_match 1.2.4 "a b c d e f g" {f 3 b} {1 1}
432
+ test_fts3_near_match 1.2.5 "a b c d e f g" {"a b" 2 "f g"} {0 0}
433
+ test_fts3_near_match 1.2.6 "a b c d e f g" {"a b" 3 "f g"} {1 1}
434
+
435
+ set A "a b c d e f g h i j k l m n o p q r s t u v w x y z"
436
+ test_fts3_near_match 1.3.1 $A {"c d" 5 "i j" 1 "e f"} {0 0 0}
437
+ test_fts3_near_match 1.3.2 $A {"c d" 5 "i j" 2 "e f"} {1 1 1}
438
+
439
+ #--------------------------------------------------------------------------
440
+ # Test cases fts3auto-2.* run some simple tests using the
441
+ # [do_fts3query_test] proc.
442
+ #
443
+ foreach {tn create} {
444
+ 1 "fts4(a, b)"
445
+ 2 "fts4(a, b, order=DESC)"
446
+ 3 "fts4(a, b, order=ASC)"
447
+ 4 "fts4(a, b, prefix=1)"
448
+ 5 "fts4(a, b, order=DESC, prefix=1)"
449
+ 6 "fts4(a, b, order=ASC, prefix=1)"
450
+ } {
451
+ do_test 2.$tn.1 {
452
+ catchsql { DROP TABLE t1 }
453
+ execsql "CREATE VIRTUAL TABLE t1 USING $create"
454
+ for {set i 0} {$i<32} {incr i} {
455
+ set doc [list]
456
+ if {$i&0x01} {lappend doc one}
457
+ if {$i&0x02} {lappend doc two}
458
+ if {$i&0x04} {lappend doc three}
459
+ if {$i&0x08} {lappend doc four}
460
+ if {$i&0x10} {lappend doc five}
461
+ execsql { INSERT INTO t1 VALUES($doc, null) }
462
+ }
463
+ } {}
464
+
465
+ foreach {tn2 expr} {
466
+ 1 {one}
467
+ 2 {one NEAR/1 five}
468
+ 3 {t*}
469
+ 4 {t* NEAR/0 five}
470
+ 5 {o* NEAR/1 f*}
471
+ 6 {one NEAR five NEAR two NEAR four NEAR three}
472
+ 7 {one NEAR xyz}
473
+ 8 {one OR two}
474
+ 9 {one AND two}
475
+ 10 {one NOT two}
476
+ 11 {one AND two OR three}
477
+ 12 {three OR one AND two}
478
+ 13 {(three OR one) AND two}
479
+ 14 {(three OR one) AND two NOT (five NOT four)}
480
+ 15 {"one two"}
481
+ 16 {"one two" NOT "three four"}
482
+ } {
483
+ do_fts3query_test 2.$tn.2.$tn2 t1 $expr
484
+ }
485
+ }
486
+
487
+ #--------------------------------------------------------------------------
488
+ # Some test cases involving deferred tokens.
489
+ #
490
+
491
+ foreach {tn create} {
492
+ 1 "fts4(x)"
493
+ 2 "fts4(x, order=DESC)"
494
+ } {
495
+ catchsql { DROP TABLE t1 }
496
+ execsql "CREATE VIRTUAL TABLE t1 USING $create"
497
+ do_execsql_test 3.$tn.1 {
498
+ INSERT INTO t1(docid, x) VALUES(-2, 'a b c d e f g h i j k');
499
+ INSERT INTO t1(docid, x) VALUES(-1, 'b c d e f g h i j k a');
500
+ INSERT INTO t1(docid, x) VALUES(0, 'c d e f g h i j k a b');
501
+ INSERT INTO t1(docid, x) VALUES(1, 'd e f g h i j k a b c');
502
+ INSERT INTO t1(docid, x) VALUES(2, 'e f g h i j k a b c d');
503
+ INSERT INTO t1(docid, x) VALUES(3, 'f g h i j k a b c d e');
504
+ INSERT INTO t1(docid, x) VALUES(4, 'a c e g i k');
505
+ INSERT INTO t1(docid, x) VALUES(5, 'a d g j');
506
+ INSERT INTO t1(docid, x) VALUES(6, 'c a b');
507
+ }
508
+
509
+ set limit [fts3_make_deferrable t1 c]
510
+
511
+ do_fts3query_test 3.$tn.2.1 t1 {a OR c}
512
+
513
+ ifcapable fts4_deferred {
514
+ do_test 3.$tn.3 { fts3_zero_long_segments t1 $limit } {1}
515
+ }
516
+
517
+ foreach {tn2 expr def} {
518
+ 1 {a NEAR c} {}
519
+ 2 {a AND c} c
520
+ 3 {"a c"} c
521
+ 4 {"c a"} c
522
+ 5 {"a c" NEAR/1 g} {}
523
+ 6 {"a c" NEAR/0 g} {}
524
+ } {
525
+ do_fts3query_test 3.$tn.4.$tn2 -deferred $def t1 $expr
526
+ }
527
+ }
528
+
529
+ #--------------------------------------------------------------------------
530
+ #
531
+ foreach {tn create} {
532
+ 1 "fts4(x, y)"
533
+ 2 "fts4(x, y, order=DESC)"
534
+ 3 "fts4(x, y, order=DESC, prefix=2)"
535
+ } {
536
+
537
+ execsql [subst {
538
+ DROP TABLE t1;
539
+ CREATE VIRTUAL TABLE t1 USING $create;
540
+ INSERT INTO t1 VALUES('one two five four five', '');
541
+ INSERT INTO t1 VALUES('', 'one two five four five');
542
+ INSERT INTO t1 VALUES('one two', 'five four five');
543
+ }]
544
+
545
+ do_fts3query_test 4.$tn.1.1 t1 {one AND five}
546
+ do_fts3query_test 4.$tn.1.2 t1 {one NEAR five}
547
+ do_fts3query_test 4.$tn.1.3 t1 {one NEAR/1 five}
548
+ do_fts3query_test 4.$tn.1.4 t1 {one NEAR/2 five}
549
+ do_fts3query_test 4.$tn.1.5 t1 {one NEAR/3 five}
550
+
551
+ do_test 4.$tn.2 {
552
+ set limit [fts3_make_deferrable t1 five]
553
+ execsql { INSERT INTO t1(t1) VALUES('optimize') }
554
+ ifcapable fts4_deferred {
555
+ expr {[fts3_zero_long_segments t1 $limit]>0}
556
+ } else {
557
+ expr 1
558
+ }
559
+ } {1}
560
+
561
+ do_fts3query_test 4.$tn.3.1 -deferred five t1 {one AND five}
562
+ do_fts3query_test 4.$tn.3.2 -deferred five t1 {one NEAR five}
563
+ do_fts3query_test 4.$tn.3.3 -deferred five t1 {one NEAR/1 five}
564
+ do_fts3query_test 4.$tn.3.4 -deferred five t1 {one NEAR/2 five}
565
+
566
+ do_fts3query_test 4.$tn.3.5 -deferred five t1 {one NEAR/3 five}
567
+
568
+ do_fts3query_test 4.$tn.4.1 -deferred fi* t1 {on* AND fi*}
569
+ do_fts3query_test 4.$tn.4.2 -deferred fi* t1 {on* NEAR fi*}
570
+ do_fts3query_test 4.$tn.4.3 -deferred fi* t1 {on* NEAR/1 fi*}
571
+ do_fts3query_test 4.$tn.4.4 -deferred fi* t1 {on* NEAR/2 fi*}
572
+ do_fts3query_test 4.$tn.4.5 -deferred fi* t1 {on* NEAR/3 fi*}
573
+
574
+ ifcapable fts4_deferred {
575
+ db eval {UPDATE t1_stat SET value=x'' WHERE id=0}
576
+ do_catchsql_test 4.$tn.4.6 {
577
+ SELECT docid FROM t1 WHERE t1 MATCH 'on* NEAR/3 fi*'
578
+ } {1 {database disk image is malformed}}
579
+ }
580
+ }
581
+
582
+ #--------------------------------------------------------------------------
583
+ # The following test cases - fts3auto-5.* - focus on using prefix indexes.
584
+ #
585
+ set chunkconfig [fts3_configure_incr_load 1 1]
586
+ foreach {tn create pending} {
587
+ 1 "fts4(a, b)" 1
588
+ 2 "fts4(a, b, order=ASC, prefix=1)" 1
589
+ 3 "fts4(a, b, order=ASC, prefix=\"1,3\")" 0
590
+ 4 "fts4(a, b, order=DESC, prefix=\"2,4\")" 0
591
+ 5 "fts4(a, b, order=DESC, prefix=\"1\")" 0
592
+ 6 "fts4(a, b, order=ASC, prefix=\"1,3\")" 0
593
+ } {
594
+
595
+ execsql [subst {
596
+ DROP TABLE IF EXISTS t1;
597
+ CREATE VIRTUAL TABLE t1 USING $create;
598
+ }]
599
+
600
+ if {$pending} {execsql BEGIN}
601
+
602
+ foreach {a b} {
603
+ "the song of songs which is solomons"
604
+ "let him kiss me with the kisses of his mouth for thy love is better than wine"
605
+ "because of the savour of thy good ointments thy name is as ointment poured forth therefore do the virgins love thee"
606
+ "draw me we will run after thee the king hath brought me into his chambers we will be glad and rejoice in thee we will remember thy love more than wine the upright love thee"
607
+ "i am black but comely o ye daughters of jerusalem as the tents of kedar as the curtains of solomon"
608
+ "look not upon me because i am black because the sun hath looked upon me my mothers children were angry with me they made me the keeper of the vineyards but mine own vineyard have i not kept"
609
+ "tell me o thou whom my soul loveth where thou feedest where thou makest thy flock to rest at noon for why should i be as one that turneth aside by the flocks of thy companions?"
610
+ "if thou know not o thou fairest among women go thy way forth by the footsteps of the flock and feed thy kids beside the shepherds tents"
611
+ "i have compared thee o my love to a company of horses in pharaohs chariots"
612
+ "thy cheeks are comely with rows of jewels thy neck with chains of gold"
613
+ "we will make thee borders of gold with studs of silver"
614
+ "while the king sitteth at his table my spikenard sendeth forth the smell thereof"
615
+ "a bundle of myrrh is my wellbeloved unto me he shall lie all night betwixt my breasts"
616
+ "my beloved is unto me as a cluster of camphire in the vineyards of en gedi"
617
+ "behold thou art fair my love behold thou art fair thou hast doves eyes"
618
+ "behold thou art fair my beloved yea pleasant also our bed is green"
619
+ "the beams of our house are cedar and our rafters of fir"
620
+ } {
621
+ execsql {INSERT INTO t1(a, b) VALUES($a, $b)}
622
+ }
623
+
624
+
625
+ do_fts3query_test 5.$tn.1.1 t1 {s*}
626
+ do_fts3query_test 5.$tn.1.2 t1 {so*}
627
+ do_fts3query_test 5.$tn.1.3 t1 {"s* o*"}
628
+ do_fts3query_test 5.$tn.1.4 t1 {b* NEAR/3 a*}
629
+ do_fts3query_test 5.$tn.1.5 t1 {a*}
630
+ do_fts3query_test 5.$tn.1.6 t1 {th* NEAR/5 a* NEAR/5 w*}
631
+ do_fts3query_test 5.$tn.1.7 t1 {"b* th* art* fair*"}
632
+
633
+ if {$pending} {execsql COMMIT}
634
+ }
635
+ eval fts3_configure_incr_load $chunkconfig
636
+
637
+ foreach {tn pending create} {
638
+ 1 0 "fts4(a, b, c, d)"
639
+ 2 1 "fts4(a, b, c, d)"
640
+ 3 0 "fts4(a, b, c, d, order=DESC)"
641
+ 4 1 "fts4(a, b, c, d, order=DESC)"
642
+ } {
643
+ execsql [subst {
644
+ DROP TABLE IF EXISTS t1;
645
+ CREATE VIRTUAL TABLE t1 USING $create;
646
+ }]
647
+
648
+
649
+ if {$pending} { execsql BEGIN }
650
+
651
+ foreach {a b c d} {
652
+ "A B C" "D E F" "G H I" "J K L"
653
+ "B C D" "E F G" "H I J" "K L A"
654
+ "C D E" "F G H" "I J K" "L A B"
655
+ "D E F" "G H I" "J K L" "A B C"
656
+ "E F G" "H I J" "K L A" "B C D"
657
+ "F G H" "I J K" "L A B" "C D E"
658
+ } {
659
+ execsql { INSERT INTO t1 VALUES($a, $b, $c, $d) }
660
+ }
661
+
662
+ do_fts3query_test 6.$tn.1 t1 {b:G}
663
+ do_fts3query_test 6.$tn.2 t1 {b:G AND c:I}
664
+ do_fts3query_test 6.$tn.3 t1 {b:G NEAR c:I}
665
+ do_fts3query_test 6.$tn.4 t1 {a:C OR b:G OR c:K OR d:C}
666
+
667
+ do_fts3query_test 6.$tn.5 t1 {a:G OR b:G}
668
+
669
+ catchsql { COMMIT }
670
+ }
671
+
672
+ foreach {tn create} {
673
+ 1 "fts4(x)"
674
+ 2 "fts4(x, order=DESC)"
675
+ } {
676
+ execsql [subst {
677
+ DROP TABLE IF EXISTS t1;
678
+ CREATE VIRTUAL TABLE t1 USING $create;
679
+ }]
680
+
681
+ foreach {x} {
682
+ "F E N O T K X V A X I E X A P G Q V H U"
683
+ "R V A E T C V Q N I E L O N U G J K L U"
684
+ "U Y I G W M V F J L X I D C H F P J Q B"
685
+ "S G D Z X R P G S S Y B K A S G A I L L"
686
+ "L S I C H T Z S R Q P R N K J X L F M J"
687
+ "C C C D P X B Z C M A D A C X S B T X V"
688
+ "W Y J M D R G V R K B X S A W R I T N C"
689
+ "P K L W T M S P O Y Y V V O E H Q A I R"
690
+ "C D Y I C Z F H J C O Y A Q F L S B D K"
691
+ "P G S C Y C Y V I M B D S Z D D Y W I E"
692
+ "Z K Z U E E S F Y X T U A L W O U J C Q"
693
+ "P A T Z S W L P L Q V Y Y I P W U X S S"
694
+ "I U I H U O F Z F R H R F T N D X A G M"
695
+ "N A B M S H K X S O Y D T X S B R Y H Z"
696
+ "L U D A S K I L S V Z J P U B E B Y H M"
697
+ } {
698
+ execsql { INSERT INTO t1 VALUES($x) }
699
+ }
700
+
701
+ # Add extra documents to the database such that token "B" will be considered
702
+ # deferrable if considering the other tokens means that 2 or fewer documents
703
+ # will be loaded into memory.
704
+ #
705
+ fts3_make_deferrable t1 B 2
706
+
707
+ # B is not deferred in either of the first two tests below, since filtering
708
+ # on "M" or "D" returns 10 documents or so. But filtering on "M * D" only
709
+ # returns 2, so B is deferred in this case.
710
+ #
711
+ do_fts3query_test 7.$tn.1 t1 {"M B"}
712
+ do_fts3query_test 7.$tn.2 t1 {"B D"}
713
+ do_fts3query_test 7.$tn.3 -deferred B t1 {"M B D"}
714
+ }
715
+
716
+ set sqlite_fts3_enable_parentheses $sfep
717
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fts3cov.test ADDED
@@ -0,0 +1,434 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2009 December 03
2
+ #
3
+ # May you do good and not evil.
4
+ # May you find forgiveness for yourself and forgive others.
5
+ # May you share freely, never taking more than you give.
6
+ #
7
+ #***********************************************************************
8
+ #
9
+ # The tests in this file are structural coverage tests for FTS3.
10
+ #
11
+
12
+ set testdir [file dirname $argv0]
13
+ source $testdir/tester.tcl
14
+
15
+ # If this build does not include FTS3, skip the tests in this file.
16
+ #
17
+ ifcapable !fts3 { finish_test ; return }
18
+ source $testdir/fts3_common.tcl
19
+ source $testdir/malloc_common.tcl
20
+
21
+ set DO_MALLOC_TEST 0
22
+ set testprefix fts3cov
23
+
24
+ #--------------------------------------------------------------------------
25
+ # When it first needs to read a block from the %_segments table, the FTS3
26
+ # module compiles an SQL statement for that purpose. The statement is
27
+ # stored and reused each subsequent time a block is read. This test case
28
+ # tests the effects of an OOM error occuring while compiling the statement.
29
+ #
30
+ # Similarly, when FTS3 first needs to scan through a set of segment leaves
31
+ # to find a set of documents that matches a term, it allocates a string
32
+ # containing the text of the required SQL, and compiles one or more
33
+ # statements to traverse the leaves. This test case tests that OOM errors
34
+ # that occur while allocating this string and statement are handled correctly
35
+ # also.
36
+ #
37
+ do_test fts3cov-1.1 {
38
+ execsql {
39
+ CREATE VIRTUAL TABLE t1 USING fts3(x);
40
+ INSERT INTO t1(t1) VALUES('nodesize=24');
41
+ BEGIN;
42
+ INSERT INTO t1 VALUES('Is the night chilly and dark?');
43
+ INSERT INTO t1 VALUES('The night is chilly, but not dark.');
44
+ INSERT INTO t1 VALUES('The thin gray cloud is spread on high,');
45
+ INSERT INTO t1 VALUES('It covers but not hides the sky.');
46
+ COMMIT;
47
+ SELECT count(*)>0 FROM t1_segments;
48
+ }
49
+ } {1}
50
+
51
+ set DO_MALLOC_TEST 1
52
+ do_restart_select_test fts3cov-1.2 {
53
+ SELECT docid FROM t1 WHERE t1 MATCH 'chilly';
54
+ } {1 2}
55
+ set DO_MALLOC_TEST 0
56
+
57
+ #--------------------------------------------------------------------------
58
+ # When querying the full-text index, if an expected internal node block is
59
+ # missing from the %_segments table, or if a NULL value is stored in the
60
+ # %_segments table instead of a binary blob, database corruption should be
61
+ # reported.
62
+ #
63
+ # Even with tiny 24 byte nodes, it takes a fair bit of data to produce a
64
+ # segment b-tree that uses the %_segments table to store internal nodes.
65
+ #
66
+ do_test fts3cov-2.1 {
67
+ execsql {
68
+ INSERT INTO t1(t1) VALUES('nodesize=24');
69
+ BEGIN;
70
+ INSERT INTO t1 VALUES('The moon is behind, and at the full;');
71
+ INSERT INTO t1 VALUES('And yet she looks both small and dull.');
72
+ INSERT INTO t1 VALUES('The night is chill, the cloud is gray:');
73
+ INSERT INTO t1 VALUES('''T is a month before the month of May,');
74
+ INSERT INTO t1 VALUES('And the Spring comes slowly up this way.');
75
+ INSERT INTO t1 VALUES('The lovely lady, Christabel,');
76
+ INSERT INTO t1 VALUES('Whom her father loves so well,');
77
+ INSERT INTO t1 VALUES('What makes her in the wood so late,');
78
+ INSERT INTO t1 VALUES('A furlong from the castle gate?');
79
+ INSERT INTO t1 VALUES('She had dreams all yesternight');
80
+ INSERT INTO t1 VALUES('Of her own betrothed knight;');
81
+ INSERT INTO t1 VALUES('And she in the midnight wood will pray');
82
+ INSERT INTO t1 VALUES('For the weal of her lover that''s far away.');
83
+ COMMIT;
84
+ }
85
+ execsql {
86
+ INSERT INTO t1(t1) VALUES('optimize');
87
+ SELECT substr(hex(root), 1, 2) FROM t1_segdir;
88
+ }
89
+ } {03}
90
+
91
+ # Test the "missing entry" case:
92
+ sqlite3_db_config db DEFENSIVE 0
93
+ do_test fts3cov-2.2 {
94
+ set root [db one {SELECT root FROM t1_segdir}]
95
+ read_fts3varint [string range $root 1 end] left_child
96
+ execsql { DELETE FROM t1_segments WHERE blockid = $left_child }
97
+ } {}
98
+ do_error_test fts3cov-2.3 {
99
+ SELECT * FROM t1 WHERE t1 MATCH 'c*'
100
+ } {database disk image is malformed}
101
+
102
+ # Test the "replaced with NULL" case:
103
+ do_test fts3cov-2.4 {
104
+ execsql { INSERT INTO t1_segments VALUES($left_child, NULL) }
105
+ } {}
106
+ do_error_test fts3cov-2.5 {
107
+ SELECT * FROM t1 WHERE t1 MATCH 'cloud'
108
+ } {database disk image is malformed}
109
+
110
+ #--------------------------------------------------------------------------
111
+ # The following tests are to test the effects of OOM errors while storing
112
+ # terms in the pending-hash table. Specifically, while creating doclist
113
+ # blobs to store in the table. More specifically, to test OOM errors while
114
+ # appending column numbers to doclists. For example, if a doclist consists
115
+ # of:
116
+ #
117
+ # <docid> <column 0 offset-list> 0x01 <column N> <column N offset-list>
118
+ #
119
+ # The following tests check that malloc errors encountered while appending
120
+ # the "0x01 <column N>" data to the dynamically growable blob used to
121
+ # accumulate the doclist in memory are handled correctly.
122
+ #
123
+ do_test fts3cov-3.1 {
124
+ set cols [list]
125
+ set vals [list]
126
+ for {set i 0} {$i < 120} {incr i} {
127
+ lappend cols "col$i"
128
+ lappend vals "'word'"
129
+ }
130
+ execsql "CREATE VIRTUAL TABLE t2 USING fts3([join $cols ,])"
131
+ } {}
132
+ set DO_MALLOC_TEST 1
133
+ do_write_test fts3cov-3.2 t2_content "
134
+ INSERT INTO t2(docid, [join $cols ,]) VALUES(1, [join $vals ,])
135
+ "
136
+ do_write_test fts3cov-3.3 t2_content "
137
+ INSERT INTO t2(docid, [join $cols ,]) VALUES(200, [join $vals ,])
138
+ "
139
+ do_write_test fts3cov-3.4 t2_content "
140
+ INSERT INTO t2(docid, [join $cols ,]) VALUES(60000, [join $vals ,])
141
+ "
142
+
143
+ #-------------------------------------------------------------------------
144
+ # If too much data accumulates in the pending-terms hash table, it is
145
+ # flushed to the database automatically, even if the transaction has not
146
+ # finished. The following tests check the effects of encountering an OOM
147
+ # while doing this.
148
+ #
149
+ do_test fts3cov-4.1 {
150
+ execsql {
151
+ CREATE VIRTUAL TABLE t3 USING fts3(x);
152
+ INSERT INTO t3(t3) VALUES('nodesize=24');
153
+ INSERT INTO t3(t3) VALUES('maxpending=100');
154
+ }
155
+ } {}
156
+ set DO_MALLOC_TEST 1
157
+ do_write_test fts3cov-4.2 t3_content {
158
+ INSERT INTO t3(docid, x)
159
+ SELECT 1, 'Then Christabel stretched forth her hand,' UNION ALL
160
+ SELECT 3, 'And comforted fair Geraldine:' UNION ALL
161
+ SELECT 4, '''O well, bright dame, may you command' UNION ALL
162
+ SELECT 5, 'The service of Sir Leoline;' UNION ALL
163
+ SELECT 2, 'And gladly our stout chivalry' UNION ALL
164
+ SELECT 7, 'Will he send forth, and friends withal,' UNION ALL
165
+ SELECT 8, 'To guide and guard you safe and free' UNION ALL
166
+ SELECT 6, 'Home to your noble father''s hall.'''
167
+ }
168
+
169
+ #-------------------------------------------------------------------------
170
+ # When building the internal tree structure for each segment b-tree, FTS3
171
+ # assumes that the content of each internal node will be less than
172
+ # $nodesize bytes, where $nodesize is the advisory node size. If this turns
173
+ # out to be untrue, then an extra buffer must be malloc'd for each term.
174
+ # This test case tests these paths and the effects of said mallocs failing
175
+ # by inserting insert a document with some fairly large terms into a
176
+ # full-text table with a very small node-size.
177
+ #
178
+ # Test this handling of large terms in three contexts:
179
+ #
180
+ # 1. When flushing the pending-terms table.
181
+ # 2. When optimizing the data structures using the INSERT syntax.
182
+ # 2. When optimizing the data structures using the deprecated SELECT syntax.
183
+ #
184
+ do_test fts3cov-5.1 {
185
+ execsql {
186
+ CREATE VIRTUAL TABLE t4 USING fts3(x);
187
+ INSERT INTO t4(t4) VALUES('nodesize=24');
188
+ }
189
+ } {}
190
+ set DO_MALLOC_TEST 1
191
+
192
+ # Test when flushing pending-terms table.
193
+ do_write_test fts3cov-5.2 t4_content {
194
+ INSERT INTO t4
195
+ SELECT 'ItisanancientMarinerAndhestoppethoneofthreeAA' UNION ALL
196
+ SELECT 'ItisanancientMarinerAndhestoppethoneofthreeBB' UNION ALL
197
+ SELECT 'ItisanancientMarinerAndhestoppethoneofthreeCC' UNION ALL
198
+ SELECT 'BythylonggreybeardandglitteringeyeNowwhereforestoppstAA' UNION ALL
199
+ SELECT 'BythylonggreybeardandglitteringeyeNowwhereforestoppstBB' UNION ALL
200
+ SELECT 'BythylonggreybeardandglitteringeyeNowwhereforestoppstCC'
201
+ }
202
+
203
+ # Test when optimizing via INSERT.
204
+ do_test fts3cov-5.3 { execsql { INSERT INTO t4 VALUES('extra!') } } {}
205
+ do_write_test fts3cov-5.2 t4_segments { INSERT INTO t4(t4) VALUES('optimize') }
206
+
207
+ # Test when optimizing via SELECT.
208
+ do_test fts3cov-5.5 { execsql { INSERT INTO t4 VALUES('more extra!') } } {}
209
+ do_write_test fts3cov-5.6 t4_segments {
210
+ SELECT * FROM (SELECT optimize(t4) FROM t4 LIMIT 1)
211
+ EXCEPT SELECT 'Index optimized'
212
+ }
213
+
214
+ #-------------------------------------------------------------------------
215
+ # When merging all segments at a given level to create a single segment
216
+ # at level+1, FTS3 runs a query of the form:
217
+ #
218
+ # SELECT count(*) FROM %_segdir WHERE level = ?
219
+ #
220
+ # The query is compiled the first time this operation is required and
221
+ # reused thereafter. This test aims to test the effects of an OOM while
222
+ # preparing and executing this query for the first time.
223
+ #
224
+ # Then, keep inserting rows into the table so that the effects of an OOM
225
+ # while re-executing the same query can also be tested.
226
+ #
227
+ do_test fts3cov-6.1 {
228
+ execsql { CREATE VIRTUAL TABLE t5 USING fts3(x) }
229
+ for {set i 0} {$i<16} {incr i} { execsql "INSERT INTO t5 VALUES('term$i')" }
230
+ execsql { SELECT count(*) FROM t5_segdir }
231
+ } {16}
232
+
233
+ # First time.
234
+ db close
235
+ sqlite3 db test.db
236
+ do_write_test fts3cov-6.2 t5_content {
237
+ INSERT INTO t5 VALUES('segment number 16!');
238
+ }
239
+
240
+ # Second time.
241
+ do_test fts3cov-6.3 {
242
+ for {set i 1} {$i<16} {incr i} { execsql "INSERT INTO t5 VALUES('term$i')" }
243
+ execsql { SELECT count(*) FROM t5_segdir }
244
+ } {17}
245
+ do_write_test fts3cov-6.4 t5_content {
246
+ INSERT INTO t5 VALUES('segment number 16!');
247
+ }
248
+
249
+ #-------------------------------------------------------------------------
250
+ # Update the docid of a row. Test this in two scenarios:
251
+ #
252
+ # 1. When the row being updated is the only row in the table.
253
+ # 2. When it is not.
254
+ #
255
+ # The two cases above take different paths because in case 1 all data
256
+ # structures can simply be emptied before inserting the new row record.
257
+ # In case 2, the data structures actually have to be updated.
258
+ #
259
+ do_test fts3cov-7.1 {
260
+ execsql {
261
+ CREATE VIRTUAL TABLE t7 USING fts3(a, b, c);
262
+ INSERT INTO t7 VALUES('A', 'B', 'C');
263
+ UPDATE t7 SET docid = 5;
264
+ SELECT docid, * FROM t7;
265
+ }
266
+ } {5 A B C}
267
+ do_test fts3cov-7.2 {
268
+ execsql {
269
+ INSERT INTO t7 VALUES('D', 'E', 'F');
270
+ UPDATE t7 SET docid = 1 WHERE docid = 6;
271
+ SELECT docid, * FROM t7;
272
+ }
273
+ } {1 D E F 5 A B C}
274
+
275
+ #-------------------------------------------------------------------------
276
+ # If a set of documents are modified within a transaction, the
277
+ # pending-terms table must be flushed each time a document with a docid
278
+ # less than or equal to the previous docid is modified.
279
+ #
280
+ # This test checks the effects of an OOM error occuring when the
281
+ # pending-terms table is flushed for this reason as part of a DELETE
282
+ # statement.
283
+ #
284
+ do_malloc_test fts3cov-8 -sqlprep {
285
+ BEGIN;
286
+ CREATE VIRTUAL TABLE t8 USING fts3;
287
+ INSERT INTO t8 VALUES('the output of each batch run');
288
+ INSERT INTO t8 VALUES('(possibly a day''s work)');
289
+ INSERT INTO t8 VALUES('was written to two separate disks');
290
+ COMMIT;
291
+ } -sqlbody {
292
+ BEGIN;
293
+ DELETE FROM t8 WHERE rowid = 3;
294
+ DELETE FROM t8 WHERE rowid = 2;
295
+ DELETE FROM t8 WHERE rowid = 1;
296
+ COMMIT;
297
+ }
298
+
299
+ #-------------------------------------------------------------------------
300
+ # Test some branches in the code that handles "special" inserts like:
301
+ #
302
+ # INSERT INTO t1(t1) VALUES('optimize');
303
+ #
304
+ # Also test that an optimize (INSERT method) works on an empty table.
305
+ #
306
+ set DO_MALLOC_TEST 0
307
+ do_test fts3cov-9.1 {
308
+ execsql { CREATE VIRTUAL TABLE xx USING fts3 }
309
+ } {}
310
+ do_error_test fts3cov-9.2 {
311
+ INSERT INTO xx(xx) VALUES('optimise'); -- British spelling
312
+ } {SQL logic error}
313
+ do_error_test fts3cov-9.3 {
314
+ INSERT INTO xx(xx) VALUES('short');
315
+ } {SQL logic error}
316
+ do_error_test fts3cov-9.4 {
317
+ INSERT INTO xx(xx) VALUES('waytoolongtobecorrect');
318
+ } {SQL logic error}
319
+ do_test fts3cov-9.5 {
320
+ execsql { INSERT INTO xx(xx) VALUES('optimize') }
321
+ } {}
322
+
323
+ #-------------------------------------------------------------------------
324
+ # Test that a table can be optimized in the middle of a transaction when
325
+ # the pending-terms table is non-empty. This case involves some extra
326
+ # branches because data must be read not only from the database, but
327
+ # also from the pending-terms table.
328
+ #
329
+ do_malloc_test fts3cov-10 -sqlprep {
330
+ CREATE VIRTUAL TABLE t10 USING fts3;
331
+ INSERT INTO t10 VALUES('Optimising images for the web is a tricky business');
332
+ BEGIN;
333
+ INSERT INTO t10 VALUES('You have to get the right balance between');
334
+ } -sqlbody {
335
+ INSERT INTO t10(t10) VALUES('optimize');
336
+ }
337
+
338
+ #-------------------------------------------------------------------------
339
+ # Test a full-text query for a term that was once in the index, but is
340
+ # no longer.
341
+ #
342
+ do_test fts3cov-11.1 {
343
+ execsql {
344
+ CREATE VIRTUAL TABLE xx USING fts3;
345
+ INSERT INTO xx VALUES('one two three');
346
+ INSERT INTO xx VALUES('four five six');
347
+ DELETE FROM xx WHERE docid = 1;
348
+ }
349
+ execsql { SELECT * FROM xx WHERE xx MATCH 'two' }
350
+ } {}
351
+
352
+
353
+ do_malloc_test fts3cov-12 -sqlprep {
354
+ CREATE VIRTUAL TABLE t12 USING fts3;
355
+ INSERT INTO t12 VALUES('is one of the two togther');
356
+ BEGIN;
357
+ INSERT INTO t12 VALUES('one which was appropriate at the time');
358
+ } -sqlbody {
359
+ SELECT * FROM t12 WHERE t12 MATCH 'one'
360
+ }
361
+
362
+ do_malloc_test fts3cov-13 -sqlprep {
363
+ PRAGMA encoding = 'UTF-16';
364
+ CREATE VIRTUAL TABLE t13 USING fts3;
365
+ INSERT INTO t13 VALUES('two scalar functions');
366
+ INSERT INTO t13 VALUES('scalar two functions');
367
+ INSERT INTO t13 VALUES('functions scalar two');
368
+ } -sqlbody {
369
+ SELECT snippet(t13, '%%', '%%', '#') FROM t13 WHERE t13 MATCH 'two';
370
+ SELECT snippet(t13, '%%', '%%') FROM t13 WHERE t13 MATCH 'two';
371
+ SELECT snippet(t13, '%%') FROM t13 WHERE t13 MATCH 'two';
372
+ }
373
+
374
+ do_execsql_test 14.0 {
375
+ CREATE VIRTUAL TABLE t14 USING fts4(a, b);
376
+ INSERT INTO t14 VALUES('one two three', 'one three four');
377
+ INSERT INTO t14 VALUES('a b c', 'd e a');
378
+ }
379
+ do_execsql_test 14.1 {
380
+ SELECT rowid FROM t14 WHERE t14 MATCH '"one two three"'
381
+ } {1}
382
+ do_execsql_test 14.2 {
383
+ SELECT rowid FROM t14 WHERE t14 MATCH '"one four"'
384
+ } {}
385
+ do_execsql_test 14.3 {
386
+ SELECT rowid FROM t14 WHERE t14 MATCH '"e a"'
387
+ } {2}
388
+ do_execsql_test 14.5 {
389
+ SELECT rowid FROM t14 WHERE t14 MATCH '"e b"'
390
+ } {}
391
+ do_catchsql_test 14.6 {
392
+ SELECT rowid FROM t14 WHERE rowid MATCH 'one'
393
+ } {1 {unable to use function MATCH in the requested context}}
394
+ do_catchsql_test 14.7 {
395
+ SELECT rowid FROM t14 WHERE docid MATCH 'one'
396
+ } {1 {unable to use function MATCH in the requested context}}
397
+
398
+ do_execsql_test 15.0 {
399
+ CREATE VIRTUAL TABLE t15 USING fts4(a, b, c);
400
+ INSERT INTO t15 VALUES('abc def ghi', 'abc2 def2 ghi2', 'abc3 def3 ghi3');
401
+ INSERT INTO t15 VALUES('abc2 def2 ghi2', 'abc2 def2 ghi2', 'abc def3 ghi3');
402
+ }
403
+ do_execsql_test 15.1 {
404
+ SELECT rowid FROM t15 WHERE t15 MATCH '"abc* def2"'
405
+ } {1 2}
406
+
407
+ # Test a corruption case.
408
+ #
409
+ sqlite3_db_config db DEFENSIVE 0
410
+ do_execsql_test 16.1 {
411
+ CREATE VIRTUAL TABLE t16 USING fts4;
412
+ INSERT INTO t16 VALUES('theoretical work to examine the relationship');
413
+ INSERT INTO t16 VALUES('solution of our problems on the invisible');
414
+ DELETE FROM t16_content WHERE rowid = 2;
415
+ }
416
+ do_catchsql_test 16.2 {
417
+ SELECT * FROM t16 WHERE t16 MATCH 'invisible'
418
+ } {1 {database disk image is malformed}}
419
+
420
+ # And another corruption test case.
421
+ #
422
+ do_execsql_test 17.1 {
423
+ CREATE VIRTUAL TABLE t17 USING fts4;
424
+ INSERT INTO t17(content) VALUES('one one one');
425
+ UPDATE t17_segdir SET root = X'00036F6E65FFFFFFFFFFFFFFFFFFFFFF02030300'
426
+ } {}
427
+ do_catchsql_test 17.2 {
428
+ SELECT * FROM t17 WHERE t17 MATCH 'one'
429
+ } {1 {database disk image is malformed}}
430
+
431
+
432
+
433
+
434
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fts3e.test ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2008 July 29
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #*************************************************************************
11
+ # These tests exercise the various types of fts3 cursors.
12
+ #
13
+ # $Id: fts3e.test,v 1.1 2008/07/29 20:24:46 shess Exp $
14
+ #
15
+
16
+ set testdir [file dirname $argv0]
17
+ source $testdir/tester.tcl
18
+
19
+ # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
20
+ ifcapable !fts3 {
21
+ finish_test
22
+ return
23
+ }
24
+
25
+ #*************************************************************************
26
+ # Test table scan (QUERY_GENERIC). This kind of query happens for
27
+ # queries with no WHERE clause, or for WHERE clauses which cannot be
28
+ # satisfied by an index.
29
+ db eval {
30
+ DROP TABLE IF EXISTS t1;
31
+ CREATE VIRTUAL TABLE t1 USING fts3(c);
32
+ INSERT INTO t1 (docid, c) VALUES (1, 'This is a test');
33
+ INSERT INTO t1 (docid, c) VALUES (2, 'That was a test');
34
+ INSERT INTO t1 (docid, c) VALUES (3, 'This is a test');
35
+ }
36
+
37
+ do_test fts3e-1.1 {
38
+ execsql {
39
+ SELECT docid FROM t1 ORDER BY docid;
40
+ }
41
+ } {1 2 3}
42
+
43
+ do_test fts3e-1.2 {
44
+ execsql {
45
+ SELECT docid FROM t1 WHERE c LIKE '%test' ORDER BY docid;
46
+ }
47
+ } {1 2 3}
48
+
49
+ do_test fts3e-1.3 {
50
+ execsql {
51
+ SELECT docid FROM t1 WHERE c LIKE 'That%' ORDER BY docid;
52
+ }
53
+ } {2}
54
+
55
+ #*************************************************************************
56
+ # Test lookup by docid (QUERY_DOCID). This kind of query happens for
57
+ # queries which select by the docid/rowid implicit index.
58
+ db eval {
59
+ DROP TABLE IF EXISTS t1;
60
+ DROP TABLE IF EXISTS t2;
61
+ CREATE VIRTUAL TABLE t1 USING fts3(c);
62
+ CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
63
+ INSERT INTO t2 VALUES (null, 10);
64
+ INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
65
+ INSERT INTO t2 VALUES (null, 5);
66
+ INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test');
67
+ INSERT INTO t2 VALUES (null, 20);
68
+ INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
69
+ }
70
+
71
+ # TODO(shess): This actually is doing QUERY_GENERIC? I'd have
72
+ # expected QUERY_DOCID in this case, as for a very large table the
73
+ # full scan is less efficient.
74
+ do_test fts3e-2.1 {
75
+ execsql {
76
+ SELECT docid FROM t1 WHERE docid in (1, 2, 10);
77
+ SELECT rowid FROM t1 WHERE rowid in (1, 2, 10);
78
+ }
79
+ } {1 2 1 2}
80
+
81
+ do_test fts3e-2.2 {
82
+ execsql {
83
+ SELECT docid, weight FROM t1, t2 WHERE t2.id = t1.docid ORDER BY weight;
84
+ SELECT t1.rowid, weight FROM t1, t2 WHERE t2.id = t1.rowid ORDER BY weight;
85
+ }
86
+ } {2 5 1 10 3 20 2 5 1 10 3 20}
87
+
88
+ do_test fts3e-2.3 {
89
+ execsql {
90
+ SELECT docid, weight FROM t1, t2
91
+ WHERE t2.weight>5 AND t2.id = t1.docid ORDER BY weight;
92
+ SELECT t1.rowid, weight FROM t1, t2
93
+ WHERE t2.weight>5 AND t2.id = t1.rowid ORDER BY weight;
94
+ }
95
+ } {1 10 3 20 1 10 3 20}
96
+
97
+ #*************************************************************************
98
+ # Test lookup by MATCH (QUERY_FULLTEXT). This is the fulltext index.
99
+ db eval {
100
+ DROP TABLE IF EXISTS t1;
101
+ DROP TABLE IF EXISTS t2;
102
+ CREATE VIRTUAL TABLE t1 USING fts3(c);
103
+ CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
104
+ INSERT INTO t2 VALUES (null, 10);
105
+ INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
106
+ INSERT INTO t2 VALUES (null, 5);
107
+ INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test');
108
+ INSERT INTO t2 VALUES (null, 20);
109
+ INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
110
+ }
111
+
112
+ do_test fts3e-3.1 {
113
+ execsql {
114
+ SELECT docid FROM t1 WHERE t1 MATCH 'this' ORDER BY docid;
115
+ }
116
+ } {1 3}
117
+
118
+ do_test fts3e-3.2 {
119
+ execsql {
120
+ SELECT docid, weight FROM t1, t2
121
+ WHERE t1 MATCH 'this' AND t1.docid = t2.id ORDER BY weight;
122
+ }
123
+ } {1 10 3 20}
124
+
125
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fts3fault.test ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2010 June 15
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+
13
+ set testdir [file dirname $argv0]
14
+ source $testdir/tester.tcl
15
+
16
+ set ::testprefix fts3fault
17
+
18
+ # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
19
+ ifcapable !fts3 { finish_test ; return }
20
+
21
+ set ::TMPDBERROR [list 1 \
22
+ {unable to open a temporary database file for storing temporary tables}
23
+ ]
24
+
25
+ # Test error handling in the sqlite3Fts3Init() function. This is the
26
+ # function that registers the FTS3 module and various support functions
27
+ # with SQLite.
28
+ #
29
+ do_faultsim_test 1 -body {
30
+ sqlite3 db test.db
31
+ expr 0
32
+ } -test {
33
+ catch { db close }
34
+ }
35
+
36
+ # Test error handling in an "ALTER TABLE ... RENAME TO" statement on an
37
+ # FTS3 table. Specifically, test renaming the table within a transaction
38
+ # after it has been written to.
39
+ #
40
+ faultsim_delete_and_reopen
41
+ do_execsql_test 2.0 {
42
+ CREATE VIRTUAL TABLE t1 USING fts3;
43
+ INSERT INTO t1 VALUES('test renaming the table');
44
+ INSERT INTO t1 VALUES(' after it has been written');
45
+ }
46
+ do_faultsim_test 2 -prep {
47
+ sqlite3 db test.db
48
+ execsql {
49
+ BEGIN;
50
+ INSERT INTO t1 VALUES('registers the FTS3 module');
51
+ INSERT INTO t1 VALUES('various support functions');
52
+ }
53
+ } -body {
54
+ execsql { ALTER TABLE t1 RENAME TO t2 }
55
+ } -test {
56
+ faultsim_test_result {0 {}} $::TMPDBERROR
57
+ }
58
+
59
+ # Test error handling in the special case where a single prefix query
60
+ # matches terms that reside on a large range of leaf nodes.
61
+ #
62
+ do_test fts3fault-3.0 {
63
+ sqlite3 db test.db
64
+ execsql { CREATE VIRTUAL TABLE t3 USING fts4; }
65
+ execsql { INSERT INTO t3(t3) VALUES('nodesize=50') }
66
+ execsql { BEGIN }
67
+ for {set i 0} {$i < 1000} {incr i} {
68
+ execsql { INSERT INTO t3 VALUES('aaa' || $i) }
69
+ }
70
+ execsql { COMMIT }
71
+ } {}
72
+
73
+ do_faultsim_test 3 -faults oom-transient -prep {
74
+ sqlite3 db test.db
75
+ execsql { SELECT * FROM t3 WHERE t3 MATCH 'x' }
76
+ } -body {
77
+ execsql { SELECT count(rowid) FROM t3 WHERE t3 MATCH 'aa*' }
78
+ } -test {
79
+ faultsim_test_result {0 1000}
80
+ }
81
+
82
+ do_test fts3fault-4.0 {
83
+ faultsim_delete_and_reopen
84
+ execsql {
85
+ CREATE VIRTUAL TABLE t4 USING fts4;
86
+ INSERT INTO t4 VALUES('The British Government called on');
87
+ INSERT INTO t4 VALUES('as pesetas then became much');
88
+ }
89
+ } {}
90
+ faultsim_save_and_close
91
+ do_faultsim_test 4 -prep {
92
+ faultsim_restore_and_reopen
93
+ execsql { SELECT content FROM t4 }
94
+ } -body {
95
+ execsql { SELECT optimize(t4) FROM t4 LIMIT 1 }
96
+ } -test {
97
+ faultsim_test_result {0 {{Index optimized}}}
98
+ }
99
+
100
+ do_test fts3fault-5.0 {
101
+ faultsim_delete_and_reopen
102
+ execsql {
103
+ CREATE VIRTUAL TABLE t5 USING fts4;
104
+ INSERT INTO t5 VALUES('The British Government called on');
105
+ INSERT INTO t5 VALUES('as pesetas then became much');
106
+ }
107
+ } {}
108
+ faultsim_save_and_close
109
+ do_faultsim_test 5 -prep {
110
+ faultsim_restore_and_reopen
111
+ execsql {
112
+ BEGIN;
113
+ INSERT INTO t5 VALUES('influential in shaping his future outlook');
114
+ INSERT INTO t5 VALUES('might be acceptable to the British electorate');
115
+ }
116
+ } -body {
117
+ execsql { SELECT rowid FROM t5 WHERE t5 MATCH 'british' }
118
+ } -test {
119
+ faultsim_test_result {0 {1 4}}
120
+ }
121
+
122
+ do_test fts3fault-6.0 {
123
+ faultsim_delete_and_reopen
124
+ execsql { CREATE VIRTUAL TABLE t6 USING fts4 }
125
+ } {}
126
+ faultsim_save_and_close
127
+ do_faultsim_test 6 -prep {
128
+ faultsim_restore_and_reopen
129
+ execsql { SELECT rowid FROM t6 }
130
+ } -body {
131
+ execsql { DROP TABLE t6 }
132
+ } -test {
133
+ faultsim_test_result {0 {}}
134
+ }
135
+
136
+ # Test various malloc failures while processing FTS4 parameters.
137
+ #
138
+ do_faultsim_test 7.1 -prep {
139
+ faultsim_delete_and_reopen
140
+ } -body {
141
+ execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fts3) }
142
+ } -test {
143
+ faultsim_test_result {0 {}}
144
+ }
145
+ do_faultsim_test 7.2 -prep {
146
+ faultsim_delete_and_reopen
147
+ } -body {
148
+ execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fs3) }
149
+ } -test {
150
+ faultsim_test_result {1 {unrecognized matchinfo: fs3}} \
151
+ {1 {vtable constructor failed: t1}} \
152
+ {1 {SQL logic error}}
153
+ }
154
+ do_faultsim_test 7.3 -prep {
155
+ faultsim_delete_and_reopen
156
+ } -body {
157
+ execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchnfo=fts3) }
158
+ } -test {
159
+ faultsim_test_result {1 {unrecognized parameter: matchnfo=fts3}} \
160
+ {1 {vtable constructor failed: t1}} \
161
+ {1 {SQL logic error}}
162
+ }
163
+
164
+
165
+ proc mit {blob} {
166
+ set scan(littleEndian) i*
167
+ set scan(bigEndian) I*
168
+ binary scan $blob $scan($::tcl_platform(byteOrder)) r
169
+ return $r
170
+ }
171
+
172
+ do_test 8.0 {
173
+ faultsim_delete_and_reopen
174
+ execsql { CREATE VIRTUAL TABLE t8 USING fts4 }
175
+ execsql "INSERT INTO t8 VALUES('a b c')"
176
+ execsql "INSERT INTO t8 VALUES('b b b')"
177
+ execsql "INSERT INTO t8 VALUES('[string repeat {c } 50000]')"
178
+ execsql "INSERT INTO t8 VALUES('d d d')"
179
+ execsql "INSERT INTO t8 VALUES('e e e')"
180
+ execsql "INSERT INTO t8(t8) VALUES('optimize')"
181
+ faultsim_save_and_close
182
+ } {}
183
+
184
+ ifcapable fts4_deferred {
185
+ do_faultsim_test 8.1 -faults oom-t* -prep {
186
+ faultsim_restore_and_reopen
187
+ db func mit mit
188
+ } -body {
189
+ execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' }
190
+ } -test {
191
+ faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}}
192
+ }
193
+ }
194
+
195
+ do_faultsim_test 8.2 -faults oom-t* -prep {
196
+ faultsim_restore_and_reopen
197
+ db func mit mit
198
+ } -body {
199
+ execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' }
200
+ } -test {
201
+ faultsim_test_result {0 3} $::TMPDBERROR
202
+ }
203
+ do_faultsim_test 8.3 -prep {
204
+ faultsim_restore_and_reopen
205
+ db func mit mit
206
+ } -body {
207
+ execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' }
208
+ } -test {
209
+ faultsim_test_result {0 10002}
210
+ }
211
+ do_faultsim_test 8.4 -prep {
212
+ faultsim_restore_and_reopen
213
+ db func mit mit
214
+ } -body {
215
+ execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' }
216
+ } -test {
217
+ faultsim_test_result {0 3}
218
+ }
219
+
220
+ do_test 9.0 {
221
+ faultsim_delete_and_reopen
222
+ execsql {
223
+ CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter);
224
+ INSERT INTO t9 VALUES(
225
+ 'this record is used toooooooooooooooooooooooooooooooooooooo try to'
226
+ );
227
+ SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*';
228
+ }
229
+ faultsim_save_and_close
230
+ } {}
231
+ do_faultsim_test 9.1 -prep {
232
+ faultsim_restore_and_reopen
233
+ } -body {
234
+ execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' }
235
+ } -test {
236
+ faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}}
237
+ }
238
+
239
+ do_faultsim_test 10.1 -prep {
240
+ faultsim_delete_and_reopen
241
+ } -body {
242
+ execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=d) }
243
+ } -test {
244
+ faultsim_test_result {0 {}}
245
+ }
246
+
247
+ #-------------------------------------------------------------------------
248
+ reset_db
249
+ do_execsql_test 11.0 {
250
+ CREATE VIRTUAL TABLE t1 USING fts3(a, b);
251
+ }
252
+ faultsim_save_and_close
253
+
254
+ do_faultsim_test 11 -faults oom* -prep {
255
+ faultsim_restore_and_reopen
256
+ } -body {
257
+ execsql { DROP TABLE t1 }
258
+ } -test {
259
+ faultsim_test_result {0 {}}
260
+ }
261
+
262
+
263
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fts3misc.test ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2017 March 22
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #*************************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this script is testing the FTS3 module.
13
+ #
14
+
15
+ set testdir [file dirname $argv0]
16
+ source $testdir/tester.tcl
17
+ set testprefix fts3misc
18
+
19
+ # If SQLITE_ENABLE_FTS3 is defined, omit this file.
20
+ ifcapable !fts3 {
21
+ finish_test
22
+ return
23
+ }
24
+
25
+ #-------------------------------------------------------------------------
26
+ # A self-join.
27
+ #
28
+ do_execsql_test 1.0 {
29
+ CREATE VIRTUAL TABLE t1 USING fts3(a, b);
30
+ INSERT INTO t1 VALUES('one', 'i');
31
+ INSERT INTO t1 VALUES('one', 'ii');
32
+ INSERT INTO t1 VALUES('two', 'i');
33
+ INSERT INTO t1 VALUES('two', 'ii');
34
+ }
35
+
36
+ do_execsql_test 1.1 {
37
+ SELECT a.a, b.b FROM t1 a, t1 b WHERE a.t1 MATCH 'two' AND b.t1 MATCH 'i'
38
+ } {two i two i two i two i}
39
+
40
+ #-------------------------------------------------------------------------
41
+ # FTS tables with 128 or more columns.
42
+ #
43
+ proc v1 {v} {
44
+ set vector [list a b c d e f g h]
45
+ set res [list]
46
+ for {set i 0} {$i<8} {incr i} {
47
+ if {$v & (1 << $i)} { lappend res [lindex $vector $i] }
48
+ }
49
+ set res
50
+ }
51
+ proc v2 {v} {
52
+ set vector [list d e f g h i j k]
53
+ set res [list]
54
+ for {set i 0} {$i<8} {incr i} {
55
+ if {$v & (1 << $i)} { lappend res [lindex $vector $i] }
56
+ }
57
+ set res
58
+ }
59
+ db func v1 v1
60
+ db func v2 v2
61
+
62
+ do_test 2.0 {
63
+ set cols [list]
64
+ for {set i 0} {$i<200} {incr i} {
65
+ lappend cols "c$i"
66
+ }
67
+ execsql "CREATE VIRTUAL TABLE t2 USING fts3([join $cols ,])"
68
+ execsql {
69
+ WITH data(i) AS (
70
+ SELECT 1 UNION ALL SELECT i+1 FROM data WHERE i<200
71
+ )
72
+ INSERT INTO t2(c198, c199) SELECT v1(i), v2(i) FROM data;
73
+ }
74
+ } {}
75
+ do_execsql_test 2.1 {
76
+ SELECT rowid FROM t2 WHERE t2 MATCH '"a b c"'
77
+ } {
78
+ 7 15 23 31 39 47 55 63 71 79 87 95 103 111
79
+ 119 127 135 143 151 159 167 175 183 191 199
80
+ }
81
+ do_execsql_test 2.2 {
82
+ SELECT rowid FROM t2 WHERE t2 MATCH '"g h i"'
83
+ } {
84
+ 56 57 58 59 60 61 62 63 120 121 122 123 124
85
+ 125 126 127 184 185 186 187 188 189 190 191
86
+ }
87
+ do_execsql_test 2.3 {
88
+ SELECT rowid FROM t2 WHERE t2 MATCH '"i h"'
89
+ } {
90
+ }
91
+ do_execsql_test 2.4 {
92
+ SELECT rowid FROM t2 WHERE t2 MATCH '"f e"'
93
+ } {
94
+ }
95
+ do_execsql_test 2.5 {
96
+ SELECT rowid FROM t2 WHERE t2 MATCH '"e f"'
97
+ } {
98
+ 6 7 14 15 22 23 30 31 38 39 46 47 48 49 50 51 52 53 54 55 56
99
+ 57 58 59 60 61 62 63 70 71 78 79 86 87 94 95 102 103 110
100
+ 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
101
+ 134 135 142 143 150 151 158 159 166 167 174 175 176 177 178 179 180
102
+ 181 182 183 184 185 186 187 188 189 190 191 198 199
103
+ }
104
+
105
+ #-------------------------------------------------------------------------
106
+ # Range constraints on the docid using non-integer values.
107
+ #
108
+ do_execsql_test 2.6 {
109
+ SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN NULL AND 45;
110
+ } {}
111
+ do_execsql_test 2.7 {
112
+ SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN 11.5 AND 48.2;
113
+ } {
114
+ 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
115
+ 29 30 31 34 35 38 39 42 43 46 47 48
116
+ }
117
+ do_execsql_test 2.8 {
118
+ SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN '11.5' AND '48.2';
119
+ } {
120
+ 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
121
+ 29 30 31 34 35 38 39 42 43 46 47 48
122
+ }
123
+
124
+ #-------------------------------------------------------------------------
125
+ # Phrase query tests.
126
+ #
127
+ do_execsql_test 3.1.1 {
128
+ CREATE VIRTUAL TABLE t3 USING fts3;
129
+ INSERT INTO t3 VALUES('a b c');
130
+ INSERT INTO t3 VALUES('d e f');
131
+ INSERT INTO t3 VALUES('a b d');
132
+ INSERT INTO t3 VALUES('1 2 3 4 5 6 7 8 9 10 11');
133
+ }
134
+ do_execsql_test 3.1.2 {
135
+ SELECT * FROM t3 WHERE t3 MATCH '"a b x y"' ORDER BY docid DESC
136
+ }
137
+ do_execsql_test 3.1.3 {
138
+ SELECT * FROM t3 WHERE t3 MATCH '"a b c" OR "a b x y"' ORDER BY docid DESC
139
+ } {{a b c}}
140
+ do_execsql_test 3.1.4 {
141
+ SELECT * FROM t3 WHERE t3 MATCH '"a* b* x* a*"'
142
+ }
143
+ do_execsql_test 3.1.5 {
144
+ SELECT rowid FROM t3 WHERE t3 MATCH '"2 3 4 5 6 7 8 9"'
145
+ } {4}
146
+
147
+ #-------------------------------------------------------------------------
148
+ #
149
+ reset_db
150
+ ifcapable fts4_deferred {
151
+ do_execsql_test 4.0 {
152
+ PRAGMA page_size = 512;
153
+ CREATE VIRTUAL TABLE t4 USING fts4;
154
+ WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<8000 )
155
+ INSERT INTO t4 SELECT 'a b c a b c a b c' FROM s;
156
+ }
157
+ do_execsql_test 4.1 {
158
+ SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
159
+ } {8000}
160
+ do_execsql_test 4.2 {
161
+ SELECT quote(value) from t4_stat where id=0
162
+ } {X'C03EC0B204C0A608'}
163
+ sqlite3_db_config db DEFENSIVE 0
164
+ do_execsql_test 4.3 {
165
+ UPDATE t4_stat SET value = X'C03EC0B204C0A60800' WHERE id=0;
166
+ }
167
+ do_catchsql_test 4.4 {
168
+ SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
169
+ } {1 {database disk image is malformed}}
170
+ do_execsql_test 4.5 {
171
+ UPDATE t4_stat SET value = X'00C03EC0B204C0A608' WHERE id=0;
172
+ }
173
+ do_catchsql_test 4.6 {
174
+ SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
175
+ } {1 {database disk image is malformed}}
176
+ }
177
+
178
+ #-------------------------------------------------------------------------
179
+ #
180
+ reset_db
181
+ do_execsql_test 5.0 {
182
+ CREATE VIRTUAL TABLE t5 USING fts4;
183
+ INSERT INTO t5 VALUES('a x x x x b x x x x c');
184
+ INSERT INTO t5 VALUES('a x x x x b x x x x c');
185
+ INSERT INTO t5 VALUES('a x x x x b x x x x c');
186
+ }
187
+ do_execsql_test 5.1 {
188
+ SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/4 b NEAR/4 c'
189
+ } {1 2 3}
190
+ do_execsql_test 5.2 {
191
+ SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/3 b NEAR/4 c'
192
+ } {}
193
+ do_execsql_test 5.3 {
194
+ SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/4 b NEAR/3 c'
195
+ } {}
196
+ do_execsql_test 5.4 {
197
+ SELECT rowid FROM t5 WHERE t5 MATCH 'y NEAR/4 b NEAR/4 c'
198
+ } {}
199
+ do_execsql_test 5.5 {
200
+ SELECT rowid FROM t5 WHERE t5 MATCH 'x OR a NEAR/3 b NEAR/3 c'
201
+ } {1 2 3}
202
+ do_execsql_test 5.5 {
203
+ SELECT rowid FROM t5 WHERE t5 MATCH 'x OR y NEAR/3 b NEAR/3 c'
204
+ } {1 2 3}
205
+
206
+ #-------------------------------------------------------------------------
207
+ #
208
+ reset_db
209
+ do_execsql_test 6.0 {
210
+ CREATE VIRTUAL TABLE t6 USING fts4;
211
+
212
+ BEGIN;
213
+ WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000)
214
+ INSERT INTO t6 SELECT 'x x x x x x x x x x x' FROM s;
215
+
216
+ INSERT INTO t6 VALUES('x x x x x x x x x x x A');
217
+ INSERT INTO t6 VALUES('x x x x x x x x x x x B');
218
+ INSERT INTO t6 VALUES('x x x x x x x x x x x A');
219
+ INSERT INTO t6 VALUES('x x x x x x x x x x x B');
220
+
221
+ WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000)
222
+ INSERT INTO t6 SELECT 'x x x x x x x x x x x' FROM s;
223
+ COMMIT;
224
+ }
225
+ do_execsql_test 6.1 {
226
+ SELECT rowid FROM t6 WHERE t6 MATCH 'b OR "x a"'
227
+ } {50001 50002 50003 50004}
228
+
229
+ #-------------------------------------------------------------------------
230
+ #
231
+ reset_db
232
+ do_execsql_test 7.0 {
233
+ CREATE VIRTUAL TABLE vt0 USING fts3(c0);
234
+ INSERT INTO vt0 VALUES (x'00');
235
+ }
236
+ do_execsql_test 7.1 {
237
+ INSERT INTO vt0(vt0) VALUES('integrity-check');
238
+ }
239
+
240
+ #-------------------------------------------------------------------------
241
+ # Ticket [8a6fa2bb].
242
+ #
243
+ reset_db
244
+ do_execsql_test 7.0.1 {
245
+ CREATE VIRTUAL TABLE vt0 USING fts4(c0, order=DESC);
246
+ INSERT INTO vt0(c0) VALUES (0), (0);
247
+ }
248
+ do_execsql_test 7.0.2 {
249
+ INSERT INTO vt0(vt0) VALUES('integrity-check');
250
+ }
251
+ reset_db
252
+ do_execsql_test 7.1.1 {
253
+ CREATE VIRTUAL TABLE vt0 USING fts4(c0, order=ASC);
254
+ INSERT INTO vt0(c0) VALUES (0), (0);
255
+ }
256
+ do_execsql_test 7.1.2 {
257
+ INSERT INTO vt0(vt0) VALUES('integrity-check');
258
+ }
259
+ do_execsql_test 7.2.1 {
260
+ CREATE VIRTUAL TABLE ft USING fts4(c0, c1, order=DESC, prefix=1);
261
+ INSERT INTO ft VALUES('a b c d', 'hello world');
262
+ INSERT INTO ft VALUES('negative', 'positive');
263
+ INSERT INTO ft VALUES('hello world', 'a b c d');
264
+ }
265
+ do_execsql_test 7.2.2 {
266
+ INSERT INTO vt0(vt0) VALUES('integrity-check');
267
+ }
268
+
269
+ #-------------------------------------------------------------------------
270
+ # Ticket [745f1abc].
271
+ #
272
+ reset_db
273
+ do_execsql_test 8.1 {
274
+ CREATE VIRTUAL TABLE vt0 USING fts4(c0, prefix=1);
275
+ }
276
+ do_execsql_test 8.2 {
277
+ BEGIN;
278
+ INSERT INTO vt0 VALUES (0);
279
+ INSERT INTO vt0(vt0) VALUES('optimize');
280
+ COMMIT;
281
+ }
282
+ do_execsql_test 8.3 {
283
+ INSERT INTO vt0(vt0) VALUES('integrity-check');
284
+ }
285
+
286
+ #-------------------------------------------------------------------------
287
+ #
288
+ reset_db
289
+ do_execsql_test 9.0 {
290
+ CREATE VIRTUAL TABLE t1 using fts4(mailcontent);
291
+ insert into t1(rowid, mailcontent) values
292
+ (-4764623217061966105, 'we are going to upgrade'),
293
+ (8324454597464624651, 'we are going to upgrade');
294
+ }
295
+
296
+ do_execsql_test 9.1 {
297
+ INSERT INTO t1(t1) VALUES('integrity-check');
298
+ }
299
+
300
+ do_execsql_test 9.2 {
301
+ SELECT rowid FROM t1 WHERE t1 MATCH 'upgrade';
302
+ } {
303
+ -4764623217061966105 8324454597464624651
304
+ }
305
+
306
+ #-------------------------------------------------------------------------
307
+ reset_db
308
+ do_execsql_test 10.0 {
309
+ CREATE VIRTUAL TABLE f USING fts3(a,b);
310
+ CREATE TABLE 'f_stat'(id INTEGER PRIMARY KEY, value BLOB);
311
+ INSERT INTO f_stat VALUES (1,x'3b3b3b3b3b3b3b28ffffffffffffffffff1807f9073481f1d43bc93b3b3b3b3b3b3b3b3b3b18073b3b3b3b3b3b3b9b003b');
312
+ } {}
313
+
314
+ do_catchsql_test 10.1 {
315
+ INSERT INTO f(f) VALUES ('merge=69,59');
316
+ } {1 {database disk image is malformed}}
317
+
318
+ #-------------------------------------------------------------------------
319
+ do_execsql_test 11.0 {
320
+ CREATE VIRTUAL TABLE xyz USING fts3();
321
+ }
322
+ do_execsql_test 11.1 {
323
+ SELECT * FROM xyz WHERE xyz MATCH 'a NEAR/4294836224 a';
324
+ }
325
+
326
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fts3prefix2.test ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2012 January 25
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #*************************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this script is testing the FTS3 module.
13
+ #
14
+
15
+ set testdir [file dirname $argv0]
16
+ source $testdir/tester.tcl
17
+ set testprefix fts3prefix2
18
+
19
+ ifcapable !fts3 {
20
+ finish_test
21
+ return
22
+ }
23
+
24
+ do_execsql_test 1.0 { PRAGMA page_size = 512 }
25
+ do_execsql_test 1.1 {
26
+ CREATE VIRTUAL TABLE t1 USING fts4(x, prefix="2,3");
27
+
28
+ BEGIN;
29
+ INSERT INTO t1 VALUES('T TX T TX T TX T TX T TX');
30
+ INSERT INTO t1 SELECT * FROM t1; -- 2
31
+ INSERT INTO t1 SELECT * FROM t1; -- 4
32
+ INSERT INTO t1 SELECT * FROM t1; -- 8
33
+ INSERT INTO t1 SELECT * FROM t1; -- 16
34
+ INSERT INTO t1 SELECT * FROM t1; -- 32
35
+ INSERT INTO t1 SELECT * FROM t1; -- 64
36
+ INSERT INTO t1 SELECT * FROM t1; -- 128
37
+ INSERT INTO t1 SELECT * FROM t1; -- 256
38
+ INSERT INTO t1 SELECT * FROM t1; -- 512
39
+ INSERT INTO t1 SELECT * FROM t1; -- 1024
40
+ INSERT INTO t1 SELECT * FROM t1; -- 2048
41
+ COMMIT;
42
+ }
43
+
44
+ do_execsql_test 1.2 {
45
+ INSERT INTO t1 SELECT * FROM t1 LIMIT 10;
46
+ INSERT INTO t1 SELECT * FROM t1 LIMIT 10;
47
+ INSERT INTO t1 SELECT * FROM t1 LIMIT 10;
48
+ DELETE FROM t1 WHERE docid > 5;
49
+ }
50
+
51
+ do_execsql_test 1.3 {
52
+ SELECT * FROM t1 WHERE t1 MATCH 'T*';
53
+ } {
54
+ {T TX T TX T TX T TX T TX}
55
+ {T TX T TX T TX T TX T TX}
56
+ {T TX T TX T TX T TX T TX}
57
+ {T TX T TX T TX T TX T TX}
58
+ {T TX T TX T TX T TX T TX}
59
+ }
60
+
61
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fts3varint.test ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2007 November 23
2
+ #
3
+ # May you do good and not evil.
4
+ # May you find forgiveness for yourself and forgive others.
5
+ # May you share freely, never taking more than you give.
6
+ #
7
+ #***********************************************************************
8
+ # This file runs all tests.
9
+ #
10
+ # $Id: fts3.test,v 1.2 2008/07/23 18:17:32 drh Exp $
11
+
12
+ set testdir [file dirname $argv0]
13
+ source $testdir/tester.tcl
14
+ set testprefix fts3varint
15
+
16
+ ifcapable !fts3 {
17
+ finish_test
18
+ return
19
+ }
20
+
21
+ proc test_list {list} {
22
+ foreach n $list { fts3_test_varint $n }
23
+ }
24
+
25
+ proc do_fts3_varint_test {tn list} {
26
+ uplevel [list do_test $tn [list test_list $list] {}]
27
+ }
28
+
29
+ do_fts3_varint_test 1.0 {
30
+ 1 10 100 1000 10000 100000 1000000
31
+ 10000000 100000000 1000000000 10000000000
32
+ 100000000000 1000000000000 10000000000000
33
+ }
34
+
35
+ do_fts3_varint_test 1.1 {
36
+ -1 -10 -100 -1000 -10000 -100000 -1000000
37
+ -10000000 -100000000 -1000000000 -10000000000
38
+ -100000000000 -1000000000000 -10000000000000
39
+ }
40
+
41
+ do_fts3_varint_test 2.0 { 0 1 2 }
42
+ do_fts3_varint_test 2.1 { 1 2 3 }
43
+ do_fts3_varint_test 2.2 { 3 4 5 }
44
+ do_fts3_varint_test 2.3 { 7 8 9 }
45
+ do_fts3_varint_test 2.4 { 15 16 17 }
46
+ do_fts3_varint_test 2.5 { 31 32 33 }
47
+ do_fts3_varint_test 2.6 { 63 64 65 }
48
+ do_fts3_varint_test 2.7 { 127 128 129 }
49
+ do_fts3_varint_test 2.8 { 255 256 257 }
50
+ do_fts3_varint_test 2.9 { 511 512 513 }
51
+ do_fts3_varint_test 2.10 { 1023 1024 1025 }
52
+ do_fts3_varint_test 2.11 { 2047 2048 2049 }
53
+ do_fts3_varint_test 2.12 { 4095 4096 4097 }
54
+ do_fts3_varint_test 2.13 { 8191 8192 8193 }
55
+ do_fts3_varint_test 2.14 { 16383 16384 16385 }
56
+ do_fts3_varint_test 2.15 { 32767 32768 32769 }
57
+ do_fts3_varint_test 2.16 { 65535 65536 65537 }
58
+ do_fts3_varint_test 2.17 { 131071 131072 131073 }
59
+ do_fts3_varint_test 2.18 { 262143 262144 262145 }
60
+ do_fts3_varint_test 2.19 { 524287 524288 524289 }
61
+ do_fts3_varint_test 2.20 { 1048575 1048576 1048577 }
62
+ do_fts3_varint_test 2.21 { 2097151 2097152 2097153 }
63
+ do_fts3_varint_test 2.22 { 4194303 4194304 4194305 }
64
+ do_fts3_varint_test 2.23 { 8388607 8388608 8388609 }
65
+ do_fts3_varint_test 2.24 { 16777215 16777216 16777217 }
66
+ do_fts3_varint_test 2.25 { 33554431 33554432 33554433 }
67
+ do_fts3_varint_test 2.26 { 67108863 67108864 67108865 }
68
+ do_fts3_varint_test 2.27 { 134217727 134217728 134217729 }
69
+ do_fts3_varint_test 2.28 { 268435455 268435456 268435457 }
70
+ do_fts3_varint_test 2.29 { 536870911 536870912 536870913 }
71
+ do_fts3_varint_test 2.30 { 1073741823 1073741824 1073741825 }
72
+ do_fts3_varint_test 2.31 { 2147483647 2147483648 2147483649 }
73
+ do_fts3_varint_test 2.32 { 4294967295 4294967296 4294967297 }
74
+ do_fts3_varint_test 2.33 { 8589934591 8589934592 8589934593 }
75
+ do_fts3_varint_test 2.34 { 17179869183 17179869184 17179869185 }
76
+ do_fts3_varint_test 2.35 { 34359738367 34359738368 34359738369 }
77
+ do_fts3_varint_test 2.36 { 68719476735 68719476736 68719476737 }
78
+ do_fts3_varint_test 2.37 { 137438953471 137438953472 137438953473 }
79
+ do_fts3_varint_test 2.38 { 274877906943 274877906944 274877906945 }
80
+ do_fts3_varint_test 2.39 { 549755813887 549755813888 549755813889 }
81
+ do_fts3_varint_test 2.40 { 1099511627775 1099511627776 1099511627777 }
82
+ do_fts3_varint_test 2.41 { 2199023255551 2199023255552 2199023255553 }
83
+ do_fts3_varint_test 2.42 { 4398046511103 4398046511104 4398046511105 }
84
+ do_fts3_varint_test 2.43 { 8796093022207 8796093022208 8796093022209 }
85
+ do_fts3_varint_test 2.44 { 17592186044415 17592186044416 17592186044417 }
86
+ do_fts3_varint_test 2.45 { 35184372088831 35184372088832 35184372088833 }
87
+ do_fts3_varint_test 2.46 { 70368744177663 70368744177664 70368744177665 }
88
+ do_fts3_varint_test 2.47 { 140737488355327 140737488355328 140737488355329 }
89
+ do_fts3_varint_test 2.48 { 281474976710655 281474976710656 281474976710657 }
90
+ do_fts3_varint_test 2.49 { 562949953421311 562949953421312 562949953421313 }
91
+ do_fts3_varint_test 2.50 { 1125899906842623 1125899906842624 1125899906842625 }
92
+ do_fts3_varint_test 2.51 { 2251799813685247 2251799813685248 2251799813685249 }
93
+ do_fts3_varint_test 2.52 { 4503599627370495 4503599627370496 4503599627370497 }
94
+ do_fts3_varint_test 2.53 { 9007199254740991 9007199254740992 9007199254740993 }
95
+ do_fts3_varint_test 2.54 {
96
+ 18014398509481983 18014398509481984 18014398509481985 }
97
+ do_fts3_varint_test 2.55 {
98
+ 36028797018963967 36028797018963968 36028797018963969 }
99
+ do_fts3_varint_test 2.56 {
100
+ 72057594037927935 72057594037927936 72057594037927937 }
101
+ do_fts3_varint_test 2.57 {
102
+ 144115188075855871 144115188075855872 144115188075855873 }
103
+ do_fts3_varint_test 2.58 {
104
+ 288230376151711743 288230376151711744 288230376151711745 }
105
+ do_fts3_varint_test 2.59 {
106
+ 576460752303423487 576460752303423488 576460752303423489 }
107
+ do_fts3_varint_test 2.60 {
108
+ 1152921504606846975 1152921504606846976 1152921504606846977 }
109
+ do_fts3_varint_test 2.61 {
110
+ 2305843009213693951 2305843009213693952 2305843009213693953 }
111
+ do_fts3_varint_test 2.62 {
112
+ 4611686018427387903 4611686018427387904 4611686018427387905 }
113
+
114
+ if {![catch {fts3_test_varint 18446744073709551615}]} {
115
+ do_fts3_varint_test 2.63 {
116
+ 9223372036854775807 9223372036854775808 9223372036854775809 }
117
+
118
+ do_fts3_varint_test 3.0 { 18446744073709551615 -18446744073709551615 }
119
+ }
120
+
121
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fts4aa.test ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2010 February 02
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #*************************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this script is testing the FTS4 module.
13
+ #
14
+ #
15
+
16
+ set testdir [file dirname $argv0]
17
+ source $testdir/tester.tcl
18
+
19
+ # If SQLITE_ENABLE_FTS3 is defined, omit this file.
20
+ ifcapable !fts3 {
21
+ finish_test
22
+ return
23
+ }
24
+
25
+ # Create the fts_kjv_genesis procedure which fills and FTS3/4 table with
26
+ # the complete text of the Book of Genesis.
27
+ #
28
+ source $testdir/genesis.tcl
29
+
30
+ # The following is a list of queries to perform against the above
31
+ # FTS3/FTS4 database. We will be trying these queries in various
32
+ # configurations to ensure that they always return the same answers.
33
+ #
34
+ set fts4aa_queries {
35
+ {abraham}
36
+ {the king}
37
+ {"the king"}
38
+ {abraham OR joseph}
39
+ {ab* OR jos*}
40
+ {lived t*}
41
+ {spake hebrew}
42
+ {melchizedek}
43
+ {t* melchizedek}
44
+ {melchizedek t*}
45
+ }
46
+ unset -nocomplain fts4aa_res
47
+
48
+ # Set up the baseline results
49
+ #
50
+ do_test fts4aa-1.0 {
51
+ db eval {
52
+ CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
53
+ }
54
+ fts_kjv_genesis
55
+ foreach q $::fts4aa_queries {
56
+ set r [db eval {SELECT docid FROM t1 WHERE words MATCH $q ORDER BY docid}]
57
+ set ::fts4aa_res($q) $r
58
+ }
59
+ } {}
60
+
61
+ # Legacy test cases
62
+ #
63
+ do_test fts4aa-1.1 {
64
+ db eval {
65
+ SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize
66
+ }
67
+ } {}
68
+ do_test fts4aa-1.2 {
69
+ db eval {
70
+ SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1
71
+ }
72
+ } {}
73
+
74
+ proc mit {blob} {
75
+ set scan(littleEndian) i*
76
+ set scan(bigEndian) I*
77
+ binary scan $blob $scan($::tcl_platform(byteOrder)) r
78
+ return $r
79
+ }
80
+ db func mit mit
81
+
82
+ do_test fts4aa-1.3 {
83
+ db eval {
84
+ SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 WHERE t1 MATCH 'melchizedek';
85
+ }
86
+ } {1014018 {1 1 1 1 1 1533 25 20}}
87
+ do_test fts4aa-1.4 {
88
+ db eval {
89
+ SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
90
+ WHERE t1 MATCH 'spake hebrew'
91
+ ORDER BY docid;
92
+ }
93
+ } {1039014 {2 1 1 40 40 1 6 6 1533 25 42} 1039017 {2 1 1 40 40 1 6 6 1533 25 26}}
94
+ do_test fts4aa-1.5 {
95
+ db eval {
96
+ SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
97
+ WHERE t1 MATCH 'laban overtook jacob'
98
+ ORDER BY docid;
99
+ }
100
+ } {1031025 {3 1 2 54 46 1 3 3 2 181 160 1533 25 24}}
101
+
102
+ do_test fts4aa-1.6 {
103
+ db eval {
104
+ DELETE FROM t1 WHERE docid!=1050026;
105
+ SELECT hex(size) FROM t1_docsize;
106
+ SELECT hex(value) FROM t1_stat;
107
+ }
108
+ } {17 01176F}
109
+
110
+ do_test fts4aa-1.7 {
111
+ db eval {
112
+ SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize
113
+ }
114
+ } {}
115
+ do_test fts4aa-1.8 {
116
+ db eval {
117
+ SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1
118
+ }
119
+ } {}
120
+ ifcapable fts4_deferred {
121
+ do_test fts4aa-1.9 {
122
+ # Note: Token 'in' is being deferred in the following query.
123
+ db eval {
124
+ SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
125
+ WHERE t1 MATCH 'joseph died in egypt'
126
+ ORDER BY docid;
127
+ }
128
+ } {1050026 {4 1 1 1 1 1 1 1 2 1 1 1 1 1 1 23 23}}
129
+ }
130
+
131
+ # Should get the same search results from FTS3
132
+ #
133
+ do_test fts4aa-2.0 {
134
+ db eval {
135
+ DROP TABLE t1;
136
+ CREATE VIRTUAL TABLE t1 USING fts3(words, tokenize porter);
137
+ }
138
+ fts_kjv_genesis
139
+ } {}
140
+ unset -nocomplain ii
141
+ set ii 0
142
+ foreach {q r} [array get fts4aa_res] {
143
+ incr ii
144
+ do_test fts4aa-2.$ii {
145
+ db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
146
+ } $r
147
+ }
148
+
149
+ # Should get the same search results when the page size is very large
150
+ #
151
+ do_test fts4aa-3.0 {
152
+ db close
153
+ forcedelete test.db
154
+ sqlite3 db test.db
155
+ db eval {
156
+ PRAGMA page_size=65536;
157
+ CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
158
+ }
159
+ fts_kjv_genesis
160
+ } {}
161
+ unset -nocomplain ii
162
+ set ii 0
163
+ foreach {q r} [array get fts4aa_res] {
164
+ incr ii
165
+ do_test fts4aa-3.$ii {
166
+ db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
167
+ } $r
168
+ }
169
+
170
+ # Should get the same search results when an authorizer prevents
171
+ # all PRAGMA statements.
172
+ #
173
+ proc no_pragma_auth {code arg1 arg2 arg3 arg4 args} {
174
+ if {$code=="SQLITE_PRAGMA"} {return SQLITE_DENY}
175
+ return SQLITE_OK;
176
+ }
177
+ do_test fts4aa-4.0 {
178
+ db auth ::no_pragma_auth
179
+ db eval {
180
+ DROP TABLE t1;
181
+ CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
182
+ }
183
+ fts_kjv_genesis
184
+ } {}
185
+ unset -nocomplain ii
186
+ set ii 0
187
+ foreach {q r} [array get fts4aa_res] {
188
+ incr ii
189
+ do_test fts4aa-4.$ii {
190
+ db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
191
+ } $r
192
+ }
193
+
194
+ # 2019-11-16 https://bugs.chromium.org/p/chromium/issues/detail?id=1025472
195
+ #
196
+ db close
197
+ sqlite3 db :memory:
198
+ do_execsql_test fts4aa-5.10 {
199
+ CREATE VIRTUAL TABLE t1 USING fts4(a, b, c, d, e,f,g,h,i,j,k,l,m,n,o,p,q,r);
200
+ INSERT INTO t1 VALUES('X Y', '2', '3', '4', '5', '6', '7', '8', '9', '0',
201
+ 'a','b','c','d','e','f','g','h');
202
+ UPDATE t1_docsize SET size=x'88' WHERE docid=1;
203
+ } {}
204
+ do_catchsql_test fts4aa-5.20 {
205
+ SELECT quote(matchinfo(t1, 'l')) FROM t1 WHERE t1 MATCH 'X Y';
206
+ } {1 {database disk image is malformed}}
207
+ do_execsql_test fts4aa-5.30 {
208
+ DROP TABLE t1;
209
+ CREATE VIRTUAL TABLE t1 USING fts4(a,b,c,d);
210
+ INSERT INTO t1 VALUES('one two','three four','five six','seven eight');
211
+ } {}
212
+ do_catchsql_test fts4aa-5.40 {
213
+ UPDATE t1_stat SET value=x'01010101' WHERE id=0;
214
+ SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two';
215
+ } {1 {database disk image is malformed}}
216
+ do_catchsql_test fts4aa-5.50 {
217
+ UPDATE t1_stat SET value=x'010101' WHERE id=0;
218
+ SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two';
219
+ } {1 {database disk image is malformed}}
220
+ do_catchsql_test fts4aa-5.60 {
221
+ UPDATE t1_stat SET value=x'01' WHERE id=0;
222
+ SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two';
223
+ } {1 {database disk image is malformed}}
224
+ do_catchsql_test fts4aa-5.70 {
225
+ UPDATE t1_stat SET value=x'' WHERE id=0;
226
+ SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two';
227
+ } {1 {database disk image is malformed}}
228
+
229
+ # 2019-11-18 https://bugs.chromium.org/p/chromium/issues/detail?id=1025467
230
+ db close
231
+ sqlite3 db :memory:
232
+ if {$tcl_platform(byteOrder)=="littleEndian"} {
233
+ set res {X'0200000000000000000000000E0000000E00000001000000010000000100000001000000'}
234
+ } else {
235
+ set res {X'0000000200000000000000000000000E0000000E00000001000000010000000100000001'}
236
+ }
237
+ do_catchsql_test fts4aa-6.10 {
238
+ CREATE VIRTUAL TABLE f USING fts4();
239
+ INSERT INTO f_segdir VALUES (77,91,0,0,'255 77',x'0001308000004d5c4ddddddd4d4d7b4d4d4d614d8019ff4d05000001204d4d2e4d6e4d4d4d4b4d6c4d004d4d4d4d4d4d3d000000004d5d4d4d645d4d004d4d4d4d4d4d4d4d4d454d6910004d05ffff054d646c4d004d5d4d4d4d4d3d000000004d4d4d4d4d4d4d4d4d4d4d69624d4d4d04004d4d4d4d4d604d4ce1404d554d45');
240
+ INSERT INTO f_segdir VALUES (77,108,0,0,'255 77',x'0001310000fa64004d4d4d3c5d4d654d4d4d614d8000ff4d05000001204d4d2e4d6e4d4d4dff4d4d4d4d4d4d00104d4d4d4d000000004d4d4d0400311d4d4d4d4d4d4d4d4d4d684d6910004d05ffff054d4d6c4d004d4d4d4d4d4d3d000000004d4d4d4d644d4d4d4d4d4d69624d4d4d03ed4d4d4d4d4d604d4ce1404d550080');
241
+ INSERT INTO f_stat VALUES (0,x'80808080100000000064004d4d4d3c4d4d654d4d4d614d8000ff4df6ff1a00204d4d2e4d6e4d4d4d104d4d4d4d4d4d00104d4d4d4d4d4d69574d4d4d000031044d4d4d3e4d4d4c4d05004d6910');
242
+ SELECT quote(matchinfo(f,'pnax')) from f where f match '0 1';
243
+ } {1 {database disk image is malformed}}
244
+
245
+ # 2019-11-18 Detect infinite loop in fts3SelectLeaf()
246
+ db close
247
+ sqlite3 db :memory:
248
+ do_catchsql_test fts4aa-7.10 {
249
+ CREATE VIRTUAL TABLE f USING fts4();
250
+ INSERT INTO f_segdir VALUES (63,60,60,60,'60 60',x'3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c483c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c20003c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c283c3c3c3c3c3c3c3c3c3c3c223c3c3c3c3c3c3c3c3c');
251
+ INSERT INTO f_segments VALUES (60,x'3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c5a3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2a3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c5e3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c803c3c3c3c3c3c233c3c3c3c1c3c3c3c3c3c3c3c3c3c3c3c1b3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c273c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1a3c3c3c3c3c3c000200003c3c3c3c3c3c3c3c3c3c3c3c3c383c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d898d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d3c3c3c3c3c3c3c3c3c3cba3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c00023c3c3c3c3c3c383c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cbc3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2c3c3c3c403c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c16161616161616163c3c3c3c3c3c3c3c3c3c3c3c3c583c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2b3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1c013c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c20003c3c3c3c3c3c3c3c3c3c3c800000003c3c3c3c3c3c3c2c3c3c3c3c3c3c353c08080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808f4080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808083c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c323c3c3c3c3c3c3c3c3c3c3c4f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cfcfcfcfcfcfcfcfcfcfcfc10fcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfd02fcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfc03e8fcfcfcfc3c3c3c3c3c3c8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c553c3c3c3c3c3c3c3c3c3c3c3c3c573c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c000000803c3c4dd5d5a6d52cf3d5d5d5d5d5d5d5d5d5d5d5d5d5d53c3c3c3c3f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c013c3c3c3c00643c3c3c3ce93c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c263c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c363c3c3c3c3c3c3c3c3c3c3c3c3c3c543c3c3c3c3c3c3c3c3c3c273c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c330000003c3c3c3c3c3c3c3c3c3c3c3c3c3c4d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c000010003c3c3c3c3c3c413c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c403c3c3c3c3c3c3c3c3c3c3c3cec0000fa3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c4c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c5e3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1b3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c593c3c3c3c3c3c243c3c373c3c3c3c3cff3c3c3c3c3c3c3c3c3c3c3c3c3c000080003c3c3c3c3c3c3c3c3c3c353c3c3c3c3c3d3c3c3c3c3c3c3c3c3c3c3c3c4d3c3c3c3c3c3c3c3c3c3c3c3c3c40003c3c3c3c3c293c3c3c3c3c3c3c3c3c3d3c3c3c3c3c3c3c3c353c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c4f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cff7f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3ca43c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cbf3c3c3c3c3c3c3c3c3c008000003c3c3c3c3c3c3c3c343c3c373c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c593c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c');
252
+ SELECT * from f where f match '0';
253
+ } {1 {database disk image is malformed}}
254
+
255
+
256
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fts4growth.test ADDED
@@ -0,0 +1,441 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2014 May 12
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #*************************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this script is testing the FTS4 module.
13
+ #
14
+ #
15
+
16
+ set testdir [file dirname $argv0]
17
+ source $testdir/tester.tcl
18
+ set testprefix fts4growth
19
+
20
+ # If SQLITE_ENABLE_FTS3 is defined, omit this file.
21
+ ifcapable !fts3 {
22
+ finish_test
23
+ return
24
+ }
25
+
26
+ source $testdir/genesis.tcl
27
+
28
+ sqlite3_db_config db DEFENSIVE 0
29
+ do_execsql_test 1.1 { CREATE VIRTUAL TABLE x1 USING fts3; }
30
+
31
+ do_test 1.2 {
32
+ foreach L {
33
+ {"See here, young man," said Mulga Bill, "from Walgett to the sea,}
34
+ {From Conroy's Gap to Castlereagh, there's none can ride like me.}
35
+ {I'm good all round at everything as everybody knows,}
36
+ {Although I'm not the one to talk -- I hate a man that blows.}
37
+ } {
38
+ execsql { INSERT INTO x1 VALUES($L) }
39
+ }
40
+ execsql { SELECT end_block, length(root) FROM x1_segdir }
41
+ } {{0 114} 114 {0 118} 118 {0 95} 95 {0 115} 115}
42
+
43
+ do_execsql_test 1.3 {
44
+ INSERT INTO x1(x1) VALUES('optimize');
45
+ SELECT level, end_block, length(root) FROM x1_segdir;
46
+ } {0 {0 394} 394}
47
+
48
+ do_test 1.4 {
49
+ foreach L {
50
+ {But riding is my special gift, my chiefest, sole delight;}
51
+ {Just ask a wild duck can it swim, a wildcat can it fight.}
52
+ {There's nothing clothed in hair or hide, or built of flesh or steel,}
53
+ {There's nothing walks or jumps, or runs, on axle, hoof, or wheel,}
54
+ {But what I'll sit, while hide will hold and girths and straps are tight:}
55
+ {I'll ride this here two-wheeled concern right straight away at sight."}
56
+ } {
57
+ execsql { INSERT INTO x1 VALUES($L) }
58
+ }
59
+ execsql {
60
+ INSERT INTO x1(x1) VALUES('merge=4,4');
61
+ SELECT level, end_block, length(root) FROM x1_segdir;
62
+ }
63
+ } {1 {224 921} 2}
64
+
65
+ do_execsql_test 1.5 {
66
+ SELECT length(block) FROM x1_segments;
67
+ } {921 {}}
68
+
69
+ do_test 1.6 {
70
+ foreach L {
71
+ {'Twas Mulga Bill, from Eaglehawk, that sought his own abode,}
72
+ {That perched above Dead Man's Creek, beside the mountain road.}
73
+ {He turned the cycle down the hill and mounted for the fray,}
74
+ {But 'ere he'd gone a dozen yards it bolted clean away.}
75
+
76
+ {It left the track, and through the trees, just like a silver steak,}
77
+ {It whistled down the awful slope towards the Dead Man's Creek.}
78
+ {It shaved a stump by half an inch, it dodged a big white-box:}
79
+ {The very wallaroos in fright went scrambling up the rocks,}
80
+
81
+ {The wombats hiding in their caves dug deeper underground,}
82
+ {As Mulga Bill, as white as chalk, sat tight to every bound.}
83
+ {It struck a stone and gave a spring that cleared a fallen tree,}
84
+ {It raced beside a precipice as close as close could be;}
85
+
86
+ {And then as Mulga Bill let out one last despairing shriek}
87
+ {It made a leap of twenty feet into the Dead Man's Creek.}
88
+ {It shaved a stump by half an inch, it dodged a big white-box:}
89
+ {The very wallaroos in fright went scrambling up the rocks,}
90
+ {The wombats hiding in their caves dug deeper underground,}
91
+ } {
92
+ execsql { INSERT INTO x1 VALUES($L) }
93
+ }
94
+ execsql {
95
+ SELECT level, end_block, length(root) FROM x1_segdir;
96
+ }
97
+ } {1 {224 921} 2 1 {226 1230} 7 0 {0 98} 98}
98
+
99
+ do_execsql_test 1.7 {
100
+ SELECT sum(length(block)) FROM x1_segments WHERE blockid IN (224,225,226)
101
+ } {1230}
102
+
103
+ #-------------------------------------------------------------------------
104
+ #
105
+ do_execsql_test 2.1 {
106
+ CREATE TABLE t1(docid, words);
107
+ CREATE VIRTUAL TABLE x2 USING fts4;
108
+ }
109
+ fts_kjv_genesis
110
+ do_test 2.2 {
111
+ foreach id [db eval {SELECT docid FROM t1}] {
112
+ execsql {
113
+ INSERT INTO x2(docid, content) SELECT $id, words FROM t1 WHERE docid=$id
114
+ }
115
+ }
116
+ foreach id [db eval {SELECT docid FROM t1}] {
117
+ execsql {
118
+ INSERT INTO x2(docid, content) SELECT NULL, words FROM t1 WHERE docid=$id
119
+ }
120
+ if {[db one {SELECT count(*) FROM x2_segdir WHERE level<2}]==2} break
121
+ }
122
+ } {}
123
+
124
+ do_execsql_test 2.3 {
125
+ SELECT count(*) FROM x2_segdir WHERE level=2;
126
+ SELECT count(*) FROM x2_segdir WHERE level=3;
127
+ } {6 0}
128
+
129
+ do_execsql_test 2.4 {
130
+ INSERT INTO x2(x2) VALUES('merge=4,4');
131
+ SELECT count(*) FROM x2_segdir WHERE level=2;
132
+ SELECT count(*) FROM x2_segdir WHERE level=3;
133
+ } {6 1}
134
+
135
+ do_execsql_test 2.5 {
136
+ SELECT end_block FROM x2_segdir WHERE level=3;
137
+ INSERT INTO x2(x2) VALUES('merge=4,4');
138
+ SELECT end_block FROM x2_segdir WHERE level=3;
139
+ INSERT INTO x2(x2) VALUES('merge=4,4');
140
+ SELECT end_block FROM x2_segdir WHERE level=3;
141
+ } {{5588 -3950} {5588 -11766} {5588 -15541}}
142
+
143
+ do_execsql_test 2.6 {
144
+ SELECT sum(length(block)) FROM x2_segdir, x2_segments WHERE
145
+ blockid BETWEEN start_block AND leaves_end_block
146
+ AND level=3
147
+ } {15541}
148
+
149
+ do_execsql_test 2.7 {
150
+ INSERT INTO x2(x2) VALUES('merge=1000,4');
151
+ SELECT end_block FROM x2_segdir WHERE level=3;
152
+ } {{5588 127563}}
153
+
154
+ do_execsql_test 2.8 {
155
+ SELECT sum(length(block)) FROM x2_segdir, x2_segments WHERE
156
+ blockid BETWEEN start_block AND leaves_end_block
157
+ AND level=3
158
+ } {127563}
159
+
160
+ #--------------------------------------------------------------------------
161
+ # Test that delete markers are removed from FTS segments when possible.
162
+ # It is only possible to remove delete markers when the output of the
163
+ # merge operation will become the oldest segment in the index.
164
+ #
165
+ # 3.1 - when the oldest segment is created by an 'optimize'.
166
+ # 3.2 - when the oldest segment is created by an incremental merge.
167
+ # 3.3 - by a crisis merge.
168
+ #
169
+
170
+ proc insert_doc {args} {
171
+ foreach iDoc $args {
172
+ set L [lindex {
173
+ {In your eagerness to engage the Trojans,}
174
+ {don’t any of you charge ahead of others,}
175
+ {trusting in your strength and horsemanship.}
176
+ {And don’t lag behind. That will hurt our charge.}
177
+ {Any man whose chariot confronts an enemy’s}
178
+ {should thrust with his spear at him from there.}
179
+ {That’s the most effective tactic, the way}
180
+ {men wiped out city strongholds long ago —}
181
+ {their chests full of that style and spirit.}
182
+ } [expr $iDoc%9]]
183
+ execsql { REPLACE INTO x3(docid, content) VALUES($iDoc, $L) }
184
+ }
185
+ }
186
+
187
+ proc delete_doc {args} {
188
+ foreach iDoc $args {
189
+ execsql { DELETE FROM x3 WHERE docid = $iDoc }
190
+ }
191
+ }
192
+
193
+ proc second {x} { lindex $x 1 }
194
+ db func second second
195
+
196
+ do_execsql_test 3.0 { CREATE VIRTUAL TABLE x3 USING fts4 }
197
+
198
+ do_test 3.1.1 {
199
+ db transaction { insert_doc 1 2 3 4 5 6 }
200
+ execsql { SELECT level, idx, second(end_block) FROM x3_segdir }
201
+ } {0 0 412}
202
+ do_test 3.1.2 {
203
+ delete_doc 1 2 3 4 5 6
204
+ execsql { SELECT count(*) FROM x3_segdir }
205
+ } {0}
206
+ do_test 3.1.3 {
207
+ db transaction {
208
+ insert_doc 1 2 3 4 5 6 7 8 9
209
+ delete_doc 9 8 7
210
+ }
211
+ execsql { SELECT level, idx, second(end_block) FROM x3_segdir }
212
+ } {0 0 591 0 1 65 0 2 72 0 3 76}
213
+ do_test 3.1.4 {
214
+ execsql { INSERT INTO x3(x3) VALUES('optimize') }
215
+ execsql { SELECT level, idx, second(end_block) FROM x3_segdir }
216
+ } {0 0 412}
217
+
218
+ do_test 3.2.1 {
219
+ execsql { DELETE FROM x3 }
220
+ insert_doc 8 7 6 5 4 3 2 1
221
+ delete_doc 7 8
222
+ execsql { SELECT count(*) FROM x3_segdir }
223
+ } {10}
224
+ do_test 3.2.2 {
225
+ execsql { INSERT INTO x3(x3) VALUES('merge=500,10') }
226
+ execsql { SELECT level, idx, second(end_block) FROM x3_segdir }
227
+ } {1 0 412}
228
+
229
+ # This assumes the crisis merge happens when there are already 16
230
+ # segments and one more is added.
231
+ #
232
+ do_test 3.3.1 {
233
+ execsql { DELETE FROM x3 }
234
+ insert_doc 1 2 3 4 5 6 7 8 9 10 11
235
+ delete_doc 11 10 9 8 7
236
+ execsql { SELECT count(*) FROM x3_segdir }
237
+ } {16}
238
+
239
+ do_test 3.3.2 {
240
+ insert_doc 12
241
+ execsql { SELECT level, idx, second(end_block) FROM x3_segdir WHERE level=1 }
242
+ } {1 0 412}
243
+
244
+ #--------------------------------------------------------------------------
245
+ # Check a theory on a bug in fts4 - that segments with idx==0 were not
246
+ # being incrementally merged correctly. Theory turned out to be false.
247
+ #
248
+ do_execsql_test 4.1 {
249
+ DROP TABLE IF EXISTS x4;
250
+ DROP TABLE IF EXISTS t1;
251
+ CREATE TABLE t1(docid, words);
252
+ CREATE VIRTUAL TABLE x4 USING fts4(words);
253
+ }
254
+ do_test 4.2 {
255
+ fts_kjv_genesis
256
+ execsql { INSERT INTO x4 SELECT words FROM t1 }
257
+ execsql { INSERT INTO x4 SELECT words FROM t1 }
258
+ } {}
259
+
260
+ do_execsql_test 4.3 {
261
+ SELECT level, idx, second(end_block) FROM x4_segdir
262
+ } {0 0 117483 0 1 118006}
263
+
264
+ do_execsql_test 4.4 {
265
+ INSERT INTO x4(x4) VALUES('merge=10,2');
266
+ SELECT count(*) FROM x4_segdir;
267
+ } {3}
268
+
269
+ do_execsql_test 4.5 {
270
+ INSERT INTO x4(x4) VALUES('merge=10,2');
271
+ SELECT count(*) FROM x4_segdir;
272
+ } {3}
273
+
274
+ do_execsql_test 4.6 {
275
+ INSERT INTO x4(x4) VALUES('merge=1000,2');
276
+ SELECT count(*) FROM x4_segdir;
277
+ } {1}
278
+
279
+
280
+
281
+ #--------------------------------------------------------------------------
282
+ # Check that segments are not promoted if the "end_block" field does not
283
+ # contain a size.
284
+ #
285
+ do_execsql_test 5.1 {
286
+ DROP TABLE IF EXISTS x2;
287
+ DROP TABLE IF EXISTS t1;
288
+ CREATE TABLE t1(docid, words);
289
+ CREATE VIRTUAL TABLE x2 USING fts4;
290
+ }
291
+ fts_kjv_genesis
292
+
293
+ proc first {L} {lindex $L 0}
294
+ db func first first
295
+
296
+ do_test 5.2 {
297
+ foreach r [db eval { SELECT rowid FROM t1 }] {
298
+ execsql {
299
+ INSERT INTO x2(docid, content) SELECT docid, words FROM t1 WHERE rowid=$r
300
+ }
301
+ }
302
+ foreach d [db eval { SELECT docid FROM t1 LIMIT -1 OFFSET 20 }] {
303
+ execsql { DELETE FROM x2 WHERE docid = $d }
304
+ }
305
+
306
+ execsql {
307
+ INSERT INTO x2(x2) VALUES('optimize');
308
+ SELECT level, idx, end_block FROM x2_segdir
309
+ }
310
+ } {2 0 {752 1926}}
311
+
312
+ do_execsql_test 5.3 {
313
+ UPDATE x2_segdir SET end_block = CAST( first(end_block) AS INTEGER );
314
+ SELECT end_block, typeof(end_block) FROM x2_segdir;
315
+ } {752 integer}
316
+
317
+ do_execsql_test 5.4 {
318
+ INSERT INTO x2 SELECT words FROM t1 LIMIT 50;
319
+ SELECT level, idx, end_block FROM x2_segdir
320
+ } {2 0 752 0 0 {758 5174}}
321
+
322
+ do_execsql_test 5.5 {
323
+ UPDATE x2_segdir SET end_block = end_block || ' 1926' WHERE level=2;
324
+ INSERT INTO x2 SELECT words FROM t1 LIMIT 40;
325
+ SELECT level, idx, end_block FROM x2_segdir
326
+ } {0 0 {752 1926} 0 1 {758 5174} 0 2 {763 4170}}
327
+
328
+ proc t1_to_x2 {} {
329
+ foreach id [db eval {SELECT docid FROM t1 LIMIT 2}] {
330
+ execsql {
331
+ DELETE FROM x2 WHERE docid=$id;
332
+ INSERT INTO x2(docid, content) SELECT $id, words FROM t1 WHERE docid=$id;
333
+ }
334
+ }
335
+ }
336
+
337
+ #--------------------------------------------------------------------------
338
+ # Check that segments created by auto-merge are not promoted until they
339
+ # are completed.
340
+ #
341
+
342
+ do_execsql_test 6.1 {
343
+ CREATE VIRTUAL TABLE x5 USING fts4;
344
+ INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 0;
345
+ INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 25;
346
+ INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 50;
347
+ INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 75;
348
+ SELECT count(*) FROM x5_segdir
349
+ } {4}
350
+
351
+ do_execsql_test 6.2 {
352
+ INSERT INTO x5(x5) VALUES('merge=2,4');
353
+ SELECT level, idx, end_block FROM x5_segdir;
354
+ } {0 0 {10 9216} 0 1 {21 9330} 0 2 {31 8850} 0 3 {40 8689} 1 0 {1320 -3117}}
355
+
356
+ do_execsql_test 6.3 {
357
+ INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 100;
358
+ SELECT level, idx, end_block FROM x5_segdir;
359
+ } {
360
+ 0 0 {10 9216} 0 1 {21 9330} 0 2 {31 8850}
361
+ 0 3 {40 8689} 1 0 {1320 -3117} 0 4 {1329 8297}
362
+ }
363
+
364
+ do_execsql_test 6.4 {
365
+ INSERT INTO x5(x5) VALUES('merge=200,4');
366
+ SELECT level, idx, end_block FROM x5_segdir;
367
+ } {0 0 {1329 8297} 1 0 {1320 28009}}
368
+
369
+ do_execsql_test 6.5 {
370
+ INSERT INTO x5 SELECT words FROM t1;
371
+ SELECT level, idx, end_block FROM x5_segdir;
372
+ } {
373
+ 0 1 {1329 8297} 0 0 {1320 28009} 0 2 {1449 118006}
374
+ }
375
+
376
+ #--------------------------------------------------------------------------
377
+ # Ensure that if part of an incremental merge is performed by an old
378
+ # version that does not support storing segment sizes in the end_block
379
+ # field, no size is stored in the final segment (as it would be incorrect).
380
+ #
381
+ do_execsql_test 7.1 {
382
+ CREATE VIRTUAL TABLE x6 USING fts4;
383
+ INSERT INTO x6 SELECT words FROM t1;
384
+ INSERT INTO x6 SELECT words FROM t1;
385
+ INSERT INTO x6 SELECT words FROM t1;
386
+ INSERT INTO x6 SELECT words FROM t1;
387
+ INSERT INTO x6 SELECT words FROM t1;
388
+ INSERT INTO x6 SELECT words FROM t1;
389
+ SELECT level, idx, end_block FROM x6_segdir;
390
+ } {
391
+ 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006}
392
+ 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006}
393
+ }
394
+
395
+ do_execsql_test 7.2 {
396
+ INSERT INTO x6(x6) VALUES('merge=25,4');
397
+ SELECT level, idx, end_block FROM x6_segdir;
398
+ } {
399
+ 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006}
400
+ 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006}
401
+ 1 0 {23694 -69477}
402
+ }
403
+
404
+ do_execsql_test 7.3 {
405
+ UPDATE x6_segdir SET end_block = first(end_block) WHERE level=1;
406
+ SELECT level, idx, end_block FROM x6_segdir;
407
+ } {
408
+ 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006}
409
+ 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006}
410
+ 1 0 23694
411
+ }
412
+
413
+ do_execsql_test 7.4 {
414
+ INSERT INTO x6(x6) VALUES('merge=25,4');
415
+ SELECT level, idx, end_block FROM x6_segdir;
416
+ } {
417
+ 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006}
418
+ 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006}
419
+ 1 0 23694
420
+ }
421
+
422
+ do_execsql_test 7.5 {
423
+ INSERT INTO x6(x6) VALUES('merge=2500,4');
424
+ SELECT level, idx, start_block, leaves_end_block, end_block FROM x6_segdir;
425
+ } {
426
+ 1 0 719 1171 23694
427
+ }
428
+
429
+ do_execsql_test 7.6 {
430
+ INSERT INTO x6(x6) VALUES('merge=2500,2');
431
+ SELECT level, idx, start_block, leaves_end_block, end_block FROM x6_segdir;
432
+ } {
433
+ 1 0 719 1171 23694
434
+ }
435
+
436
+ do_execsql_test 7.7 {
437
+ SELECT sum(length(block)) FROM x6_segments
438
+ } {635247}
439
+
440
+
441
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fts4merge5.test ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2019 October 02
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #*************************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this script is testing the FTS4 module.
13
+ #
14
+
15
+ set testdir [file dirname $argv0]
16
+ source $testdir/tester.tcl
17
+ set testprefix fts4merge5
18
+
19
+ # If SQLITE_ENABLE_FTS3 is defined, omit this file.
20
+ ifcapable !fts3 {
21
+ finish_test
22
+ return
23
+ }
24
+
25
+ source $testdir/genesis.tcl
26
+
27
+ do_execsql_test 1.1 {
28
+ CREATE TABLE t1(docid, words);
29
+ }
30
+ fts_kjv_genesis
31
+
32
+ do_execsql_test 1.2 {
33
+ CREATE VIRTUAL TABLE x1 USING fts3;
34
+ INSERT INTO x1(x1) VALUES('nodesize=64');
35
+ INSERT INTO x1(x1) VALUES('maxpending=64');
36
+ }
37
+
38
+ do_execsql_test 1.3 {
39
+ INSERT INTO x1(docid, content) SELECT * FROM t1;
40
+ }
41
+
42
+ for {set tn 1} {1} {incr tn} {
43
+ set tc1 [db total_changes]
44
+ do_execsql_test 1.4.$tn.1 {
45
+ INSERT INTO x1(x1) VALUES('merge=1,2');
46
+ }
47
+ set tc2 [db total_changes]
48
+
49
+ if {($tc2 - $tc1)<2} break
50
+
51
+ do_execsql_test 1.4.$tn.1 {
52
+ INSERT INTO x1(x1) VALUES('integrity-check');
53
+ }
54
+ }
55
+
56
+
57
+
58
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/fuzzer2.test ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2016 February 4
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # The focus of the tests is the word-fuzzer virtual table. The tests
12
+ # in this file are slower than those in fuzzer1.test. So this file does
13
+ # not run as part of veryquick.test etc.
14
+ #
15
+
16
+ set testdir [file dirname $argv0]
17
+ source $testdir/tester.tcl
18
+
19
+ ifcapable !vtab {
20
+ finish_test
21
+ return
22
+ }
23
+
24
+ set ::testprefix fuzzer2
25
+ load_static_extension db fuzzer
26
+
27
+ #-------------------------------------------------------------------------
28
+ # This test uses a fuzzer table with many rules. There is one rule to
29
+ # map each possible two character string, where characters are lower-case
30
+ # letters used in the English language, to all other possible two character
31
+ # strings. In total, (26^4)-(26^2) mappings (the subtracted term represents
32
+ # the no-op mappings discarded automatically by the fuzzer).
33
+ #
34
+ #
35
+ do_execsql_test 1.1.1 {
36
+ DROP TABLE IF EXISTS x1;
37
+ DROP TABLE IF EXISTS x1_rules;
38
+ CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost);
39
+ }
40
+ puts "This test is slow - perhaps around 7 seconds on an average pc"
41
+ do_test 1.1.2 {
42
+ set LETTERS {a b c d e f g h i j k l m n o p q r s t u v w x y z}
43
+ set cost 1
44
+ db transaction {
45
+ foreach c1 $LETTERS {
46
+ foreach c2 $LETTERS {
47
+ foreach c3 $LETTERS {
48
+ foreach c4 $LETTERS {
49
+ db eval {INSERT INTO x1_rules VALUES(0, $c1||$c2, $c3||$c4, $cost)}
50
+ set cost [expr ($cost%1000) + 1]
51
+ }
52
+ }
53
+ }
54
+ }
55
+ db eval {UPDATE x1_rules SET cost = 20 WHERE cost<20 AND cFrom!='xx'}
56
+ }
57
+ } {}
58
+
59
+ do_execsql_test 1.2 {
60
+ SELECT count(*) FROM x1_rules WHERE cTo!=cFrom;
61
+ } [expr 26*26*26*26 - 26*26]
62
+
63
+ do_execsql_test 1.2.1 {
64
+ CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules);
65
+ SELECT word FROM x1 WHERE word MATCH 'xx' LIMIT 10;
66
+ } {xx hw hx hy hz ia ib ic id ie}
67
+ do_execsql_test 1.2.2 {
68
+ SELECT cTo FROM x1_rules WHERE cFrom='xx'
69
+ ORDER BY cost asc, rowid asc LIMIT 9;
70
+ } {hw hx hy hz ia ib ic id ie}
71
+
72
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/incrvacuum.test ADDED
@@ -0,0 +1,892 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2007 April 26
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this file is testing the incremental vacuum feature.
13
+ #
14
+ # Note: There are also some tests for incremental vacuum and IO
15
+ # errors in incrvacuum_ioerr.test.
16
+ #
17
+ # $Id: incrvacuum.test,v 1.23 2009/02/18 20:31:18 drh Exp $
18
+
19
+ set testdir [file dirname $argv0]
20
+ source $testdir/tester.tcl
21
+
22
+ # If this build of the library does not support auto-vacuum, omit this
23
+ # whole file.
24
+ ifcapable {!autovacuum || !pragma} {
25
+ finish_test
26
+ return
27
+ }
28
+
29
+ #---------------------------------------------------------------------
30
+ # Test the pragma on an empty database.
31
+ #
32
+ do_test incrvacuum-1.1 {
33
+ execsql {
34
+ pragma auto_vacuum;
35
+ }
36
+ } $sqlite_options(default_autovacuum)
37
+ do_test incrvacuum-1.2.0 {
38
+ # File size is sometimes 1 instead of 0 due to the hack we put in
39
+ # to work around ticket #3260. Search for comments on #3260 in
40
+ # os_unix.c.
41
+ expr {[file size test.db] > 1}
42
+ } {0}
43
+ do_test incrvacuum-1.2 {
44
+ # This command will create the database.
45
+ execsql {
46
+ pragma auto_vacuum = 'full';
47
+ pragma auto_vacuum;
48
+ }
49
+ } {1}
50
+ do_test incrvacuum-1.2.1 {
51
+ expr {[file size test.db] > 0}
52
+ } {1}
53
+ do_test incrvacuum-1.3 {
54
+ execsql {
55
+ pragma auto_vacuum = 'incremental';
56
+ pragma auto_vacuum;
57
+ }
58
+ } {2}
59
+ do_test incrvacuum-1.4 {
60
+ # In this case the invalid value is ignored and the auto_vacuum
61
+ # setting remains unchanged.
62
+ execsql {
63
+ pragma auto_vacuum = 'invalid';
64
+ pragma auto_vacuum;
65
+ }
66
+ } {2}
67
+ do_test incrvacuum-1.5 {
68
+ execsql {
69
+ pragma auto_vacuum = 1;
70
+ pragma auto_vacuum;
71
+ }
72
+ } {1}
73
+ do_test incrvacuum-1.6 {
74
+ execsql {
75
+ pragma auto_vacuum = '2';
76
+ pragma auto_vacuum;
77
+ }
78
+ } {2}
79
+ do_test incrvacuum-1.7 {
80
+ # Invalid value. auto_vacuum setting remains unchanged.
81
+ execsql {
82
+ pragma auto_vacuum = 5;
83
+ pragma auto_vacuum;
84
+ }
85
+ } {2}
86
+
87
+ #---------------------------------------------------------------------
88
+ # Test the pragma on a non-empty database. It is possible to toggle
89
+ # the connection between "full" and "incremental" mode, but not to
90
+ # change from either of these to "none", or from "none" to "full" or
91
+ # "incremental".
92
+ #
93
+ do_test incrvacuum-2.1 {
94
+ execsql {
95
+ pragma auto_vacuum = 1;
96
+ CREATE TABLE abc(a, b, c);
97
+ }
98
+ } {}
99
+ do_test incrvacuum-2.2 {
100
+ execsql {
101
+ pragma auto_vacuum = 'none';
102
+ pragma auto_vacuum;
103
+ }
104
+ } {1}
105
+ do_test incrvacuum-2.2.1 {
106
+ db close
107
+ sqlite3 db test.db
108
+ execsql {
109
+ pragma auto_vacuum;
110
+ }
111
+ } {1}
112
+ do_test incrvacuum-2.3 {
113
+ execsql {
114
+ pragma auto_vacuum = 'incremental';
115
+ pragma auto_vacuum;
116
+ }
117
+ } {2}
118
+ do_test incrvacuum-2.4 {
119
+ execsql {
120
+ pragma auto_vacuum = 'full';
121
+ pragma auto_vacuum;
122
+ }
123
+ } {1}
124
+
125
+ #---------------------------------------------------------------------
126
+ # Test that when the auto_vacuum mode is "incremental", the database
127
+ # does not shrink when pages are removed from it. But it does if
128
+ # the mode is set to "full".
129
+ #
130
+ do_test incrvacuum-3.1 {
131
+ execsql {
132
+ pragma auto_vacuum;
133
+ }
134
+ } {1}
135
+ do_test incrvacuum-3.2 {
136
+ set ::str [string repeat 1234567890 110]
137
+ execsql {
138
+ PRAGMA auto_vacuum = 2;
139
+ BEGIN;
140
+ CREATE TABLE tbl2(str);
141
+ INSERT INTO tbl2 VALUES($::str);
142
+ COMMIT;
143
+ }
144
+ # 5 pages:
145
+ #
146
+ # 1 -> database header
147
+ # 2 -> first back-pointer page
148
+ # 3 -> table abc
149
+ # 4 -> table tbl2
150
+ # 5 -> table tbl2 overflow page.
151
+ #
152
+ expr {[file size test.db] / 1024}
153
+ } {5}
154
+ do_test incrvacuum-3.3 {
155
+ execsql {
156
+ DROP TABLE abc;
157
+ DELETE FROM tbl2;
158
+ }
159
+ expr {[file size test.db] / 1024}
160
+ } {5}
161
+ do_test incrvacuum-3.4 {
162
+ execsql {
163
+ PRAGMA auto_vacuum = 1;
164
+ INSERT INTO tbl2 VALUES('hello world');
165
+ }
166
+ expr {[file size test.db] / 1024}
167
+ } {3}
168
+
169
+ #---------------------------------------------------------------------
170
+ # Try to run a very simple incremental vacuum. Also verify that
171
+ # PRAGMA incremental_vacuum is a harmless no-op against a database that
172
+ # does not support auto-vacuum.
173
+ #
174
+ do_test incrvacuum-4.1 {
175
+ set ::str [string repeat 1234567890 110]
176
+ execsql {
177
+ PRAGMA auto_vacuum = 2;
178
+ INSERT INTO tbl2 VALUES($::str);
179
+ CREATE TABLE tbl1(a, b, c);
180
+ }
181
+ expr {[file size test.db] / 1024}
182
+ } {5}
183
+ do_test incrvacuum-4.2 {
184
+ execsql {
185
+ DELETE FROM tbl2;
186
+ DROP TABLE tbl1;
187
+ }
188
+ expr {[file size test.db] / 1024}
189
+ } {5}
190
+ do_test incrvacuum-4.3 {
191
+ set ::nStep 0
192
+ db eval {pragma incremental_vacuum(10)} {
193
+ incr ::nStep
194
+ }
195
+ list [expr {[file size test.db] / 1024}] $::nStep
196
+ } {3 2}
197
+
198
+ #---------------------------------------------------------------------
199
+ # The following tests - incrvacuum-5.* - test incremental vacuum
200
+ # from within a transaction.
201
+ #
202
+ do_test incrvacuum-5.1.1 {
203
+ expr {[file size test.db] / 1024}
204
+ } {3}
205
+ do_test incrvacuum-5.1.2 {
206
+ execsql {
207
+ BEGIN;
208
+ DROP TABLE tbl2;
209
+ PRAGMA incremental_vacuum;
210
+ COMMIT;
211
+ }
212
+ expr {[file size test.db] / 1024}
213
+ } {1}
214
+
215
+ do_test incrvacuum-5.2.1 {
216
+ set ::str [string repeat abcdefghij 110]
217
+ execsql {
218
+ BEGIN;
219
+ CREATE TABLE tbl1(a);
220
+ INSERT INTO tbl1 VALUES($::str);
221
+ PRAGMA incremental_vacuum; -- this is a no-op.
222
+ COMMIT;
223
+ }
224
+ expr {[file size test.db] / 1024}
225
+ } {4}
226
+ do_test incrvacuum-5.2.2 {
227
+ set ::str [string repeat abcdefghij 110]
228
+ execsql {
229
+ BEGIN;
230
+ INSERT INTO tbl1 VALUES($::str);
231
+ INSERT INTO tbl1 SELECT * FROM tbl1;
232
+ DELETE FROM tbl1 WHERE oid%2; -- Put 2 overflow pages on free-list.
233
+ COMMIT;
234
+ }
235
+ expr {[file size test.db] / 1024}
236
+ } {7}
237
+ do_test incrvacuum-5.2.3 {
238
+ execsql {
239
+ BEGIN;
240
+ PRAGMA incremental_vacuum; -- Vacuum up the two pages.
241
+ CREATE TABLE tbl2(b); -- Use one free page as a table root.
242
+ INSERT INTO tbl2 VALUES('a nice string');
243
+ COMMIT;
244
+ }
245
+ expr {[file size test.db] / 1024}
246
+ } {6}
247
+ do_test incrvacuum-5.2.4 {
248
+ execsql {
249
+ SELECT * FROM tbl2;
250
+ }
251
+ } {{a nice string}}
252
+ do_test incrvacuum-5.2.5 {
253
+ execsql {
254
+ DROP TABLE tbl1;
255
+ DROP TABLE tbl2;
256
+ PRAGMA incremental_vacuum;
257
+ }
258
+ expr {[file size test.db] / 1024}
259
+ } {1}
260
+
261
+
262
+ # Test cases incrvacuum-5.3.* use the following list as input data.
263
+ # Two new databases are opened, one with incremental vacuum enabled,
264
+ # the other with no auto-vacuum completely disabled. After executing
265
+ # each element of the following list on both databases, test that
266
+ # the integrity-check passes and the contents of each are identical.
267
+ #
268
+ set TestScriptList [list {
269
+ BEGIN;
270
+ CREATE TABLE t1(a, b);
271
+ CREATE TABLE t2(a, b);
272
+ CREATE INDEX t1_i ON t1(a);
273
+ CREATE INDEX t2_i ON t2(a);
274
+ } {
275
+ INSERT INTO t1 VALUES($::str1, $::str2);
276
+ INSERT INTO t1 VALUES($::str1||$::str2, $::str2||$::str1);
277
+ INSERT INTO t2 SELECT b, a FROM t1;
278
+ INSERT INTO t2 SELECT a, b FROM t1;
279
+ INSERT INTO t1 SELECT b, a FROM t2;
280
+ UPDATE t2 SET b = '';
281
+ PRAGMA incremental_vacuum;
282
+ } {
283
+ UPDATE t2 SET b = (SELECT b FROM t1 WHERE t1.oid = t2.oid);
284
+ PRAGMA incremental_vacuum;
285
+ } {
286
+ CREATE TABLE t3(a, b);
287
+ INSERT INTO t3 SELECT * FROM t2;
288
+ DROP TABLE t2;
289
+ PRAGMA incremental_vacuum;
290
+ } {
291
+ CREATE INDEX t3_i ON t3(a);
292
+ COMMIT;
293
+ } {
294
+ BEGIN;
295
+ DROP INDEX t3_i;
296
+ PRAGMA incremental_vacuum;
297
+ INSERT INTO t3 VALUES('hello', 'world');
298
+ ROLLBACK;
299
+ } {
300
+ INSERT INTO t3 VALUES('hello', 'world');
301
+ }
302
+ ]
303
+
304
+ # If this build omits subqueries, step 2 in the above list will not
305
+ # work. Replace it with "" in this case.
306
+ #
307
+ ifcapable !subquery { lset TestScriptList 2 "" }
308
+
309
+ # Compare the contents of databases $A and $B.
310
+ #
311
+ proc compare_dbs {A B tname} {
312
+ set tbl_list [execsql {
313
+ SELECT tbl_name FROM sqlite_master WHERE type = 'table'
314
+ } $A]
315
+
316
+ do_test ${tname}.1 [subst {
317
+ execsql {
318
+ SELECT tbl_name FROM sqlite_master WHERE type = 'table'
319
+ } $B
320
+ }] $tbl_list
321
+
322
+ set tn 1
323
+ foreach tbl $tbl_list {
324
+ set control [execsql "SELECT * FROM $tbl" $A]
325
+ do_test ${tname}.[incr tn] [subst {
326
+ execsql "SELECT * FROM $tbl" $B
327
+ }] $control
328
+ }
329
+ }
330
+
331
+ set ::str1 [string repeat abcdefghij 130]
332
+ set ::str2 [string repeat 1234567890 105]
333
+
334
+ forcedelete test1.db test1.db-journal test2.db test2.db-journal
335
+ sqlite3 db1 test1.db
336
+ sqlite3 db2 test2.db
337
+ execsql { PRAGMA auto_vacuum = 'none' } db1
338
+ execsql { PRAGMA auto_vacuum = 'incremental' } db2
339
+
340
+ set tn 1
341
+ foreach sql $::TestScriptList {
342
+ execsql $sql db1
343
+ execsql $sql db2
344
+
345
+ compare_dbs db1 db2 incrvacuum-5.3.${tn}
346
+ do_test incrvacuum-5.3.${tn}.integrity1 {
347
+ execsql { PRAGMA integrity_check; } db1
348
+ } {ok}
349
+ do_test incrvacuum-5.3.${tn}.integrity2 {
350
+ execsql { PRAGMA integrity_check; } db2
351
+ } {ok}
352
+ incr tn
353
+ }
354
+ db1 close
355
+ db2 close
356
+ #
357
+ # End of test cases 5.3.*
358
+
359
+ #---------------------------------------------------------------------
360
+ # The following tests - incrvacuum-6.* - test running incremental
361
+ # vacuum while another statement (a read) is being executed.
362
+ #
363
+ for {set jj 0} {$jj < 10} {incr jj} {
364
+ # Build some test data. Two tables are created in an empty
365
+ # database. tbl1 data is a contiguous block starting at page 5 (pages
366
+ # 3 and 4 are the table roots). tbl2 is a contiguous block starting
367
+ # right after tbl1.
368
+ #
369
+ # Then drop tbl1 so that when an incr vacuum is run the pages
370
+ # of tbl2 have to be moved to fill the gap.
371
+ #
372
+ do_test incrvacuum-6.${jj}.1 {
373
+ execsql {
374
+ DROP TABLE IF EXISTS tbl1;
375
+ DROP TABLE IF EXISTS tbl2;
376
+ PRAGMA incremental_vacuum;
377
+ CREATE TABLE tbl1(a, b);
378
+ CREATE TABLE tbl2(a, b);
379
+ BEGIN;
380
+ }
381
+ for {set ii 0} {$ii < 1000} {incr ii} {
382
+ db eval {INSERT INTO tbl1 VALUES($ii, $ii || $ii)}
383
+ }
384
+ execsql {
385
+ INSERT INTO tbl2 SELECT * FROM tbl1;
386
+ COMMIT;
387
+ DROP TABLE tbl1;
388
+ }
389
+ expr {[file size test.db] / 1024}
390
+ } {36}
391
+
392
+ # Run a linear scan query on tbl2. After reading ($jj*100) rows,
393
+ # run the incremental vacuum to shrink the database.
394
+ #
395
+ do_test incrvacuum-6.${jj}.2 {
396
+ set ::nRow 0
397
+ db eval {SELECT a FROM tbl2} {} {
398
+ if {$a == [expr $jj*100]} {
399
+ db eval {PRAGMA incremental_vacuum}
400
+ }
401
+ incr ::nRow
402
+ }
403
+ list [expr {[file size test.db] / 1024}] $nRow
404
+ } {19 1000}
405
+ }
406
+
407
+ #---------------------------------------------------------------------
408
+ # This test - incrvacuum-7.* - is to check that the database can be
409
+ # written in the middle of an incremental vacuum.
410
+ #
411
+ set ::iWrite 1
412
+ while 1 {
413
+ do_test incrvacuum-7.${::iWrite}.1 {
414
+ execsql {
415
+ DROP TABLE IF EXISTS tbl1;
416
+ DROP TABLE IF EXISTS tbl2;
417
+ PRAGMA incremental_vacuum;
418
+ CREATE TABLE tbl1(a, b);
419
+ CREATE TABLE tbl2(a, b);
420
+ BEGIN;
421
+ }
422
+ for {set ii 0} {$ii < 1000} {incr ii} {
423
+ db eval {INSERT INTO tbl1 VALUES($ii, $ii || $ii)}
424
+ }
425
+ execsql {
426
+ INSERT INTO tbl2 SELECT * FROM tbl1;
427
+ COMMIT;
428
+ DROP TABLE tbl1;
429
+ }
430
+ expr {[file size test.db] / 1024}
431
+ } {36}
432
+
433
+ do_test incrvacuum-7.${::iWrite}.2 {
434
+ set ::nRow 0
435
+ db eval {PRAGMA incremental_vacuum} {
436
+ incr ::nRow
437
+ if {$::nRow == $::iWrite} {
438
+ db eval {
439
+ CREATE TABLE tbl1(a, b);
440
+ INSERT INTO tbl1 VALUES('hello', 'world');
441
+ }
442
+ }
443
+ }
444
+ list [expr {[file size test.db] / 1024}]
445
+ } {20}
446
+
447
+ do_test incrvacuum-7.${::iWrite}.3 {
448
+ execsql {
449
+ SELECT * FROM tbl1;
450
+ }
451
+ } {hello world}
452
+
453
+ if {$::nRow == $::iWrite} break
454
+ incr ::iWrite
455
+ }
456
+
457
+ #---------------------------------------------------------------------
458
+ # This test - incrvacuum-8.* - is to check that nothing goes wrong
459
+ # with an incremental-vacuum if it is the first statement executed
460
+ # after an existing database is opened.
461
+ #
462
+ # At one point, this would always return SQLITE_SCHEMA (which
463
+ # causes an infinite loop in tclsqlite.c if using the Tcl interface).
464
+ #
465
+ do_test incrvacuum-8.1 {
466
+ db close
467
+ sqlite3 db test.db
468
+ execsql {
469
+ PRAGMA incremental_vacuum(50);
470
+ }
471
+ } {}
472
+
473
+ #---------------------------------------------------------------------
474
+ # At one point this test case was causing an assert() to fail.
475
+ #
476
+ do_test incrvacuum-9.1 {
477
+ db close
478
+ forcedelete test.db test.db-journal
479
+ sqlite3 db test.db
480
+
481
+ execsql {
482
+ PRAGMA auto_vacuum = 'incremental';
483
+ CREATE TABLE t1(a, b, c);
484
+ CREATE TABLE t2(a, b, c);
485
+ INSERT INTO t2 VALUES(randstr(500,500),randstr(500,500),randstr(500,500));
486
+ INSERT INTO t1 VALUES(1, 2, 3);
487
+ INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;
488
+ INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;
489
+ INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;
490
+ INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;
491
+ INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;
492
+ INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;
493
+ INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;
494
+ INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;
495
+ }
496
+ } {}
497
+
498
+ do_test incrvacuum-9.2 {
499
+ execsql {
500
+ PRAGMA synchronous = 'OFF';
501
+ BEGIN;
502
+ UPDATE t1 SET a = a, b = b, c = c;
503
+ DROP TABLE t2;
504
+ PRAGMA incremental_vacuum(10);
505
+ ROLLBACK;
506
+ }
507
+ } {}
508
+
509
+ do_test incrvacuum-9.3 {
510
+ execsql {
511
+ PRAGMA cache_size = 10;
512
+ BEGIN;
513
+ UPDATE t1 SET a = a, b = b, c = c;
514
+ DROP TABLE t2;
515
+ PRAGMA incremental_vacuum(10);
516
+ ROLLBACK;
517
+ }
518
+ } {}
519
+
520
+ #---------------------------------------------------------------------
521
+ # Test that the parameter to the incremental_vacuum pragma works. That
522
+ # is, if the user executes "PRAGMA incremental_vacuum(N)", at most
523
+ # N pages are vacuumed.
524
+ #
525
+ do_test incrvacuum-10.1 {
526
+ execsql {
527
+ DROP TABLE t1;
528
+ DROP TABLE t2;
529
+ }
530
+ expr [file size test.db] / 1024
531
+ } {29}
532
+
533
+ do_test incrvacuum-10.2 {
534
+ execsql {
535
+ PRAGMA incremental_vacuum(1);
536
+ }
537
+ expr [file size test.db] / 1024
538
+ } {28}
539
+
540
+ do_test incrvacuum-10.3 {
541
+ execsql {
542
+ PRAGMA incremental_vacuum(5);
543
+ }
544
+ expr [file size test.db] / 1024
545
+ } {23}
546
+
547
+ do_test incrvacuum-10.4 {
548
+ execsql {
549
+ PRAGMA incremental_vacuum('1');
550
+ }
551
+ expr [file size test.db] / 1024
552
+ } {22}
553
+
554
+ do_test incrvacuum-10.5 {
555
+ execsql {
556
+ PRAGMA incremental_vacuum("+3");
557
+ }
558
+ expr [file size test.db] / 1024
559
+ } {19}
560
+
561
+ do_test incrvacuum-10.6 {
562
+ execsql {
563
+ PRAGMA incremental_vacuum = 1;
564
+ }
565
+ expr [file size test.db] / 1024
566
+ } {18}
567
+
568
+ do_test incrvacuum-10.7 {
569
+ # Use a really big number as an argument to incremetal_vacuum. Should
570
+ # be interpreted as "free all possible space".
571
+ execsql {
572
+ PRAGMA incremental_vacuum(2147483649);
573
+ }
574
+ expr [file size test.db] / 1024
575
+ } {1}
576
+
577
+ do_test incrvacuum-10.8 {
578
+ execsql {
579
+ CREATE TABLE t1(x);
580
+ INSERT INTO t1 VALUES(hex(randomblob(1000)));
581
+ DROP TABLE t1;
582
+ }
583
+ # A negative number means free all possible space.
584
+ execsql {
585
+ PRAGMA incremental_vacuum=-1;
586
+ }
587
+ expr [file size test.db] / 1024
588
+ } {1}
589
+
590
+ #----------------------------------------------------------------
591
+ # Test that if we set the auto_vacuum mode to 'incremental', then
592
+ # create a database, thereafter that database defaults to incremental
593
+ # vacuum mode.
594
+ #
595
+ db close
596
+ forcedelete test.db test.db-journal
597
+ sqlite3 db test.db
598
+
599
+ ifcapable default_autovacuum {
600
+ do_test incrvacuum-11.1-av-dflt-on {
601
+ execsql {
602
+ PRAGMA auto_vacuum;
603
+ }
604
+ } $AUTOVACUUM
605
+ } else {
606
+ do_test incrvacuum-11.1-av-dflt-off {
607
+ execsql {
608
+ PRAGMA auto_vacuum;
609
+ }
610
+ } {0}
611
+ }
612
+ do_test incrvacuum-11.2 {
613
+ execsql {
614
+ PRAGMA auto_vacuum = incremental;
615
+ }
616
+ } {}
617
+ do_test incrvacuum-11.3 {
618
+ execsql {
619
+ PRAGMA auto_vacuum;
620
+ }
621
+ } {2}
622
+ do_test incrvacuum-11.4 {
623
+ # The database has now been created.
624
+ expr {[file size test.db]>0}
625
+ } {1}
626
+ do_test incrvacuum-11.5 {
627
+ # Close and reopen the connection.
628
+ db close
629
+ sqlite3 db test.db
630
+
631
+ # Test we are still in incremental vacuum mode.
632
+ execsql { PRAGMA auto_vacuum; }
633
+ } {2}
634
+ do_test incrvacuum-11.6 {
635
+ execsql {
636
+ PRAGMA auto_vacuum = 'full';
637
+ PRAGMA auto_vacuum;
638
+ }
639
+ } {1}
640
+ do_test incrvacuum-11.7 {
641
+ # Close and reopen the connection.
642
+ db close
643
+ sqlite3 db test.db
644
+
645
+ # Test we are still in "full" auto-vacuum mode.
646
+ execsql { PRAGMA auto_vacuum; }
647
+ } {1}
648
+
649
+ #----------------------------------------------------------------------
650
+ # Special case: What happens if the database is locked when a "PRAGMA
651
+ # auto_vacuum = XXX" statement is executed.
652
+ #
653
+ db close
654
+ forcedelete test.db test.db-journal
655
+ sqlite3 db test.db
656
+
657
+ do_test incrvacuum-12.1 {
658
+ execsql {
659
+ PRAGMA auto_vacuum = 1;
660
+ }
661
+ expr {[file size test.db]>0}
662
+ } {1}
663
+
664
+ # Try to change the auto-vacuum from "full" to "incremental" while the
665
+ # database is locked. Nothing should change.
666
+ #
667
+ do_test incrvacuum-12.2 {
668
+ sqlite3 db2 test.db
669
+ execsql { BEGIN EXCLUSIVE; } db2
670
+ catchsql { PRAGMA auto_vacuum = 2; }
671
+ } {1 {database is locked}}
672
+
673
+ do_test incrvacuum-12.3 {
674
+ execsql { ROLLBACK; } db2
675
+ execsql { PRAGMA auto_vacuum }
676
+ } {2} ;# Still 2 because PRAGMA auto_vacuum setting held in case of vacuum
677
+ do_test incrvacuum-12.4 {
678
+ db close
679
+ sqlite3 db test.db
680
+ execsql { PRAGMA auto_vacuum }
681
+ } {1} ;# Revert to 1 because the database file did not change
682
+
683
+ do_test incrvacuum-12.5 {
684
+ execsql { SELECT * FROM sqlite_master }
685
+ execsql { PRAGMA auto_vacuum }
686
+ } {1}
687
+
688
+ #----------------------------------------------------------------------
689
+ # Special case #2: What if one process prepares a "PRAGMA auto_vacuum = XXX"
690
+ # statement when the database is empty, but doesn't execute it until
691
+ # after some other process has created the database.
692
+ #
693
+ db2 close
694
+ db close
695
+ forcedelete test.db test.db-journal
696
+ sqlite3 db test.db ; set ::DB [sqlite3_connection_pointer db]
697
+ sqlite3 db2 test.db
698
+
699
+ do_test incrvacuum-13.1 {
700
+ # File size is sometimes 1 instead of 0 due to the hack we put in
701
+ # to work around ticket #3260. Search for comments on #3260 in
702
+ # os_unix.c.
703
+ expr {[file size test.db]>1}
704
+ } {0}
705
+ do_test incrvacuum-13.2 {
706
+ set ::STMT [sqlite3_prepare $::DB {PRAGMA auto_vacuum = 2} -1 DUMMY]
707
+ execsql {
708
+ PRAGMA auto_vacuum = none;
709
+ PRAGMA default_cache_size = 1024;
710
+ PRAGMA auto_vacuum;
711
+ } db2
712
+ } {0}
713
+ do_test incrvacuum-13.3 {
714
+ expr {[file size test.db]>0}
715
+ } {1}
716
+ do_test incrvacuum-13.4 {
717
+ set rc [sqlite3_step $::STMT]
718
+ list $rc [sqlite3_finalize $::STMT]
719
+ } {SQLITE_DONE SQLITE_OK}
720
+ do_test incrvacuum-13.5 {
721
+ execsql {
722
+ PRAGMA auto_vacuum;
723
+ }
724
+ } {0}
725
+
726
+
727
+ # Verify that the incremental_vacuum pragma fails gracefully if it
728
+ # is used against an invalid database file.
729
+ #
730
+ if {[permutation] == ""} {
731
+ do_test incrvacuum-14.1 {
732
+ set out [open invalid.db w]
733
+ puts $out "This is not an SQLite database file"
734
+ close $out
735
+ sqlite3 db3 invalid.db
736
+ catchsql {
737
+ PRAGMA incremental_vacuum(10);
738
+ } db3
739
+ } {1 {file is not a database}}
740
+ db3 close
741
+ }
742
+
743
+ do_test incrvacuum-15.1 {
744
+ db close
745
+ db2 close
746
+ forcedelete test.db
747
+ sqlite3 db test.db
748
+
749
+ set str [string repeat "abcdefghij" 500]
750
+
751
+ execsql {
752
+ PRAGMA cache_size = 10;
753
+ PRAGMA auto_vacuum = incremental;
754
+ CREATE TABLE t1(x, y);
755
+ INSERT INTO t1 VALUES('a', $str);
756
+ INSERT INTO t1 VALUES('b', $str);
757
+ INSERT INTO t1 VALUES('c', $str);
758
+ INSERT INTO t1 VALUES('d', $str);
759
+ INSERT INTO t1 VALUES('e', $str);
760
+ INSERT INTO t1 VALUES('f', $str);
761
+ INSERT INTO t1 VALUES('g', $str);
762
+ INSERT INTO t1 VALUES('h', $str);
763
+ INSERT INTO t1 VALUES('i', $str);
764
+ INSERT INTO t1 VALUES('j', $str);
765
+ INSERT INTO t1 VALUES('j', $str);
766
+
767
+ CREATE TABLE t2(x PRIMARY KEY, y);
768
+ INSERT INTO t2 VALUES('a', $str);
769
+ INSERT INTO t2 VALUES('b', $str);
770
+ INSERT INTO t2 VALUES('c', $str);
771
+ INSERT INTO t2 VALUES('d', $str);
772
+
773
+ BEGIN;
774
+ DELETE FROM t2;
775
+ PRAGMA incremental_vacuum;
776
+ }
777
+
778
+ catchsql {INSERT INTO t2 SELECT * FROM t1}
779
+
780
+ execsql {
781
+ COMMIT;
782
+ PRAGMA integrity_check;
783
+ }
784
+ } {ok}
785
+
786
+ #-------------------------------------------------------------------------
787
+ # At one point it was unsafe to truncate a db file on windows while there
788
+ # were outstanding xFetch() references. This test case attempts to hit
789
+ # that case.
790
+ #
791
+ ifcapable mmap {
792
+ reset_db
793
+ do_execsql_test incrvacuum-16.0 {
794
+ PRAGMA auto_vacuum = 2;
795
+ CREATE TABLE t3(a);
796
+ INSERT INTO t3 VALUES(1), (2), (3), (4);
797
+
798
+ CREATE TABLE t2(x);
799
+ INSERT INTO t2 VALUES( randomblob(1000) );
800
+ INSERT INTO t2 VALUES( randomblob(1000) );
801
+ INSERT INTO t2 VALUES( randomblob(1000) );
802
+ INSERT INTO t2 VALUES( randomblob(1000) );
803
+ INSERT INTO t2 VALUES( randomblob(1000) );
804
+ INSERT INTO t2 VALUES( randomblob(1000) );
805
+ } {}
806
+
807
+ # Reopen db to ensure the page-cache is empty.
808
+ #
809
+ db close
810
+ sqlite3 db test.db
811
+
812
+ # Open db in mmap-mode. Open a transaction, delete some data, then run
813
+ # incremental-vacuum. Do not commit the transaction.
814
+ #
815
+ do_execsql_test incrvacuum-16.1 {
816
+ PRAGMA mmap_size = 1000000;
817
+ BEGIN;
818
+ DELETE FROM t2;
819
+ PRAGMA incremental_vacuum = 1000;
820
+ } {1000000}
821
+
822
+ # Scan through table t3 (which is all clean pages - so mmap is used). Then,
823
+ # midway through, commit the transaction. This causes the db to be truncated
824
+ # while there are outstanding xFetch pages.
825
+ #
826
+ do_test incrvacuum-16.2 {
827
+ set res [list]
828
+ db eval { SELECT a FROM t3 } {
829
+ if {$a==3} { db eval COMMIT }
830
+ lappend res $a
831
+ }
832
+ set res
833
+ } {1 2 3 4}
834
+ }
835
+
836
+ # 2021-04-05 dbsqlfuzz cced0668cfd4da4eb2382cb9dd26c17c64aaff76
837
+ #
838
+ # This is an incremental vacuum database that has one free page that
839
+ # needs to be filled. After removing the last page from the end of
840
+ # the database file to fill the free page slot, the last page that
841
+ # is left is the tail of an overflow chain.
842
+ #
843
+ # But the size of the database file is shorter than the actual data
844
+ # so that after incremental vacuum runs, the file is actually too
845
+ # small to hold the last page of the overflow chain.
846
+ #
847
+ # At one point this caused an assertion fault in
848
+ # sqlite3PagerTruncateImage().
849
+ #
850
+ do_test incrvacuum-17.0 {
851
+ sqlite3 db {}
852
+ database_may_be_corrupt
853
+ db deserialize [decode_hexdb {
854
+ | size 20480 pagesize 4096 filename x2.db
855
+ | page 1 offset 0
856
+ | 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
857
+ | 16: 10 00 01 01 00 40 20 20 00 00 00 05 00 00 00 07 .....@ ........
858
+ | 32: 00 00 00 04 00 00 00 01 00 00 00 03 00 00 00 04 ................
859
+ | 48: 00 00 00 00 00 00 00 03 00 00 00 01 00 00 00 00 ................
860
+ | 64: 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 ................
861
+ | 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 ................
862
+ | 96: 00 2e 53 60 0d 0f dc 00 01 0f b8 00 0f b8 0f b8 ..S`............
863
+ | 4016: 00 00 00 00 00 00 00 00 22 02 06 17 11 11 01 31 ...............1
864
+ | 4032: 74 61 62 6c 65 74 32 74 32 03 43 52 45 41 54 45 tablet2t2.CREATE
865
+ | 4048: 20 54 41 42 4c 45 20 74 32 28 79 29 00 00 00 24 TABLE t2(y)...$
866
+ | 4064: 11 11 01 31 74 61 62 6c 65 74 31 74 31 03 43 52 ...1tablet1t1.CR
867
+ | 4080: 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 78 29 EATE TABLE t1(x)
868
+ | page 2 offset 4096
869
+ | 0: 01 00 00 00 00 02 00 00 00 00 03 00 00 00 03 04 ................
870
+ | 16: 00 00 00 05 03 00 00 00 03 00 00 00 00 00 00 00 ................
871
+ | page 3 offset 8192
872
+ | 0: 0d 00 00 00 02 05 47 00 08 dd 05 47 00 00 00 00 ......G....G....
873
+ | 1344: 00 00 00 00 00 00 00 a7 0b 02 03 ce 1c 00 00 00 ................
874
+ | 2256: 00 00 00 00 00 00 00 00 00 00 00 00 07 ce 14 01 ................
875
+ | 2272: 04 81 9c 2c 00 00 00 00 00 00 00 00 00 00 00 00 ...,............
876
+ | 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 ................
877
+ | page 4 offset 12288
878
+ | 0: 00 00 00 00 00 00 00 00 08 dd 05 47 00 00 00 00 ...........G....
879
+ | 1344: 00 00 00 00 00 00 00 a7 0b 02 03 ce 1c 00 00 00 ................
880
+ | 2256: 00 00 00 00 00 00 00 00 00 00 00 00 07 ce 14 01 ................
881
+ | 2272: 04 81 9c 2c 00 00 00 00 00 00 00 00 00 00 00 00 ...,............
882
+ | 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 ................
883
+ | page 5 offset 16384
884
+ | 0: 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 00 ................
885
+ | end x2.db
886
+ }]} {}
887
+ do_catchsql_test incrvacuum-17.1 {
888
+ PRAGMA writable_schema=ON;
889
+ PRAGMA incremental_vacuum(10);
890
+ } {0 {}}
891
+
892
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/join3.test ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2002 May 24
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library.
12
+ #
13
+ # This file implements tests for joins, including outer joins, where
14
+ # there are a large number of tables involved in the join.
15
+ #
16
+ # $Id: join3.test,v 1.4 2005/01/19 23:24:51 drh Exp $
17
+
18
+ set testdir [file dirname $argv0]
19
+ source $testdir/tester.tcl
20
+
21
+ # An unrestricted join
22
+ #
23
+ catch {unset ::result}
24
+ set result {}
25
+ for {set N 1} {$N<=$bitmask_size} {incr N} {
26
+ lappend result $N
27
+ do_test join3-1.$N {
28
+ execsql "CREATE TABLE t${N}(x);"
29
+ execsql "INSERT INTO t$N VALUES($N)"
30
+ set sql "SELECT * FROM t1"
31
+ for {set i 2} {$i<=$N} {incr i} {append sql ", t$i"}
32
+ execsql $sql
33
+ } $result
34
+ }
35
+
36
+ # Joins with a comparison
37
+ #
38
+ set result {}
39
+ for {set N 1} {$N<=$bitmask_size} {incr N} {
40
+ lappend result $N
41
+ do_test join3-2.$N {
42
+ set sql "SELECT * FROM t1"
43
+ for {set i 2} {$i<=$N} {incr i} {append sql ", t$i"}
44
+ set sep WHERE
45
+ for {set i 1} {$i<$N} {incr i} {
46
+ append sql " $sep t[expr {$i+1}].x==t$i.x+1"
47
+ set sep AND
48
+ }
49
+ execsql $sql
50
+ } $result
51
+ }
52
+
53
+ # Error of too many tables in the join
54
+ #
55
+ do_test join3-3.1 {
56
+ set sql "SELECT * FROM t1 AS t0, t1"
57
+ for {set i 2} {$i<=$bitmask_size} {incr i} {append sql ", t$i"}
58
+ catchsql $sql
59
+ } [list 1 "at most $bitmask_size tables in a join"]
60
+
61
+
62
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/joinD.test ADDED
The diff for this file is too large to render. See raw diff
 
local-test-sqlite3-delta-03/afc-sqlite3/test/joinF.test ADDED
@@ -0,0 +1,613 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2022-05-31
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # This file implements tests for JOINs
13
+ #
14
+ # The test case output is (mostly) all generated by PostgreSQL 14. This
15
+ # test module was created as follows:
16
+ #
17
+ # 1. Run a TCL script (included at the bottom of this file) that
18
+ # generates an input script for "psql" that will run man
19
+ # diverse tests on joins.
20
+ #
21
+ # 2. Run the script from step (1) through psql and collect the
22
+ # output.
23
+ #
24
+ # 3. Make a few minor global search-and-replace operations to convert
25
+ # the psql output into a form suitable for this test module.
26
+ #
27
+ # 4. Add this header, and the script content at the footer.
28
+ #
29
+ # A few extra tests that were not generated from postgresql output are
30
+ # added at the end.
31
+ #
32
+ set testdir [file dirname $argv0]
33
+ source $testdir/tester.tcl
34
+ db nullvalue -
35
+ db eval {
36
+ CREATE TABLE t1(x INT);
37
+ CREATE TABLE t2(y INT);
38
+ CREATE TABLE t3(z INT);
39
+ CREATE TABLE t4(w INT);
40
+ INSERT INTO t1 VALUES(10);
41
+ INSERT INTO t3 VALUES(20),(30);
42
+ INSERT INTO t4 VALUES(50);
43
+ }
44
+ do_execsql_test joinF-1 {
45
+ SELECT *
46
+ FROM t1 INNER JOIN t2 ON true
47
+ INNER JOIN t3 ON t2.y IS NOT NULL
48
+ INNER JOIN t4 ON true
49
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
50
+ } {
51
+ }
52
+ do_execsql_test joinF-2 {
53
+ SELECT *
54
+ FROM t1 INNER JOIN t2 ON true
55
+ INNER JOIN t3 ON t2.y IS NOT NULL
56
+ INNER JOIN t4 ON true
57
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
58
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
59
+ } {
60
+ }
61
+ do_execsql_test joinF-3 {
62
+ SELECT *
63
+ FROM t1 INNER JOIN t2 ON true
64
+ INNER JOIN t3 ON t2.y IS NOT NULL
65
+ LEFT JOIN t4 ON true
66
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
67
+ } {
68
+ }
69
+ do_execsql_test joinF-4 {
70
+ SELECT *
71
+ FROM t1 INNER JOIN t2 ON true
72
+ INNER JOIN t3 ON t2.y IS NOT NULL
73
+ LEFT JOIN t4 ON true
74
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
75
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
76
+ } {
77
+ }
78
+ do_execsql_test joinF-5 {
79
+ SELECT *
80
+ FROM t1 INNER JOIN t2 ON true
81
+ INNER JOIN t3 ON t2.y IS NOT NULL
82
+ RIGHT JOIN t4 ON true
83
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
84
+ } {
85
+ - - - 50
86
+ }
87
+ do_execsql_test joinF-6 {
88
+ SELECT *
89
+ FROM t1 INNER JOIN t2 ON true
90
+ INNER JOIN t3 ON t2.y IS NOT NULL
91
+ RIGHT JOIN t4 ON true
92
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
93
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
94
+ } {
95
+ }
96
+ do_execsql_test joinF-7 {
97
+ SELECT *
98
+ FROM t1 INNER JOIN t2 ON true
99
+ LEFT JOIN t3 ON t2.y IS NOT NULL
100
+ INNER JOIN t4 ON true
101
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
102
+ } {
103
+ }
104
+ do_execsql_test joinF-8 {
105
+ SELECT *
106
+ FROM t1 INNER JOIN t2 ON true
107
+ LEFT JOIN t3 ON t2.y IS NOT NULL
108
+ INNER JOIN t4 ON true
109
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
110
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
111
+ } {
112
+ }
113
+ do_execsql_test joinF-9 {
114
+ SELECT *
115
+ FROM t1 INNER JOIN t2 ON true
116
+ LEFT JOIN t3 ON t2.y IS NOT NULL
117
+ LEFT JOIN t4 ON true
118
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
119
+ } {
120
+ }
121
+ do_execsql_test joinF-10 {
122
+ SELECT *
123
+ FROM t1 INNER JOIN t2 ON true
124
+ LEFT JOIN t3 ON t2.y IS NOT NULL
125
+ LEFT JOIN t4 ON true
126
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
127
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
128
+ } {
129
+ }
130
+ do_execsql_test joinF-11 {
131
+ SELECT *
132
+ FROM t1 INNER JOIN t2 ON true
133
+ LEFT JOIN t3 ON t2.y IS NOT NULL
134
+ RIGHT JOIN t4 ON true
135
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
136
+ } {
137
+ - - - 50
138
+ }
139
+ do_execsql_test joinF-12 {
140
+ SELECT *
141
+ FROM t1 INNER JOIN t2 ON true
142
+ LEFT JOIN t3 ON t2.y IS NOT NULL
143
+ RIGHT JOIN t4 ON true
144
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
145
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
146
+ } {
147
+ }
148
+ do_execsql_test joinF-13 {
149
+ SELECT *
150
+ FROM t1 INNER JOIN t2 ON true
151
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
152
+ INNER JOIN t4 ON true
153
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
154
+ } {
155
+ - - 20 50
156
+ - - 30 50
157
+ }
158
+ do_execsql_test joinF-14 {
159
+ SELECT *
160
+ FROM t1 INNER JOIN t2 ON true
161
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
162
+ INNER JOIN t4 ON true
163
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
164
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
165
+ } {
166
+ - - 20 50
167
+ - - 30 50
168
+ }
169
+ do_execsql_test joinF-15 {
170
+ SELECT *
171
+ FROM t1 INNER JOIN t2 ON true
172
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
173
+ LEFT JOIN t4 ON true
174
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
175
+ } {
176
+ - - 20 50
177
+ - - 30 50
178
+ }
179
+ do_execsql_test joinF-16 {
180
+ SELECT *
181
+ FROM t1 INNER JOIN t2 ON true
182
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
183
+ LEFT JOIN t4 ON true
184
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
185
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
186
+ } {
187
+ - - 20 50
188
+ - - 30 50
189
+ }
190
+ do_execsql_test joinF-17 {
191
+ SELECT *
192
+ FROM t1 INNER JOIN t2 ON true
193
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
194
+ RIGHT JOIN t4 ON true
195
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
196
+ } {
197
+ - - 20 50
198
+ - - 30 50
199
+ }
200
+ do_execsql_test joinF-18 {
201
+ SELECT *
202
+ FROM t1 INNER JOIN t2 ON true
203
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
204
+ RIGHT JOIN t4 ON true
205
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
206
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
207
+ } {
208
+ - - 20 50
209
+ - - 30 50
210
+ }
211
+ do_execsql_test joinF-19 {
212
+ SELECT *
213
+ FROM t1 LEFT JOIN t2 ON true
214
+ INNER JOIN t3 ON t2.y IS NOT NULL
215
+ INNER JOIN t4 ON true
216
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
217
+ } {
218
+ }
219
+ do_execsql_test joinF-20 {
220
+ SELECT *
221
+ FROM t1 LEFT JOIN t2 ON true
222
+ INNER JOIN t3 ON t2.y IS NOT NULL
223
+ INNER JOIN t4 ON true
224
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
225
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
226
+ } {
227
+ }
228
+ do_execsql_test joinF-21 {
229
+ SELECT *
230
+ FROM t1 LEFT JOIN t2 ON true
231
+ INNER JOIN t3 ON t2.y IS NOT NULL
232
+ LEFT JOIN t4 ON true
233
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
234
+ } {
235
+ }
236
+ do_execsql_test joinF-22 {
237
+ SELECT *
238
+ FROM t1 LEFT JOIN t2 ON true
239
+ INNER JOIN t3 ON t2.y IS NOT NULL
240
+ LEFT JOIN t4 ON true
241
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
242
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
243
+ } {
244
+ }
245
+ do_execsql_test joinF-23 {
246
+ SELECT *
247
+ FROM t1 LEFT JOIN t2 ON true
248
+ INNER JOIN t3 ON t2.y IS NOT NULL
249
+ RIGHT JOIN t4 ON true
250
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
251
+ } {
252
+ - - - 50
253
+ }
254
+ do_execsql_test joinF-24 {
255
+ SELECT *
256
+ FROM t1 LEFT JOIN t2 ON true
257
+ INNER JOIN t3 ON t2.y IS NOT NULL
258
+ RIGHT JOIN t4 ON true
259
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
260
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
261
+ } {
262
+ }
263
+ do_execsql_test joinF-25 {
264
+ SELECT *
265
+ FROM t1 LEFT JOIN t2 ON true
266
+ LEFT JOIN t3 ON t2.y IS NOT NULL
267
+ INNER JOIN t4 ON true
268
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
269
+ } {
270
+ 10 - - 50
271
+ }
272
+ do_execsql_test joinF-26 {
273
+ SELECT *
274
+ FROM t1 LEFT JOIN t2 ON true
275
+ LEFT JOIN t3 ON t2.y IS NOT NULL
276
+ INNER JOIN t4 ON true
277
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
278
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
279
+ } {
280
+ }
281
+ do_execsql_test joinF-27 {
282
+ SELECT *
283
+ FROM t1 LEFT JOIN t2 ON true
284
+ LEFT JOIN t3 ON t2.y IS NOT NULL
285
+ LEFT JOIN t4 ON true
286
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
287
+ } {
288
+ 10 - - 50
289
+ }
290
+ do_execsql_test joinF-28 {
291
+ SELECT *
292
+ FROM t1 LEFT JOIN t2 ON true
293
+ LEFT JOIN t3 ON t2.y IS NOT NULL
294
+ LEFT JOIN t4 ON true
295
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
296
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
297
+ } {
298
+ }
299
+ do_execsql_test joinF-29 {
300
+ SELECT *
301
+ FROM t1 LEFT JOIN t2 ON true
302
+ LEFT JOIN t3 ON t2.y IS NOT NULL
303
+ RIGHT JOIN t4 ON true
304
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
305
+ } {
306
+ 10 - - 50
307
+ }
308
+ do_execsql_test joinF-30 {
309
+ SELECT *
310
+ FROM t1 LEFT JOIN t2 ON true
311
+ LEFT JOIN t3 ON t2.y IS NOT NULL
312
+ RIGHT JOIN t4 ON true
313
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
314
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
315
+ } {
316
+ }
317
+ do_execsql_test joinF-31 {
318
+ SELECT *
319
+ FROM t1 LEFT JOIN t2 ON true
320
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
321
+ INNER JOIN t4 ON true
322
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
323
+ } {
324
+ - - 20 50
325
+ - - 30 50
326
+ }
327
+ do_execsql_test joinF-32 {
328
+ SELECT *
329
+ FROM t1 LEFT JOIN t2 ON true
330
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
331
+ INNER JOIN t4 ON true
332
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
333
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
334
+ } {
335
+ - - 20 50
336
+ - - 30 50
337
+ }
338
+ do_execsql_test joinF-33 {
339
+ SELECT *
340
+ FROM t1 LEFT JOIN t2 ON true
341
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
342
+ LEFT JOIN t4 ON true
343
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
344
+ } {
345
+ - - 20 50
346
+ - - 30 50
347
+ }
348
+ do_execsql_test joinF-34 {
349
+ SELECT *
350
+ FROM t1 LEFT JOIN t2 ON true
351
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
352
+ LEFT JOIN t4 ON true
353
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
354
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
355
+ } {
356
+ - - 20 50
357
+ - - 30 50
358
+ }
359
+ do_execsql_test joinF-35 {
360
+ SELECT *
361
+ FROM t1 LEFT JOIN t2 ON true
362
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
363
+ RIGHT JOIN t4 ON true
364
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
365
+ } {
366
+ - - 20 50
367
+ - - 30 50
368
+ }
369
+ do_execsql_test joinF-36 {
370
+ SELECT *
371
+ FROM t1 LEFT JOIN t2 ON true
372
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
373
+ RIGHT JOIN t4 ON true
374
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
375
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
376
+ } {
377
+ - - 20 50
378
+ - - 30 50
379
+ }
380
+ do_execsql_test joinF-37 {
381
+ SELECT *
382
+ FROM t1 RIGHT JOIN t2 ON true
383
+ INNER JOIN t3 ON t2.y IS NOT NULL
384
+ INNER JOIN t4 ON true
385
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
386
+ } {
387
+ }
388
+ do_execsql_test joinF-38 {
389
+ SELECT *
390
+ FROM t1 RIGHT JOIN t2 ON true
391
+ INNER JOIN t3 ON t2.y IS NOT NULL
392
+ INNER JOIN t4 ON true
393
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
394
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
395
+ } {
396
+ }
397
+ do_execsql_test joinF-39 {
398
+ SELECT *
399
+ FROM t1 RIGHT JOIN t2 ON true
400
+ INNER JOIN t3 ON t2.y IS NOT NULL
401
+ LEFT JOIN t4 ON true
402
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
403
+ } {
404
+ }
405
+ do_execsql_test joinF-40 {
406
+ SELECT *
407
+ FROM t1 RIGHT JOIN t2 ON true
408
+ INNER JOIN t3 ON t2.y IS NOT NULL
409
+ LEFT JOIN t4 ON true
410
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
411
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
412
+ } {
413
+ }
414
+ do_execsql_test joinF-41 {
415
+ SELECT *
416
+ FROM t1 RIGHT JOIN t2 ON true
417
+ INNER JOIN t3 ON t2.y IS NOT NULL
418
+ RIGHT JOIN t4 ON true
419
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
420
+ } {
421
+ - - - 50
422
+ }
423
+ do_execsql_test joinF-42 {
424
+ SELECT *
425
+ FROM t1 RIGHT JOIN t2 ON true
426
+ INNER JOIN t3 ON t2.y IS NOT NULL
427
+ RIGHT JOIN t4 ON true
428
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
429
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
430
+ } {
431
+ }
432
+ do_execsql_test joinF-43 {
433
+ SELECT *
434
+ FROM t1 RIGHT JOIN t2 ON true
435
+ LEFT JOIN t3 ON t2.y IS NOT NULL
436
+ INNER JOIN t4 ON true
437
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
438
+ } {
439
+ }
440
+ do_execsql_test joinF-44 {
441
+ SELECT *
442
+ FROM t1 RIGHT JOIN t2 ON true
443
+ LEFT JOIN t3 ON t2.y IS NOT NULL
444
+ INNER JOIN t4 ON true
445
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
446
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
447
+ } {
448
+ }
449
+ do_execsql_test joinF-45 {
450
+ SELECT *
451
+ FROM t1 RIGHT JOIN t2 ON true
452
+ LEFT JOIN t3 ON t2.y IS NOT NULL
453
+ LEFT JOIN t4 ON true
454
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
455
+ } {
456
+ }
457
+ do_execsql_test joinF-46 {
458
+ SELECT *
459
+ FROM t1 RIGHT JOIN t2 ON true
460
+ LEFT JOIN t3 ON t2.y IS NOT NULL
461
+ LEFT JOIN t4 ON true
462
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
463
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
464
+ } {
465
+ }
466
+ do_execsql_test joinF-47 {
467
+ SELECT *
468
+ FROM t1 RIGHT JOIN t2 ON true
469
+ LEFT JOIN t3 ON t2.y IS NOT NULL
470
+ RIGHT JOIN t4 ON true
471
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
472
+ } {
473
+ - - - 50
474
+ }
475
+ do_execsql_test joinF-48 {
476
+ SELECT *
477
+ FROM t1 RIGHT JOIN t2 ON true
478
+ LEFT JOIN t3 ON t2.y IS NOT NULL
479
+ RIGHT JOIN t4 ON true
480
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
481
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
482
+ } {
483
+ }
484
+ do_execsql_test joinF-49 {
485
+ SELECT *
486
+ FROM t1 RIGHT JOIN t2 ON true
487
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
488
+ INNER JOIN t4 ON true
489
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
490
+ } {
491
+ - - 20 50
492
+ - - 30 50
493
+ }
494
+ do_execsql_test joinF-50 {
495
+ SELECT *
496
+ FROM t1 RIGHT JOIN t2 ON true
497
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
498
+ INNER JOIN t4 ON true
499
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
500
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
501
+ } {
502
+ - - 20 50
503
+ - - 30 50
504
+ }
505
+ do_execsql_test joinF-51 {
506
+ SELECT *
507
+ FROM t1 RIGHT JOIN t2 ON true
508
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
509
+ LEFT JOIN t4 ON true
510
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
511
+ } {
512
+ - - 20 50
513
+ - - 30 50
514
+ }
515
+ do_execsql_test joinF-52 {
516
+ SELECT *
517
+ FROM t1 RIGHT JOIN t2 ON true
518
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
519
+ LEFT JOIN t4 ON true
520
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
521
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
522
+ } {
523
+ - - 20 50
524
+ - - 30 50
525
+ }
526
+ do_execsql_test joinF-53 {
527
+ SELECT *
528
+ FROM t1 RIGHT JOIN t2 ON true
529
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
530
+ RIGHT JOIN t4 ON true
531
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
532
+ } {
533
+ - - 20 50
534
+ - - 30 50
535
+ }
536
+ do_execsql_test joinF-54 {
537
+ SELECT *
538
+ FROM t1 RIGHT JOIN t2 ON true
539
+ RIGHT JOIN t3 ON t2.y IS NOT NULL
540
+ RIGHT JOIN t4 ON true
541
+ WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)
542
+ ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);
543
+ } {
544
+ - - 20 50
545
+ - - 30 50
546
+ }
547
+ finish_test
548
+
549
+ ############################################################################
550
+ # This is the TCL script used to generate the psql script that generated
551
+ # the data above.
552
+ #
553
+ # puts "
554
+ # \\pset border off
555
+ # \\pset tuples_only on
556
+ # \\pset null -
557
+ #
558
+ # DROP TABLE IF EXISTS t1;
559
+ # DROP TABLE IF EXISTS t2;
560
+ # DROP TABLE IF EXISTS t3;
561
+ # DROP TABLE IF EXISTS t4;
562
+ # CREATE TABLE t1(x INT);
563
+ # CREATE TABLE t2(y INT);
564
+ # CREATE TABLE t3(z INT);
565
+ # CREATE TABLE t4(w INT);
566
+ # INSERT INTO t1 VALUES(10);
567
+ # INSERT INTO t3 VALUES(20),(30);
568
+ # INSERT INTO t4 VALUES(50);
569
+ # "
570
+ #
571
+ # proc echo {prefix txt} {
572
+ # regsub -all {\n} $txt \n$prefix txt
573
+ # puts "$prefix$txt"
574
+ # }
575
+ #
576
+ # set n 0
577
+ # foreach j1 {INNER LEFT RIGHT} {
578
+ # foreach j2 {INNER LEFT RIGHT} {
579
+ # foreach j3 {INNER LEFT RIGHT} {
580
+ #
581
+ # incr n
582
+ # set q1 ""
583
+ # append q1 "SELECT *\n"
584
+ # append q1 " FROM t1 $j1 JOIN t2 ON true\n"
585
+ # append q1 " $j2 JOIN t3 ON t2.y IS NOT NULL\n"
586
+ # append q1 " $j3 JOIN t4 ON true\n"
587
+ # append q1 " ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);"
588
+ #
589
+ # echo "\\qecho " "do_execsql_test joinF-$n \{"
590
+ # echo "\\qecho X " $q1
591
+ # echo "\\qecho " "\} \{"
592
+ # puts $q1
593
+ # echo "\\qecho " "\}"
594
+ #
595
+ # incr n
596
+ # set q1 ""
597
+ # append q1 "SELECT *\n"
598
+ # append q1 " FROM t1 $j1 JOIN t2 ON true\n"
599
+ # append q1 " $j2 JOIN t3 ON t2.y IS NOT NULL\n"
600
+ # append q1 " $j3 JOIN t4 ON true\n"
601
+ # append q1 " WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600)\n"
602
+ # append q1 " ORDER BY coalesce(t1.x,t2.y,t3.z,t4.w,0);"
603
+ #
604
+ # echo "\\qecho " "do_execsql_test joinF-$n \{"
605
+ # echo "\\qecho X " $q1
606
+ # echo "\\qecho " "\} \{"
607
+ # puts $q1
608
+ # echo "\\qecho " "\}"
609
+ #
610
+ # }
611
+ # }
612
+ # }
613
+ #
local-test-sqlite3-delta-03/afc-sqlite3/test/lastinsert.test ADDED
@@ -0,0 +1,377 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # The author disclaims copyright to this source code. In place of
2
+ # a legal notice, here is a blessing:
3
+ #
4
+ # May you do good and not evil.
5
+ # May you find forgiveness for yourself and forgive others.
6
+ # May you share freely, never taking more than you give.
7
+ #
8
+ #***********************************************************************
9
+ #
10
+ # Tests to make sure that value returned by last_insert_rowid() (LIRID)
11
+ # is updated properly, especially inside triggers
12
+ #
13
+ # Note 1: insert into table is now the only statement which changes LIRID
14
+ # Note 2: upon entry into before or instead of triggers,
15
+ # LIRID is unchanged (rather than -1)
16
+ # Note 3: LIRID is changed within the context of a trigger,
17
+ # but is restored once the trigger exits
18
+ # Note 4: LIRID is not changed by an insert into a view (since everything
19
+ # is done within instead of trigger context)
20
+ #
21
+
22
+ set testdir [file dirname $argv0]
23
+ source $testdir/tester.tcl
24
+
25
+ # ----------------------------------------------------------------------------
26
+ # 1.x - basic tests (no triggers)
27
+
28
+ # LIRID changed properly after an insert into a table
29
+ do_test lastinsert-1.1 {
30
+ catchsql {
31
+ create table t1 (k integer primary key);
32
+ insert into t1 values (1);
33
+ insert into t1 values (NULL);
34
+ insert into t1 values (NULL);
35
+ select last_insert_rowid();
36
+ }
37
+ } {0 3}
38
+
39
+ # EVIDENCE-OF: R-47220-63683 The sqlite3_last_insert_rowid() function
40
+ # does not work for WITHOUT ROWID tables.
41
+ #
42
+ do_test lastinsert-1.1w {
43
+ catchsql {
44
+ create table t1w (k integer primary key) WITHOUT ROWID;
45
+ insert into t1w values (123456);
46
+ select last_insert_rowid(); -- returns 3 from above.
47
+ }
48
+ } {0 3}
49
+
50
+ # LIRID unchanged after an update on a table
51
+ do_test lastinsert-1.2 {
52
+ catchsql {
53
+ update t1 set k=4 where k=2;
54
+ select last_insert_rowid();
55
+ }
56
+ } {0 3}
57
+
58
+ # LIRID unchanged after a delete from a table
59
+ do_test lastinsert-1.3 {
60
+ catchsql {
61
+ delete from t1 where k=4;
62
+ select last_insert_rowid();
63
+ }
64
+ } {0 3}
65
+
66
+ # LIRID unchanged after create table/view statements
67
+ do_test lastinsert-1.4.1 {
68
+ catchsql {
69
+ create table t2 (k integer primary key, val1, val2, val3);
70
+ select last_insert_rowid();
71
+ }
72
+ } {0 3}
73
+ ifcapable view {
74
+ do_test lastinsert-1.4.2 {
75
+ catchsql {
76
+ create view v as select * from t1;
77
+ select last_insert_rowid();
78
+ }
79
+ } {0 3}
80
+ } ;# ifcapable view
81
+
82
+ # All remaining tests involve triggers. Skip them if triggers are not
83
+ # supported in this build.
84
+ #
85
+ ifcapable {!trigger} {
86
+ finish_test
87
+ return
88
+ }
89
+
90
+ # ----------------------------------------------------------------------------
91
+ # 2.x - tests with after insert trigger
92
+
93
+ # LIRID changed properly after an insert into table containing an after trigger
94
+ do_test lastinsert-2.1 {
95
+ catchsql {
96
+ delete from t2;
97
+ create trigger r1 after insert on t1 for each row begin
98
+ insert into t2 values (NEW.k*2, last_insert_rowid(), NULL, NULL);
99
+ update t2 set k=k+10, val2=100+last_insert_rowid();
100
+ update t2 set val3=1000+last_insert_rowid();
101
+ end;
102
+ insert into t1 values (13);
103
+ select last_insert_rowid();
104
+ }
105
+ } {0 13}
106
+
107
+ # LIRID equals NEW.k upon entry into after insert trigger
108
+ do_test lastinsert-2.2 {
109
+ catchsql {
110
+ select val1 from t2;
111
+ }
112
+ } {0 13}
113
+
114
+ # LIRID changed properly by insert within context of after insert trigger
115
+ do_test lastinsert-2.3 {
116
+ catchsql {
117
+ select val2 from t2;
118
+ }
119
+ } {0 126}
120
+
121
+ # LIRID unchanged by update within context of after insert trigger
122
+ do_test lastinsert-2.4 {
123
+ catchsql {
124
+ select val3 from t2;
125
+ }
126
+ } {0 1026}
127
+
128
+ # ----------------------------------------------------------------------------
129
+ # 3.x - tests with after update trigger
130
+
131
+ # LIRID not changed after an update onto a table containing an after trigger
132
+ do_test lastinsert-3.1 {
133
+ catchsql {
134
+ delete from t2;
135
+ drop trigger r1;
136
+ create trigger r1 after update on t1 for each row begin
137
+ insert into t2 values (NEW.k*2, last_insert_rowid(), NULL, NULL);
138
+ update t2 set k=k+10, val2=100+last_insert_rowid();
139
+ update t2 set val3=1000+last_insert_rowid();
140
+ end;
141
+ update t1 set k=14 where k=3;
142
+ select last_insert_rowid();
143
+ }
144
+ } {0 13}
145
+
146
+ # LIRID unchanged upon entry into after update trigger
147
+ do_test lastinsert-3.2 {
148
+ catchsql {
149
+ select val1 from t2;
150
+ }
151
+ } {0 13}
152
+
153
+ # LIRID changed properly by insert within context of after update trigger
154
+ do_test lastinsert-3.3 {
155
+ catchsql {
156
+ select val2 from t2;
157
+ }
158
+ } {0 128}
159
+
160
+ # LIRID unchanged by update within context of after update trigger
161
+ do_test lastinsert-3.4 {
162
+ catchsql {
163
+ select val3 from t2;
164
+ }
165
+ } {0 1028}
166
+
167
+ # ----------------------------------------------------------------------------
168
+ # 4.x - tests with instead of insert trigger
169
+ # These may not be run if either views or triggers were disabled at
170
+ # compile-time
171
+
172
+ ifcapable {view && trigger} {
173
+ # LIRID not changed after an insert into view containing an instead of trigger
174
+ do_test lastinsert-4.1 {
175
+ catchsql {
176
+ delete from t2;
177
+ drop trigger r1;
178
+ create trigger r1 instead of insert on v for each row begin
179
+ insert into t2 values (NEW.k*2, last_insert_rowid(), NULL, NULL);
180
+ update t2 set k=k+10, val2=100+last_insert_rowid();
181
+ update t2 set val3=1000+last_insert_rowid();
182
+ end;
183
+ insert into v values (15);
184
+ select last_insert_rowid();
185
+ }
186
+ } {0 13}
187
+
188
+ # LIRID unchanged upon entry into instead of trigger
189
+ do_test lastinsert-4.2 {
190
+ catchsql {
191
+ select val1 from t2;
192
+ }
193
+ } {0 13}
194
+
195
+ # LIRID changed properly by insert within context of instead of trigger
196
+ do_test lastinsert-4.3 {
197
+ catchsql {
198
+ select val2 from t2;
199
+ }
200
+ } {0 130}
201
+
202
+ # LIRID unchanged by update within context of instead of trigger
203
+ do_test lastinsert-4.4 {
204
+ catchsql {
205
+ select val3 from t2;
206
+ }
207
+ } {0 1030}
208
+ } ;# ifcapable (view && trigger)
209
+
210
+ # ----------------------------------------------------------------------------
211
+ # 5.x - tests with before delete trigger
212
+
213
+ # LIRID not changed after a delete on a table containing a before trigger
214
+ do_test lastinsert-5.1 {
215
+ catchsql {
216
+ drop trigger r1; -- This was not created if views are disabled.
217
+ }
218
+ catchsql {
219
+ delete from t2;
220
+ create trigger r1 before delete on t1 for each row begin
221
+ insert into t2 values (77, last_insert_rowid(), NULL, NULL);
222
+ update t2 set k=k+10, val2=100+last_insert_rowid();
223
+ update t2 set val3=1000+last_insert_rowid();
224
+ end;
225
+ delete from t1 where k=1;
226
+ select last_insert_rowid();
227
+ }
228
+ } {0 13}
229
+
230
+ # LIRID unchanged upon entry into delete trigger
231
+ do_test lastinsert-5.2 {
232
+ catchsql {
233
+ select val1 from t2;
234
+ }
235
+ } {0 13}
236
+
237
+ # LIRID changed properly by insert within context of delete trigger
238
+ do_test lastinsert-5.3 {
239
+ catchsql {
240
+ select val2 from t2;
241
+ }
242
+ } {0 177}
243
+
244
+ # LIRID unchanged by update within context of delete trigger
245
+ do_test lastinsert-5.4 {
246
+ catchsql {
247
+ select val3 from t2;
248
+ }
249
+ } {0 1077}
250
+
251
+ # ----------------------------------------------------------------------------
252
+ # 6.x - tests with instead of update trigger
253
+ # These tests may not run if either views or triggers are disabled.
254
+
255
+ ifcapable {view && trigger} {
256
+ # LIRID not changed after an update on a view containing an instead of trigger
257
+ do_test lastinsert-6.1 {
258
+ catchsql {
259
+ delete from t2;
260
+ drop trigger r1;
261
+ create trigger r1 instead of update on v for each row begin
262
+ insert into t2 values (NEW.k*2, last_insert_rowid(), NULL, NULL);
263
+ update t2 set k=k+10, val2=100+last_insert_rowid();
264
+ update t2 set val3=1000+last_insert_rowid();
265
+ end;
266
+ update v set k=16 where k=14;
267
+ select last_insert_rowid();
268
+ }
269
+ } {0 13}
270
+
271
+ # LIRID unchanged upon entry into instead of trigger
272
+ do_test lastinsert-6.2 {
273
+ catchsql {
274
+ select val1 from t2;
275
+ }
276
+ } {0 13}
277
+
278
+ # LIRID changed properly by insert within context of instead of trigger
279
+ do_test lastinsert-6.3 {
280
+ catchsql {
281
+ select val2 from t2;
282
+ }
283
+ } {0 132}
284
+
285
+ # LIRID unchanged by update within context of instead of trigger
286
+ do_test lastinsert-6.4 {
287
+ catchsql {
288
+ select val3 from t2;
289
+ }
290
+ } {0 1032}
291
+ } ;# ifcapable (view && trigger)
292
+
293
+ # ----------------------------------------------------------------------------
294
+ # 7.x - complex tests with temporary tables and nested instead of triggers
295
+ # These do not run if views or triggers are disabled.
296
+
297
+ ifcapable {trigger && view && tempdb} {
298
+ do_test lastinsert-7.1 {
299
+ catchsql {
300
+ drop table t1; drop table t2; drop trigger r1;
301
+ create temp table t1 (k integer primary key);
302
+ create temp table t2 (k integer primary key);
303
+ create temp view v1 as select * from t1;
304
+ create temp view v2 as select * from t2;
305
+ create temp table rid (k integer primary key, rin, rout);
306
+ insert into rid values (1, NULL, NULL);
307
+ insert into rid values (2, NULL, NULL);
308
+ create temp trigger r1 instead of insert on v1 for each row begin
309
+ update rid set rin=last_insert_rowid() where k=1;
310
+ insert into t1 values (100+NEW.k);
311
+ insert into v2 values (100+last_insert_rowid());
312
+ update rid set rout=last_insert_rowid() where k=1;
313
+ end;
314
+ create temp trigger r2 instead of insert on v2 for each row begin
315
+ update rid set rin=last_insert_rowid() where k=2;
316
+ insert into t2 values (1000+NEW.k);
317
+ update rid set rout=last_insert_rowid() where k=2;
318
+ end;
319
+ insert into t1 values (77);
320
+ select last_insert_rowid();
321
+ }
322
+ } {0 77}
323
+
324
+ do_test lastinsert-7.2 {
325
+ catchsql {
326
+ insert into v1 values (5);
327
+ select last_insert_rowid();
328
+ }
329
+ } {0 77}
330
+
331
+ do_test lastinsert-7.3 {
332
+ catchsql {
333
+ select rin from rid where k=1;
334
+ }
335
+ } {0 77}
336
+
337
+ do_test lastinsert-7.4 {
338
+ catchsql {
339
+ select rout from rid where k=1;
340
+ }
341
+ } {0 105}
342
+
343
+ do_test lastinsert-7.5 {
344
+ catchsql {
345
+ select rin from rid where k=2;
346
+ }
347
+ } {0 105}
348
+
349
+ do_test lastinsert-7.6 {
350
+ catchsql {
351
+ select rout from rid where k=2;
352
+ }
353
+ } {0 1205}
354
+
355
+ do_test lastinsert-8.1 {
356
+ db close
357
+ sqlite3 db test.db
358
+ execsql {
359
+ CREATE TABLE t2(x INTEGER PRIMARY KEY, y);
360
+ CREATE TABLE t3(a, b);
361
+ CREATE TRIGGER after_t2 AFTER INSERT ON t2 BEGIN
362
+ INSERT INTO t3 VALUES(new.x, new.y);
363
+ END;
364
+ INSERT INTO t2 VALUES(5000000000, 1);
365
+ SELECT last_insert_rowid();
366
+ }
367
+ } 5000000000
368
+
369
+ do_test lastinsert-9.1 {
370
+ db eval {INSERT INTO t2 VALUES(123456789012345,0)}
371
+ db last_insert_rowid
372
+ } {123456789012345}
373
+
374
+
375
+ } ;# ifcapable (view && trigger)
376
+
377
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/laststmtchanges.test ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # The author disclaims copyright to this source code. In place of
3
+ # a legal notice, here is a blessing:
4
+ #
5
+ # May you do good and not evil.
6
+ # May you find forgiveness for yourself and forgive others.
7
+ # May you share freely, never taking more than you give.
8
+ #
9
+ #***********************************************************************
10
+ #
11
+ # Tests to make sure that values returned by changes() and total_changes()
12
+ # are updated properly, especially inside triggers
13
+ #
14
+ # Note 1: changes() remains constant within a statement and only updates
15
+ # once the statement is finished (triggers count as part of
16
+ # statement).
17
+ # Note 2: changes() is changed within the context of a trigger much like
18
+ # last_insert_rowid() (see lastinsert.test), but is restored once
19
+ # the trigger exits.
20
+ # Note 3: changes() is not changed by a change to a view (since everything
21
+ # is done within instead of trigger context).
22
+ #
23
+ # $Id: laststmtchanges.test,v 1.7 2008/10/27 13:59:34 danielk1977 Exp $
24
+
25
+ set testdir [file dirname $argv0]
26
+ source $testdir/tester.tcl
27
+
28
+ # ----------------------------------------------------------------------------
29
+ # 1.x - basic tests (no triggers)
30
+
31
+ # changes() set properly after insert
32
+ do_test laststmtchanges-1.1 {
33
+ catchsql {
34
+ create table t0 (x);
35
+ insert into t0 values (1);
36
+ insert into t0 values (1);
37
+ insert into t0 values (2);
38
+ insert into t0 values (2);
39
+ insert into t0 values (1);
40
+ insert into t0 values (1);
41
+ insert into t0 values (1);
42
+ insert into t0 values (2);
43
+ select changes(), total_changes();
44
+ }
45
+ } {0 {1 8}}
46
+
47
+ # changes() set properly after update
48
+ do_test laststmtchanges-1.2 {
49
+ catchsql {
50
+ update t0 set x=3 where x=1;
51
+ select changes(), total_changes();
52
+ }
53
+ } {0 {5 13}}
54
+
55
+ # There was some goofy change-counting logic in sqlite3_exec() that
56
+ # appears to have been left over from SQLite version 2. This test
57
+ # makes sure it has been removed.
58
+ #
59
+ do_test laststmtchanges-1.2.1 {
60
+ db cache flush
61
+ sqlite3_exec_printf db {update t0 set x=4 where x=3; select 1;} {}
62
+ execsql {select changes()}
63
+ } {5}
64
+
65
+ # changes() unchanged within an update statement
66
+ do_test laststmtchanges-1.3 {
67
+ execsql {update t0 set x=3 where x=4}
68
+ catchsql {
69
+ update t0 set x=x+changes() where x=3;
70
+ select count() from t0 where x=8;
71
+ }
72
+ } {0 5}
73
+
74
+ # changes() set properly after update on table where no rows changed
75
+ do_test laststmtchanges-1.4 {
76
+ catchsql {
77
+ update t0 set x=77 where x=88;
78
+ select changes();
79
+ }
80
+ } {0 0}
81
+
82
+ # changes() set properly after delete from table
83
+ do_test laststmtchanges-1.5 {
84
+ catchsql {
85
+ delete from t0 where x=2;
86
+ select changes();
87
+ }
88
+ } {0 3}
89
+
90
+ # All remaining tests involve triggers. Skip them if triggers are not
91
+ # supported in this build.
92
+ #
93
+ ifcapable {!trigger} {
94
+ finish_test
95
+ return
96
+ }
97
+
98
+
99
+ # ----------------------------------------------------------------------------
100
+ # 2.x - tests with after insert trigger
101
+
102
+ # changes() changed properly after insert into table containing after trigger
103
+ do_test laststmtchanges-2.1 {
104
+ set ::tc [db total_changes]
105
+ catchsql {
106
+ create table t1 (k integer primary key);
107
+ create table t2 (k integer primary key, v1, v2);
108
+ create trigger r1 after insert on t1 for each row begin
109
+ insert into t2 values (NULL, changes(), NULL);
110
+ update t0 set x=x;
111
+ update t2 set v2=changes();
112
+ end;
113
+ insert into t1 values (77);
114
+ select changes();
115
+ }
116
+ } {0 1}
117
+
118
+ # changes() unchanged upon entry into after insert trigger
119
+ do_test laststmtchanges-2.2 {
120
+ catchsql {
121
+ select v1 from t2;
122
+ }
123
+ } {0 3}
124
+
125
+ # changes() changed properly by update within context of after insert trigger
126
+ do_test laststmtchanges-2.3 {
127
+ catchsql {
128
+ select v2 from t2;
129
+ }
130
+ } {0 5}
131
+
132
+ # Total changes caused by firing the trigger above:
133
+ #
134
+ # 1 from "insert into t1 values(77)" +
135
+ # 1 from "insert into t2 values (NULL, changes(), NULL);" +
136
+ # 5 from "update t0 set x=x;" +
137
+ # 1 from "update t2 set v2=changes();"
138
+ #
139
+ do_test laststmtchanges-2.4 {
140
+ expr [db total_changes] - $::tc
141
+ } {8}
142
+
143
+ # ----------------------------------------------------------------------------
144
+ # 3.x - tests with after update trigger
145
+
146
+ # changes() changed properly after update into table containing after trigger
147
+ do_test laststmtchanges-3.1 {
148
+ catchsql {
149
+ drop trigger r1;
150
+ delete from t2; delete from t2;
151
+ create trigger r1 after update on t1 for each row begin
152
+ insert into t2 values (NULL, changes(), NULL);
153
+ delete from t0 where oid=1 or oid=2;
154
+ update t2 set v2=changes();
155
+ end;
156
+ update t1 set k=k;
157
+ select changes();
158
+ }
159
+ } {0 1}
160
+
161
+ # changes() unchanged upon entry into after update trigger
162
+ do_test laststmtchanges-3.2 {
163
+ catchsql {
164
+ select v1 from t2;
165
+ }
166
+ } {0 0}
167
+
168
+ # changes() changed properly by delete within context of after update trigger
169
+ do_test laststmtchanges-3.3 {
170
+ catchsql {
171
+ select v2 from t2;
172
+ }
173
+ } {0 2}
174
+
175
+ # ----------------------------------------------------------------------------
176
+ # 4.x - tests with before delete trigger
177
+
178
+ # changes() changed properly on delete from table containing before trigger
179
+ do_test laststmtchanges-4.1 {
180
+ catchsql {
181
+ drop trigger r1;
182
+ delete from t2; delete from t2;
183
+ create trigger r1 before delete on t1 for each row begin
184
+ insert into t2 values (NULL, changes(), NULL);
185
+ insert into t0 values (5);
186
+ update t2 set v2=changes();
187
+ end;
188
+ delete from t1;
189
+ select changes();
190
+ }
191
+ } {0 1}
192
+
193
+ # changes() unchanged upon entry into before delete trigger
194
+ do_test laststmtchanges-4.2 {
195
+ catchsql {
196
+ select v1 from t2;
197
+ }
198
+ } {0 0}
199
+
200
+ # changes() changed properly by insert within context of before delete trigger
201
+ do_test laststmtchanges-4.3 {
202
+ catchsql {
203
+ select v2 from t2;
204
+ }
205
+ } {0 1}
206
+
207
+ # ----------------------------------------------------------------------------
208
+ # 5.x - complex tests with temporary tables and nested instead of triggers
209
+ # These tests cannot run if the library does not have view support enabled.
210
+
211
+ ifcapable view&&tempdb {
212
+
213
+ do_test laststmtchanges-5.1 {
214
+ catchsql {
215
+ drop table t0; drop table t1; drop table t2;
216
+ create temp table t0(x);
217
+ create temp table t1 (k integer primary key);
218
+ create temp table t2 (k integer primary key);
219
+ create temp view v1 as select * from t1;
220
+ create temp view v2 as select * from t2;
221
+ create temp table n1 (k integer primary key, n);
222
+ create temp table n2 (k integer primary key, n);
223
+ insert into t0 values (1);
224
+ insert into t0 values (2);
225
+ insert into t0 values (1);
226
+ insert into t0 values (1);
227
+ insert into t0 values (1);
228
+ insert into t0 values (2);
229
+ insert into t0 values (2);
230
+ insert into t0 values (1);
231
+ create temp trigger r1 instead of insert on v1 for each row begin
232
+ insert into n1 values (NULL, changes());
233
+ update t0 set x=x*10 where x=1;
234
+ insert into n1 values (NULL, changes());
235
+ insert into t1 values (NEW.k);
236
+ insert into n1 values (NULL, changes());
237
+ update t0 set x=x*10 where x=0;
238
+ insert into v2 values (100+NEW.k);
239
+ insert into n1 values (NULL, changes());
240
+ end;
241
+ create temp trigger r2 instead of insert on v2 for each row begin
242
+ insert into n2 values (NULL, changes());
243
+ insert into t2 values (1000+NEW.k);
244
+ insert into n2 values (NULL, changes());
245
+ update t0 set x=x*100 where x=0;
246
+ insert into n2 values (NULL, changes());
247
+ delete from t0 where x=2;
248
+ insert into n2 values (NULL, changes());
249
+ end;
250
+ insert into t1 values (77);
251
+ select changes();
252
+ }
253
+ } {0 1}
254
+
255
+ do_test laststmtchanges-5.2 {
256
+ catchsql {
257
+ delete from t1 where k=88;
258
+ select changes();
259
+ }
260
+ } {0 0}
261
+
262
+ do_test laststmtchanges-5.3 {
263
+ catchsql {
264
+ insert into v1 values (5);
265
+ select changes();
266
+ }
267
+ } {0 0}
268
+
269
+ do_test laststmtchanges-5.4 {
270
+ catchsql {
271
+ select n from n1;
272
+ }
273
+ } {0 {0 5 1 0}}
274
+
275
+ do_test laststmtchanges-5.5 {
276
+ catchsql {
277
+ select n from n2;
278
+ }
279
+ } {0 {0 1 0 3}}
280
+
281
+ } ;# ifcapable view
282
+
283
+
284
+ # ----------------------------------------------------------------------------
285
+ # 6.x - Test "DELETE FROM <table>" in the absence of triggers
286
+ #
287
+ do_test laststmtchanges-6.1 {
288
+ execsql {
289
+ CREATE TABLE t3(a, b, c);
290
+ INSERT INTO t3 VALUES(1, 2, 3);
291
+ INSERT INTO t3 VALUES(4, 5, 6);
292
+ }
293
+ } {}
294
+ do_test laststmtchanges-6.2 {
295
+ execsql {
296
+ BEGIN;
297
+ DELETE FROM t3;
298
+ SELECT changes();
299
+ }
300
+ } {2}
301
+ do_test laststmtchanges-6.3 {
302
+ execsql {
303
+ ROLLBACK;
304
+ BEGIN;
305
+ DELETE FROM t3 WHERE a IS NOT NULL;
306
+ SELECT changes();
307
+ }
308
+ } {2}
309
+ do_test laststmtchanges-6.4 {
310
+ execsql {
311
+ ROLLBACK;
312
+ CREATE INDEX t3_i1 ON t3(a);
313
+ BEGIN;
314
+ DELETE FROM t3;
315
+ SELECT changes();
316
+ }
317
+ } {2}
318
+ do_test laststmtchanges-6.5 {
319
+ execsql { ROLLBACK }
320
+ set nTotalChange [execsql {SELECT total_changes()}]
321
+ expr 0
322
+ } {0}
323
+ do_test laststmtchanges-6.6 {
324
+ execsql {
325
+ SELECT total_changes();
326
+ DELETE FROM t3;
327
+ SELECT total_changes();
328
+ }
329
+ } [list $nTotalChange [expr $nTotalChange+2]]
330
+
331
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/lock2.test ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2001 September 15
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this script is database locks between competing processes.
13
+ #
14
+ # $Id: lock2.test,v 1.11 2009/05/01 10:55:34 danielk1977 Exp $
15
+
16
+
17
+ set testdir [file dirname $argv0]
18
+ source $testdir/tester.tcl
19
+ source $testdir/lock_common.tcl
20
+
21
+
22
+ # Simple locking test case:
23
+ #
24
+ # lock2-1.1: Connect a second process to the database.
25
+ # lock2-1.2: Establish a RESERVED lock with this process.
26
+ # lock2-1.3: Get a SHARED lock with the second process.
27
+ # lock2-1.4: Try for a RESERVED lock with process 2. This fails.
28
+ # lock2-1.5: Try to upgrade the first process to EXCLUSIVE, this fails so
29
+ # it gets PENDING.
30
+ # lock2-1.6: Release the SHARED lock held by the second process.
31
+ # lock2-1.7: Attempt to reaquire a SHARED lock with the second process.
32
+ # this fails due to the PENDING lock.
33
+ # lock2-1.8: Ensure the first process can now upgrade to EXCLUSIVE.
34
+ #
35
+ do_test lock2-1.1 {
36
+ set ::tf1 [launch_testfixture]
37
+ testfixture $::tf1 {
38
+ sqlite3 db test.db -key xyzzy
39
+ db eval {select * from sqlite_master}
40
+ }
41
+ } {}
42
+ do_test lock2-1.1.1 {
43
+ execsql {pragma lock_status}
44
+ } {main unlocked temp closed}
45
+ sqlite3_soft_heap_limit 0
46
+ do_test lock2-1.2 {
47
+ execsql {
48
+ BEGIN;
49
+ CREATE TABLE abc(a, b, c);
50
+ }
51
+ } {}
52
+ do_test lock2-1.3 {
53
+ testfixture $::tf1 {
54
+ db eval {
55
+ BEGIN;
56
+ SELECT * FROM sqlite_master;
57
+ }
58
+ }
59
+ } {}
60
+ do_test lock2-1.4 {
61
+ testfixture $::tf1 {
62
+ catch { db eval { CREATE TABLE def(d, e, f) } } msg
63
+ set msg
64
+ }
65
+ } {database is locked}
66
+ do_test lock2-1.5 {
67
+ catchsql {
68
+ COMMIT;
69
+ }
70
+ } {1 {database is locked}}
71
+ do_test lock2-1.6 {
72
+ testfixture $::tf1 {
73
+ db eval {
74
+ SELECT * FROM sqlite_master;
75
+ COMMIT;
76
+ }
77
+ }
78
+ } {}
79
+ do_test lock2-1.7 {
80
+ testfixture $::tf1 {
81
+ catch { db eval {
82
+ BEGIN;
83
+ SELECT * FROM sqlite_master;
84
+ } } msg
85
+ set msg
86
+ }
87
+ } {database is locked}
88
+ do_test lock2-1.8 {
89
+ catchsql {
90
+ COMMIT;
91
+ }
92
+ } {0 {}}
93
+ do_test lock2-1.9 {
94
+ execsql {
95
+ SELECT * FROM sqlite_master;
96
+ }
97
+ } "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}"
98
+ catch flush_async_queue
99
+ do_test lock2-1.10 {
100
+ testfixture $::tf1 {
101
+ db eval {
102
+ SELECT * FROM sqlite_master;
103
+ }
104
+ }
105
+ } "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}"
106
+
107
+ catch {testfixture $::tf1 {db close}}
108
+ catch {close $::tf1}
109
+ sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit)
110
+
111
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/malloc3.test ADDED
@@ -0,0 +1,703 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2005 November 30
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # This file contains tests to ensure that the library handles malloc() failures
13
+ # correctly. The emphasis of these tests are the _prepare(), _step() and
14
+ # _finalize() calls.
15
+ #
16
+ # $Id: malloc3.test,v 1.24 2008/10/14 15:54:08 drh Exp $
17
+
18
+ set testdir [file dirname $argv0]
19
+ source $testdir/tester.tcl
20
+ source $testdir/malloc_common.tcl
21
+
22
+ # Only run these tests if memory debugging is turned on.
23
+ #
24
+ if {!$MEMDEBUG} {
25
+ puts "Skipping malloc3 tests: not compiled with -DSQLITE_MEMDEBUG..."
26
+ finish_test
27
+ return
28
+ }
29
+
30
+ # Do not run these tests if F2FS batch writes are supported. In this case,
31
+ # it is possible for a single DML statement in an implicit transaction
32
+ # to fail with SQLITE_NOMEM, but for the transaction to still end up
33
+ # committed to disk. Which confuses the tests in this module.
34
+ #
35
+ if {[atomic_batch_write test.db]} {
36
+ puts "Skipping malloc3 tests: atomic-batch support"
37
+ finish_test
38
+ return
39
+ }
40
+
41
+
42
+ # Do not run these tests with an in-memory journal.
43
+ #
44
+ # In the pager layer, if an IO or OOM error occurs during a ROLLBACK, or
45
+ # when flushing a page to disk due to cache-stress, the pager enters an
46
+ # "error state". The only way out of the error state is to unlock the
47
+ # database file and end the transaction, leaving whatever journal and
48
+ # database files happen to be on disk in place. The next time the current
49
+ # (or any other) connection opens a read transaction, hot-journal rollback
50
+ # is performed if necessary.
51
+ #
52
+ # Of course, this doesn't work with an in-memory journal.
53
+ #
54
+ if {[permutation]=="inmemory_journal"} {
55
+ finish_test
56
+ return
57
+ }
58
+
59
+ #--------------------------------------------------------------------------
60
+ # NOTES ON RECOVERING FROM A MALLOC FAILURE
61
+ #
62
+ # The tests in this file test the behaviours described in the following
63
+ # paragraphs. These tests test the behaviour of the system when malloc() fails
64
+ # inside of a call to _prepare(), _step(), _finalize() or _reset(). The
65
+ # handling of malloc() failures within ancillary procedures is tested
66
+ # elsewhere.
67
+ #
68
+ # Overview:
69
+ #
70
+ # Executing a statement is done in three stages (prepare, step and finalize). A
71
+ # malloc() failure may occur within any stage. If a memory allocation fails
72
+ # during statement preparation, no statement handle is returned. From the users
73
+ # point of view the system state is as if _prepare() had never been called.
74
+ #
75
+ # If the memory allocation fails during the _step() or _finalize() calls, then
76
+ # the database may be left in one of two states (after finalize() has been
77
+ # called):
78
+ #
79
+ # * As if the neither _step() nor _finalize() had ever been called on
80
+ # the statement handle (i.e. any changes made by the statement are
81
+ # rolled back).
82
+ # * The current transaction may be rolled back. In this case a hot-journal
83
+ # may or may not actually be present in the filesystem.
84
+ #
85
+ # The caller can tell the difference between these two scenarios by invoking
86
+ # _get_autocommit().
87
+ #
88
+ #
89
+ # Handling of sqlite3_reset():
90
+ #
91
+ # If a malloc() fails while executing an sqlite3_reset() call, this is handled
92
+ # in the same way as a failure within _finalize(). The statement handle
93
+ # is not deleted and must be passed to _finalize() for resource deallocation.
94
+ # Attempting to _step() or _reset() the statement after a failed _reset() will
95
+ # always return SQLITE_NOMEM.
96
+ #
97
+ #
98
+ # Other active SQL statements:
99
+ #
100
+ # The effect of a malloc failure on concurrently executing SQL statements,
101
+ # particularly when the statement is executing with READ_UNCOMMITTED set and
102
+ # the malloc() failure mandates statement rollback only. Currently, if
103
+ # transaction rollback is required, all other vdbe's are aborted.
104
+ #
105
+ # Non-transient mallocs in btree.c:
106
+ # * The Btree structure itself
107
+ # * Each BtCursor structure
108
+ #
109
+ # Mallocs in pager.c:
110
+ # readMasterJournal() - Space to read the master journal name
111
+ # pager_delmaster() - Space for the entire master journal file
112
+ #
113
+ # sqlite3pager_open() - The pager structure itself
114
+ # sqlite3_pagerget() - Space for a new page
115
+ # pager_open_journal() - Pager.aInJournal[] bitmap
116
+ # sqlite3pager_write() - For in-memory databases only: history page and
117
+ # statement history page.
118
+ # pager_stmt_begin() - Pager.aInStmt[] bitmap
119
+ #
120
+ # None of the above are a huge problem. The most troublesome failures are the
121
+ # transient malloc() calls in btree.c, which can occur during the tree-balance
122
+ # operation. This means the tree being balanced will be internally inconsistent
123
+ # after the malloc() fails. To avoid the corrupt tree being read by a
124
+ # READ_UNCOMMITTED query, we have to make sure the transaction or statement
125
+ # rollback occurs before sqlite3_step() returns, not during a subsequent
126
+ # sqlite3_finalize().
127
+ #--------------------------------------------------------------------------
128
+
129
+ #--------------------------------------------------------------------------
130
+ # NOTES ON TEST IMPLEMENTATION
131
+ #
132
+ # The tests in this file are implemented differently from those in other
133
+ # files. Instead, tests are specified using three primitives: SQL, PREP and
134
+ # TEST. Each primitive has a single argument. Primitives are processed in
135
+ # the order they are specified in the file.
136
+ #
137
+ # A TEST primitive specifies a TCL script as its argument. When a TEST
138
+ # directive is encountered the Tcl script is evaluated. Usually, this Tcl
139
+ # script contains one or more calls to [do_test].
140
+ #
141
+ # A PREP primitive specifies an SQL script as its argument. When a PREP
142
+ # directive is encountered the SQL is evaluated using database connection
143
+ # [db].
144
+ #
145
+ # The SQL primitives are where the action happens. An SQL primitive must
146
+ # contain a single, valid SQL statement as its argument. When an SQL
147
+ # primitive is encountered, it is evaluated one or more times to test the
148
+ # behaviour of the system when malloc() fails during preparation or
149
+ # execution of said statement. The Nth time the statement is executed,
150
+ # the Nth malloc is said to fail. The statement is executed until it
151
+ # succeeds, i.e. (M+1) times, where M is the number of mallocs() required
152
+ # to prepare and execute the statement.
153
+ #
154
+ # Each time an SQL statement fails, the driver program (see proc [run_test]
155
+ # below) figures out if a transaction has been automatically rolled back.
156
+ # If not, it executes any TEST block immediately proceeding the SQL
157
+ # statement, then reexecutes the SQL statement with the next value of N.
158
+ #
159
+ # If a transaction has been automatically rolled back, then the driver
160
+ # program executes all the SQL specified as part of SQL or PREP primitives
161
+ # between the current SQL statement and the most recent "BEGIN". Any
162
+ # TEST block immediately proceeding the SQL statement is evaluated, and
163
+ # then the SQL statement reexecuted with the incremented N value.
164
+ #
165
+ # That make any sense? If not, read the code in [run_test] and it might.
166
+ #
167
+ # Extra restriction imposed by the implementation:
168
+ #
169
+ # * If a PREP block starts a transaction, it must finish it.
170
+ # * A PREP block may not close a transaction it did not start.
171
+ #
172
+ #--------------------------------------------------------------------------
173
+
174
+
175
+ # These procs are used to build up a "program" in global variable
176
+ # ::run_test_script. At the end of this file, the proc [run_test] is used
177
+ # to execute the program (and all test cases contained therein).
178
+ #
179
+ set ::run_test_sql_id 0
180
+ set ::run_test_script [list]
181
+ proc TEST {id t} {lappend ::run_test_script -test [list $id $t]}
182
+ proc PREP {p} {lappend ::run_test_script -prep [string trim $p]}
183
+ proc DEBUG {s} {lappend ::run_test_script -debug $s}
184
+
185
+ # SQL --
186
+ #
187
+ # SQL ?-norollback? <sql-text>
188
+ #
189
+ # Add an 'SQL' primitive to the program (see notes above). If the -norollback
190
+ # switch is present, then the statement is not allowed to automatically roll
191
+ # back any active transaction if malloc() fails. It must rollback the statement
192
+ # transaction only.
193
+ #
194
+ proc SQL {a1 {a2 ""}} {
195
+ # An SQL primitive parameter is a list of three elements, an id, a boolean
196
+ # value indicating if the statement may cause transaction rollback when
197
+ # malloc() fails, and the sql statement itself.
198
+ set id [incr ::run_test_sql_id]
199
+ if {$a2 == ""} {
200
+ lappend ::run_test_script -sql [list $id true [string trim $a1]]
201
+ } else {
202
+ lappend ::run_test_script -sql [list $id false [string trim $a2]]
203
+ }
204
+ }
205
+
206
+ # TEST_AUTOCOMMIT --
207
+ #
208
+ # A shorthand test to see if a transaction is active or not. The first
209
+ # argument - $id - is the integer number of the test case. The second
210
+ # argument is either 1 or 0, the expected value of the auto-commit flag.
211
+ #
212
+ proc TEST_AUTOCOMMIT {id a} {
213
+ TEST $id "do_test \$testid { sqlite3_get_autocommit \$::DB } {$a}"
214
+ }
215
+
216
+ #--------------------------------------------------------------------------
217
+ # Start of test program declaration
218
+ #
219
+
220
+
221
+ # Warm body test. A malloc() fails in the middle of a CREATE TABLE statement
222
+ # in a single-statement transaction on an empty database. Not too much can go
223
+ # wrong here.
224
+ #
225
+ TEST 1 {
226
+ do_test $testid {
227
+ execsql {SELECT tbl_name FROM sqlite_master;}
228
+ } {}
229
+ }
230
+ SQL {
231
+ CREATE TABLE IF NOT EXISTS abc(a, b, c);
232
+ }
233
+ TEST 2 {
234
+ do_test $testid.1 {
235
+ execsql {SELECT tbl_name FROM sqlite_master;}
236
+ } {abc}
237
+ }
238
+
239
+ # Insert a couple of rows into the table. each insert is in its own
240
+ # transaction. test that the table is unpopulated before running the inserts
241
+ # (and hence after each failure of the first insert), and that it has been
242
+ # populated correctly after the final insert succeeds.
243
+ #
244
+ TEST 3 {
245
+ do_test $testid.2 {
246
+ execsql {SELECT * FROM abc}
247
+ } {}
248
+ }
249
+ SQL {INSERT INTO abc VALUES(1, 2, 3);}
250
+ SQL {INSERT INTO abc VALUES(4, 5, 6);}
251
+ SQL {INSERT INTO abc VALUES(7, 8, 9);}
252
+ TEST 4 {
253
+ do_test $testid {
254
+ execsql {SELECT * FROM abc}
255
+ } {1 2 3 4 5 6 7 8 9}
256
+ }
257
+
258
+ # Test a CREATE INDEX statement. Because the table 'abc' is so small, the index
259
+ # will all fit on a single page, so this doesn't test too much that the CREATE
260
+ # TABLE statement didn't test. A few of the transient malloc()s in btree.c
261
+ # perhaps.
262
+ #
263
+ SQL {CREATE INDEX abc_i ON abc(a, b, c);}
264
+ TEST 4 {
265
+ do_test $testid {
266
+ execsql {
267
+ SELECT * FROM abc ORDER BY a DESC;
268
+ }
269
+ } {7 8 9 4 5 6 1 2 3}
270
+ }
271
+
272
+ # Test a DELETE statement. Also create a trigger and a view, just to make sure
273
+ # these statements don't have any obvious malloc() related bugs in them. Note
274
+ # that the test above will be executed each time the DELETE fails, so we're
275
+ # also testing rollback of a DELETE from a table with an index on it.
276
+ #
277
+ SQL {DELETE FROM abc WHERE a > 2;}
278
+ SQL {CREATE TRIGGER abc_t AFTER INSERT ON abc BEGIN SELECT 'trigger!'; END;}
279
+ SQL {CREATE VIEW abc_v AS SELECT * FROM abc;}
280
+ TEST 5 {
281
+ do_test $testid {
282
+ execsql {
283
+ SELECT name, tbl_name FROM sqlite_master ORDER BY name;
284
+ SELECT * FROM abc;
285
+ }
286
+ } {abc abc abc_i abc abc_t abc abc_v abc_v 1 2 3}
287
+ }
288
+
289
+ set sql {
290
+ BEGIN;DELETE FROM abc;
291
+ }
292
+ for {set i 1} {$i < 100} {incr i} {
293
+ set a $i
294
+ set b "String value $i"
295
+ set c [string repeat X $i]
296
+ append sql "INSERT INTO abc VALUES ($a, '$b', '$c');"
297
+ }
298
+ append sql {COMMIT;}
299
+ PREP $sql
300
+
301
+ SQL {
302
+ DELETE FROM abc WHERE oid IN (SELECT oid FROM abc ORDER BY random() LIMIT 5);
303
+ }
304
+ TEST 6 {
305
+ do_test $testid.1 {
306
+ execsql {SELECT count(*) FROM abc}
307
+ } {94}
308
+ do_test $testid.2 {
309
+ execsql {
310
+ SELECT min(
311
+ (oid == a) AND 'String value ' || a == b AND a == length(c)
312
+ ) FROM abc;
313
+ }
314
+ } {1}
315
+ }
316
+ SQL {
317
+ DELETE FROM abc WHERE oid IN (SELECT oid FROM abc ORDER BY random() LIMIT 5);
318
+ }
319
+ TEST 7 {
320
+ do_test $testid {
321
+ execsql {SELECT count(*) FROM abc}
322
+ } {89}
323
+ do_test $testid {
324
+ execsql {
325
+ SELECT min(
326
+ (oid == a) AND 'String value ' || a == b AND a == length(c)
327
+ ) FROM abc;
328
+ }
329
+ } {1}
330
+ }
331
+ SQL {
332
+ DELETE FROM abc WHERE oid IN (SELECT oid FROM abc ORDER BY random() LIMIT 5);
333
+ }
334
+ TEST 9 {
335
+ do_test $testid {
336
+ execsql {SELECT count(*) FROM abc}
337
+ } {84}
338
+ do_test $testid {
339
+ execsql {
340
+ SELECT min(
341
+ (oid == a) AND 'String value ' || a == b AND a == length(c)
342
+ ) FROM abc;
343
+ }
344
+ } {1}
345
+ }
346
+
347
+ set padding [string repeat X 500]
348
+ PREP [subst {
349
+ DROP TABLE abc;
350
+ CREATE TABLE abc(a PRIMARY KEY, padding, b, c);
351
+ INSERT INTO abc VALUES(0, '$padding', 2, 2);
352
+ INSERT INTO abc VALUES(3, '$padding', 5, 5);
353
+ INSERT INTO abc VALUES(6, '$padding', 8, 8);
354
+ }]
355
+
356
+ TEST 10 {
357
+ do_test $testid {
358
+ execsql {SELECT a, b, c FROM abc}
359
+ } {0 2 2 3 5 5 6 8 8}
360
+ }
361
+
362
+ SQL {BEGIN;}
363
+ SQL {INSERT INTO abc VALUES(9, 'XXXXX', 11, 12);}
364
+ TEST_AUTOCOMMIT 11 0
365
+ SQL -norollback {UPDATE abc SET a = a + 1, c = c + 1;}
366
+ TEST_AUTOCOMMIT 12 0
367
+ SQL {DELETE FROM abc WHERE a = 10;}
368
+ TEST_AUTOCOMMIT 13 0
369
+ SQL {COMMIT;}
370
+
371
+ TEST 14 {
372
+ do_test $testid.1 {
373
+ sqlite3_get_autocommit $::DB
374
+ } {1}
375
+ do_test $testid.2 {
376
+ execsql {SELECT a, b, c FROM abc}
377
+ } {1 2 3 4 5 6 7 8 9}
378
+ }
379
+
380
+ PREP [subst {
381
+ DROP TABLE abc;
382
+ CREATE TABLE abc(a, padding, b, c);
383
+ INSERT INTO abc VALUES(1, '$padding', 2, 3);
384
+ INSERT INTO abc VALUES(4, '$padding', 5, 6);
385
+ INSERT INTO abc VALUES(7, '$padding', 8, 9);
386
+ CREATE INDEX abc_i ON abc(a, padding, b, c);
387
+ }]
388
+
389
+ TEST 15 {
390
+ db eval {PRAGMA cache_size = 10}
391
+ }
392
+
393
+ SQL {BEGIN;}
394
+ SQL -norllbck {INSERT INTO abc (oid, a, padding, b, c) SELECT NULL, * FROM abc}
395
+ TEST 16 {
396
+ do_test $testid {
397
+ execsql {SELECT a, count(*) FROM abc GROUP BY a;}
398
+ } {1 2 4 2 7 2}
399
+ }
400
+ SQL -norllbck {INSERT INTO abc (oid, a, padding, b, c) SELECT NULL, * FROM abc}
401
+ TEST 17 {
402
+ do_test $testid {
403
+ execsql {SELECT a, count(*) FROM abc GROUP BY a;}
404
+ } {1 4 4 4 7 4}
405
+ }
406
+ SQL -norllbck {INSERT INTO abc (oid, a, padding, b, c) SELECT NULL, * FROM abc}
407
+ TEST 18 {
408
+ do_test $testid {
409
+ execsql {SELECT a, count(*) FROM abc GROUP BY a;}
410
+ } {1 8 4 8 7 8}
411
+ }
412
+ SQL -norllbck {INSERT INTO abc (oid, a, padding, b, c) SELECT NULL, * FROM abc}
413
+ TEST 19 {
414
+ do_test $testid {
415
+ execsql {SELECT a, count(*) FROM abc GROUP BY a;}
416
+ } {1 16 4 16 7 16}
417
+ }
418
+ SQL {COMMIT;}
419
+ TEST 21 {
420
+ do_test $testid {
421
+ execsql {SELECT a, count(*) FROM abc GROUP BY a;}
422
+ } {1 16 4 16 7 16}
423
+ }
424
+
425
+ SQL {BEGIN;}
426
+ SQL {DELETE FROM abc WHERE oid %2}
427
+ TEST 22 {
428
+ do_test $testid {
429
+ execsql {SELECT a, count(*) FROM abc GROUP BY a;}
430
+ } {1 8 4 8 7 8}
431
+ }
432
+ SQL {DELETE FROM abc}
433
+ TEST 23 {
434
+ do_test $testid {
435
+ execsql {SELECT * FROM abc}
436
+ } {}
437
+ }
438
+ SQL {ROLLBACK;}
439
+ TEST 24 {
440
+ do_test $testid {
441
+ execsql {SELECT a, count(*) FROM abc GROUP BY a;}
442
+ } {1 16 4 16 7 16}
443
+ }
444
+
445
+ # Test some schema modifications inside of a transaction. These should all
446
+ # cause transaction rollback if they fail. Also query a view, to cover a bit
447
+ # more code.
448
+ #
449
+ PREP {DROP VIEW abc_v;}
450
+ TEST 25 {
451
+ do_test $testid {
452
+ execsql {
453
+ SELECT name, tbl_name FROM sqlite_master;
454
+ }
455
+ } {abc abc abc_i abc}
456
+ }
457
+ SQL {BEGIN;}
458
+ SQL {CREATE TABLE def(d, e, f);}
459
+ SQL {CREATE TABLE ghi(g, h, i);}
460
+ TEST 26 {
461
+ do_test $testid {
462
+ execsql {
463
+ SELECT name, tbl_name FROM sqlite_master;
464
+ }
465
+ } {abc abc abc_i abc def def ghi ghi}
466
+ }
467
+ SQL {CREATE VIEW v1 AS SELECT * FROM def, ghi}
468
+ SQL {CREATE UNIQUE INDEX ghi_i1 ON ghi(g);}
469
+ TEST 27 {
470
+ do_test $testid {
471
+ execsql {
472
+ SELECT name, tbl_name FROM sqlite_master;
473
+ }
474
+ } {abc abc abc_i abc def def ghi ghi v1 v1 ghi_i1 ghi}
475
+ }
476
+ SQL {INSERT INTO def VALUES('a', 'b', 'c')}
477
+ SQL {INSERT INTO def VALUES(1, 2, 3)}
478
+ SQL -norollback {INSERT INTO ghi SELECT * FROM def}
479
+ TEST 28 {
480
+ do_test $testid {
481
+ execsql {
482
+ SELECT * FROM def, ghi WHERE d = g;
483
+ }
484
+ } {a b c a b c 1 2 3 1 2 3}
485
+ }
486
+ SQL {COMMIT}
487
+ TEST 29 {
488
+ do_test $testid {
489
+ execsql {
490
+ SELECT * FROM v1 WHERE d = g;
491
+ }
492
+ } {a b c a b c 1 2 3 1 2 3}
493
+ }
494
+
495
+ # Test a simple multi-file transaction
496
+ #
497
+ forcedelete test2.db
498
+ ifcapable attach {
499
+ SQL {ATTACH 'test2.db' AS aux;}
500
+ SQL {BEGIN}
501
+ SQL {CREATE TABLE aux.tbl2(x, y, z)}
502
+ SQL {INSERT INTO tbl2 VALUES(1, 2, 3)}
503
+ SQL {INSERT INTO def VALUES(4, 5, 6)}
504
+ TEST 30 {
505
+ do_test $testid {
506
+ execsql {
507
+ SELECT * FROM tbl2, def WHERE d = x;
508
+ }
509
+ } {1 2 3 1 2 3}
510
+ }
511
+ SQL {COMMIT}
512
+ TEST 31 {
513
+ do_test $testid {
514
+ execsql {
515
+ SELECT * FROM tbl2, def WHERE d = x;
516
+ }
517
+ } {1 2 3 1 2 3}
518
+ }
519
+ }
520
+
521
+ # Test what happens when a malloc() fails while there are other active
522
+ # statements. This changes the way sqlite3VdbeHalt() works.
523
+ TEST 32 {
524
+ if {![info exists ::STMT32]} {
525
+ set sql "SELECT name FROM sqlite_master"
526
+ set ::STMT32 [sqlite3_prepare $::DB $sql -1 DUMMY]
527
+ do_test $testid {
528
+ sqlite3_step $::STMT32
529
+ } {SQLITE_ROW}
530
+ }
531
+ }
532
+ SQL BEGIN
533
+ TEST 33 {
534
+ do_test $testid {
535
+ execsql {SELECT * FROM ghi}
536
+ } {a b c 1 2 3}
537
+ }
538
+ SQL -norollback {
539
+ -- There is a unique index on ghi(g), so this statement may not cause
540
+ -- an automatic ROLLBACK. Hence the "-norollback" switch.
541
+ INSERT INTO ghi SELECT '2'||g, h, i FROM ghi;
542
+ }
543
+ TEST 34 {
544
+ if {[info exists ::STMT32]} {
545
+ do_test $testid {
546
+ sqlite3_finalize $::STMT32
547
+ } {SQLITE_OK}
548
+ unset ::STMT32
549
+ }
550
+ }
551
+ SQL COMMIT
552
+
553
+ #
554
+ # End of test program declaration
555
+ #--------------------------------------------------------------------------
556
+
557
+ proc run_test {arglist iRepeat {pcstart 0} {iFailStart 1}} {
558
+ if {[llength $arglist] %2} {
559
+ error "Uneven number of arguments to TEST"
560
+ }
561
+
562
+ for {set i 0} {$i < $pcstart} {incr i} {
563
+ set k2 [lindex $arglist [expr {2 * $i}]]
564
+ set v2 [lindex $arglist [expr {2 * $i + 1}]]
565
+ set ac [sqlite3_get_autocommit $::DB] ;# Auto-Commit
566
+ switch -- $k2 {
567
+ -sql {db eval [lindex $v2 2]}
568
+ -prep {db eval $v2}
569
+ -debug {eval $v2}
570
+ }
571
+ set nac [sqlite3_get_autocommit $::DB] ;# New Auto-Commit
572
+ if {$ac && !$nac} {set begin_pc $i}
573
+ }
574
+
575
+ db rollback_hook [list incr ::rollback_hook_count]
576
+
577
+ set iFail $iFailStart
578
+ set pc $pcstart
579
+ while {$pc*2 < [llength $arglist]} {
580
+ # Fetch the current instruction type and payload.
581
+ set k [lindex $arglist [expr {2 * $pc}]]
582
+ set v [lindex $arglist [expr {2 * $pc + 1}]]
583
+
584
+ # Id of this iteration:
585
+ set iterid "pc=$pc.iFail=$iFail$k"
586
+
587
+ switch -- $k {
588
+
589
+ -test {
590
+ foreach {id script} $v {}
591
+ set testid "malloc3-(test $id).$iterid"
592
+ eval $script
593
+ incr pc
594
+ }
595
+
596
+ -sql {
597
+ set ::rollback_hook_count 0
598
+
599
+ set id [lindex $v 0]
600
+ set testid "malloc3-(integrity $id).$iterid"
601
+
602
+ set ac [sqlite3_get_autocommit $::DB] ;# Auto-Commit
603
+ sqlite3_memdebug_fail $iFail -repeat 0
604
+ set rc [catch {db eval [lindex $v 2]} msg] ;# True error occurs
605
+ set nac [sqlite3_get_autocommit $::DB] ;# New Auto-Commit
606
+
607
+ if {$rc != 0 && $nac && !$ac} {
608
+ # Before [db eval] the auto-commit flag was clear. Now it
609
+ # is set. Since an error occurred we assume this was not a
610
+ # commit - therefore a rollback occurred. Check that the
611
+ # rollback-hook was invoked.
612
+ do_test malloc3-rollback_hook_count.$iterid {
613
+ set ::rollback_hook_count
614
+ } {1}
615
+ }
616
+
617
+ set nFail [sqlite3_memdebug_fail -1 -benigncnt nBenign]
618
+ if {$rc == 0} {
619
+ # Successful execution of sql. The number of failed malloc()
620
+ # calls should be equal to the number of benign failures.
621
+ # Otherwise a malloc() failed and the error was not reported.
622
+ #
623
+ set expr {$nFail!=$nBenign}
624
+ if {[expr $expr]} {
625
+ error "Unreported malloc() failure, test \"$testid\", $expr"
626
+ }
627
+
628
+ if {$ac && !$nac} {
629
+ # Before the [db eval] the auto-commit flag was set, now it
630
+ # is clear. We can deduce that a "BEGIN" statement has just
631
+ # been successfully executed.
632
+ set begin_pc $pc
633
+ }
634
+
635
+ incr pc
636
+ set iFail 1
637
+ integrity_check $testid
638
+ } elseif {[regexp {.*out of memory} $msg] || [db errorcode] == 3082} {
639
+ # Out of memory error, as expected.
640
+ #
641
+ integrity_check $testid
642
+ incr iFail
643
+ if {$nac && !$ac} {
644
+ if {![lindex $v 1] && [db errorcode] != 3082} {
645
+ # error "Statement \"[lindex $v 2]\" caused a rollback"
646
+ }
647
+
648
+ for {set i $begin_pc} {$i < $pc} {incr i} {
649
+ set k2 [lindex $arglist [expr {2 * $i}]]
650
+ set v2 [lindex $arglist [expr {2 * $i + 1}]]
651
+ set catchupsql ""
652
+ switch -- $k2 {
653
+ -sql {set catchupsql [lindex $v2 2]}
654
+ -prep {set catchupsql $v2}
655
+ }
656
+ db eval $catchupsql
657
+ }
658
+ }
659
+ } else {
660
+ error $msg
661
+ }
662
+
663
+ # back up to the previous "-test" block.
664
+ while {[lindex $arglist [expr {2 * ($pc - 1)}]] == "-test"} {
665
+ incr pc -1
666
+ }
667
+ }
668
+
669
+ -prep {
670
+ db eval $v
671
+ incr pc
672
+ }
673
+
674
+ -debug {
675
+ eval $v
676
+ incr pc
677
+ }
678
+
679
+ default { error "Unknown switch: $k" }
680
+ }
681
+ }
682
+ }
683
+
684
+ # Turn off the Tcl interface's prepared statement caching facility. Then
685
+ # run the tests with "persistent" malloc failures.
686
+ sqlite3_extended_result_codes db 1
687
+ db cache size 0
688
+ run_test $::run_test_script 1
689
+
690
+ # Close and reopen the db.
691
+ db close
692
+ forcedelete test.db test.db-journal test2.db test2.db-journal
693
+ sqlite3 db test.db
694
+ sqlite3_extended_result_codes db 1
695
+ set ::DB [sqlite3_connection_pointer db]
696
+
697
+ # Turn off the Tcl interface's prepared statement caching facility in
698
+ # the new connnection. Then run the tests with "transient" malloc failures.
699
+ db cache size 0
700
+ run_test $::run_test_script 0
701
+
702
+ sqlite3_memdebug_fail -1
703
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/mallocG.test ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2007 Aug 29
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # This test script checks malloc failures in various obscure operations.
13
+ #
14
+ # $Id: mallocG.test,v 1.5 2008/08/01 18:47:02 drh Exp $
15
+
16
+ set testdir [file dirname $argv0]
17
+ source $testdir/tester.tcl
18
+ source $testdir/malloc_common.tcl
19
+
20
+ # Only run these tests if memory debugging is turned on.
21
+ #
22
+ if {!$MEMDEBUG} {
23
+ puts "Skipping mallocG tests: not compiled with -DSQLITE_MEMDEBUG..."
24
+ finish_test
25
+ return
26
+ }
27
+
28
+ # Malloc failures while opening a database connection.
29
+ #
30
+ do_malloc_test mallocG-1 -tclbody {
31
+ db close
32
+ sqlite3 db test.db
33
+ }
34
+
35
+ do_malloc_test mallocG-2 -sqlprep {
36
+ CREATE TABLE t1(x, y);
37
+ CREATE TABLE t2(x INTEGER PRIMARY KEY);
38
+ } -sqlbody {
39
+ SELECT y FROM t1 WHERE x IN t2;
40
+ }
41
+
42
+ do_malloc_test mallocG-3 -sqlprep {
43
+ CREATE TABLE t1(x UNIQUE);
44
+ INSERT INTO t1 VALUES ('hello');
45
+ INSERT INTO t1 VALUES ('out there');
46
+ } -sqlbody {
47
+ SELECT * FROM t1
48
+ WHERE x BETWEEN 'a' AND 'z'
49
+ AND x BETWEEN 'c' AND 'w'
50
+ AND x BETWEEN 'e' AND 'u'
51
+ AND x BETWEEN 'g' AND 'r'
52
+ AND x BETWEEN 'i' AND 'q'
53
+ AND x BETWEEN 'i' AND 'm'
54
+ }
55
+
56
+ ifcapable !utf16 {
57
+ finish_test
58
+ return
59
+ }
60
+
61
+ proc utf16 {utf8} {
62
+ set utf16 [encoding convertto unicode $utf8]
63
+ append utf16 "\x00\x00"
64
+ return $utf16
65
+ }
66
+
67
+ do_malloc_test mallocG-4 -tclbody {
68
+ set rc [sqlite3_complete16 [utf16 "SELECT * FROM t1;"]]
69
+ if {$rc==1} {set rc 0} {error "out of memory"}
70
+ set rc
71
+ }
72
+
73
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/notify3.test ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2010 June 30
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library. The
12
+ # focus of this file is testing the sqlite3_unlock_notify() API.
13
+ #
14
+
15
+ set testdir [file dirname $argv0]
16
+ source $testdir/tester.tcl
17
+
18
+ # This script only runs if shared-cache and unlock-notify are available.
19
+ #
20
+ ifcapable !unlock_notify||!shared_cache {
21
+ finish_test
22
+ return
23
+ }
24
+
25
+ set esc [sqlite3_enable_shared_cache 1]
26
+
27
+ sqlite3 db test.db
28
+ forcedelete test.db2 test.db2-journal test.db2-wal
29
+ sqlite3 db2 test.db2
30
+
31
+ do_test notify3-1.1 {
32
+ execsql {
33
+ CREATE TABLE t1(a, b);
34
+ INSERT INTO t1 VALUES('t1 A', 't1 B');
35
+ }
36
+ } {}
37
+ do_test notify3-1.2 {
38
+ execsql {
39
+ CREATE TABLE t2(a, b);
40
+ INSERT INTO t2 VALUES('t2 A', 't2 B');
41
+ } db2
42
+ } {}
43
+
44
+ do_test notify3-1.3 {
45
+ execsql {
46
+ BEGIN EXCLUSIVE;
47
+ INSERT INTO t2 VALUES('t2 C', 't2 D');
48
+ } db2
49
+ } {}
50
+ do_test notify3-1.4 {
51
+ catchsql { ATTACH 'test.db2' AS aux }
52
+ } {0 {}}
53
+
54
+ do_test notify3-1.5 {
55
+ catchsql { SELECT * FROM t2 }
56
+ } {1 {database schema is locked: aux}}
57
+
58
+ do_test notify3-1.6 {
59
+ list [sqlite3_errcode db] [sqlite3_extended_errcode db]
60
+ } {SQLITE_LOCKED SQLITE_LOCKED_SHAREDCACHE}
61
+
62
+ do_test notify3-1.7 {
63
+ sqlite3_extended_result_codes db 1
64
+ catch { set ::stmt [sqlite3_prepare_v2 db "SELECT * FROM t2" -1 tail] } msg
65
+ set msg
66
+ } {(262) database schema is locked: aux}
67
+
68
+ do_test notify3-1.8 {
69
+ set ::when 1
70
+ db unlock_notify { set ::res $::when }
71
+ set ::when 2
72
+ execsql { COMMIT } db2
73
+ set ::res
74
+ } {2}
75
+ do_test notify3-1.9 {
76
+ catchsql { SELECT * FROM t2 }
77
+ } {0 {{t2 A} {t2 B} {t2 C} {t2 D}}}
78
+ db close
79
+
80
+
81
+ set err {{1 {unable to open database: test.db2}}}
82
+ set noerr {{0 {}}}
83
+
84
+ # When a new database is attached, the connection doing the attaching
85
+ # tries to load any unloaded schemas for both the new database and any
86
+ # already attached databases (including the main database). If it is
87
+ # unable to load any such schemas, then the ATTACH statement fails.
88
+ #
89
+ # This block tests that if the loading of schemas as a result of an
90
+ # ATTACH fails due to locks on the schema table held by other shared-cache
91
+ # connections the extended error code is SQLITE_LOCKED_SHAREDCACHE and
92
+ # it is possible to use the unlock-notify mechanism to determine when
93
+ # the ATTACH might succeed.
94
+ #
95
+ # This test does not work for test-permutations that specify SQL to
96
+ # be executed as part of the [sqlite3] command that opens the database.
97
+ # Executing such SQL causes SQLite to load the database schema into memory
98
+ # earlier than expected, causing test cases to fail.
99
+ #
100
+ if {[presql] == ""} {
101
+ foreach {
102
+ tn
103
+ db1_loaded
104
+ db2_loaded
105
+ enable_extended_errors
106
+ result
107
+ error1 error2
108
+ } "
109
+ 0 0 0 0 $err SQLITE_LOCKED SQLITE_LOCKED_SHAREDCACHE
110
+ 1 0 0 1 $err SQLITE_LOCKED_SHAREDCACHE SQLITE_LOCKED_SHAREDCACHE
111
+ 2 0 1 0 $noerr SQLITE_OK SQLITE_OK
112
+ 3 0 1 1 $noerr SQLITE_OK SQLITE_OK
113
+ 4 1 0 0 $err SQLITE_LOCKED SQLITE_LOCKED_SHAREDCACHE
114
+ 5 1 0 1 $err SQLITE_LOCKED_SHAREDCACHE SQLITE_LOCKED_SHAREDCACHE
115
+ 6 1 1 0 $noerr SQLITE_OK SQLITE_OK
116
+ 7 1 1 1 $noerr SQLITE_OK SQLITE_OK
117
+ " {
118
+
119
+ do_test notify3-2.$tn.1 {
120
+ catch { db1 close }
121
+ catch { db2 close }
122
+ sqlite3 db1 test.db
123
+ sqlite3 db2 test.db2
124
+
125
+ sqlite3_extended_result_codes db1 $enable_extended_errors
126
+ sqlite3_extended_result_codes db2 $enable_extended_errors
127
+
128
+ if { $db1_loaded } { db1 eval "SELECT * FROM sqlite_master" }
129
+ if { $db2_loaded } { db2 eval "SELECT * FROM sqlite_master" }
130
+
131
+ db2 eval "BEGIN EXCLUSIVE"
132
+ catchsql "ATTACH 'test.db2' AS two" db1
133
+ } $result
134
+
135
+ do_test notify3-2.$tn.2 {
136
+ list [sqlite3_errcode db1] [sqlite3_extended_errcode db1]
137
+ } [list $error1 $error2]
138
+
139
+ do_test notify3-2.$tn.3 {
140
+ db1 unlock_notify {set invoked 1}
141
+ set invoked 0
142
+ db2 eval commit
143
+ set invoked
144
+ } [lindex $result 0]
145
+ }
146
+ }
147
+ catch { db1 close }
148
+ catch { db2 close }
149
+
150
+
151
+ sqlite3_enable_shared_cache $esc
152
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/offset1.test ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2015-10-06
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # This file implements test cases for the [b65cb2c8d91f6685841d7d1e13b6]
13
+ # bug: Correct handling of LIMIT and OFFSET on a UNION ALL query where
14
+ # the right-hand SELECT contains an ORDER BY in a subquery.
15
+ #
16
+
17
+ set testdir [file dirname $argv0]
18
+ source $testdir/tester.tcl
19
+
20
+ ifcapable !compound {
21
+ finish_test
22
+ return
23
+ }
24
+
25
+ do_execsql_test offset1-1.1 {
26
+ CREATE TABLE t1(a,b);
27
+ INSERT INTO t1 VALUES(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e');
28
+ CREATE TABLE t2(x,y);
29
+ INSERT INTO t2 VALUES(8,'y'),(9,'z'),(6,'w'),(7,'x');
30
+ SELECT count(*) FROM t1, t2;
31
+ } {20}
32
+
33
+ do_execsql_test offset1-1.2.0 {
34
+ SELECT a, b FROM t1
35
+ UNION ALL
36
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
37
+ LIMIT 3 OFFSET 0;
38
+ } {1 a 2 b 3 c}
39
+ do_execsql_test offset1-1.2.1 {
40
+ SELECT a, b FROM t1
41
+ UNION ALL
42
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
43
+ LIMIT 3 OFFSET 1;
44
+ } {2 b 3 c 4 d}
45
+ do_execsql_test offset1-1.2.2 {
46
+ SELECT a, b FROM t1
47
+ UNION ALL
48
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
49
+ LIMIT 3 OFFSET 2;
50
+ } {3 c 4 d 5 e}
51
+ do_execsql_test offset1-1.2.3 {
52
+ SELECT a, b FROM t1
53
+ UNION ALL
54
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
55
+ LIMIT 3 OFFSET 3;
56
+ } {4 d 5 e 6 w}
57
+ do_execsql_test offset1-1.2.4 {
58
+ SELECT a, b FROM t1
59
+ UNION ALL
60
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
61
+ LIMIT 3 OFFSET 4;
62
+ } {5 e 6 w 7 x}
63
+ do_execsql_test offset1-1.2.5 {
64
+ SELECT a, b FROM t1
65
+ UNION ALL
66
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
67
+ LIMIT 3 OFFSET 5;
68
+ } {6 w 7 x 8 y}
69
+ do_execsql_test offset1-1.2.6 {
70
+ SELECT a, b FROM t1
71
+ UNION ALL
72
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
73
+ LIMIT 3 OFFSET 6;
74
+ } {7 x 8 y 9 z}
75
+ do_execsql_test offset1-1.2.7 {
76
+ SELECT a, b FROM t1
77
+ UNION ALL
78
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
79
+ LIMIT 3 OFFSET 7;
80
+ } {8 y 9 z}
81
+ do_execsql_test offset1-1.2.8 {
82
+ SELECT a, b FROM t1
83
+ UNION ALL
84
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
85
+ LIMIT 3 OFFSET 8;
86
+ } {9 z}
87
+ do_execsql_test offset1-1.2.9 {
88
+ SELECT a, b FROM t1
89
+ UNION ALL
90
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
91
+ LIMIT 3 OFFSET 9;
92
+ } {}
93
+
94
+ do_execsql_test offset1-1.3.0 {
95
+ SELECT * FROM t1 LIMIT 0;
96
+ } {}
97
+
98
+ do_execsql_test offset1-1.4.0 {
99
+ SELECT a, b FROM t1
100
+ UNION ALL
101
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
102
+ LIMIT 0 OFFSET 1;
103
+ } {}
104
+ do_execsql_test offset1-1.4.1 {
105
+ SELECT a, b FROM t1
106
+ UNION ALL
107
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
108
+ LIMIT 1 OFFSET 1;
109
+ } {2 b}
110
+ do_execsql_test offset1-1.4.2 {
111
+ SELECT a, b FROM t1
112
+ UNION ALL
113
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
114
+ LIMIT 2 OFFSET 1;
115
+ } {2 b 3 c}
116
+ do_execsql_test offset1-1.4.3 {
117
+ SELECT a, b FROM t1
118
+ UNION ALL
119
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
120
+ LIMIT 3 OFFSET 1;
121
+ } {2 b 3 c 4 d}
122
+ do_execsql_test offset1-1.4.4 {
123
+ SELECT a, b FROM t1
124
+ UNION ALL
125
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
126
+ LIMIT 4 OFFSET 1;
127
+ } {2 b 3 c 4 d 5 e}
128
+ do_execsql_test offset1-1.4.5 {
129
+ SELECT a, b FROM t1
130
+ UNION ALL
131
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
132
+ LIMIT 5 OFFSET 1;
133
+ } {2 b 3 c 4 d 5 e 6 w}
134
+ do_execsql_test offset1-1.4.6 {
135
+ SELECT a, b FROM t1
136
+ UNION ALL
137
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
138
+ LIMIT 6 OFFSET 1;
139
+ } {2 b 3 c 4 d 5 e 6 w 7 x}
140
+ do_execsql_test offset1-1.4.7 {
141
+ SELECT a, b FROM t1
142
+ UNION ALL
143
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
144
+ LIMIT 7 OFFSET 1;
145
+ } {2 b 3 c 4 d 5 e 6 w 7 x 8 y}
146
+ do_execsql_test offset1-1.4.8 {
147
+ SELECT a, b FROM t1
148
+ UNION ALL
149
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
150
+ LIMIT 8 OFFSET 1;
151
+ } {2 b 3 c 4 d 5 e 6 w 7 x 8 y 9 z}
152
+ do_execsql_test offset1-1.4.9 {
153
+ SELECT a, b FROM t1
154
+ UNION ALL
155
+ SELECT * FROM (SELECT x, y FROM t2 ORDER BY y)
156
+ LIMIT 9 OFFSET 1;
157
+ } {2 b 3 c 4 d 5 e 6 w 7 x 8 y 9 z}
158
+
159
+ # 2022-08-04
160
+ # https://sqlite.org/forum/forumpost/6b5e9188f0657616
161
+ #
162
+ do_execsql_test offset1-2.0 {
163
+ CREATE TABLE employees (
164
+ id integer primary key,
165
+ name text,
166
+ city text,
167
+ department text,
168
+ salary integer
169
+ );
170
+ INSERT INTO employees VALUES
171
+ (11,'Diane','London','hr',70),
172
+ (12,'Bob','London','hr',78),
173
+ (21,'Emma','London','it',84),
174
+ (22,'Grace','Berlin','it',90),
175
+ (23,'Henry','London','it',104),
176
+ (24,'Irene','Berlin','it',104),
177
+ (25,'Frank','Berlin','it',120),
178
+ (31,'Cindy','Berlin','sales',96),
179
+ (32,'Dave','London','sales',96),
180
+ (33,'Alice','Berlin','sales',100);
181
+ CREATE VIEW v AS
182
+ SELECT * FROM (
183
+ SELECT * FROM employees
184
+ WHERE salary < 100
185
+ ORDER BY salary desc)
186
+ UNION ALL
187
+ SELECT * FROM (
188
+ SELECT * FROM employees
189
+ WHERE salary >= 100
190
+ ORDER BY salary asc);
191
+ } {}
192
+ do_execsql_test offset1-2.1 {
193
+ SELECT * FROM v LIMIT 5 OFFSET 2;
194
+ } {
195
+ 22 Grace Berlin it 90
196
+ 21 Emma London it 84
197
+ 12 Bob London hr 78
198
+ 11 Diane London hr 70
199
+ 33 Alice Berlin sales 100
200
+ }
201
+
202
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/pcache.test ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2008 August 29
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ #
12
+ # This file is focused on testing the pcache module.
13
+ #
14
+ # $Id: pcache.test,v 1.5 2009/05/08 06:52:48 danielk1977 Exp $
15
+
16
+ set testdir [file dirname $argv0]
17
+ source $testdir/tester.tcl
18
+
19
+ # Do not use a codec for tests in this file, as the database file is
20
+ # manipulated directly using tcl scripts (using the [hexio_write] command).
21
+ #
22
+ do_not_use_codec
23
+
24
+ # Only works with a mode-2 pcache where all pcaches share a single set
25
+ # of pages.
26
+ #
27
+ ifcapable {!memorymanage && threadsafe} {
28
+ finish_test
29
+ return
30
+ }
31
+
32
+ # The pcache module limits the number of pages available to purgeable
33
+ # caches to the sum of the 'cache_size' values for the set of open
34
+ # caches. This block of tests, pcache-1.*, test that the library behaves
35
+ # corrctly when it is forced to exceed this limit.
36
+ #
37
+ do_test pcache-1.1 {
38
+ db close
39
+ pcache_stats
40
+ } {current 0 max 0 min 0 recyclable 0}
41
+
42
+ do_test pcache-1.2 {
43
+ sqlite3 db test.db
44
+ execsql {
45
+ PRAGMA cache_size=12;
46
+ PRAGMA auto_vacuum=0;
47
+ PRAGMA mmap_size=0;
48
+ }
49
+ pcache_stats
50
+ } {current 1 max 12 min 10 recyclable 1}
51
+
52
+ do_test pcache-1.3 {
53
+ execsql {
54
+ BEGIN;
55
+ CREATE TABLE t1(a, b, c);
56
+ CREATE TABLE t2(a, b, c);
57
+ CREATE TABLE t3(a, b, c);
58
+ CREATE TABLE t4(a, b, c);
59
+ CREATE TABLE t5(a, b, c);
60
+ }
61
+ pcache_stats
62
+ } {current 6 max 12 min 10 recyclable 0}
63
+
64
+ do_test pcache-1.4 {
65
+ execsql {
66
+ CREATE TABLE t6(a, b, c);
67
+ CREATE TABLE t7(a, b, c);
68
+ CREATE TABLE t8(a, b, c);
69
+ CREATE TABLE t9(a, b, c);
70
+ }
71
+ pcache_stats
72
+ } {current 10 max 12 min 10 recyclable 0}
73
+
74
+ do_test pcache-1.5 {
75
+ sqlite3 db2 test.db
76
+ execsql "PRAGMA cache_size; PRAGMA cache_size=10" db2
77
+ pcache_stats
78
+ } {current 11 max 22 min 20 recyclable 1}
79
+
80
+ do_test pcache-1.6.1 {
81
+ execsql {
82
+ BEGIN;
83
+ SELECT * FROM sqlite_master;
84
+ } db2
85
+ pcache_stats
86
+ } {current 11 max 22 min 20 recyclable 0}
87
+
88
+ # At this point connection db2 has a read lock on the database file and a
89
+ # single pinned page in its cache. Connection [db] is holding 10 dirty
90
+ # pages. It cannot recycle them because of the read lock held by db2.
91
+ #
92
+ do_test pcache-1.6.2 {
93
+ execsql {
94
+ CREATE INDEX i1 ON t1(a, b);
95
+ CREATE INDEX i2 ON t2(a, b);
96
+ CREATE INDEX i3 ON t3(a, b);
97
+ CREATE INDEX i4 ON t4(a, b);
98
+ CREATE INDEX i5 ON t5(a, b);
99
+ CREATE INDEX i6 ON t6(a, b);
100
+ CREATE INDEX i7 ON t7(a, b);
101
+ CREATE INDEX i8 ON t8(a, b);
102
+ CREATE INDEX i9 ON t9(a, b);
103
+ CREATE INDEX i10 ON t9(a, b);
104
+ CREATE INDEX i11 ON t9(a, b);
105
+ }
106
+ pcache_stats
107
+ } {current 23 max 22 min 20 recyclable 0}
108
+
109
+ do_test pcache-1.7 {
110
+ execsql {
111
+ CREATE TABLE t10(a, b, c);
112
+ }
113
+ pcache_stats
114
+ } {current 24 max 22 min 20 recyclable 0}
115
+
116
+ # Rolling back the transaction held by db2 at this point releases a pinned
117
+ # page. Because the number of allocated pages is greater than the
118
+ # configured maximum, this page should be freed immediately instead of
119
+ # recycled.
120
+ #
121
+ do_test pcache-1.8 {
122
+ execsql {ROLLBACK} db2
123
+ pcache_stats
124
+ } {current 23 max 22 min 20 recyclable 0}
125
+
126
+ do_test pcache-1.9 {
127
+ execsql COMMIT
128
+ pcache_stats
129
+ } {current 22 max 22 min 20 recyclable 22}
130
+
131
+ do_test pcache-1.10 {
132
+ db2 close
133
+ pcache_stats
134
+ } {current 12 max 12 min 10 recyclable 12}
135
+
136
+ do_test pcache-1.11 {
137
+ execsql { PRAGMA cache_size = 20 }
138
+ pcache_stats
139
+ } {current 12 max 20 min 10 recyclable 12}
140
+
141
+ do_test pcache-1.12 {
142
+ execsql {
143
+ SELECT * FROM t1 ORDER BY a; SELECT * FROM t1;
144
+ SELECT * FROM t2 ORDER BY a; SELECT * FROM t2;
145
+ SELECT * FROM t3 ORDER BY a; SELECT * FROM t3;
146
+ SELECT * FROM t4 ORDER BY a; SELECT * FROM t4;
147
+ SELECT * FROM t5 ORDER BY a; SELECT * FROM t5;
148
+ SELECT * FROM t6 ORDER BY a; SELECT * FROM t6;
149
+ SELECT * FROM t7 ORDER BY a; SELECT * FROM t7;
150
+ SELECT * FROM t8 ORDER BY a; SELECT * FROM t8;
151
+ SELECT * FROM t9 ORDER BY a; SELECT * FROM t9;
152
+ }
153
+ pcache_stats
154
+ } {current 19 max 20 min 10 recyclable 19}
155
+
156
+ do_test pcache-1.13 {
157
+ execsql { PRAGMA cache_size = 15 }
158
+ pcache_stats
159
+ } {current 15 max 15 min 10 recyclable 15}
160
+
161
+ do_test pcache-1.14 {
162
+ hexio_write test.db 24 [hexio_render_int32 1000]
163
+ execsql { SELECT * FROM sqlite_master }
164
+ pcache_stats
165
+ } {current 2 max 15 min 10 recyclable 2}
166
+
167
+ do_test pcache-1.15 {
168
+ execsql {
169
+ SELECT * FROM t1 ORDER BY a; SELECT * FROM t1;
170
+ SELECT * FROM t2 ORDER BY a; SELECT * FROM t2;
171
+ SELECT * FROM t3 ORDER BY a; SELECT * FROM t3;
172
+ SELECT * FROM t4 ORDER BY a; SELECT * FROM t4;
173
+ SELECT * FROM t5 ORDER BY a; SELECT * FROM t5;
174
+ SELECT * FROM t6 ORDER BY a; SELECT * FROM t6;
175
+ SELECT * FROM t7 ORDER BY a; SELECT * FROM t7;
176
+ SELECT * FROM t8 ORDER BY a; SELECT * FROM t8;
177
+ SELECT * FROM t9 ORDER BY a; SELECT * FROM t9;
178
+ }
179
+ pcache_stats
180
+ } {current 14 max 15 min 10 recyclable 14}
181
+
182
+ finish_test
local-test-sqlite3-delta-03/afc-sqlite3/test/pragma5.test ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2017 August 25
2
+ #
3
+ # The author disclaims copyright to this source code. In place of
4
+ # a legal notice, here is a blessing:
5
+ #
6
+ # May you do good and not evil.
7
+ # May you find forgiveness for yourself and forgive others.
8
+ # May you share freely, never taking more than you give.
9
+ #
10
+ #***********************************************************************
11
+ # This file implements regression tests for SQLite library.
12
+ #
13
+ # This file implements tests for the PRAGMA command. Specifically,
14
+ # those pragmas that are not disabled at build time by setting:
15
+ #
16
+ # -DSQLITE_OMIT_INTROSPECTION_PRAGMAS
17
+ #
18
+
19
+ set testdir [file dirname $argv0]
20
+ source $testdir/tester.tcl
21
+ set testprefix pragma5
22
+
23
+ if { [catch {db one "SELECT count(*) FROM pragma_function_list"}] } {
24
+ finish_test
25
+ return
26
+ }
27
+
28
+ db function external external
29
+
30
+ do_execsql_test 1.0 {
31
+ PRAGMA table_info(pragma_function_list)
32
+ } {
33
+ 0 name {} 0 {} 0
34
+ 1 builtin {} 0 {} 0
35
+ 2 type {} 0 {} 0
36
+ 3 enc {} 0 {} 0
37
+ 4 narg {} 0 {} 0
38
+ 5 flags {} 0 {} 0
39
+ }
40
+ do_execsql_test 1.1 {
41
+ SELECT DISTINCT name, builtin
42
+ FROM pragma_function_list WHERE name='upper' AND builtin
43
+ } {upper 1}
44
+ do_execsql_test 1.2 {
45
+ SELECT DISTINCT name, builtin
46
+ FROM pragma_function_list WHERE name LIKE 'exter%';
47
+ } {external 0}
48
+
49
+ ifcapable fts5 {
50
+ do_execsql_test 2.0 {
51
+ PRAGMA table_info(pragma_module_list)
52
+ } {
53
+ 0 name {} 0 {} 0
54
+ }
55
+ do_execsql_test 2.1 {
56
+ SELECT * FROM pragma_module_list WHERE name='fts5'
57
+ } {fts5}
58
+ }
59
+
60
+ do_execsql_test 3.0 {
61
+ PRAGMA table_info(pragma_pragma_list)
62
+ } {
63
+ 0 name {} 0 {} 0
64
+ }
65
+ do_execsql_test 3.1 {
66
+ SELECT * FROM pragma_pragma_list WHERE name='pragma_list'
67
+ } {pragma_list}
68
+
69
+
70
+ finish_test