xref: /sqlite-3.40.0/test/withM.test (revision a23bc8a3)
14e9119d9Sdan# 2014 January 11
24e9119d9Sdan#
34e9119d9Sdan# The author disclaims copyright to this source code.  In place of
44e9119d9Sdan# a legal notice, here is a blessing:
54e9119d9Sdan#
64e9119d9Sdan#    May you do good and not evil.
74e9119d9Sdan#    May you find forgiveness for yourself and forgive others.
84e9119d9Sdan#    May you share freely, never taking more than you give.
94e9119d9Sdan#
104e9119d9Sdan#***********************************************************************
114e9119d9Sdan# This file implements regression tests for SQLite library.  The
124e9119d9Sdan# focus of this file is testing the WITH clause.
134e9119d9Sdan#
144e9119d9Sdan
154e9119d9Sdanset testdir [file dirname $argv0]
164e9119d9Sdansource $testdir/tester.tcl
174e9119d9Sdansource $testdir/malloc_common.tcl
184e9119d9Sdanset ::testprefix withM
194e9119d9Sdan
20eede6a53Sdanifcapable {!cte} {
21eede6a53Sdan  finish_test
22eede6a53Sdan  return
23eede6a53Sdan}
24eede6a53Sdan
254e9119d9Sdando_execsql_test 1.0 {
264e9119d9Sdan  CREATE TABLE t1(x INTEGER, y INTEGER);
274e9119d9Sdan  INSERT INTO t1 VALUES(123, 456);
284e9119d9Sdan}
294e9119d9Sdan
30a9f5c13dSdando_faultsim_test withM-1.1 -prep {
314e9119d9Sdan  sqlite3 db test.db
324e9119d9Sdan} -body {
334e9119d9Sdan  execsql {
344e9119d9Sdan    WITH tmp AS ( SELECT * FROM t1 )
354e9119d9Sdan    SELECT * FROM tmp;
364e9119d9Sdan  }
374e9119d9Sdan} -test {
384e9119d9Sdan  faultsim_test_result {0 {123 456}}
394e9119d9Sdan  db close
404e9119d9Sdan}
414e9119d9Sdan
42a9f5c13dSdando_faultsim_test withM-1.2 -prep {
43a9f5c13dSdan  sqlite3 db test.db
44a9f5c13dSdan} -body {
45a9f5c13dSdan  execsql {
46a9f5c13dSdan    WITH w1 AS ( SELECT * FROM t1 ),
47a9f5c13dSdan         w2 AS (
48a9f5c13dSdan           WITH w3 AS ( SELECT * FROM w1 )
49a9f5c13dSdan           SELECT * FROM w3
50a9f5c13dSdan         )
51a9f5c13dSdan    SELECT * FROM w2;
52a9f5c13dSdan  }
53a9f5c13dSdan} -test {
54a9f5c13dSdan  faultsim_test_result {0 {123 456}}
55a9f5c13dSdan  db close
56a9f5c13dSdan}
57a9f5c13dSdan
58*1fe3c4b5Sdando_faultsim_test withM-1.3 -prep {
59*1fe3c4b5Sdan  sqlite3 db test.db
60*1fe3c4b5Sdan} -body {
61*1fe3c4b5Sdan  execsql {
62*1fe3c4b5Sdan    WITH w1(a,b) AS (
63*1fe3c4b5Sdan      SELECT 1, 1
64*1fe3c4b5Sdan      UNION ALL
65*1fe3c4b5Sdan      SELECT a+1, b + 2*a + 1 FROM w1
66*1fe3c4b5Sdan    )
67*1fe3c4b5Sdan    SELECT * FROM w1 LIMIT 5;
68*1fe3c4b5Sdan  }
69*1fe3c4b5Sdan} -test {
70*1fe3c4b5Sdan  faultsim_test_result {0 {1 1 2 4 3 9 4 16 5 25}}
71*1fe3c4b5Sdan  db close
72*1fe3c4b5Sdan}
73*1fe3c4b5Sdan
744e9119d9Sdanfinish_test
75