15aa550cfSdan# 2017 Jun 24 25aa550cfSdan# 35aa550cfSdan# The author disclaims copyright to this source code. In place of 45aa550cfSdan# a legal notice, here is a blessing: 55aa550cfSdan# 65aa550cfSdan# May you do good and not evil. 75aa550cfSdan# May you find forgiveness for yourself and forgive others. 85aa550cfSdan# May you share freely, never taking more than you give. 95aa550cfSdan# 105aa550cfSdan#*********************************************************************** 115aa550cfSdan# 125aa550cfSdan# Test that partial indexes work with bound variables. 135aa550cfSdan# 145aa550cfSdan 155aa550cfSdanset testdir [file dirname $argv0] 165aa550cfSdansource $testdir/tester.tcl 175aa550cfSdanset testprefix index9 185aa550cfSdan 195aa550cfSdanproc sqluses {sql} { 205aa550cfSdan array unset ::T 215aa550cfSdan uplevel [list db eval "EXPLAIN $sql" a { 225aa550cfSdan if {$a(opcode)=="OpenRead"} { set ::T($a(p2)) 1 } 235aa550cfSdan }] 245aa550cfSdan 255aa550cfSdan set in [join [array names ::T] ,] 265aa550cfSdan db eval "SELECT name FROM sqlite_master WHERE rootpage IN ($in) ORDER BY 1" 275aa550cfSdan} 285aa550cfSdan 295aa550cfSdanproc do_sqluses_test {tn sql objects} { 305aa550cfSdan uplevel [list do_test $tn [list sqluses $sql] $objects] 315aa550cfSdan} 325aa550cfSdan 335aa550cfSdando_execsql_test 1.0 { 345aa550cfSdan CREATE TABLE t1(x, y); 355aa550cfSdan CREATE INDEX t1x ON t1(x) WHERE y=45; 365aa550cfSdan} 37*f6bee94eSdrhunset -nocomplain a 385aa550cfSdanset y [expr 45] 395aa550cfSdando_sqluses_test 1.1 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1 t1x} 405aa550cfSdanset y [expr 45.1] 415aa550cfSdando_sqluses_test 1.2 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1} 425aa550cfSdanset y [expr 44] 435aa550cfSdando_sqluses_test 1.3 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1} 445aa550cfSdanunset -nocomplain y 455aa550cfSdando_sqluses_test 1.4 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1} 465aa550cfSdanset y [string range "45" 0 end] 475aa550cfSdando_sqluses_test 1.5 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1} 485aa550cfSdan 495aa550cfSdando_execsql_test 2.0 { 505aa550cfSdan CREATE INDEX t1x2 ON t1(x) WHERE y=-20111000111 515aa550cfSdan} 525aa550cfSdando_sqluses_test 2.1 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 535aa550cfSdanset y [expr -20111000111] 545aa550cfSdando_sqluses_test 2.2 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1 t1x2} 555aa550cfSdanset y [expr -20111000110] 565aa550cfSdando_sqluses_test 2.3 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 575aa550cfSdanset y [expr -20111000112] 585aa550cfSdando_sqluses_test 2.4 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 595aa550cfSdan 605aa550cfSdando_execsql_test 3.0 { 615aa550cfSdan CREATE INDEX t1x3 ON t1(x) WHERE y=9223372036854775807 625aa550cfSdan} 635aa550cfSdanset y [expr 9223372036854775807] 645aa550cfSdando_sqluses_test 3.1 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1 t1x3} 655aa550cfSdanset y [expr 9223372036854775808] 665aa550cfSdando_sqluses_test 3.2 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 675aa550cfSdanset y [expr 9223372036854775806] 685aa550cfSdando_sqluses_test 3.3 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 693e380a44Sdrhdb cache flush 703e380a44Sdrhsqlite3_db_config db QPSG 1 713e380a44Sdrhset y [expr 9223372036854775807] 723e380a44Sdrhdo_sqluses_test 3.4 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 733e380a44Sdrhset y [expr 9223372036854775808] 743e380a44Sdrhdo_sqluses_test 3.5 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 753e380a44Sdrhsqlite3_db_config db QPSG 0 763e380a44Sdrhdb cache flush 775aa550cfSdan 783e380a44Sdrh 793e380a44Sdrhdo_execsql_test 4.0 { 805aa550cfSdan CREATE INDEX t1x4 ON t1(x) WHERE y=-9223372036854775808 815aa550cfSdan} 825aa550cfSdanset y [expr -9223372036854775808] 833e380a44Sdrhdo_sqluses_test 4.1 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1 t1x4} 845aa550cfSdanset y [expr -9223372036854775807] 853e380a44Sdrhdo_sqluses_test 4.2 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 865aa550cfSdanset y [expr -9223372036854775809] 873e380a44Sdrhdo_sqluses_test 4.3 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1} 885aa550cfSdanset y [expr -9223372036854775808] 893e380a44Sdrhdo_sqluses_test 4.4 { SELECT * FROM t1 WHERE $y=y ORDER BY x } {t1 t1x4} 903e380a44Sdrhdb cache flush 913e380a44Sdrhsqlite3_db_config db QPSG 1 923e380a44Sdrhdo_sqluses_test 4.5 { SELECT * FROM t1 WHERE $y=y ORDER BY x } {t1} 933e380a44Sdrhsqlite3_db_config db QPSG 0 943e380a44Sdrhdb cache flush 955aa550cfSdan 965aa550cfSdanfinish_test 97