format3.test revision 2
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A# 2001 September 15
2N/A#
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A#
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this file is testing the the library is able to correctly
2N/A# handle file-format 3 (version 2.6.x) databases.
2N/A#
2N/A# $Id: format3.test,v 1.4 2003/12/23 02:17:35 drh Exp $
2N/A
2N/Aset testdir [file dirname $argv0]
2N/Asource $testdir/tester.tcl
2N/A
2N/A# Create a bunch of data to sort against
2N/A#
2N/Ado_test format3-1.0 {
2N/A set fd [open data.txt w]
2N/A puts $fd "1\tone\t0\tI\t3.141592653"
2N/A puts $fd "2\ttwo\t1\tII\t2.15"
2N/A puts $fd "3\tthree\t1\tIII\t4221.0"
2N/A puts $fd "4\tfour\t2\tIV\t-0.0013442"
2N/A puts $fd "5\tfive\t2\tV\t-11"
2N/A puts $fd "6\tsix\t2\tVI\t0.123"
2N/A puts $fd "7\tseven\t2\tVII\t123.0"
2N/A puts $fd "8\teight\t3\tVIII\t-1.6"
2N/A close $fd
2N/A execsql {
2N/A CREATE TABLE t1(
2N/A n int,
2N/A v varchar(10),
2N/A log int,
2N/A roman varchar(10),
2N/A flt real
2N/A );
2N/A COPY t1 FROM 'data.txt'
2N/A }
2N/A file delete data.txt
2N/A db close
2N/A set ::bt [btree_open test.db]
2N/A btree_begin_transaction $::bt
2N/A set m [btree_get_meta $::bt]
2N/A set m [lreplace $m 2 2 3]
2N/A eval btree_update_meta $::bt $m
2N/A btree_commit $::bt
2N/A btree_close $::bt
2N/A sqlite db test.db
2N/A execsql {SELECT count(*) FROM t1}
2N/A} {8}
2N/A
2N/Ado_test format3-1.1 {
2N/A execsql {SELECT n FROM t1 ORDER BY n}
2N/A} {1 2 3 4 5 6 7 8}
2N/Ado_test format3-1.1.1 {
2N/A execsql {SELECT n FROM t1 ORDER BY n ASC}
2N/A} {1 2 3 4 5 6 7 8}
2N/Ado_test format3-1.1.1 {
2N/A execsql {SELECT ALL n FROM t1 ORDER BY n ASC}
2N/A} {1 2 3 4 5 6 7 8}
2N/Ado_test format3-1.2 {
2N/A execsql {SELECT n FROM t1 ORDER BY n DESC}
2N/A} {8 7 6 5 4 3 2 1}
2N/Ado_test format3-1.3a {
2N/A execsql {SELECT v FROM t1 ORDER BY v}
2N/A} {eight five four one seven six three two}
2N/Ado_test format3-1.3b {
2N/A execsql {SELECT n FROM t1 ORDER BY v}
2N/A} {8 5 4 1 7 6 3 2}
2N/Ado_test format3-1.4 {
2N/A execsql {SELECT n FROM t1 ORDER BY v DESC}
2N/A} {2 3 6 7 1 4 5 8}
2N/Ado_test format3-1.5 {
2N/A execsql {SELECT flt FROM t1 ORDER BY flt}
2N/A} {-11 -1.6 -0.0013442 0.123 2.15 3.141592653 123.0 4221.0}
2N/Ado_test format3-1.6 {
2N/A execsql {SELECT flt FROM t1 ORDER BY flt DESC}
2N/A} {4221.0 123.0 3.141592653 2.15 0.123 -0.0013442 -1.6 -11}
2N/Ado_test format3-1.7 {
2N/A execsql {SELECT roman FROM t1 ORDER BY roman}
2N/A} {I II III IV V VI VII VIII}
2N/Ado_test format3-1.8 {
2N/A execsql {SELECT n FROM t1 ORDER BY log, flt}
2N/A} {1 2 3 5 4 6 7 8}
2N/Ado_test format3-1.8.1 {
2N/A execsql {SELECT n FROM t1 ORDER BY log asc, flt}
2N/A} {1 2 3 5 4 6 7 8}
2N/Ado_test format3-1.8.2 {
2N/A execsql {SELECT n FROM t1 ORDER BY log, flt ASC}
2N/A} {1 2 3 5 4 6 7 8}
2N/Ado_test format3-1.8.3 {
2N/A execsql {SELECT n FROM t1 ORDER BY log ASC, flt asc}
2N/A} {1 2 3 5 4 6 7 8}
2N/Ado_test format3-1.9 {
2N/A execsql {SELECT n FROM t1 ORDER BY log, flt DESC}
2N/A} {1 3 2 7 6 4 5 8}
2N/Ado_test format3-1.9.1 {
2N/A execsql {SELECT n FROM t1 ORDER BY log ASC, flt DESC}
2N/A} {1 3 2 7 6 4 5 8}
2N/Ado_test format3-1.10 {
2N/A execsql {SELECT n FROM t1 ORDER BY log DESC, flt}
2N/A} {8 5 4 6 7 2 3 1}
2N/Ado_test format3-1.11 {
2N/A execsql {SELECT n FROM t1 ORDER BY log DESC, flt DESC}
2N/A} {8 7 6 4 5 3 2 1}
2N/A
2N/A# These tests are designed to reach some hard-to-reach places
2N/A# inside the string comparison routines.
2N/A#
2N/A# (Later) The sorting behavior changed in 2.7.0. But we will
2N/A# keep these tests. You can never have too many test cases!
2N/A#
2N/Ado_test format3-2.1.1 {
2N/A execsql {
2N/A UPDATE t1 SET v='x' || -flt;
2N/A UPDATE t1 SET v='x-2b' where v=='x-0.123';
2N/A SELECT v FROM t1 ORDER BY v;
2N/A }
2N/A} {x-123 x-2.15 x-2b x-3.141592653 x-4221 x0.0013442 x1.6 x11}
2N/Ado_test format3-2.1.2 {
2N/A execsql {
2N/A SELECT v FROM t1 ORDER BY substr(v,2,999);
2N/A }
2N/A} {x-4221 x-123 x-3.141592653 x-2.15 x0.0013442 x1.6 x11 x-2b}
2N/Ado_test format3-2.1.3 {
2N/A execsql {
2N/A SELECT v FROM t1 ORDER BY substr(v,2,999)+0.0;
2N/A }
2N/A} {x-4221 x-123 x-3.141592653 x-2.15 x-2b x0.0013442 x1.6 x11}
2N/Ado_test format3-2.1.4 {
2N/A execsql {
2N/A SELECT v FROM t1 ORDER BY substr(v,2,999) DESC;
2N/A }
2N/A} {x-2b x11 x1.6 x0.0013442 x-2.15 x-3.141592653 x-123 x-4221}
2N/Ado_test format3-2.1.5 {
2N/A execsql {
2N/A SELECT v FROM t1 ORDER BY substr(v,2,999)+0.0 DESC;
2N/A }
2N/A} {x11 x1.6 x0.0013442 x-2b x-2.15 x-3.141592653 x-123 x-4221}
2N/A
2N/A# This is a bug fix for 2.2.4.
2N/A# Strings are normally mapped to upper-case for a caseless comparison.
2N/A# But this can cause problems for characters in between 'Z' and 'a'.
2N/A#
2N/Ado_test format3-3.1 {
2N/A execsql {
2N/A CREATE TABLE t2(a,b);
2N/A INSERT INTO t2 VALUES('AGLIENTU',1);
2N/A INSERT INTO t2 VALUES('AGLIE`',2);
2N/A INSERT INTO t2 VALUES('AGNA',3);
2N/A SELECT a, b FROM t2 ORDER BY a;
2N/A }
2N/A} {AGLIENTU 1 AGLIE` 2 AGNA 3}
2N/Ado_test format3-3.2 {
2N/A execsql {
2N/A SELECT a, b FROM t2 ORDER BY a DESC;
2N/A }
2N/A} {AGNA 3 AGLIE` 2 AGLIENTU 1}
2N/Ado_test format3-3.3 {
2N/A execsql {
2N/A DELETE FROM t2;
2N/A INSERT INTO t2 VALUES('aglientu',1);
2N/A INSERT INTO t2 VALUES('aglie`',2);
2N/A INSERT INTO t2 VALUES('agna',3);
2N/A SELECT a, b FROM t2 ORDER BY a;
2N/A }
2N/A} {aglie` 2 aglientu 1 agna 3}
2N/Ado_test format3-3.4 {
2N/A execsql {
2N/A SELECT a, b FROM t2 ORDER BY a DESC;
2N/A }
2N/A} {agna 3 aglientu 1 aglie` 2}
2N/A
2N/A# Version 2.7.0 testing.
2N/A#
2N/Ado_test format3-4.1 {
2N/A execsql {
2N/A INSERT INTO t1 VALUES(9,'x2.7',3,'IX',4.0e5);
2N/A INSERT INTO t1 VALUES(10,'x5.0e10',3,'X',-4.0e5);
2N/A INSERT INTO t1 VALUES(11,'x-4.0e9',3,'XI',4.1e4);
2N/A INSERT INTO t1 VALUES(12,'x01234567890123456789',3,'XII',-4.2e3);
2N/A SELECT n FROM t1 ORDER BY n;
2N/A }
2N/A} {1 2 3 4 5 6 7 8 9 10 11 12}
2N/Ado_test format3-4.2 {
2N/A execsql {
2N/A SELECT n||'' FROM t1 ORDER BY 1;
2N/A }
2N/A} {1 2 3 4 5 6 7 8 9 10 11 12}
2N/Ado_test format3-4.3 {
2N/A execsql {
2N/A SELECT n+0 FROM t1 ORDER BY 1;
2N/A }
2N/A} {1 2 3 4 5 6 7 8 9 10 11 12}
2N/Ado_test format3-4.4 {
2N/A execsql {
2N/A SELECT n||'' FROM t1 ORDER BY 1 DESC;
2N/A }
2N/A} {12 11 10 9 8 7 6 5 4 3 2 1}
2N/Ado_test format3-4.5 {
2N/A execsql {
2N/A SELECT n+0 FROM t1 ORDER BY 1 DESC;
2N/A }
2N/A} {12 11 10 9 8 7 6 5 4 3 2 1}
2N/Ado_test format3-4.6 {
2N/A execsql {
2N/A SELECT v FROM t1 ORDER BY 1;
2N/A }
2N/A} {x-123 x-2.15 x-2b x-3.141592653 x-4.0e9 x-4221 x0.0013442 x01234567890123456789 x1.6 x11 x2.7 x5.0e10}
2N/Ado_test format3-4.7 {
2N/A execsql {
2N/A SELECT v FROM t1 ORDER BY 1 DESC;
2N/A }
2N/A} {x5.0e10 x2.7 x11 x1.6 x01234567890123456789 x0.0013442 x-4221 x-4.0e9 x-3.141592653 x-2b x-2.15 x-123}
2N/Ado_test format3-4.8 {
2N/A execsql {
2N/A SELECT substr(v,2,99) FROM t1 ORDER BY 1;
2N/A }
2N/A} {-4.0e9 -4221 -123 -3.141592653 -2.15 0.0013442 1.6 2.7 11 5.0e10 01234567890123456789 -2b}
2N/A
2N/A# Build some new test data, this time with indices.
2N/A#
2N/Ado_test format3-5.0 {
2N/A execsql {
2N/A DROP TABLE t1;
2N/A CREATE TABLE t1(w int, x text, y blob);
2N/A DROP TABLE t2;
2N/A CREATE TABLE t2(p varchar(1), q clob, r real, s numeric(8));
2N/A }
2N/A for {set i 1} {$i<=100} {incr i} {
2N/A set w $i
2N/A set x [expr {int(log($i)/log(2))}]
2N/A set y [expr {$i*$i + 2*$i + 1}]
2N/A execsql "INSERT INTO t1 VALUES($w,$x,$y)"
2N/A }
2N/A execsql {
2N/A INSERT INTO t2 SELECT 101-w, x, (SELECT max(y) FROM t1)+1-y, y FROM t1;
2N/A CREATE INDEX i1w ON t1(w);
2N/A CREATE INDEX i1xy ON t1(x,y);
2N/A CREATE INDEX i2p ON t2(p);
2N/A CREATE INDEX i2r ON t2(r);
2N/A CREATE INDEX i2qs ON t2(q, s);
2N/A }
2N/A} {}
2N/A
2N/A# Do an SQL statement. Append the search count to the end of the result.
2N/A#
2N/Aproc count sql {
2N/A set ::sqlite_search_count 0
2N/A return [concat [execsql $sql] $::sqlite_search_count]
2N/A}
2N/A
2N/A# Verify that queries use an index. We are using the special variable
2N/A# "sqlite_search_count" which tallys the number of executions of MoveTo
2N/A# and Next operators in the VDBE. By verifing that the search count is
2N/A# small we can be assured that indices are being used properly.
2N/A#
2N/Ado_test format3-5.1 {
2N/A db close
2N/A sqlite db test.db
2N/A count {SELECT x, y FROM t1 WHERE w=10}
2N/A} {3 121 3}
2N/Ado_test format3-5.2 {
2N/A count {SELECT x, y FROM t1 WHERE w=11}
2N/A} {3 144 3}
2N/Ado_test format3-5.3 {
2N/A count {SELECT x, y FROM t1 WHERE 11=w}
2N/A} {3 144 3}
2N/Ado_test format3-5.4 {
2N/A count {SELECT x, y FROM t1 WHERE 11=w AND x>2}
2N/A} {3 144 3}
2N/Ado_test format3-5.5 {
2N/A count {SELECT x, y FROM t1 WHERE y<200 AND w=11 AND x>2}
2N/A} {3 144 3}
2N/Ado_test format3-5.6 {
2N/A count {SELECT x, y FROM t1 WHERE y<200 AND x>2 AND w=11}
2N/A} {3 144 3}
2N/Ado_test format3-5.7 {
2N/A count {SELECT x, y FROM t1 WHERE w=11 AND y<200 AND x>2}
2N/A} {3 144 3}
2N/Ado_test format3-5.8 {
2N/A count {SELECT x, y FROM t1 WHERE w>10 AND y=144 AND x=3}
2N/A} {3 144 3}
2N/Ado_test format3-5.9 {
2N/A count {SELECT x, y FROM t1 WHERE y=144 AND w>10 AND x=3}
2N/A} {3 144 3}
2N/Ado_test format3-5.10 {
2N/A count {SELECT x, y FROM t1 WHERE x=3 AND w>=10 AND y=121}
2N/A} {3 121 3}
2N/Ado_test format3-5.11 {
2N/A count {SELECT x, y FROM t1 WHERE x=3 AND y=100 AND w<10}
2N/A} {3 100 3}
2N/A
2N/A# New for SQLite version 2.1: Verify that that inequality constraints
2N/A# are used correctly.
2N/A#
2N/Ado_test format3-5.12 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND y<100}
2N/A} {8 3}
2N/Ado_test format3-5.13 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND 100>y}
2N/A} {8 3}
2N/Ado_test format3-5.14 {
2N/A count {SELECT w FROM t1 WHERE 3=x AND y<100}
2N/A} {8 3}
2N/Ado_test format3-5.15 {
2N/A count {SELECT w FROM t1 WHERE 3=x AND 100>y}
2N/A} {8 3}
2N/Ado_test format3-5.16 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND y<=100}
2N/A} {8 9 5}
2N/Ado_test format3-5.17 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND 100>=y}
2N/A} {8 9 5}
2N/Ado_test format3-5.18 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND y>225}
2N/A} {15 3}
2N/Ado_test format3-5.19 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND 225<y}
2N/A} {15 3}
2N/Ado_test format3-5.20 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND y>=225}
2N/A} {14 15 5}
2N/Ado_test format3-5.21 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND 225<=y}
2N/A} {14 15 5}
2N/Ado_test format3-5.22 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND y>121 AND y<196}
2N/A} {11 12 5}
2N/Ado_test format3-5.23 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<=196}
2N/A} {10 11 12 13 9}
2N/Ado_test format3-5.24 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND 121<y AND 196>y}
2N/A} {11 12 5}
2N/Ado_test format3-5.25 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND 121<=y AND 196>=y}
2N/A} {10 11 12 13 9}
2N/A
2N/A# Need to work on optimizing the BETWEEN operator.
2N/A#
2N/A# do_test format3-5.26 {
2N/A# count {SELECT w FROM t1 WHERE x=3 AND y BETWEEN 121 AND 196}
2N/A# } {10 11 12 13 9}
2N/A
2N/Ado_test format3-5.27 {
2N/A count {SELECT w FROM t1 WHERE x=3 AND y+1==122}
2N/A} {10 17}
2N/Ado_test format3-5.28 {
2N/A count {SELECT w FROM t1 WHERE x+1=4 AND y+1==122}
2N/A} {10 99}
2N/Ado_test format3-5.29 {
2N/A count {SELECT w FROM t1 WHERE y==121}
2N/A} {10 99}
2N/A
2N/A
2N/Ado_test format3-5.30 {
2N/A count {SELECT w FROM t1 WHERE w>97}
2N/A} {98 99 100 6}
2N/Ado_test format3-5.31 {
2N/A count {SELECT w FROM t1 WHERE w>=97}
2N/A} {97 98 99 100 8}
2N/Ado_test format3-5.33 {
2N/A count {SELECT w FROM t1 WHERE w==97}
2N/A} {97 3}
2N/Ado_test format3-5.34 {
2N/A count {SELECT w FROM t1 WHERE w+1==98}
2N/A} {97 99}
2N/Ado_test format3-5.35 {
2N/A count {SELECT w FROM t1 WHERE w<3}
2N/A} {1 2 4}
2N/Ado_test format3-5.36 {
2N/A count {SELECT w FROM t1 WHERE w<=3}
2N/A} {1 2 3 6}
2N/Ado_test format3-5.37 {
2N/A count {SELECT w FROM t1 WHERE w+1<=4 ORDER BY w}
2N/A} {1 2 3 199}
2N/A
2N/A
2N/A# Do the same kind of thing except use a join as the data source.
2N/A#
2N/Ado_test format3-6.1 {
2N/A db close
2N/A sqlite db test.db
2N/A count {
2N/A SELECT w, p FROM t2, t1
2N/A WHERE x=q AND y=s AND r=8977
2N/A }
2N/A} {34 67 6}
2N/Ado_test format3-6.2 {
2N/A count {
2N/A SELECT w, p FROM t2, t1
2N/A WHERE x=q AND s=y AND r=8977
2N/A }
2N/A} {34 67 6}
2N/Ado_test format3-6.3 {
2N/A count {
2N/A SELECT w, p FROM t2, t1
2N/A WHERE x=q AND s=y AND r=8977 AND w>10
2N/A }
2N/A} {34 67 6}
2N/Ado_test format3-6.4 {
2N/A count {
2N/A SELECT w, p FROM t2, t1
2N/A WHERE p<80 AND x=q AND s=y AND r=8977 AND w>10
2N/A }
2N/A} {34 67 6}
2N/Ado_test format3-6.5 {
2N/A count {
2N/A SELECT w, p FROM t2, t1
2N/A WHERE p<80 AND x=q AND 8977=r AND s=y AND w>10
2N/A }
2N/A} {34 67 6}
2N/Ado_test format3-6.6 {
2N/A count {
2N/A SELECT w, p FROM t2, t1
2N/A WHERE x=q AND p=77 AND s=y AND w>5
2N/A }
2N/A} {24 77 6}
2N/Ado_test format3-6.7 {
2N/A count {
2N/A SELECT w, p FROM t1, t2
2N/A WHERE x=q AND p>77 AND s=y AND w=5
2N/A }
2N/A} {5 96 6}
2N/A
2N/A# Lets do a 3-way join.
2N/A#
2N/Ado_test format3-7.1 {
2N/A count {
2N/A SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C
2N/A WHERE C.w=101-B.p AND B.r=10202-A.y AND A.w=11
2N/A }
2N/A} {11 90 11 9}
2N/Ado_test format3-7.2 {
2N/A count {
2N/A SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C
2N/A WHERE C.w=101-B.p AND B.r=10202-A.y AND A.w=12
2N/A }
2N/A} {12 89 12 9}
2N/Ado_test format3-7.3 {
2N/A count {
2N/A SELECT A.w, B.p, C.w FROM t1 as A, t2 as B, t1 as C
2N/A WHERE A.w=15 AND B.p=C.w AND B.r=10202-A.y
2N/A }
2N/A} {15 86 86 9}
2N/A
2N/A# Test to see that the special case of a constant WHERE clause is
2N/A# handled.
2N/A#
2N/Ado_test format3-8.1 {
2N/A count {
2N/A SELECT * FROM t1 WHERE 0
2N/A }
2N/A} {0}
2N/Ado_test format3-8.2 {
2N/A count {
2N/A SELECT * FROM t1 WHERE 1 LIMIT 1
2N/A }
2N/A} {1 0 4 1}
2N/Ado_test format3-8.3 {
2N/A execsql {
2N/A SELECT 99 WHERE 0
2N/A }
2N/A} {}
2N/Ado_test format3-8.4 {
2N/A execsql {
2N/A SELECT 99 WHERE 1
2N/A }
2N/A} {99}
2N/A
2N/A# Verify that IN operators in a WHERE clause are handled correctly.
2N/A#
2N/Ado_test format3-9.1 {
2N/A count {
2N/A SELECT * FROM t1 WHERE rowid IN (1,2,3,1234) order by 1;
2N/A }
2N/A} {1 0 4 2 1 9 3 1 16 0}
2N/Ado_test format3-9.2 {
2N/A count {
2N/A SELECT * FROM t1 WHERE rowid+0 IN (1,2,3,1234) order by 1;
2N/A }
2N/A} {1 0 4 2 1 9 3 1 16 199}
2N/Ado_test format3-9.3 {
2N/A count {
2N/A SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1;
2N/A }
2N/A} {1 0 4 2 1 9 3 1 16 10}
2N/Ado_test format3-9.4 {
2N/A count {
2N/A SELECT * FROM t1 WHERE w+0 IN (-1,1,2,3) order by 1;
2N/A }
2N/A} {1 0 4 2 1 9 3 1 16 199}
2N/Ado_test format3-9.5 {
2N/A count {
2N/A SELECT * FROM t1 WHERE rowid IN
2N/A (select rowid from t1 where rowid IN (-1,2,4))
2N/A ORDER BY 1;
2N/A }
2N/A} {2 1 9 4 2 25 1}
2N/Ado_test format3-9.6 {
2N/A count {
2N/A SELECT * FROM t1 WHERE rowid+0 IN
2N/A (select rowid from t1 where rowid IN (-1,2,4))
2N/A ORDER BY 1;
2N/A }
2N/A} {2 1 9 4 2 25 199}
2N/Ado_test format3-9.7 {
2N/A count {
2N/A SELECT * FROM t1 WHERE w IN
2N/A (select rowid from t1 where rowid IN (-1,2,4))
2N/A ORDER BY 1;
2N/A }
2N/A} {2 1 9 4 2 25 7}
2N/Ado_test format3-9.8 {
2N/A count {
2N/A SELECT * FROM t1 WHERE w+0 IN
2N/A (select rowid from t1 where rowid IN (-1,2,4))
2N/A ORDER BY 1;
2N/A }
2N/A} {2 1 9 4 2 25 199}
2N/Ado_test format3-9.9 {
2N/A count {
2N/A SELECT * FROM t1 WHERE x IN (1,7) ORDER BY 1;
2N/A }
2N/A} {2 1 9 3 1 16 6}
2N/Ado_test format3-9.10 {
2N/A count {
2N/A SELECT * FROM t1 WHERE x+0 IN (1,7) ORDER BY 1;
2N/A }
2N/A} {2 1 9 3 1 16 199}
2N/Ado_test format3-9.11 {
2N/A count {
2N/A SELECT * FROM t1 WHERE y IN (6400,8100) ORDER BY 1;
2N/A }
2N/A} {79 6 6400 89 6 8100 199}
2N/Ado_test format3-9.12 {
2N/A count {
2N/A SELECT * FROM t1 WHERE x=6 AND y IN (6400,8100) ORDER BY 1;
2N/A }
2N/A} {79 6 6400 89 6 8100 74}
2N/Ado_test format3-9.13 {
2N/A count {
2N/A SELECT * FROM t1 WHERE x IN (1,7) AND y NOT IN (6400,8100) ORDER BY 1;
2N/A }
2N/A} {2 1 9 3 1 16 6}
2N/Ado_test format3-9.14 {
2N/A count {
2N/A SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,10) ORDER BY 1;
2N/A }
2N/A} {2 1 9 6}
2N/A
2N/A# This procedure executes the SQL. Then it checks the generated program
2N/A# for the SQL and appends a "nosort" to the result if the program contains the
2N/A# SortCallback opcode. If the program does not contain the SortCallback
2N/A# opcode it appends "sort"
2N/A#
2N/Aproc cksort {sql} {
2N/A set data [execsql $sql]
2N/A set prog [execsql "EXPLAIN $sql"]
2N/A if {[regexp SortCallback $prog]} {set x sort} {set x nosort}
2N/A lappend data $x
2N/A return $data
2N/A}
2N/A# Check out the logic that attempts to implement the ORDER BY clause
2N/A# using an index rather than by sorting.
2N/A#
2N/Ado_test format3-10.1 {
2N/A execsql {
2N/A CREATE TABLE t3(a,b,c);
2N/A CREATE INDEX t3a ON t3(a);
2N/A CREATE INDEX t3bc ON t3(b,c);
2N/A CREATE INDEX t3acb ON t3(a,c,b);
2N/A INSERT INTO t3 SELECT w, 101-w, y FROM t1;
2N/A SELECT count(*), sum(a), sum(b), sum(c) FROM t3;
2N/A }
2N/A} {100 5050 5050 348550}
2N/Ado_test format3-10.2 {
2N/A cksort {
2N/A SELECT * FROM t3 ORDER BY a LIMIT 3
2N/A }
2N/A} {1 100 4 2 99 9 3 98 16 nosort}
2N/Ado_test format3-10.3 {
2N/A cksort {
2N/A SELECT * FROM t3 ORDER BY a+1 LIMIT 3
2N/A }
2N/A} {1 100 4 2 99 9 3 98 16 sort}
2N/Ado_test format3-10.4 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE a<10 ORDER BY a LIMIT 3
2N/A }
2N/A} {1 100 4 2 99 9 3 98 16 nosort}
2N/Ado_test format3-10.5 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE a>0 AND a<10 ORDER BY a LIMIT 3
2N/A }
2N/A} {1 100 4 2 99 9 3 98 16 nosort}
2N/Ado_test format3-10.6 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE a>0 ORDER BY a LIMIT 3
2N/A }
2N/A} {1 100 4 2 99 9 3 98 16 nosort}
2N/Ado_test format3-10.7 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE b>0 ORDER BY a LIMIT 3
2N/A }
2N/A} {1 100 4 2 99 9 3 98 16 sort}
2N/Ado_test format3-10.8 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE a IN (3,5,7,1,9,4,2) ORDER BY a LIMIT 3
2N/A }
2N/A} {1 100 4 2 99 9 3 98 16 sort}
2N/Ado_test format3-10.9 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a LIMIT 3
2N/A }
2N/A} {1 100 4 nosort}
2N/Ado_test format3-10.10 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a LIMIT 3
2N/A }
2N/A} {1 100 4 nosort}
2N/Ado_test format3-10.11 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c LIMIT 3
2N/A }
2N/A} {1 100 4 nosort}
2N/Ado_test format3-10.12 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a,c,b LIMIT 3
2N/A }
2N/A} {1 100 4 nosort}
2N/Ado_test format3-10.13 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE a>0 ORDER BY a DESC LIMIT 3
2N/A }
2N/A} {100 1 10201 99 2 10000 98 3 9801 nosort}
2N/Ado_test format3-10.13.1 {
2N/A cksort {
2N/A SELECT * FROM t3 WHERE a>0 ORDER BY a+1 DESC LIMIT 3
2N/A }
2N/A} {100 1 10201 99 2 10000 98 3 9801 sort}
2N/Ado_test format3-10.14 {
2N/A cksort {
2N/A SELECT * FROM t3 ORDER BY b LIMIT 3
2N/A }
2N/A} {100 1 10201 99 2 10000 98 3 9801 nosort}
2N/Ado_test format3-10.15 {
2N/A cksort {
2N/A SELECT t3.a, t1.x FROM t3, t1 WHERE t3.a=t1.w ORDER BY t3.a LIMIT 3
2N/A }
2N/A} {1 0 2 1 3 1 nosort}
2N/Ado_test format3-10.16 {
2N/A cksort {
2N/A SELECT t3.a, t1.x FROM t3, t1 WHERE t3.a=t1.w ORDER BY t1.x, t3.a LIMIT 3
2N/A }
2N/A} {1 0 2 1 3 1 sort}
2N/Ado_test format3-10.17 {
2N/A cksort {
2N/A SELECT y FROM t1 ORDER BY w COLLATE text LIMIT 3;
2N/A }
2N/A} {4 121 10201 sort}
2N/Ado_test format3-10.18 {
2N/A cksort {
2N/A SELECT y FROM t1 ORDER BY w COLLATE numeric LIMIT 3;
2N/A }
2N/A} {4 9 16 sort}
2N/Ado_test format3-10.19 {
2N/A cksort {
2N/A SELECT y FROM t1 ORDER BY w LIMIT 3;
2N/A }
2N/A} {4 9 16 nosort}
2N/A
2N/A# Check that all comparisons are numeric. Similar tests in misc1.test
2N/A# check the same comparisons on a format4+ database and find that some
2N/A# are numeric and some are text.
2N/A#
2N/Ado_test format3-11.1 {
2N/A execsql {SELECT '0'=='0.0'}
2N/A} {1}
2N/Ado_test format3-11.2 {
2N/A execsql {SELECT '0'==0.0}
2N/A} {1}
2N/Ado_test format3-11.3 {
2N/A execsql {SELECT '123456789012345678901'=='123456789012345678900'}
2N/A} {1}
2N/Ado_test format3-11.4 {
2N/A execsql {
2N/A CREATE TABLE t6(a INT UNIQUE, b TEXT UNIQUE);
2N/A INSERT INTO t6 VALUES('0','0.0');
2N/A SELECT * FROM t6;
2N/A }
2N/A} {0 0.0}
2N/Ado_test format3-11.5 {
2N/A execsql {
2N/A INSERT OR IGNORE INTO t6 VALUES(0.0,'x');
2N/A SELECT * FROM t6;
2N/A }
2N/A} {0 0.0}
2N/Ado_test format3-11.6 {
2N/A execsql {
2N/A INSERT OR IGNORE INTO t6 VALUES('y',0);
2N/A SELECT * FROM t6;
2N/A }
2N/A} {0 0.0}
2N/Ado_test format3-11.7 {
2N/A execsql {
2N/A CREATE TABLE t7(x INTEGER, y TEXT, z);
2N/A INSERT INTO t7 VALUES(0,0,1);
2N/A INSERT INTO t7 VALUES(0.0,0,2);
2N/A INSERT INTO t7 VALUES(0,0.0,3);
2N/A INSERT INTO t7 VALUES(0.0,0.0,4);
2N/A SELECT DISTINCT x, y FROM t7 ORDER BY z;
2N/A }
2N/A} {0 0}
2N/A
2N/A# Make sure attempts to attach a format 3 database fail.
2N/A#
2N/Ado_test format3-12.1 {
2N/A file delete -force test2.db
2N/A sqlite db2 test2.db
2N/A catchsql {
2N/A CREATE TABLE t8(x,y);
2N/A ATTACH DATABASE 'test.db' AS format3;
2N/A } db2;
2N/A} {1 {incompatible file format in auxiliary database: format3}}
2N/Ado_test format3-12.2 {
2N/A catchsql {
2N/A ATTACH DATABASE 'test2.db' AS test2;
2N/A }
2N/A} {1 {cannot attach auxiliary databases to an older format master database}}
2N/Adb2 close
2N/A
2N/Afinish_test