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 in TRIGGERs and VIEWs.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set ::testprefix with4
25 ATTACH ':memory:' AS aux;
26 CREATE TABLE main.t1(a,b);
27 CREATE TABLE aux.t2(x,y);
28 INSERT INTO t1 VALUES(1,2);
29 INSERT INTO t2 VALUES(3,4);
31 do_catchsql_test 110 {
32 CREATE VIEW v1 AS SELECT * FROM t1, aux.t2;
33 } {1 {view v1 cannot reference objects in database aux}}
34 do_catchsql_test 120 {
35 CREATE VIEW v2 AS WITH v(m,n) AS (SELECT x,y FROM aux.t2) SELECT * FROM t1, v;
36 } {1 {view v2 cannot reference objects in database aux}}
37 do_catchsql_test 130 {
38 CREATE VIEW v2 AS WITH v(m,n) AS (SELECT 5,?2) SELECT * FROM t1, v;
39 } {1 {parameters are not allowed in views}}
41 do_catchsql_test 200 {
42 CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
43 WITH v(m,n) AS (SELECT x,y FROM aux.t2) SELECT * FROM t1, v;
45 } {1 {trigger r1 cannot reference objects in database aux}}
46 do_catchsql_test 210 {
47 CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
48 WITH v(m,n) AS (SELECT 5,?2) SELECT * FROM t1, v;
50 } {1 {trigger cannot use variables}}