1*5aa550cfSdan# 2017 Jun 24 2*5aa550cfSdan# 3*5aa550cfSdan# The author disclaims copyright to this source code. In place of 4*5aa550cfSdan# a legal notice, here is a blessing: 5*5aa550cfSdan# 6*5aa550cfSdan# May you do good and not evil. 7*5aa550cfSdan# May you find forgiveness for yourself and forgive others. 8*5aa550cfSdan# May you share freely, never taking more than you give. 9*5aa550cfSdan# 10*5aa550cfSdan#*********************************************************************** 11*5aa550cfSdan# 12*5aa550cfSdan# Test that partial indexes work with bound variables. 13*5aa550cfSdan# 14*5aa550cfSdan 15*5aa550cfSdanset testdir [file dirname $argv0] 16*5aa550cfSdansource $testdir/tester.tcl 17*5aa550cfSdanset testprefix index9 18*5aa550cfSdan 19*5aa550cfSdanproc sqluses {sql} { 20*5aa550cfSdan array unset ::T 21*5aa550cfSdan uplevel [list db eval "EXPLAIN $sql" a { 22*5aa550cfSdan if {$a(opcode)=="OpenRead"} { set ::T($a(p2)) 1 } 23*5aa550cfSdan }] 24*5aa550cfSdan 25*5aa550cfSdan set in [join [array names ::T] ,] 26*5aa550cfSdan db eval "SELECT name FROM sqlite_master WHERE rootpage IN ($in) ORDER BY 1" 27*5aa550cfSdan} 28*5aa550cfSdan 29*5aa550cfSdanproc do_sqluses_test {tn sql objects} { 30*5aa550cfSdan uplevel [list do_test $tn [list sqluses $sql] $objects] 31*5aa550cfSdan} 32*5aa550cfSdan 33*5aa550cfSdando_execsql_test 1.0 { 34*5aa550cfSdan CREATE TABLE t1(x, y); 35*5aa550cfSdan CREATE INDEX t1x ON t1(x) WHERE y=45; 36*5aa550cfSdan} 37*5aa550cfSdanset y [expr 45] 38*5aa550cfSdando_sqluses_test 1.1 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1 t1x} 39*5aa550cfSdanset y [expr 45.1] 40*5aa550cfSdando_sqluses_test 1.2 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1} 41*5aa550cfSdanset y [expr 44] 42*5aa550cfSdando_sqluses_test 1.3 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1} 43*5aa550cfSdanunset -nocomplain y 44*5aa550cfSdando_sqluses_test 1.4 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1} 45*5aa550cfSdanset y [string range "45" 0 end] 46*5aa550cfSdando_sqluses_test 1.5 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1} 47*5aa550cfSdan 48*5aa550cfSdando_execsql_test 2.0 { 49*5aa550cfSdan CREATE INDEX t1x2 ON t1(x) WHERE y=-20111000111 50*5aa550cfSdan} 51*5aa550cfSdando_sqluses_test 2.1 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 52*5aa550cfSdanset y [expr -20111000111] 53*5aa550cfSdando_sqluses_test 2.2 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1 t1x2} 54*5aa550cfSdanset y [expr -20111000110] 55*5aa550cfSdando_sqluses_test 2.3 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 56*5aa550cfSdanset y [expr -20111000112] 57*5aa550cfSdando_sqluses_test 2.4 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 58*5aa550cfSdan 59*5aa550cfSdando_execsql_test 3.0 { 60*5aa550cfSdan CREATE INDEX t1x3 ON t1(x) WHERE y=9223372036854775807 61*5aa550cfSdan} 62*5aa550cfSdanset y [expr 9223372036854775807] 63*5aa550cfSdando_sqluses_test 3.1 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1 t1x3} 64*5aa550cfSdanset y [expr 9223372036854775808] 65*5aa550cfSdando_sqluses_test 3.2 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 66*5aa550cfSdanset y [expr 9223372036854775806] 67*5aa550cfSdando_sqluses_test 3.3 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 68*5aa550cfSdan 69*5aa550cfSdando_execsql_test 3.0 { 70*5aa550cfSdan CREATE INDEX t1x4 ON t1(x) WHERE y=-9223372036854775808 71*5aa550cfSdan} 72*5aa550cfSdanset y [expr -9223372036854775808] 73*5aa550cfSdando_sqluses_test 3.1 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1 t1x4} 74*5aa550cfSdanset y [expr -9223372036854775807] 75*5aa550cfSdando_sqluses_test 3.2 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 76*5aa550cfSdanset y [expr -9223372036854775809] 77*5aa550cfSdando_sqluses_test 3.3 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 78*5aa550cfSdanset y [expr -9223372036854775808] 79*5aa550cfSdando_sqluses_test 3.4 { SELECT * FROM t1 WHERE $y=y ORDER BY x } {t1 t1x4} 80*5aa550cfSdan 81*5aa550cfSdanfinish_test 82*5aa550cfSdan 83