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 'hidden' virtual table columns.
14 # $Id: vtabA.test,v 1.2 2008/07/12 14:52:21 drh Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
24 proc get_decltype {table col} {
25 set STMT [sqlite3_prepare $::DB "SELECT $col FROM $table" -1 TAIL]
26 set decltype [sqlite3_column_decltype $STMT 0]
27 sqlite3_finalize $STMT
31 proc get_collist {table} {
33 db eval "PRAGMA table_info($table)" { lappend ret $name }
37 # Register the echo module
38 register_echo_module [sqlite3_connection_pointer db]
40 # Create a virtual table with a 'hidden' column (column b).
43 execsql { CREATE TABLE t1(a, b HIDDEN VARCHAR, c INTEGER) }
46 execsql { CREATE VIRTUAL TABLE t1e USING echo(t1) }
49 # Test that the hidden column is not listed by [PRAGMA table_info].
52 execsql { PRAGMA table_info(t1e) }
58 # Test that the hidden column is not require in the default column
59 # list for an INSERT statement.
63 INSERT INTO t1e VALUES('value a', 'value c');
68 SELECT a, b, c FROM t1e;
70 } {{value a} {} {value c}}
76 } {{value a} {value c}}
77 do_execsql_test vtabA-1.7 {
79 INSERT INTO t1e SELECT 'abc','def';
81 do_execsql_test vtabA-1.8 {
82 INSERT INTO t1e VALUES('ghi','jkl'),('mno','pqr'),('stu','vwx');
84 do_execsql_test vtabA-1.9 {
85 SELECT a,b,c, '|' FROM t1e ORDER BY 1;
86 } {abc {} def | ghi {} jkl | mno {} pqr | stu {} vwx |}
89 # Test that the expansion of a '*' expression in the result set of
90 # a SELECT does not include the hidden column.
94 INSERT INTO t1e SELECT * FROM t1e;
99 SELECT * FROM t1e ORDER BY 1;
101 } {abc def abc def ghi jkl ghi jkl mno pqr mno pqr stu vwx stu vwx}
103 # Test that the declaration type of the hidden column does not include
104 # the token "HIDDEN".
113 #----------------------------------------------------------------------
114 # These tests vtabA-2.* concentrate on testing that the HIDDEN token
115 # is detected and handled correctly in various declarations.
117 proc analyse_parse {columns decltype_list} {
118 db eval { DROP TABLE IF EXISTS t1e; }
119 db eval { DROP TABLE IF EXISTS t1; }
120 db eval " CREATE TABLE t1 $columns "
121 db eval { CREATE VIRTUAL TABLE t1e USING echo(t1) }
122 set ret [list [get_collist t1e]]
123 foreach c $decltype_list {
124 lappend ret [get_decltype t1e $c]
130 analyse_parse {(a text, b integer hidden, c hidden)} {a b c}
131 } {a TEXT integer {}}
134 analyse_parse {(a hidden , b integerhidden, c hidden1)} {a b c}
135 } {{b c} {} integerhidden hidden1}
138 analyse_parse {(a HiDden, b HIDDEN, c hidden)} {a b c}
142 analyse_parse {(a whatelse can i hidden test, b HIDDEN hidden)} {a b}
143 } {{} {whatelse can i test} hidden}
146 # Ticket [d2f02d37f52bfe23e421f2c60fbb8586ac76ff01]:
147 # assertion failure on an UPDATE involving two virtual tables.
151 DROP TABLE IF EXISTS t1;
152 DROP TABLE IF EXISTS t2;
153 CREATE TABLE t1(a,b);
154 INSERT INTO t1 VALUES(1,2);
155 CREATE TABLE t2(x,y);
156 INSERT INTO t2 VALUES(3,4);
157 CREATE VIRTUAL TABLE vt1 USING echo(t1);
158 CREATE VIRTUAL TABLE vt2 USING echo(t2);
159 UPDATE vt2 SET x=(SELECT a FROM vt1 WHERE b=2) WHERE y=4;