1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
# 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.
#
# $Id: whereA.test,v 1.3 2009/06/10 19:33:29 drh Exp $
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 {
db close
sqlite3 db test.db
db eval {
PRAGMA reverse_unordered_selects=1;
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;
SELECT * FROM t1 ORDER BY rowid;
}
} {1 2 3 2 hello world 3 4.53 {}}
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}
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}
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}
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}
# 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}
# Ticket https://sqlite.org/src/tktview/cb91bf4290c211 2017-08-01
# Assertion fault following PRAGMA reverse_unordered_selects=ON.
#
do_execsql_test whereA-5.1 {
PRAGMA reverse_unordered_selects=on;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,2);
CREATE INDEX t1b ON t1(b);
SELECT a FROM t1 WHERE b=-99 OR b>1;
} {1}
# 2020-10-02 OSSFuzz find for an issue introduced by a check-in
# on the previous day.
#
reset_db
do_execsql_test whereA-6.1 {
CREATE TABLE t1(a, b);
CREATE INDEX t1aa ON t1(a,a);
INSERT INTO t1 VALUES(1,2);
ANALYZE;
UPDATE sqlite_stat1 SET stat='27 3 3' WHERE idx='t1aa';
ANALYZE sqlite_schema;
PRAGMA reverse_unordered_selects (1) ;
SELECT a FROM t1 WHERE a=1 OR a=2;
} {1}
finish_test
|