xref: /sqlite-3.40.0/test/hidden.test (revision 03d69a68)
1# 2015 November 18
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#
12# Test the __hidden__ hack.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17set testprefix hidden
18
19ifcapable !hiddencolumns {
20  finish_test
21  return
22}
23
24do_execsql_test 1.1 {
25  CREATE TABLE t1(__hidden__a, b);
26  INSERT INTO t1 VALUES('1');
27  INSERT INTO t1(__hidden__a, b) VALUES('x', 'y');
28} {}
29
30do_execsql_test 1.2 {
31  SELECT * FROM t1;
32} {1 y}
33
34do_execsql_test 1.3 {
35  SELECT __hidden__a, * FROM t1;
36} {{} 1 x y}
37
38foreach {tn view} {
39  1 { CREATE VIEW v1(a, b, __hidden__c) AS SELECT a, b, c FROM x1 }
40  2 { CREATE VIEW v1 AS SELECT a, b, c AS __hidden__c FROM x1 }
41} {
42  do_execsql_test 2.$tn.1 {
43    DROP TABLE IF EXISTS x1;
44    CREATE TABLE x1(a, b, c);
45    INSERT INTO x1 VALUES(1, 2, 3);
46  }
47
48  catchsql { DROP VIEW v1 }
49  execsql $view
50
51  do_execsql_test 2.$tn.2 {
52    SELECT a, b, __hidden__c FROM v1;
53  } {1 2 3}
54
55  do_execsql_test 2.$tn.3 {
56    SELECT * FROM v1;
57  } {1 2}
58
59  do_execsql_test 2.$tn.4 {
60    CREATE TRIGGER tr1 INSTEAD OF INSERT ON v1 BEGIN
61      INSERT INTO x1 VALUES(new.a, new.b, new.__hidden__c);
62    END;
63
64    INSERT INTO v1 VALUES(4, 5);
65    SELECT * FROM x1;
66  } {1 2 3 4 5 {}}
67
68  do_execsql_test 2.$tn.5 {
69    INSERT INTO v1(a, b, __hidden__c) VALUES(7, 8, 9);
70    SELECT * FROM x1;
71  } {1 2 3 4 5 {} 7 8 9}
72}
73
74finish_test
75