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.
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
20 CREATE TABLE x1(a, b, c);
25 INSERT INTO x1(a, b, c) VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4);
27 do_execsql_test 1.1.1 {
28 INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4);
30 do_execsql_test 1.1.2 {
39 do_execsql_test 1.2.0 {
42 do_execsql_test 1.2.1 {
43 INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3) UNION ALL SELECT 4, 4, 4;
45 } {1 1 1 2 2 2 3 3 3 4 4 4}
47 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 4
49 do_execsql_test 1.2.2 {
52 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5)
53 UNION ALL SELECT 6, 6, 6;
55 } {1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6}
57 do_execsql_test 1.2.3 {
60 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4)
61 UNION ALL SELECT 6, 6, 6;
63 } {1 1 1 2 2 2 3 3 3 4 4 4 6 6 6}
65 do_execsql_test 1.2.4 {
67 INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3) UNION ALL SELECT 6, 6, 6;
79 do_execsql_test 1.2.5 {
82 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3),
83 (4, 4, $a), (5, 5, $b), (6, 6, $c)
86 do_execsql_test 1.2.6 {
97 #-------------------------------------------------------------------------
98 # SQLITE_LIMIT_COMPOUND_SELECT set to 0.
102 do_execsql_test 2.0 {
103 CREATE TABLE x1(a, b, c);
106 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 3
108 do_catchsql_test 2.1.1 {
109 INSERT INTO x1 VALUES
120 } {1 {all VALUES must have the same number of terms}}
122 do_catchsql_test 2.1.2 {
123 INSERT INTO x1 VALUES
134 } {1 {all VALUES must have the same number of terms}}
136 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 0
138 do_execsql_test 2.2 {
139 INSERT INTO x1 VALUES
151 do_execsql_test 2.3 {
152 INSERT INTO x1 VALUES
168 #-------------------------------------------------------------------------
171 do_execsql_test 3.0 {
172 CREATE TABLE y1(x, y);
175 do_execsql_test 3.1.1 {
177 INSERT INTO y1 VALUES(1, 2), (3, 4), (row_number() OVER (), 5);
179 do_execsql_test 3.1.2 {
182 do_execsql_test 3.2.1 {
184 INSERT INTO y1 VALUES(1, 2), (3, 4), (row_number() OVER (), 6)
185 , (row_number() OVER (), 7)
187 do_execsql_test 3.1.2 {
191 #-------------------------------------------------------------------------
194 do_execsql_test 4.0 {
195 CREATE TABLE x1(a PRIMARY KEY, b) WITHOUT ROWID;
198 foreach {tn iLimit} {1 0 2 3} {
199 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT $iLimit
201 do_execsql_test 4.1.1 {
203 INSERT INTO x1 VALUES
205 (2, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d')) ))
207 do_execsql_test 4.1.2 {
211 do_execsql_test 4.2.1 {
213 INSERT INTO x1 VALUES
218 (5, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d')) ))
220 do_execsql_test 4.2.2 {
222 } {1 1 2 2 3 3 4 4 5 a}
224 do_execsql_test 4.3.1 {
226 INSERT INTO x1 VALUES
227 (1, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d'), ('e')) ))
229 do_execsql_test 4.3.2 {
234 #------------------------------------------------------------------------
237 do_execsql_test 5.0 {
238 CREATE VIEW v1 AS VALUES(1, 2, 3), (4, 5, 6), (7, 8, 9);
240 do_execsql_test 5.1 {
242 } {1 2 3 4 5 6 7 8 9}
244 #-------------------------------------------------------------------------
246 do_execsql_test 6.0 {
248 INSERT INTO t1 VALUES(1), (2);
251 do_execsql_test 6.1 {
252 SELECT ( VALUES( x ), ( x ) ) FROM t1;
255 #-------------------------------------------------------------------------
257 do_execsql_test 6.0 {
259 INSERT INTO t1 VALUES('x'), ('y');
262 do_execsql_test 6.1 {
263 SELECT * FROM t1, (VALUES(1), (2))
266 do_execsql_test 6.2 {
267 VALUES(CAST(44 AS REAL)),(55);
270 #------------------------------------------------------------------------
271 do_execsql_test 7.1 {
273 VALUES(1, 2), ('a', 'b')
275 SELECT * FROM x1 one, x1 two
283 #-------------------------------------------------------------------------
287 ( VALUES('a', 'b'), ('c', 'd'), (123, NULL) )
291 SELECT 'a' AS column1, 'b' AS column2
292 UNION ALL SELECT 'c', 'd' UNION ALL SELECT 123, NULL
296 do_execsql_test 8.0 {
298 INSERT INTO t1 VALUES('d'), (NULL), (123)
301 1 "SELECT * FROM t1 LEFT JOIN VVV" {
303 {} a b {} c d {} 123 {}
304 123 a b 123 c d 123 123 {}
307 2 "SELECT * FROM t1 LEFT JOIN VVV ON (column1=x)" {
313 3 "SELECT * FROM t1 RIGHT JOIN VVV" {
315 {} a b {} c d {} 123 {}
316 123 a b 123 c d 123 123 {}
319 4 "SELECT * FROM t1 RIGHT JOIN VVV ON (column1=x)" {
325 5 "SELECT * FROM t1 FULL OUTER JOIN VVV ON (column1=x)" {
333 6 "SELECT count(*) FROM VVV" { 3 }
335 7 "SELECT (SELECT column1 FROM VVV)" { a }
337 8 "SELECT * FROM VVV UNION ALL SELECT * FROM VVV" {
342 9 "SELECT * FROM VVV INTERSECT SELECT * FROM VVV" {
346 10 "SELECT * FROM VVV eXCEPT SELECT * FROM VVV" { }
348 11 "SELECT * FROM VVV eXCEPT SELECT 'a', 'b'" { 123 {} c d }
351 set q1 [string map [list VVV $VVV] $q]
352 set q2 [string map [list VVV $VVV2] $q]
353 set q3 "WITH VVV AS $VVV $q"
355 do_execsql_test 8.1.$tn.1 $q1 $res
356 do_execsql_test 8.1.$tn.2 $q2 $res
357 do_execsql_test 8.1.$tn.3 $q3 $res
360 #-------------------------------------------------------------------------
363 do_execsql_test 9.1 {
364 VALUES(456), (123), (NULL) UNION ALL SELECT 122 ORDER BY 1
367 do_execsql_test 9.2 {
368 VALUES (1, 2), (3, 4), (
369 ( SELECT column1 FROM ( VALUES (5, 6), (7, 8) ) ),
370 ( SELECT max(column2) FROM ( VALUES (5, 1), (7, 6) ) )
374 do_execsql_test 10.1 {
375 CREATE TABLE a2(a, b, c DEFAULT 'xyz');
377 do_execsql_test 10.2 {
378 INSERT INTO a2(a) VALUES(3),(4);
381 #-------------------------------------------------------------------------
384 do_execsql_test 11.0 {
385 CREATE VIRTUAL TABLE ft USING fts3(x);
387 do_execsql_test 11.1 {
388 INSERT INTO ft VALUES('one'), ('two');
392 #-------------------------------------------------------------------------
394 do_execsql_test 12.0 {
395 CREATE TABLE t1(a, b);
397 do_execsql_test 12.1 {
398 INSERT INTO t1 SELECT 1, 2 UNION ALL VALUES(3, 4), (5, 6);
400 do_execsql_test 12.2 {
404 #-------------------------------------------------------------------------
406 do_execsql_test 13.0 {
408 INSERT INTO t1 VALUES('xyz');
411 VALUES( (max(substr('abc', 1, 1), x)) ),
418 do_catchsql_test 13.1 {
419 VALUES(300), (zeroblob(300) OVER win);
420 } {1 {zeroblob() may not be used as a window function}}
422 #--------------------------------------------------------------------------
424 do_execsql_test 14.1 {
425 PRAGMA encoding = utf16;
426 CREATE TABLE t1(a, b);
432 do_execsql_test 14.2 {
433 INSERT INTO t1 VALUES
435 (16, 'urtlek' IN(1,2,3));
438 #--------------------------------------------------------------------------
442 VALUES(1),(2),(3),(4),(5);
445 `--SCAN 5-ROW VALUES CLAUSE
447 do_execsql_test 15.2 {
448 CREATE TABLE t1(a,b);
451 INSERT INTO t1 VALUES
455 `--SCAN 3-ROW VALUES CLAUSE
458 INSERT INTO t1 VALUES
460 (5,row_number()OVER());
464 |--LEFT-MOST SUBQUERY
465 | `--SCAN 3-ROW VALUES CLAUSE
467 |--CO-ROUTINE (subquery-xxxxxx)
468 | `--SCAN CONSTANT ROW
469 `--SCAN (subquery-xxxxxx)
472 SELECT * FROM (VALUES(1),(2),(3),(4),(5),(6)), (VALUES('a'),('b'),('c'));
475 |--SCAN 6-ROW VALUES CLAUSE
476 `--SCAN 3-ROW VALUES CLAUSE
478 do_execsql_test 15.6 {
479 CREATE TABLE t2(x,y);
482 SELECT * FROM t2 UNION ALL VALUES(1,2),(3,4),(5,6),(7,8);
486 |--LEFT-MOST SUBQUERY
489 `--SCAN 4-ROW VALUES CLAUSE
492 #--------------------------------------------------------------------------
493 # The VALUES-as-coroutine optimization can be applied to later rows of
494 # a VALUES clause even if earlier rows do not qualify.
497 do_execsql_test 16.1 {
498 CREATE TABLE t1(a,b);
500 do_execsql_test 16.2 {
502 INSERT INTO t1 VALUES(1,2),(3,4),(5,6),
503 (7,row_number()OVER()),
504 (9,10), (11,12), (13,14), (15,16);
505 SELECT * FROM t1 ORDER BY a, b;
507 } {1 2 3 4 5 6 7 1 9 10 11 12 13 14 15 16}
509 INSERT INTO t1 VALUES(1,2),(3,4),(5,6),
510 (7,row_number()OVER()),
511 (9,10), (11,12), (13,14), (15,16);
515 |--LEFT-MOST SUBQUERY
516 | `--SCAN 3-ROW VALUES CLAUSE
518 | |--CO-ROUTINE (subquery-xxxxxx)
519 | | `--SCAN CONSTANT ROW
520 | `--SCAN (subquery-xxxxxx)
522 `--SCAN 4-ROW VALUES CLAUSE
524 do_execsql_test 16.4 {
526 INSERT INTO t1 VALUES
527 (1,row_number()OVER()),
529 SELECT * FROM t1 ORDER BY a, b;
533 INSERT INTO t1 VALUES
534 (1,row_number()OVER()),
539 |--LEFT-MOST SUBQUERY
540 | |--CO-ROUTINE (subquery-xxxxxx)
541 | | `--SCAN CONSTANT ROW
542 | `--SCAN (subquery-xxxxxx)
544 `--SCAN 3-ROW VALUES CLAUSE
546 do_execsql_test 16.6 {
548 INSERT INTO t1 VALUES
550 (5,row_number()OVER()),
551 (7,8),(9,10),(11,12),
552 (13,row_number()OVER()),
553 (15,16),(17,18),(19,20),(21,22);
554 SELECT * FROM t1 ORDER BY a, b;
556 } { 1 2 3 4 5 1 7 8 9 10 11 12 13 1 15 16 17 18 19 20 21 22}
558 INSERT INTO t1 VALUES
560 (5,row_number()OVER()),
561 (7,8),(9,10),(11,12),
562 (13,row_number()OVER()),
563 (15,16),(17,18),(19,20),(21,22);
567 |--LEFT-MOST SUBQUERY
568 | `--SCAN 2-ROW VALUES CLAUSE
570 | |--CO-ROUTINE (subquery-xxxxxx)
571 | | `--SCAN CONSTANT ROW
572 | `--SCAN (subquery-xxxxxx)
574 | `--SCAN 3-ROW VALUES CLAUSE
576 | |--CO-ROUTINE (subquery-xxxxxx)
577 | | `--SCAN CONSTANT ROW
578 | `--SCAN (subquery-xxxxxx)
580 `--SCAN 4-ROW VALUES CLAUSE
583 #--------------------------------------------------------------------------
584 # 2024-03-23 dbsqlfuzz crash-c2c5e7e08b7e489d270a26d895077a03f678c33b
586 do_execsql_test 17.1 {
587 DROP TABLE IF EXISTS t1;
588 CREATE TABLE t1 AS SELECT * FROM (VALUES(1,2), (3,4 IN (1,2,3)));
591 do_execsql_test 17.2 {