os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vtabA.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vtabA.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,134 @@
     1.4 +# 2007 June 26
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library.  The
    1.15 +# focus of this file is 'hidden' virtual table columns.
    1.16 +#
    1.17 +# $Id: vtabA.test,v 1.2 2008/07/12 14:52:21 drh Exp $
    1.18 +
    1.19 +set testdir [file dirname $argv0]
    1.20 +source $testdir/tester.tcl
    1.21 +
    1.22 +ifcapable !vtab {
    1.23 +  finish_test
    1.24 +  return
    1.25 +}
    1.26 +
    1.27 +proc get_decltype {table col} {
    1.28 +  set STMT [sqlite3_prepare $::DB "SELECT $col FROM $table" -1 TAIL]
    1.29 +  set decltype [sqlite3_column_decltype $STMT 0]
    1.30 +  sqlite3_finalize $STMT
    1.31 +  set decltype
    1.32 +}
    1.33 +
    1.34 +proc get_collist {table} {
    1.35 +  set ret [list]
    1.36 +  db eval "PRAGMA table_info($table)" { lappend ret $name }
    1.37 +  set ret
    1.38 +}
    1.39 +
    1.40 +# Register the echo module
    1.41 +register_echo_module [sqlite3_connection_pointer db]
    1.42 +
    1.43 +# Create a virtual table with a 'hidden' column (column b).
    1.44 +#
    1.45 +do_test vtabA-1.1 {
    1.46 +  execsql { CREATE TABLE t1(a, b HIDDEN VARCHAR, c INTEGER) }
    1.47 +} {}
    1.48 +do_test vtabA-1.2 {
    1.49 +  execsql { CREATE VIRTUAL TABLE t1e USING echo(t1) }
    1.50 +} {}
    1.51 +
    1.52 +# Test that the hidden column is not listed by [PRAGMA table_info].
    1.53 +#
    1.54 +do_test vtabA-1.3 {
    1.55 +  execsql { PRAGMA table_info(t1e) }
    1.56 +} [list              \
    1.57 +  0 a {}      0 {} 0 \
    1.58 +  1 c INTEGER 0 {} 0 \
    1.59 +]
    1.60 +
    1.61 +# Test that the hidden column is not require in the default column
    1.62 +# list for an INSERT statement.
    1.63 +#
    1.64 +do_test vtabA-1.4 {
    1.65 +  catchsql {
    1.66 +    INSERT INTO t1e VALUES('value a', 'value c');
    1.67 +  }
    1.68 +} {0 {}}
    1.69 +do_test vtabA-1.5 {
    1.70 +  execsql {
    1.71 +    SELECT a, b, c FROM t1e;
    1.72 +  }
    1.73 +} {{value a} {} {value c}}
    1.74 +
    1.75 +do_test vtabA-1.6 {
    1.76 +  execsql {
    1.77 +    SELECT * FROM t1e;
    1.78 +  }
    1.79 +} {{value a} {value c}}
    1.80 +
    1.81 +# Test that the expansion of a '*' expression in the result set of
    1.82 +# a SELECT does not include the hidden column.
    1.83 +#
    1.84 +do_test vtabA-1.7 {
    1.85 +  execsql {
    1.86 +    INSERT INTO t1e SELECT * FROM t1e;
    1.87 +  }
    1.88 +} {}
    1.89 +do_test vtabA-1.8 {
    1.90 +  execsql {
    1.91 +    SELECT * FROM t1e;
    1.92 +  }
    1.93 +} {{value a} {value c} {value a} {value c}}
    1.94 +
    1.95 +# Test that the declaration type of the hidden column does not include
    1.96 +# the token "HIDDEN".
    1.97 +#
    1.98 +do_test vtabA-1.9 {
    1.99 +  get_decltype t1e b
   1.100 +} {VARCHAR}
   1.101 +do_test vtabA-1.10 {
   1.102 +  get_collist t1e
   1.103 +} {a c}
   1.104 +
   1.105 +#----------------------------------------------------------------------
   1.106 +# These tests vtabA-2.* concentrate on testing that the HIDDEN token
   1.107 +# is detected and handled correctly in various declarations.
   1.108 +#
   1.109 +proc analyse_parse {columns decltype_list} {
   1.110 +  db eval { DROP TABLE IF EXISTS t1e; }
   1.111 +  db eval { DROP TABLE IF EXISTS t1; }
   1.112 +  db eval " CREATE TABLE t1 $columns "
   1.113 +  db eval { CREATE VIRTUAL TABLE t1e USING echo(t1) }
   1.114 +  set ret [list [get_collist t1e]]
   1.115 +  foreach c $decltype_list {
   1.116 +    lappend ret [get_decltype t1e $c]
   1.117 +  }
   1.118 +  set ret
   1.119 +}
   1.120 +
   1.121 +do_test vtabA-2.1 {
   1.122 +  analyse_parse {(a text, b integer hidden, c hidden)} {a b c}
   1.123 +} {a text integer {}}
   1.124 +
   1.125 +do_test vtabA-2.2 {
   1.126 +  analyse_parse {(a hidden   , b integerhidden, c hidden1)} {a b c}
   1.127 +} {{b c} {} integerhidden hidden1}
   1.128 +
   1.129 +do_test vtabA-2.3 {
   1.130 +  analyse_parse {(a HiDden, b HIDDEN, c hidden)} {a b c}
   1.131 +} {{} {} {} {}}
   1.132 +
   1.133 +do_test vtabA-2.4 {
   1.134 +  analyse_parse {(a whatelse can i hidden test, b HIDDEN hidden)} {a b}
   1.135 +} {{} {whatelse can i test} hidden}
   1.136 +
   1.137 +finish_test