gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/with4.test (about)

     1  # 2018-02-15
     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 in TRIGGERs and VIEWs.
    13  #
    14  
    15  set testdir [file dirname $argv0]
    16  source $testdir/tester.tcl
    17  set ::testprefix with4
    18  
    19  ifcapable {!cte} {
    20    finish_test
    21    return
    22  }
    23  
    24  do_execsql_test 100 {
    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);
    30  } {}
    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}}
    40  
    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;
    44    END;
    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;
    49    END;
    50  } {1 {trigger cannot use variables}}
    51  
    52  finish_test