sl@0: # 2007 June 26 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this file is 'hidden' virtual table columns. sl@0: # sl@0: # $Id: vtabA.test,v 1.2 2008/07/12 14:52:21 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable !vtab { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: proc get_decltype {table col} { sl@0: set STMT [sqlite3_prepare $::DB "SELECT $col FROM $table" -1 TAIL] sl@0: set decltype [sqlite3_column_decltype $STMT 0] sl@0: sqlite3_finalize $STMT sl@0: set decltype sl@0: } sl@0: sl@0: proc get_collist {table} { sl@0: set ret [list] sl@0: db eval "PRAGMA table_info($table)" { lappend ret $name } sl@0: set ret sl@0: } sl@0: sl@0: # Register the echo module sl@0: register_echo_module [sqlite3_connection_pointer db] sl@0: sl@0: # Create a virtual table with a 'hidden' column (column b). sl@0: # sl@0: do_test vtabA-1.1 { sl@0: execsql { CREATE TABLE t1(a, b HIDDEN VARCHAR, c INTEGER) } sl@0: } {} sl@0: do_test vtabA-1.2 { sl@0: execsql { CREATE VIRTUAL TABLE t1e USING echo(t1) } sl@0: } {} sl@0: sl@0: # Test that the hidden column is not listed by [PRAGMA table_info]. sl@0: # sl@0: do_test vtabA-1.3 { sl@0: execsql { PRAGMA table_info(t1e) } sl@0: } [list \ sl@0: 0 a {} 0 {} 0 \ sl@0: 1 c INTEGER 0 {} 0 \ sl@0: ] sl@0: sl@0: # Test that the hidden column is not require in the default column sl@0: # list for an INSERT statement. sl@0: # sl@0: do_test vtabA-1.4 { sl@0: catchsql { sl@0: INSERT INTO t1e VALUES('value a', 'value c'); sl@0: } sl@0: } {0 {}} sl@0: do_test vtabA-1.5 { sl@0: execsql { sl@0: SELECT a, b, c FROM t1e; sl@0: } sl@0: } {{value a} {} {value c}} sl@0: sl@0: do_test vtabA-1.6 { sl@0: execsql { sl@0: SELECT * FROM t1e; sl@0: } sl@0: } {{value a} {value c}} sl@0: sl@0: # Test that the expansion of a '*' expression in the result set of sl@0: # a SELECT does not include the hidden column. sl@0: # sl@0: do_test vtabA-1.7 { sl@0: execsql { sl@0: INSERT INTO t1e SELECT * FROM t1e; sl@0: } sl@0: } {} sl@0: do_test vtabA-1.8 { sl@0: execsql { sl@0: SELECT * FROM t1e; sl@0: } sl@0: } {{value a} {value c} {value a} {value c}} sl@0: sl@0: # Test that the declaration type of the hidden column does not include sl@0: # the token "HIDDEN". sl@0: # sl@0: do_test vtabA-1.9 { sl@0: get_decltype t1e b sl@0: } {VARCHAR} sl@0: do_test vtabA-1.10 { sl@0: get_collist t1e sl@0: } {a c} sl@0: sl@0: #---------------------------------------------------------------------- sl@0: # These tests vtabA-2.* concentrate on testing that the HIDDEN token sl@0: # is detected and handled correctly in various declarations. sl@0: # sl@0: proc analyse_parse {columns decltype_list} { sl@0: db eval { DROP TABLE IF EXISTS t1e; } sl@0: db eval { DROP TABLE IF EXISTS t1; } sl@0: db eval " CREATE TABLE t1 $columns " sl@0: db eval { CREATE VIRTUAL TABLE t1e USING echo(t1) } sl@0: set ret [list [get_collist t1e]] sl@0: foreach c $decltype_list { sl@0: lappend ret [get_decltype t1e $c] sl@0: } sl@0: set ret sl@0: } sl@0: sl@0: do_test vtabA-2.1 { sl@0: analyse_parse {(a text, b integer hidden, c hidden)} {a b c} sl@0: } {a text integer {}} sl@0: sl@0: do_test vtabA-2.2 { sl@0: analyse_parse {(a hidden , b integerhidden, c hidden1)} {a b c} sl@0: } {{b c} {} integerhidden hidden1} sl@0: sl@0: do_test vtabA-2.3 { sl@0: analyse_parse {(a HiDden, b HIDDEN, c hidden)} {a b c} sl@0: } {{} {} {} {}} sl@0: sl@0: do_test vtabA-2.4 { sl@0: analyse_parse {(a whatelse can i hidden test, b HIDDEN hidden)} {a b} sl@0: } {{} {whatelse can i test} hidden} sl@0: sl@0: finish_test