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 CREATE TABLE statement.
2N/A#
2N/A# $Id: sort.test,v 1.9 2003/04/18 17:45:15 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 sort-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 execsql {SELECT count(*) FROM t1}
2N/A} {8}
2N/A
2N/Ado_test sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-2.1.2 {
2N/A execsql {
2N/A SELECT v FROM t1 ORDER BY substr(v,2,999);
2N/A }
2N/A} {x-123 x-2.15 x-2b x-3.141592653 x-4221 x0.0013442 x1.6 x11}
2N/Ado_test sort-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 sort-2.1.4 {
2N/A execsql {
2N/A SELECT v FROM t1 ORDER BY substr(v,2,999) DESC;
2N/A }
2N/A} {x11 x1.6 x0.0013442 x-4221 x-3.141592653 x-2b x-2.15 x-123}
2N/Ado_test sort-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 sort-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 sort-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 sort-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 sort-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 sort-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 sort-4.2 {
2N/A execsql {
2N/A SELECT n||'' FROM t1 ORDER BY 1;
2N/A }
2N/A} {1 10 11 12 2 3 4 5 6 7 8 9}
2N/Ado_test sort-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 sort-4.4 {
2N/A execsql {
2N/A SELECT n||'' FROM t1 ORDER BY 1 DESC;
2N/A }
2N/A} {9 8 7 6 5 4 3 2 12 11 10 1}
2N/Ado_test sort-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 sort-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 sort-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 sort-4.8 {
2N/A execsql {
2N/A SELECT substr(v,2,99) FROM t1 ORDER BY 1;
2N/A }
2N/A} {-123 -2.15 -2b -3.141592653 -4.0e9 -4221 0.0013442 01234567890123456789 1.6 11 2.7 5.0e10}
2N/A#do_test sort-4.9 {
2N/A# execsql {
2N/A# SELECT substr(v,2,99)+0.0 FROM t1 ORDER BY 1;
2N/A# }
2N/A#} {-4000000000 -4221 -123 -3.141592653 -2.15 -2 0.0013442 1.6 2.7 11 50000000000 1.23456789012346e+18}
2N/A
2N/Ado_test sort-5.1 {
2N/A execsql {
2N/A create table t3(a,b);
2N/A insert into t3 values(5,NULL);
2N/A insert into t3 values(6,NULL);
2N/A insert into t3 values(3,NULL);
2N/A insert into t3 values(4,'cd');
2N/A insert into t3 values(1,'ab');
2N/A insert into t3 values(2,NULL);
2N/A select a from t3 order by b, a;
2N/A }
2N/A} {2 3 5 6 1 4}
2N/Ado_test sort-5.2 {
2N/A execsql {
2N/A select a from t3 order by b, a desc;
2N/A }
2N/A} {6 5 3 2 1 4}
2N/Ado_test sort-5.3 {
2N/A execsql {
2N/A select a from t3 order by b desc, a;
2N/A }
2N/A} {4 1 2 3 5 6}
2N/Ado_test sort-5.4 {
2N/A execsql {
2N/A select a from t3 order by b desc, a desc;
2N/A }
2N/A} {4 1 6 5 3 2}
2N/A
2N/Ado_test sort-6.1 {
2N/A execsql {
2N/A create index i3 on t3(b,a);
2N/A select a from t3 order by b, a;
2N/A }
2N/A} {2 3 5 6 1 4}
2N/Ado_test sort-6.2 {
2N/A execsql {
2N/A select a from t3 order by b, a desc;
2N/A }
2N/A} {6 5 3 2 1 4}
2N/Ado_test sort-6.3 {
2N/A execsql {
2N/A select a from t3 order by b desc, a;
2N/A }
2N/A} {4 1 2 3 5 6}
2N/Ado_test sort-6.4 {
2N/A execsql {
2N/A select a from t3 order by b desc, a desc;
2N/A }
2N/A} {4 1 6 5 3 2}
2N/A
2N/Ado_test sort-7.1 {
2N/A execsql {
2N/A CREATE TABLE t4(
2N/A a INTEGER,
2N/A b VARCHAR(30)
2N/A );
2N/A INSERT INTO t4 VALUES(1,1);
2N/A INSERT INTO t4 VALUES(2,2);
2N/A INSERT INTO t4 VALUES(11,11);
2N/A INSERT INTO t4 VALUES(12,12);
2N/A SELECT a FROM t4 ORDER BY 1;
2N/A }
2N/A} {1 2 11 12}
2N/Ado_test sort-7.2 {
2N/A execsql {
2N/A SELECT b FROM t4 ORDER BY 1
2N/A }
2N/A} {1 11 12 2}
2N/Ado_test sort-7.3 {
2N/A execsql {
2N/A CREATE VIEW v4 AS SELECT * FROM t4;
2N/A SELECT a FROM v4 ORDER BY 1;
2N/A }
2N/A} {1 2 11 12}
2N/Ado_test sort-7.4 {
2N/A execsql {
2N/A SELECT b FROM v4 ORDER BY 1;
2N/A }
2N/A} {1 11 12 2}
2N/Ado_test sort-7.5 {
2N/A execsql {
2N/A SELECT a FROM t4 UNION SELECT a FROM v4 ORDER BY 1;
2N/A }
2N/A} {1 2 11 12}
2N/Ado_test sort-7.6 {
2N/A execsql {
2N/A SELECT b FROM t4 UNION SELECT a FROM v4 ORDER BY 1;
2N/A }
2N/A} {1 2 11 12}
2N/Ado_test sort-7.7 {
2N/A execsql {
2N/A SELECT a FROM t4 UNION SELECT b FROM v4 ORDER BY 1;
2N/A }
2N/A} {1 2 11 12}
2N/Ado_test sort-7.8 {
2N/A execsql {
2N/A SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1;
2N/A }
2N/A} {1 11 12 2}
2N/Ado_test sort-7.9 {
2N/A execsql {
2N/A SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE numeric;
2N/A }
2N/A} {1 2 11 12}
2N/Ado_test sort-7.10 {
2N/A execsql {
2N/A SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE integer;
2N/A }
2N/A} {1 2 11 12}
2N/Ado_test sort-7.11 {
2N/A execsql {
2N/A SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE text;
2N/A }
2N/A} {1 11 12 2}
2N/Ado_test sort-7.12 {
2N/A execsql {
2N/A SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE blob;
2N/A }
2N/A} {1 11 12 2}
2N/Ado_test sort-7.13 {
2N/A execsql {
2N/A SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE clob;
2N/A }
2N/A} {1 11 12 2}
2N/Ado_test sort-7.14 {
2N/A execsql {
2N/A SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE varchar;
2N/A }
2N/A} {1 11 12 2}
2N/A
2N/A# Ticket #297
2N/A#
2N/Ado_test sort-8.1 {
2N/A execsql {
2N/A CREATE TABLE t5(a real, b text);
2N/A INSERT INTO t5 VALUES(100,'A1');
2N/A INSERT INTO t5 VALUES(100.0,'A2');
2N/A SELECT * FROM t5 ORDER BY a, b;
2N/A }
2N/A} {100 A1 100.0 A2}
2N/A
2N/Afinish_test