235N/A#pragma ident "%Z%%M% %I% %E% SMI"
235N/A# The author disclaims copyright to this source code. In place of
235N/A# a legal notice, here is a blessing:
235N/A# May you do good and not evil.
235N/A# May you find forgiveness for yourself and forgive others.
235N/A# May you share freely, never taking more than you give.
235N/A#***********************************************************************
235N/A# This file implements regression tests for SQLite library. The
235N/A# focus of this file is testing the SELECT statement.
235N/Aset testdir [file dirname $argv0]
235N/A# Create a table with some data
235N/Aexecsql {CREATE TABLE tbl1(f1 int, f2 int)}
235N/Afor {set i 0} {$i<=30} {incr i} {
235N/A puts $f "[expr {$i%9}]\t[expr {$i%10}]"
235N/A# Do a second query inside a first.
235N/A set sql {SELECT DISTINCT f1 FROM tbl1 ORDER BY f1}
235N/A set sql2 "SELECT f2 FROM tbl1 WHERE f1=$f1 ORDER BY f2"
237N/A} {0: 0 7 8 9 1: 0 1 8 9 2: 0 1 2 9 3: 0 1 2 3 4: 2 3 4 5: 3 4 5 6: 4 5 6 7: 5 6 7 8: 6 7 8}
270N/A set sql {SELECT DISTINCT f1 FROM tbl1 WHERE f1>3 AND f1<5}
set sql2 "SELECT f2 FROM tbl1 WHERE f1=$f1 ORDER BY f2"
execsql {CREATE TABLE tbl2(f1 int, f2 int, f3 int)}
for {set i 1} {$i<=30000} {incr i} {
puts $f "$i\t[expr {$i*2}]\t[expr {$i*3}]"
# execsql {--vdbe-trace-on--}
execsql {SELECT count(*) FROM tbl2}
execsql {SELECT count(*) FROM tbl2 WHERE f2>1000}
execsql {SELECT f1 FROM tbl2 WHERE 1000=f2}
execsql {CREATE INDEX idx1 ON tbl2(f2)}
execsql {SELECT f1 FROM tbl2 WHERE 1000=f2}
execsql {SELECT f1 FROM tbl2 WHERE f2=1000}
set sqlite_search_count 0
execsql {SELECT * FROM tbl2 WHERE 1000=f2}
set sqlite_search_count 0
execsql {SELECT * FROM tbl2 WHERE f2=1000}
# Make sure queries run faster with an index than without
execsql {DROP INDEX idx1}
set sqlite_search_count 0
execsql {SELECT f1 FROM tbl2 WHERE f2==2000}
# Make sure we can optimize functions in the WHERE clause that
# use fields from two or more different table. (Bug #6)
INSERT INTO aa VALUES(1);
INSERT INTO aa VALUES(3);
INSERT INTO bb VALUES(2);
INSERT INTO bb VALUES(4);
SELECT * FROM aa, bb WHERE max(a,b)>2;
INSERT INTO bb VALUES(0);
SELECT * FROM aa, bb WHERE b;
SELECT * FROM aa, bb WHERE NOT b;
SELECT * FROM aa, bb WHERE min(a,b);
SELECT * FROM aa, bb WHERE NOT min(a,b);
SELECT * FROM aa, bb WHERE CASE WHEN a=b-1 THEN 1 END;
SELECT * FROM aa, bb WHERE CASE WHEN a=b-1 THEN 0 ELSE 1 END;