2009-02-23 19:52:07 +03:00
|
|
|
# 2009 February 23
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
# This file implements regression tests for SQLite library. The
|
|
|
|
# focus of this file is testing the reverse_select_order pragma.
|
|
|
|
#
|
2009-06-10 23:33:28 +04:00
|
|
|
# $Id: whereA.test,v 1.3 2009/06/10 19:33:29 drh Exp $
|
2009-02-23 19:52:07 +03:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
|
|
|
do_test whereA-1.1 {
|
|
|
|
db eval {
|
|
|
|
CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE, c);
|
|
|
|
INSERT INTO t1 VALUES(1,2,3);
|
|
|
|
INSERT INTO t1 values(2,'hello','world');
|
|
|
|
INSERT INTO t1 VALUES(3,4.53,NULL);
|
|
|
|
SELECT * FROM t1
|
|
|
|
}
|
|
|
|
} {1 2 3 2 hello world 3 4.53 {}}
|
|
|
|
do_test whereA-1.2 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects=1;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
}
|
|
|
|
} {3 4.53 {} 2 hello world 1 2 3}
|
|
|
|
|
|
|
|
do_test whereA-1.3 {
|
2010-01-13 02:54:14 +03:00
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
2009-02-23 19:52:07 +03:00
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects=1;
|
2010-01-13 02:54:14 +03:00
|
|
|
SELECT * FROM t1;
|
|
|
|
}
|
|
|
|
} {3 4.53 {} 2 hello world 1 2 3}
|
|
|
|
do_test whereA-1.4 {
|
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects=1;
|
|
|
|
SELECT * FROM t1 ORDER BY rowid;
|
|
|
|
}
|
|
|
|
} {1 2 3 2 hello world 3 4.53 {}}
|
|
|
|
do_test whereA-1.5 {
|
|
|
|
db eval {
|
|
|
|
VACUUM;
|
2009-02-23 19:52:07 +03:00
|
|
|
SELECT * FROM t1 ORDER BY rowid;
|
|
|
|
}
|
|
|
|
} {1 2 3 2 hello world 3 4.53 {}}
|
2010-01-13 02:54:14 +03:00
|
|
|
do_test whereA-1.6 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects;
|
|
|
|
}
|
|
|
|
} {1}
|
|
|
|
do_test whereA-1.7 {
|
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects=1;
|
|
|
|
VACUUM;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
}
|
|
|
|
} {3 4.53 {} 2 hello world 1 2 3}
|
2013-08-20 21:00:55 +04:00
|
|
|
do_execsql_test whereA-1.8 {
|
|
|
|
SELECT * FROM t1 WHERE b=2 AND a IS NULL;
|
|
|
|
} {}
|
|
|
|
do_execsql_test whereA-1.9 {
|
|
|
|
SELECT * FROM t1 WHERE b=2 AND a IS NOT NULL;
|
|
|
|
} {1 2 3}
|
2009-02-23 19:52:07 +03:00
|
|
|
|
|
|
|
do_test whereA-2.1 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects=0;
|
|
|
|
SELECT * FROM t1 WHERE a>0;
|
|
|
|
}
|
|
|
|
} {1 2 3 2 hello world 3 4.53 {}}
|
|
|
|
do_test whereA-2.2 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects=1;
|
|
|
|
SELECT * FROM t1 WHERE a>0;
|
|
|
|
}
|
|
|
|
} {3 4.53 {} 2 hello world 1 2 3}
|
|
|
|
|
|
|
|
do_test whereA-2.3 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects=1;
|
|
|
|
SELECT * FROM t1 WHERE a>0 ORDER BY rowid;
|
|
|
|
}
|
|
|
|
} {1 2 3 2 hello world 3 4.53 {}}
|
|
|
|
|
|
|
|
do_test whereA-3.1 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects=0;
|
|
|
|
SELECT * FROM t1 WHERE b>0;
|
|
|
|
}
|
|
|
|
} {1 2 3 3 4.53 {} 2 hello world}
|
|
|
|
do_test whereA-3.2 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects=1;
|
|
|
|
SELECT * FROM t1 WHERE b>0;
|
|
|
|
}
|
|
|
|
} {2 hello world 3 4.53 {} 1 2 3}
|
|
|
|
do_test whereA-3.3 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA reverse_unordered_selects=1;
|
|
|
|
SELECT * FROM t1 WHERE b>0 ORDER BY b;
|
|
|
|
}
|
|
|
|
} {1 2 3 3 4.53 {} 2 hello world}
|
|
|
|
|
2009-04-06 16:26:57 +04:00
|
|
|
do_test whereA-4.1 {
|
|
|
|
db eval {
|
|
|
|
CREATE TABLE t2(x);
|
|
|
|
INSERT INTO t2 VALUES(1);
|
|
|
|
INSERT INTO t2 VALUES(2);
|
|
|
|
SELECT x FROM t2;
|
|
|
|
}
|
|
|
|
} {2 1}
|
2009-06-10 23:33:28 +04:00
|
|
|
# Do an SQL statement. Append the search count to the end of the result.
|
|
|
|
#
|
|
|
|
proc count sql {
|
|
|
|
set ::sqlite_sort_count 0
|
|
|
|
return [concat [execsql $sql] $::sqlite_sort_count]
|
|
|
|
}
|
|
|
|
do_test whereA-4.2 { ;# Ticket #3904
|
|
|
|
db eval {
|
|
|
|
CREATE INDEX t2x ON t2(x);
|
|
|
|
}
|
|
|
|
count {
|
|
|
|
SELECT x FROM t2;
|
|
|
|
}
|
|
|
|
} {2 1 0}
|
|
|
|
do_test whereA-4.3 {
|
|
|
|
count {
|
|
|
|
SELECT x FROM t2 ORDER BY x;
|
|
|
|
}
|
|
|
|
} {1 2 0}
|
|
|
|
do_test whereA-4.4 {
|
|
|
|
count {
|
|
|
|
SELECT x FROM t2 ORDER BY x DESC;
|
|
|
|
}
|
|
|
|
} {2 1 0}
|
|
|
|
do_test whereA-4.5 {
|
|
|
|
db eval {DROP INDEX t2x;}
|
|
|
|
count {
|
|
|
|
SELECT x FROM t2 ORDER BY x;
|
|
|
|
}
|
|
|
|
} {1 2 1}
|
|
|
|
do_test whereA-4.6 {
|
|
|
|
count {
|
|
|
|
SELECT x FROM t2 ORDER BY x DESC;
|
|
|
|
}
|
|
|
|
} {2 1 1}
|
2009-04-06 16:26:57 +04:00
|
|
|
|
|
|
|
|
2009-02-23 19:52:07 +03:00
|
|
|
finish_test
|