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.
     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.8 2008/01/31 15:53:46 drh Exp $
    14 
    15 set testdir [file dirname $argv0]
    16 source $testdir/tester.tcl
    17 
    18 ifcapable !vtab||!schema_pragmas {
    19   finish_test
    20   return
    21 }
    22 
    23 register_schema_module [sqlite3_connection_pointer db]
    24 do_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 
    40 # See ticket #2230.
    41 #
    42 do_test vtab2-1.2 {
    43   execsql {
    44     SELECT length(tablename) FROM schema GROUP by tablename;
    45   }
    46 } {6}
    47 do_test vtab2-1.3 {
    48   execsql {
    49     SELECT tablename FROM schema GROUP by length(tablename);
    50   }
    51 } {schema}
    52 do_test vtab2-1.4 {
    53   execsql {
    54     SELECT length(tablename) FROM schema GROUP by length(tablename);
    55   }
    56 } {6}
    57 
    58 register_tclvar_module [sqlite3_connection_pointer db]
    59 do_test vtab2-2.1 {
    60   set ::abc 123
    61   execsql {
    62     CREATE VIRTUAL TABLE vars USING tclvar;
    63     SELECT * FROM vars WHERE name='abc';
    64   }
    65 } [list abc "" 123]
    66 do_test vtab2-2.2 {
    67   set A(1) 1
    68   set A(2) 4
    69   set A(3) 9
    70   execsql {
    71     SELECT * FROM vars WHERE name='A';
    72   }
    73 } [list A 1 1 A 2 4 A 3 9]
    74 unset -nocomplain result
    75 unset -nocomplain var
    76 set result {}
    77 foreach var [lsort [info vars tcl_*]] {
    78   catch {lappend result $var [set $var]}
    79 }
    80 do_test vtab2-2.3 {
    81   execsql {
    82     SELECT name, value FROM vars
    83       WHERE name MATCH 'tcl_*' AND arrayname = '' 
    84       ORDER BY name;
    85   }
    86 } $result
    87 unset result
    88 unset var
    89 
    90 # Ticket #2894.
    91 #
    92 # Make sure we do call Column(), and Rowid() methods of
    93 # a virtual table when that table is in a LEFT JOIN.
    94 #
    95 do_test vtab2-3.1 {
    96   execsql {
    97     SELECT * FROM schema WHERE dflt_value IS NULL LIMIT 1
    98   }
    99 } {main schema 0 database {} 0 {} 0}
   100 do_test vtab2-3.2 {
   101   execsql {
   102     SELECT *, b.rowid
   103       FROM schema a LEFT JOIN schema b ON a.dflt_value=b.dflt_value
   104      WHERE a.rowid=1
   105   }
   106 } {main schema 0 database {} 0 {} 0 {} {} {} {} {} {} {} {} {}}
   107 
   108 finish_test