xref: /sqlite-3.40.0/test/vtab2.test (revision 09df9e28)
1# 2006 June 10
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# This file implements regression tests for SQLite library.
12#
13# $Id: vtab2.test,v 1.5 2006/08/13 18:43:55 drh Exp $
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17
18ifcapable !vtab||!schema_pragmas {
19  finish_test
20  return
21}
22
23register_schema_module [sqlite3_connection_pointer db]
24do_test vtab2-1.1 {
25  execsql {
26    CREATE VIRTUAL TABLE schema USING schema;
27    SELECT * FROM schema;
28  }
29} [list \
30  main schema 0 database   {} 0 {} 0 \
31  main schema 1 tablename  {} 0 {} 0 \
32  main schema 2 cid        {} 0 {} 0 \
33  main schema 3 name       {} 0 {} 0 \
34  main schema 4 type       {} 0 {} 0 \
35  main schema 5 not_null   {} 0 {} 0 \
36  main schema 6 dflt_value {} 0 {} 0 \
37  main schema 7 pk         {} 0 {} 0 \
38]
39
40register_tclvar_module [sqlite3_connection_pointer db]
41do_test vtab2-2.1 {
42  set ::abc 123
43  execsql {
44    CREATE VIRTUAL TABLE vars USING tclvar;
45    SELECT * FROM vars WHERE name='abc';
46  }
47} [list abc "" 123]
48do_test vtab2-2.2 {
49  set A(1) 1
50  set A(2) 4
51  set A(3) 9
52  execsql {
53    SELECT * FROM vars WHERE name='A';
54  }
55} [list A 1 1 A 2 4 A 3 9]
56set result {}
57foreach var [lsort [info vars tcl_*]] {
58  catch {lappend result $var [set $var]}
59}
60do_test vtab2-2.3 {
61  execsql {
62    SELECT name, value FROM vars
63      WHERE name MATCH 'tcl_*' AND arrayname = ''
64      ORDER BY name;
65  }
66} $result
67
68finish_test
69