blob: 78b757f4226b458946bcc11b0c00c854e0d9e210 [file] [log] [blame]
dan4e9119d2014-01-13 15:12:23 +00001# 2014 January 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 WITH clause.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17source $testdir/malloc_common.tcl
18set ::testprefix withM
19
daneede6a52014-01-15 19:42:23 +000020ifcapable {!cte} {
21 finish_test
22 return
23}
24
dan4e9119d2014-01-13 15:12:23 +000025do_execsql_test 1.0 {
26 CREATE TABLE t1(x INTEGER, y INTEGER);
27 INSERT INTO t1 VALUES(123, 456);
28}
29
dana9f5c132014-01-13 16:36:40 +000030do_faultsim_test withM-1.1 -prep {
dan4e9119d2014-01-13 15:12:23 +000031 sqlite3 db test.db
32} -body {
33 execsql {
34 WITH tmp AS ( SELECT * FROM t1 )
35 SELECT * FROM tmp;
36 }
37} -test {
38 faultsim_test_result {0 {123 456}}
39 db close
40}
41
dana9f5c132014-01-13 16:36:40 +000042do_faultsim_test withM-1.2 -prep {
43 sqlite3 db test.db
44} -body {
45 execsql {
46 WITH w1 AS ( SELECT * FROM t1 ),
47 w2 AS (
48 WITH w3 AS ( SELECT * FROM w1 )
49 SELECT * FROM w3
50 )
51 SELECT * FROM w2;
52 }
53} -test {
54 faultsim_test_result {0 {123 456}}
55 db close
56}
57
dan1fe3c4b2014-01-18 15:59:35 +000058do_faultsim_test withM-1.3 -prep {
59 sqlite3 db test.db
60} -body {
61 execsql {
62 WITH w1(a,b) AS (
63 SELECT 1, 1
64 UNION ALL
65 SELECT a+1, b + 2*a + 1 FROM w1
66 )
67 SELECT * FROM w1 LIMIT 5;
68 }
69} -test {
70 faultsim_test_result {0 {1 1 2 4 3 9 4 16 5 25}}
71 db close
72}
73
dan4e9119d2014-01-13 15:12:23 +000074finish_test