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}}
78 # Test that the expansion of a '*' expression in the result set of
79 # a SELECT does not include the hidden column.
83 INSERT INTO t1e SELECT * FROM t1e;
90 } {{value a} {value c} {value a} {value c}}
92 # Test that the declaration type of the hidden column does not include
102 #----------------------------------------------------------------------
103 # These tests vtabA-2.* concentrate on testing that the HIDDEN token
104 # is detected and handled correctly in various declarations.
106 proc analyse_parse {columns decltype_list} {
107 db eval { DROP TABLE IF EXISTS t1e; }
108 db eval { DROP TABLE IF EXISTS t1; }
109 db eval " CREATE TABLE t1 $columns "
110 db eval { CREATE VIRTUAL TABLE t1e USING echo(t1) }
111 set ret [list [get_collist t1e]]
112 foreach c $decltype_list {
113 lappend ret [get_decltype t1e $c]
119 analyse_parse {(a text, b integer hidden, c hidden)} {a b c}
120 } {a text integer {}}
123 analyse_parse {(a hidden , b integerhidden, c hidden1)} {a b c}
124 } {{b c} {} integerhidden hidden1}
127 analyse_parse {(a HiDden, b HIDDEN, c hidden)} {a b c}
131 analyse_parse {(a whatelse can i hidden test, b HIDDEN hidden)} {a b}
132 } {{} {whatelse can i test} hidden}
135 # Ticket [d2f02d37f52bfe23e421f2c60fbb8586ac76ff01]:
136 # assertion failure on an UPDATE involving two virtual tables.
140 DROP TABLE IF EXISTS t1;
141 DROP TABLE IF EXISTS t2;
142 CREATE TABLE t1(a,b);
143 INSERT INTO t1 VALUES(1,2);
144 CREATE TABLE t2(x,y);
145 INSERT INTO t2 VALUES(3,4);
146 CREATE VIRTUAL TABLE vt1 USING echo(t1);
147 CREATE VIRTUAL TABLE vt2 USING echo(t2);
148 UPDATE vt2 SET x=(SELECT a FROM vt1 WHERE b=2) WHERE y=4;