github.com/jdgcs/sqlite3@v1.12.1-0.20210908114423-bc5f96e4dd51/testdata/tcl/bestindex7.test (about)

     1  # 2020-01-29
     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  # 
    12  
    13  set testdir [file dirname $argv0]
    14  source $testdir/tester.tcl
    15  set testprefix bestindex7
    16  
    17  ifcapable !vtab {
    18    finish_test
    19    return
    20  }
    21  
    22  register_tcl_module db
    23  
    24  proc vtab_command {src method args} {
    25    switch -- $method {
    26      xConnect {
    27        return "CREATE TABLE xxx(a)"
    28      }
    29  
    30      xBestIndex {
    31        set clist [lindex $args 0]
    32        set iCons 0
    33        set ret [list]
    34        foreach cons $clist {
    35          catch { array unset C }
    36          array set C $cons
    37          if {$C(usable)} {
    38            lappend ret use $iCons
    39          }
    40          incr iCons
    41        }
    42        return $ret
    43      }
    44  
    45      xFilter {
    46        return [list sql "SELECT rowid, x FROM $src"]
    47      }
    48  
    49    }
    50  
    51    return {}
    52  }
    53  
    54  do_execsql_test 1.0 {
    55    CREATE TABLE t1(x);
    56    INSERT INTO t1 VALUES(0), (2);
    57    CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1);
    58  }
    59  
    60  do_execsql_test 1.1 { select * from vt1 } {0 2}
    61  do_execsql_test 1.2 { select * from vt1 WHERE a=0 } {0}
    62  do_execsql_test 1.3 { select * from vt1 WHERE a=1 } {}
    63  do_execsql_test 1.4 { select * from vt1 WHERE a=1 OR a=0} {0}
    64  
    65  do_execsql_test 1.5 {
    66    UPDATE t1 SET x=NULL WHERE x=2;
    67  }
    68  
    69  do_execsql_test 1.6 { select * from vt1 } {0 {}}
    70  do_execsql_test 1.7 { select * from vt1 WHERE a=0 } {0}
    71  do_execsql_test 1.8 { select * from vt1 WHERE a=1 } {}
    72  do_execsql_test 1.9 { select * from vt1 WHERE a=1 OR a=0} {0}
    73  do_execsql_test 1.10 { select * from vt1 WHERE a IN (2) } {}
    74  do_execsql_test 1.10 { select * from vt1 WHERE a IN (0,1,2,3) } {0}
    75  do_execsql_test 1.11 { select * from vt1 WHERE a IN (0, NULL) } {0}
    76  do_execsql_test 1.12 { select * from vt1 WHERE a IN (NULL) } {}
    77  
    78  finish_test