Merge updates from trunk.
[sqlite.git] / test / with3.test
blob62e88441ab41c5f1c9bb6bc635203586a4ce1c58
1 # 2015-11-07
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.  The
12 # focus of this file is testing the WITH clause.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set ::testprefix with3
19 ifcapable {!cte} {
20   finish_test
21   return
24 # Test problems found by Kostya Serebryany using 
25 # LibFuzzer.  (http://llvm.org/docs/LibFuzzer.html)
27 do_catchsql_test 1.0 {
28   WITH i(x) AS (
29     WITH j AS (SELECT 10)
30     SELECT 5 FROM t0 UNION SELECT 8 FROM m
31   )
32   SELECT * FROM i;
33 } {1 {no such table: m}}
35 # Additional test cases that came out of the work to
36 # fix for Kostya's problem.
38 do_execsql_test 2.0 {
39  WITH
40   x1 AS (SELECT 10),
41   x2 AS (SELECT 11),
42   x3 AS (
43     SELECT * FROM x1 UNION ALL SELECT * FROM x2
44   ),
45   x4 AS (
46     WITH
47     x1 AS (SELECT 12),
48     x2 AS (SELECT 13)
49     SELECT * FROM x3
50   )
51   SELECT * FROM x4;
53 } {10 11}
55 do_execsql_test 2.1 {
56   CREATE TABLE t1(x);
57   WITH
58     x1(a) AS (values(100))
59   INSERT INTO t1(x)
60     SELECT * FROM (WITH x2(y) AS (SELECT * FROM x1) SELECT y+a FROM x1, x2);
61   SELECT * FROM t1;
62 } {200}
64 finish_test