3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # Use tables to test leaf-node reading, and also type checking.
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # A really basic table with manifest typing and a row of each type.
24 DROP TABLE IF EXISTS types;
25 CREATE TABLE types (rowtype TEXT, value);
26 INSERT INTO types VALUES ("NULL", NULL);
27 INSERT INTO types VALUES ("INTEGER", 17);
28 INSERT INTO types VALUES ("FLOAT", 3.1415927);
29 INSERT INTO types VALUES ("TEXT", "This is text");
30 INSERT INTO types VALUES ("BLOB", CAST("This is a blob" AS BLOB));
32 -- Same contents, with an alias for rowid. Testing separately
33 -- because it changes the structure of the data (the alias column is
34 -- serialized as NULL).
35 DROP TABLE IF EXISTS types2;
36 CREATE TABLE types2 (id INTEGER PRIMARY KEY, rowtype TEXT, value);
37 INSERT INTO types2 (id, rowtype, value)
38 SELECT rowid, rowtype, value FROM types;
42 do_test recover-types-0.0 {
43 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types}
44 } {1 NULL {} null 2 INTEGER 17 integer 3 FLOAT 3.1415927 real 4 TEXT {This is text} text 5 BLOB {This is a blob} blob}
46 # With no restrictions, recover table shows identical results.
47 do_test recover-types-0.1 {
49 DROP TABLE IF EXISTS temp.types_recover;
50 CREATE VIRTUAL TABLE temp.types_recover USING recover(
56 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
57 } {1 NULL {} null 2 INTEGER 17 integer 3 FLOAT 3.1415927 real 4 TEXT {This is text} text 5 BLOB {This is a blob} blob}
60 do_test recover-types-1.0 {
62 DROP TABLE IF EXISTS temp.types_recover;
63 CREATE VIRTUAL TABLE temp.types_recover USING recover(
69 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
70 } {1 NULL {} null 2 INTEGER 17 integer}
72 # Restrict by INTEGER NOT NULL
73 do_test recover-types-1.1 {
75 DROP TABLE IF EXISTS temp.types_recover;
76 CREATE VIRTUAL TABLE temp.types_recover USING recover(
79 value INTEGER NOT NULL
82 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
83 } {2 INTEGER 17 integer}
86 do_test recover-types-2.0 {
88 DROP TABLE IF EXISTS temp.types_recover;
89 CREATE VIRTUAL TABLE temp.types_recover USING recover(
95 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
96 } {1 NULL {} null 2 INTEGER 17.0 real 3 FLOAT 3.1415927 real}
98 # Restrict by FLOAT NOT NULL
99 do_test recover-types-2.1 {
101 DROP TABLE IF EXISTS temp.types_recover;
102 CREATE VIRTUAL TABLE temp.types_recover USING recover(
108 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
109 } {2 INTEGER 17.0 real 3 FLOAT 3.1415927 real}
111 # Restrict by FLOAT STRICT
112 do_test recover-types-2.2 {
114 DROP TABLE IF EXISTS temp.types_recover;
115 CREATE VIRTUAL TABLE temp.types_recover USING recover(
121 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
122 } {1 NULL {} null 3 FLOAT 3.1415927 real}
124 # Restrict by FLOAT STRICT NOT NULL
125 do_test recover-types-2.3 {
127 DROP TABLE IF EXISTS temp.types_recover;
128 CREATE VIRTUAL TABLE temp.types_recover USING recover(
131 value FLOAT STRICT NOT NULL
134 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
135 } {3 FLOAT 3.1415927 real}
138 do_test recover-types-3.0 {
140 DROP TABLE IF EXISTS temp.types_recover;
141 CREATE VIRTUAL TABLE temp.types_recover USING recover(
147 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
148 } {1 NULL {} null 4 TEXT {This is text} text 5 BLOB {This is a blob} blob}
150 # Restrict by TEXT NOT NULL
151 do_test recover-types-3.1 {
153 DROP TABLE IF EXISTS temp.types_recover;
154 CREATE VIRTUAL TABLE temp.types_recover USING recover(
160 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
161 } {4 TEXT {This is text} text 5 BLOB {This is a blob} blob}
163 # Restrict by TEXT STRICT
164 do_test recover-types-3.2 {
166 DROP TABLE IF EXISTS temp.types_recover;
167 CREATE VIRTUAL TABLE temp.types_recover USING recover(
173 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
174 } {1 NULL {} null 4 TEXT {This is text} text}
176 # Restrict by TEXT STRICT NOT NULL
177 do_test recover-types-3.3 {
179 DROP TABLE IF EXISTS temp.types_recover;
180 CREATE VIRTUAL TABLE temp.types_recover USING recover(
183 value TEXT STRICT NOT NULL
186 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
187 } {4 TEXT {This is text} text}
190 do_test recover-types-4.0 {
192 DROP TABLE IF EXISTS temp.types_recover;
193 CREATE VIRTUAL TABLE temp.types_recover USING recover(
199 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
200 } {1 NULL {} null 5 BLOB {This is a blob} blob}
202 # Restrict by BLOB NOT NULL
203 do_test recover-types-4.1 {
205 DROP TABLE IF EXISTS temp.types_recover;
206 CREATE VIRTUAL TABLE temp.types_recover USING recover(
212 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
213 } {5 BLOB {This is a blob} blob}
216 do_test recover-types-5.0 {
218 DROP TABLE IF EXISTS temp.types_recover;
219 CREATE VIRTUAL TABLE temp.types_recover USING recover(
225 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
226 } {1 NULL {} null 2 INTEGER 17 integer 3 FLOAT 3.1415927 real 4 TEXT {This is text} text 5 BLOB {This is a blob} blob}
228 # Should get same results specifying manifest typing explicitly.
229 do_test recover-types-5.1 {
231 DROP TABLE IF EXISTS temp.types_recover;
232 CREATE VIRTUAL TABLE temp.types_recover USING recover(
238 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
239 } {1 NULL {} null 2 INTEGER 17 integer 3 FLOAT 3.1415927 real 4 TEXT {This is text} text 5 BLOB {This is a blob} blob}
241 # Same results, skipping the NULL row.
242 do_test recover-types-5.2 {
244 DROP TABLE IF EXISTS temp.types_recover;
245 CREATE VIRTUAL TABLE temp.types_recover USING recover(
251 execsql {SELECT rowid, rowtype, value, TYPEOF(value) FROM types_recover}
252 } {2 INTEGER 17 integer 3 FLOAT 3.1415927 real 4 TEXT {This is text} text 5 BLOB {This is a blob} blob}
255 do_test recover-types-6.0 {
257 DROP TABLE IF EXISTS temp.types2_recover;
258 CREATE VIRTUAL TABLE temp.types2_recover USING recover(
265 execsql {SELECT rowid, id, rowtype, value, TYPEOF(value) FROM types2_recover}
266 } {1 1 NULL {} null 2 2 INTEGER 17 integer 3 3 FLOAT 3.1415927 real 4 4 TEXT {This is text} text 5 5 BLOB {This is a blob} blob}
268 # ROWID NOT NULL is identical.
269 do_test recover-types-6.1 {
271 DROP TABLE IF EXISTS temp.types2_recover;
272 CREATE VIRTUAL TABLE temp.types2_recover USING recover(
279 execsql {SELECT rowid, id, rowtype, value, TYPEOF(value) FROM types2_recover}
280 } {1 1 NULL {} null 2 2 INTEGER 17 integer 3 3 FLOAT 3.1415927 real 4 4 TEXT {This is text} text 5 5 BLOB {This is a blob} blob}
282 # Check that each of the possible integer sizes is being decoded.
283 # TODO(shess): It would be neat to ACTUALLY test these things. As-is,
284 # this should exercise the code paths, but one needs logging or a
285 # debugger to verify that things are stored as expected.
286 do_test recover-types-7.0 {
288 DROP TABLE IF EXISTS integers;
289 CREATE TABLE integers (value);
291 -- encoded directly in type info.
292 INSERT INTO integers VALUES (0);
293 INSERT INTO integers VALUES (1);
296 INSERT INTO integers VALUES (2);
297 INSERT INTO integers VALUES (-2);
298 INSERT INTO integers VALUES (127);
299 INSERT INTO integers VALUES (-128);
302 INSERT INTO integers VALUES (12345);
303 INSERT INTO integers VALUES (-12345);
304 INSERT INTO integers VALUES (32767);
305 INSERT INTO integers VALUES (-32768);
308 INSERT INTO integers VALUES (1234567);
309 INSERT INTO integers VALUES (-1234567);
310 INSERT INTO integers VALUES (8388607);
311 INSERT INTO integers VALUES (-8388608);
314 INSERT INTO integers VALUES (1234567890);
315 INSERT INTO integers VALUES (-1234567890);
316 INSERT INTO integers VALUES (2147483647);
317 INSERT INTO integers VALUES (-2147483648);
320 INSERT INTO integers VALUES (123456789012345);
321 INSERT INTO integers VALUES (-123456789012345);
322 INSERT INTO integers VALUES (140737488355327);
323 INSERT INTO integers VALUES (-140737488355328);
326 INSERT INTO integers VALUES (9223372036854775807);
327 INSERT INTO integers VALUES (-9223372036854775808);
329 DROP TABLE IF EXISTS integers_recover;
330 CREATE VIRTUAL TABLE temp.integers_recover USING recover(
335 execsql {SELECT rowid, value FROM integers_recover}
336 } {1 0 2 1 3 2 4 -2 5 127 6 -128 7 12345 8 -12345 9 32767 10 -32768 11 1234567 12 -1234567 13 8388607 14 -8388608 15 1234567890 16 -1234567890 17 2147483647 18 -2147483648 19 123456789012345 20 -123456789012345 21 140737488355327 22 -140737488355328 23 9223372036854775807 24 -9223372036854775808}
338 # If UTF16 support is disabled, ignore the rest of the tests.
346 file delete -force test.db
349 PRAGMA encoding = 'UTF-8';
352 do_test recover-encoding-1.0 {
354 DROP TABLE IF EXISTS e;
355 CREATE TABLE e (v TEXT);
356 INSERT INTO e VALUES('Mjollnir');
357 INSERT INTO e VALUES('Mjölnir');
358 INSERT INTO e VALUES('Mjǫlnir');
359 INSERT INTO e VALUES('Mjölner');
360 INSERT INTO e VALUES('Mjølner');
361 INSERT INTO e VALUES('ハンマー');
364 DROP TABLE IF EXISTS e_recover;
365 CREATE VIRTUAL TABLE temp.e_recover USING recover(
369 SELECT rowid, v FROM e_recover ORDER BY rowid;
371 } {UTF-8 1 Mjollnir 2 Mjölnir 3 Mjǫlnir 4 Mjölner 5 Mjølner 6 ハンマー}
373 # Reset the database to UTF-16LE.
374 file delete -force test.db
377 PRAGMA encoding = 'UTF-16LE';
380 do_test recover-encoding-2.0 {
382 DROP TABLE IF EXISTS e;
383 CREATE TABLE e (v TEXT);
384 INSERT INTO e VALUES('Mjollnir');
385 INSERT INTO e VALUES('Mjölnir');
386 INSERT INTO e VALUES('Mjǫlnir');
387 INSERT INTO e VALUES('Mjölner');
388 INSERT INTO e VALUES('Mjølner');
389 INSERT INTO e VALUES('ハンマー');
392 DROP TABLE IF EXISTS e_recover;
393 CREATE VIRTUAL TABLE temp.e_recover USING recover(
397 SELECT rowid, v FROM e_recover ORDER BY rowid;
399 } {UTF-16le 1 Mjollnir 2 Mjölnir 3 Mjǫlnir 4 Mjölner 5 Mjølner 6 ハンマー}
401 # Reset the database to UTF-16BE.
402 file delete -force test.db
405 PRAGMA encoding = 'UTF-16BE';
408 do_test recover-encoding-3.0 {
410 DROP TABLE IF EXISTS e;
411 CREATE TABLE e (v TEXT);
412 INSERT INTO e VALUES('Mjollnir');
413 INSERT INTO e VALUES('Mjölnir');
414 INSERT INTO e VALUES('Mjǫlnir');
415 INSERT INTO e VALUES('Mjölner');
416 INSERT INTO e VALUES('Mjølner');
417 INSERT INTO e VALUES('ハンマー');
420 DROP TABLE IF EXISTS e_recover;
421 CREATE VIRTUAL TABLE temp.e_recover USING recover(
425 SELECT rowid, v FROM e_recover ORDER BY rowid;
427 } {UTF-16be 1 Mjollnir 2 Mjölnir 3 Mjǫlnir 4 Mjölner 5 Mjølner 6 ハンマー}