os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vtab2.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2006 June 10
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
# This file implements regression tests for SQLite library.
sl@0
    12
#
sl@0
    13
# $Id: vtab2.test,v 1.8 2008/01/31 15:53:46 drh Exp $
sl@0
    14
sl@0
    15
set testdir [file dirname $argv0]
sl@0
    16
source $testdir/tester.tcl
sl@0
    17
sl@0
    18
ifcapable !vtab||!schema_pragmas {
sl@0
    19
  finish_test
sl@0
    20
  return
sl@0
    21
}
sl@0
    22
sl@0
    23
register_schema_module [sqlite3_connection_pointer db]
sl@0
    24
do_test vtab2-1.1 {
sl@0
    25
  execsql {
sl@0
    26
    CREATE VIRTUAL TABLE schema USING schema;
sl@0
    27
    SELECT * FROM schema;
sl@0
    28
  }
sl@0
    29
} [list \
sl@0
    30
  main schema 0 database   {} 0 {} 0 \
sl@0
    31
  main schema 1 tablename  {} 0 {} 0 \
sl@0
    32
  main schema 2 cid        {} 0 {} 0 \
sl@0
    33
  main schema 3 name       {} 0 {} 0 \
sl@0
    34
  main schema 4 type       {} 0 {} 0 \
sl@0
    35
  main schema 5 not_null   {} 0 {} 0 \
sl@0
    36
  main schema 6 dflt_value {} 0 {} 0 \
sl@0
    37
  main schema 7 pk         {} 0 {} 0 \
sl@0
    38
]
sl@0
    39
sl@0
    40
# See ticket #2230.
sl@0
    41
#
sl@0
    42
do_test vtab2-1.2 {
sl@0
    43
  execsql {
sl@0
    44
    SELECT length(tablename) FROM schema GROUP by tablename;
sl@0
    45
  }
sl@0
    46
} {6}
sl@0
    47
do_test vtab2-1.3 {
sl@0
    48
  execsql {
sl@0
    49
    SELECT tablename FROM schema GROUP by length(tablename);
sl@0
    50
  }
sl@0
    51
} {schema}
sl@0
    52
do_test vtab2-1.4 {
sl@0
    53
  execsql {
sl@0
    54
    SELECT length(tablename) FROM schema GROUP by length(tablename);
sl@0
    55
  }
sl@0
    56
} {6}
sl@0
    57
sl@0
    58
register_tclvar_module [sqlite3_connection_pointer db]
sl@0
    59
do_test vtab2-2.1 {
sl@0
    60
  set ::abc 123
sl@0
    61
  execsql {
sl@0
    62
    CREATE VIRTUAL TABLE vars USING tclvar;
sl@0
    63
    SELECT * FROM vars WHERE name='abc';
sl@0
    64
  }
sl@0
    65
} [list abc "" 123]
sl@0
    66
do_test vtab2-2.2 {
sl@0
    67
  set A(1) 1
sl@0
    68
  set A(2) 4
sl@0
    69
  set A(3) 9
sl@0
    70
  execsql {
sl@0
    71
    SELECT * FROM vars WHERE name='A';
sl@0
    72
  }
sl@0
    73
} [list A 1 1 A 2 4 A 3 9]
sl@0
    74
unset -nocomplain result
sl@0
    75
unset -nocomplain var
sl@0
    76
set result {}
sl@0
    77
foreach var [lsort [info vars tcl_*]] {
sl@0
    78
  catch {lappend result $var [set $var]}
sl@0
    79
}
sl@0
    80
do_test vtab2-2.3 {
sl@0
    81
  execsql {
sl@0
    82
    SELECT name, value FROM vars
sl@0
    83
      WHERE name MATCH 'tcl_*' AND arrayname = '' 
sl@0
    84
      ORDER BY name;
sl@0
    85
  }
sl@0
    86
} $result
sl@0
    87
unset result
sl@0
    88
unset var
sl@0
    89
sl@0
    90
# Ticket #2894.
sl@0
    91
#
sl@0
    92
# Make sure we do call Column(), and Rowid() methods of
sl@0
    93
# a virtual table when that table is in a LEFT JOIN.
sl@0
    94
#
sl@0
    95
do_test vtab2-3.1 {
sl@0
    96
  execsql {
sl@0
    97
    SELECT * FROM schema WHERE dflt_value IS NULL LIMIT 1
sl@0
    98
  }
sl@0
    99
} {main schema 0 database {} 0 {} 0}
sl@0
   100
do_test vtab2-3.2 {
sl@0
   101
  execsql {
sl@0
   102
    SELECT *, b.rowid
sl@0
   103
      FROM schema a LEFT JOIN schema b ON a.dflt_value=b.dflt_value
sl@0
   104
     WHERE a.rowid=1
sl@0
   105
  }
sl@0
   106
} {main schema 0 database {} 0 {} 0 {} {} {} {} {} {} {} {} {}}
sl@0
   107
sl@0
   108
finish_test