xref: /sqlite-3.40.0/test/rowvalue5.test (revision d96ab995)
19cd4933eSdan# 2016 July 29
29cd4933eSdan#
39cd4933eSdan# The author disclaims copyright to this source code.  In place of
49cd4933eSdan# a legal notice, here is a blessing:
59cd4933eSdan#
69cd4933eSdan#    May you do good and not evil.
79cd4933eSdan#    May you find forgiveness for yourself and forgive others.
89cd4933eSdan#    May you share freely, never taking more than you give.
99cd4933eSdan#
109cd4933eSdan#***********************************************************************
119cd4933eSdan# This file implements regression tests for SQLite library.  The
129cd4933eSdan# focus of this file is syntax errors involving row-values and
139cd4933eSdan# virtual tables.
149cd4933eSdan#
159cd4933eSdan
169cd4933eSdanset testdir [file dirname $argv0]
179cd4933eSdansource $testdir/tester.tcl
189cd4933eSdanset ::testprefix rowvalue5
199cd4933eSdan
209871664eSdanifcapable !vtab {
219871664eSdan  finish_test
229871664eSdan  return
239871664eSdan}
249871664eSdan
259cd4933eSdanproc vtab_command {method args} {
269cd4933eSdan  switch -- $method {
279cd4933eSdan    xConnect {
289cd4933eSdan      return "CREATE TABLE t1(a, b, c, d, expr)"
299cd4933eSdan    }
309cd4933eSdan
319cd4933eSdan    xBestIndex {
329cd4933eSdan      set COL(0) a
339cd4933eSdan      set COL(1) b
349cd4933eSdan      set COL(2) c
359cd4933eSdan      set COL(3) d
369cd4933eSdan      set COL(4) expr
379cd4933eSdan
389cd4933eSdan      set OP(eq) =
399cd4933eSdan      set OP(ne) !=
409cd4933eSdan      set OP(gt) >
419cd4933eSdan      set OP(le) <=
429cd4933eSdan      set OP(lt) <
439cd4933eSdan      set OP(ge) >=
449cd4933eSdan      set OP(match) MATCH
459cd4933eSdan      set OP(like) LIKE
469cd4933eSdan      set OP(glob) GLOB
479cd4933eSdan      set OP(regexp) REGEXP
489cd4933eSdan
49*d96ab995Sdrh      set hdl [lindex $args 0]
50*d96ab995Sdrh      set clist [$hdl constraints]
51*d96ab995Sdrh
529cd4933eSdan      set ret [list]
539cd4933eSdan      set elist [list]
549cd4933eSdan      set i 0
559cd4933eSdan      foreach c $clist {
569cd4933eSdan        array set C $c
579cd4933eSdan        if {$C(usable)} {
589cd4933eSdan          lappend ret omit $i
599cd4933eSdan          lappend elist "$COL($C(column)) $OP($C(op)) %$i%"
609cd4933eSdan        }
619cd4933eSdan        incr i
629cd4933eSdan      }
639cd4933eSdan
649cd4933eSdan      lappend ret idxstr [join $elist " AND "]
659cd4933eSdan      #puts "xBestIndex: $ret"
669cd4933eSdan      return $ret
679cd4933eSdan    }
689cd4933eSdan
699cd4933eSdan    xFilter {
709cd4933eSdan      foreach {idxnum idxstr arglist} $args {}
719cd4933eSdan      set i 0
729cd4933eSdan      set ee $idxstr
739cd4933eSdan      foreach a $arglist {
749cd4933eSdan        if {[string is double $a]==0} {
759cd4933eSdan          set a "'[string map {' ''} $a]'"
769cd4933eSdan        }
779cd4933eSdan        set ee [string map [list "%$i%" $a] $ee]
789cd4933eSdan        incr i
799cd4933eSdan      }
809cd4933eSdan      set ee [string map [list "'" "''"] $ee]
819cd4933eSdan
829cd4933eSdan      set ret [list sql "SELECT 1, 'a', 'b', 'c', 'd', '$ee'"]
839cd4933eSdan      #puts "xFilter: $ret"
849cd4933eSdan      return $ret
859cd4933eSdan    }
869cd4933eSdan  }
879cd4933eSdan
889cd4933eSdan  return {}
899cd4933eSdan}
909cd4933eSdan
919cd4933eSdanregister_tcl_module db
929cd4933eSdando_execsql_test 1.0 {
939cd4933eSdan  CREATE VIRTUAL TABLE x1 USING tcl(vtab_command);
949cd4933eSdan} {}
959cd4933eSdan
969cd4933eSdan
979cd4933eSdanforeach {tn where res} {
989cd4933eSdan  1 "1"                              {{}}
999cd4933eSdan  2 "a=1"                            {{a = 1}}
1009cd4933eSdan  3 "a=1 AND 4 = b"                  {{a = 1 AND b = 4}}
1019cd4933eSdan  4 "c>'hello'"                      {{c > 'hello'}}
1029cd4933eSdan  5 "c<='hel''lo'"                   {{c <= 'hel''lo'}}
1039cd4933eSdan  6 "(a, b) = (SELECT 9, 10)"        {{a = 9 AND b = 10}}
1049cd4933eSdan  7 "(+a, b) = (SELECT 'a', 'b')"    {{b = 'b'}}
1059cd4933eSdan  8 "(a, +b) = (SELECT 'a', 'b')"    {{a = 'a'}}
1069cd4933eSdan  11 "(+a, b) IN (SELECT 'a', 'b')"  {{b = 'b'}}
1079cd4933eSdan  12 "(a, +b) IN (SELECT 'a', 'b')"  {{a = 'a'}}
1089cd4933eSdan
1099cd4933eSdan  13 "(a, b) < ('d', 'e')"           {{a <= 'd'}}
1109cd4933eSdan  14 "(a, b) < ('a', 'c')"           {{a <= 'a'}}
1119cd4933eSdan  15 "(a, b) <= ('a', 'b')"          {{a <= 'a'}}
1129cd4933eSdan  16 "(a, b) < ('a', 'b')"           {}
1139cd4933eSdan} {
1149cd4933eSdan  do_execsql_test 1.$tn "SELECT expr FROM x1 WHERE $where" $res
1159cd4933eSdan}
1169cd4933eSdan
1179cd4933eSdanfinish_test
118