2016-02-22 20:51:08 +01:00
|
|
|
# 2009 Nov 11
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
|
|
|
# The focus of this file is testing the CLI shell tool. Specifically,
|
|
|
|
# the ".recommend" command.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
# Test plan:
|
|
|
|
#
|
|
|
|
#
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2017-04-08 20:56:32 +02:00
|
|
|
set testprefix expert1
|
2016-02-22 20:51:08 +01:00
|
|
|
|
|
|
|
if {$tcl_platform(platform)=="windows"} {
|
2017-04-08 20:56:32 +02:00
|
|
|
set CMD "sqlite3_expert.exe"
|
2016-02-22 20:51:08 +01:00
|
|
|
} else {
|
2017-04-08 20:56:32 +02:00
|
|
|
set CMD ".././sqlite3_expert"
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
2017-04-08 20:56:32 +02:00
|
|
|
if {![file executable $CMD]} {
|
2016-02-22 20:51:08 +01:00
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
proc squish {txt} {
|
|
|
|
regsub -all {[[:space:]]+} $txt { }
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_rec_test {tn sql res} {
|
|
|
|
set res [squish [string trim $res]]
|
|
|
|
set tst [subst -nocommands {
|
2017-04-08 20:56:32 +02:00
|
|
|
squish [string trim [exec $::CMD -verbose 0 -sql {$sql;} test.db]]
|
2016-02-22 20:51:08 +01:00
|
|
|
}]
|
|
|
|
uplevel [list do_test $tn $tst $res]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_setup_rec_test {tn setup sql res} {
|
|
|
|
reset_db
|
|
|
|
db eval $setup
|
|
|
|
uplevel [list do_rec_test $tn $sql $res]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
do_setup_rec_test 1.1 { CREATE TABLE t1(a, b, c) } {
|
|
|
|
SELECT * FROM t1
|
|
|
|
} {
|
|
|
|
(no new indexes)
|
|
|
|
0|0|0|SCAN TABLE t1
|
|
|
|
}
|
|
|
|
|
|
|
|
do_setup_rec_test 1.2 {
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 WHERE b>?;
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_00000062 ON t1(b);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SEARCH TABLE t1 USING INDEX t1_idx_00000062 (b>?)
|
|
|
|
}
|
|
|
|
|
|
|
|
do_setup_rec_test 1.3 {
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 WHERE b COLLATE nocase BETWEEN ? AND ?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_3e094c27 ON t1(b COLLATE NOCASE);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SEARCH TABLE t1 USING INDEX t1_idx_3e094c27 (b>? AND b<?)
|
|
|
|
}
|
|
|
|
|
|
|
|
do_setup_rec_test 1.4 {
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT a FROM t1 ORDER BY b;
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_00000062 ON t1(b);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SCAN TABLE t1 USING INDEX t1_idx_00000062
|
|
|
|
}
|
|
|
|
|
|
|
|
do_setup_rec_test 1.5 {
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT a FROM t1 WHERE a=? ORDER BY b;
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_000123a7 ON t1(a, b);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SEARCH TABLE t1 USING COVERING INDEX t1_idx_000123a7 (a=?)
|
|
|
|
}
|
|
|
|
|
|
|
|
do_setup_rec_test 1.6 {
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT min(a) FROM t1
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_00000061 ON t1(a);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SEARCH TABLE t1 USING COVERING INDEX t1_idx_00000061
|
|
|
|
}
|
|
|
|
|
|
|
|
do_setup_rec_test 1.7 {
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 ORDER BY a, b, c;
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_033e95fe ON t1(a, b, c);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SCAN TABLE t1 USING COVERING INDEX t1_idx_033e95fe
|
|
|
|
}
|
|
|
|
|
|
|
|
do_setup_rec_test 1.8 {
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 ORDER BY a ASC, b COLLATE nocase DESC, c ASC;
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_5be6e222 ON t1(a, b COLLATE NOCASE DESC, c);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SCAN TABLE t1 USING COVERING INDEX t1_idx_5be6e222
|
|
|
|
}
|
|
|
|
|
|
|
|
do_setup_rec_test 1.9 {
|
|
|
|
CREATE TABLE t1(a COLLATE NOCase, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 WHERE a=?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_00000061 ON t1(a);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SEARCH TABLE t1 USING INDEX t1_idx_00000061 (a=?)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Tables with names that require quotes.
|
|
|
|
#
|
|
|
|
do_setup_rec_test 8.1 {
|
|
|
|
CREATE TABLE "t t"(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM "t t" WHERE a=?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX 't t_idx_00000061' ON 't t'(a);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SEARCH TABLE t t USING INDEX t t_idx_00000061 (a=?)
|
|
|
|
}
|
|
|
|
|
|
|
|
do_setup_rec_test 8.2 {
|
|
|
|
CREATE TABLE "t t"(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM "t t" WHERE b BETWEEN ? AND ?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX 't t_idx_00000062' ON 't t'(b);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SEARCH TABLE t t USING INDEX t t_idx_00000062 (b>? AND b<?)
|
|
|
|
}
|
|
|
|
|
|
|
|
# Columns with names that require quotes.
|
|
|
|
#
|
|
|
|
do_setup_rec_test 9.1 {
|
|
|
|
CREATE TABLE t3(a, "b b", c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t3 WHERE "b b" = ?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t3_idx_00050c52 ON t3('b b');
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SEARCH TABLE t3 USING INDEX t3_idx_00050c52 (b b=?)
|
|
|
|
}
|
|
|
|
|
|
|
|
do_setup_rec_test 9.2 {
|
|
|
|
CREATE TABLE t3(a, "b b", c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t3 ORDER BY "b b"
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t3_idx_00050c52 ON t3('b b');
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|0|SCAN TABLE t3 USING INDEX t3_idx_00050c52
|
|
|
|
}
|
|
|
|
|
|
|
|
# Transitive constraints
|
|
|
|
#
|
|
|
|
do_setup_rec_test 10.1 {
|
|
|
|
CREATE TABLE t5(a, b);
|
|
|
|
CREATE TABLE t6(c, d);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t5, t6 WHERE a=? AND b=c AND c=?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t5_idx_000123a7 ON t5(a, b);
|
|
|
|
CREATE INDEX t6_idx_00000063 ON t6(c);
|
2016-02-22 20:51:08 +01:00
|
|
|
0|0|1|SEARCH TABLE t6 USING INDEX t6_idx_00000063 (c=?)
|
|
|
|
0|1|0|SEARCH TABLE t5 USING COVERING INDEX t5_idx_000123a7 (a=? AND b=?)
|
|
|
|
}
|
|
|
|
|
2017-04-04 19:50:31 +02:00
|
|
|
# OR terms.
|
|
|
|
#
|
|
|
|
do_setup_rec_test 11.1 {
|
|
|
|
CREATE TABLE t7(a, b);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t7 WHERE a=? OR b=?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t7_idx_00000062 ON t7(b);
|
2017-04-08 20:56:32 +02:00
|
|
|
CREATE INDEX t7_idx_00000061 ON t7(a);
|
2017-04-04 19:50:31 +02:00
|
|
|
0|0|0|SEARCH TABLE t7 USING INDEX t7_idx_00000061 (a=?)
|
|
|
|
0|0|0|SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
|
|
|
|
}
|
|
|
|
|
2016-02-22 20:51:08 +01:00
|
|
|
finish_test
|
2017-04-04 19:50:31 +02:00
|
|
|
|