drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 1 | # 2001 September 15 |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 2 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 5 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 9 | # |
| 10 | #*********************************************************************** |
| 11 | # This file implements regression tests for SQLite library. The |
| 12 | # focus of this file is testing the SELECT statement. |
| 13 | # |
drh | 33e619f | 2009-05-28 01:00:55 +0000 | [diff] [blame] | 14 | # $Id: select1.test,v 1.70 2009/05/28 01:00:56 drh Exp $ |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
| 19 | # Try to select on a non-existant table. |
| 20 | # |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 21 | do_test select1-1.1 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 22 | set v [catch {execsql {SELECT * FROM test1}} msg] |
| 23 | lappend v $msg |
| 24 | } {1 {no such table: test1}} |
| 25 | |
danielk1977 | 13a68c3 | 2005-12-15 10:11:30 +0000 | [diff] [blame] | 26 | |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 27 | execsql {CREATE TABLE test1(f1 int, f2 int)} |
| 28 | |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 29 | do_test select1-1.2 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 30 | set v [catch {execsql {SELECT * FROM test1, test2}} msg] |
| 31 | lappend v $msg |
| 32 | } {1 {no such table: test2}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 33 | do_test select1-1.3 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 34 | set v [catch {execsql {SELECT * FROM test2, test1}} msg] |
| 35 | lappend v $msg |
| 36 | } {1 {no such table: test2}} |
| 37 | |
| 38 | execsql {INSERT INTO test1(f1,f2) VALUES(11,22)} |
| 39 | |
| 40 | |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 41 | # Make sure the columns are extracted correctly. |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 42 | # |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 43 | do_test select1-1.4 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 44 | execsql {SELECT f1 FROM test1} |
| 45 | } {11} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 46 | do_test select1-1.5 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 47 | execsql {SELECT f2 FROM test1} |
| 48 | } {22} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 49 | do_test select1-1.6 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 50 | execsql {SELECT f2, f1 FROM test1} |
| 51 | } {22 11} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 52 | do_test select1-1.7 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 53 | execsql {SELECT f1, f2 FROM test1} |
| 54 | } {11 22} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 55 | do_test select1-1.8 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 56 | execsql {SELECT * FROM test1} |
| 57 | } {11 22} |
drh | 7c917d1 | 2001-12-16 20:05:05 +0000 | [diff] [blame] | 58 | do_test select1-1.8.1 { |
| 59 | execsql {SELECT *, * FROM test1} |
| 60 | } {11 22 11 22} |
| 61 | do_test select1-1.8.2 { |
| 62 | execsql {SELECT *, min(f1,f2), max(f1,f2) FROM test1} |
| 63 | } {11 22 11 22} |
| 64 | do_test select1-1.8.3 { |
| 65 | execsql {SELECT 'one', *, 'two', * FROM test1} |
| 66 | } {one 11 22 two 11 22} |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 67 | |
| 68 | execsql {CREATE TABLE test2(r1 real, r2 real)} |
| 69 | execsql {INSERT INTO test2(r1,r2) VALUES(1.1,2.2)} |
| 70 | |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 71 | do_test select1-1.9 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 72 | execsql {SELECT * FROM test1, test2} |
| 73 | } {11 22 1.1 2.2} |
drh | 7c917d1 | 2001-12-16 20:05:05 +0000 | [diff] [blame] | 74 | do_test select1-1.9.1 { |
| 75 | execsql {SELECT *, 'hi' FROM test1, test2} |
| 76 | } {11 22 1.1 2.2 hi} |
| 77 | do_test select1-1.9.2 { |
| 78 | execsql {SELECT 'one', *, 'two', * FROM test1, test2} |
| 79 | } {one 11 22 1.1 2.2 two 11 22 1.1 2.2} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 80 | do_test select1-1.10 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 81 | execsql {SELECT test1.f1, test2.r1 FROM test1, test2} |
| 82 | } {11 1.1} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 83 | do_test select1-1.11 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 84 | execsql {SELECT test1.f1, test2.r1 FROM test2, test1} |
| 85 | } {11 1.1} |
drh | 17e24df | 2001-11-06 14:10:41 +0000 | [diff] [blame] | 86 | do_test select1-1.11.1 { |
| 87 | execsql {SELECT * FROM test2, test1} |
| 88 | } {1.1 2.2 11 22} |
| 89 | do_test select1-1.11.2 { |
| 90 | execsql {SELECT * FROM test1 AS a, test1 AS b} |
| 91 | } {11 22 11 22} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 92 | do_test select1-1.12 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 93 | execsql {SELECT max(test1.f1,test2.r1), min(test1.f2,test2.r2) |
| 94 | FROM test2, test1} |
| 95 | } {11 2.2} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 96 | do_test select1-1.13 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 97 | execsql {SELECT min(test1.f1,test2.r1), max(test1.f2,test2.r2) |
| 98 | FROM test1, test2} |
| 99 | } {1.1 22} |
| 100 | |
drh | 832508b | 2002-03-02 17:04:07 +0000 | [diff] [blame] | 101 | set long {This is a string that is too big to fit inside a NBFS buffer} |
| 102 | do_test select1-2.0 { |
| 103 | execsql " |
| 104 | DROP TABLE test2; |
| 105 | DELETE FROM test1; |
| 106 | INSERT INTO test1 VALUES(11,22); |
| 107 | INSERT INTO test1 VALUES(33,44); |
| 108 | CREATE TABLE t3(a,b); |
| 109 | INSERT INTO t3 VALUES('abc',NULL); |
| 110 | INSERT INTO t3 VALUES(NULL,'xyz'); |
| 111 | INSERT INTO t3 SELECT * FROM test1; |
| 112 | CREATE TABLE t4(a,b); |
| 113 | INSERT INTO t4 VALUES(NULL,'$long'); |
| 114 | SELECT * FROM t3; |
| 115 | " |
| 116 | } {abc {} {} xyz 11 22 33 44} |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 117 | |
| 118 | # Error messges from sqliteExprCheck |
| 119 | # |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 120 | do_test select1-2.1 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 121 | set v [catch {execsql {SELECT count(f1,f2) FROM test1}} msg] |
| 122 | lappend v $msg |
drh | 89425d5 | 2002-02-28 03:04:48 +0000 | [diff] [blame] | 123 | } {1 {wrong number of arguments to function count()}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 124 | do_test select1-2.2 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 125 | set v [catch {execsql {SELECT count(f1) FROM test1}} msg] |
| 126 | lappend v $msg |
| 127 | } {0 2} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 128 | do_test select1-2.3 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 129 | set v [catch {execsql {SELECT Count() FROM test1}} msg] |
| 130 | lappend v $msg |
| 131 | } {0 2} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 132 | do_test select1-2.4 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 133 | set v [catch {execsql {SELECT COUNT(*) FROM test1}} msg] |
| 134 | lappend v $msg |
| 135 | } {0 2} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 136 | do_test select1-2.5 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 137 | set v [catch {execsql {SELECT COUNT(*)+1 FROM test1}} msg] |
| 138 | lappend v $msg |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 139 | } {0 3} |
drh | 832508b | 2002-03-02 17:04:07 +0000 | [diff] [blame] | 140 | do_test select1-2.5.1 { |
| 141 | execsql {SELECT count(*),count(a),count(b) FROM t3} |
| 142 | } {4 3 3} |
| 143 | do_test select1-2.5.2 { |
| 144 | execsql {SELECT count(*),count(a),count(b) FROM t4} |
| 145 | } {1 0 1} |
| 146 | do_test select1-2.5.3 { |
| 147 | execsql {SELECT count(*),count(a),count(b) FROM t4 WHERE b=5} |
| 148 | } {0 0 0} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 149 | do_test select1-2.6 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 150 | set v [catch {execsql {SELECT min(*) FROM test1}} msg] |
| 151 | lappend v $msg |
drh | fbc9908 | 2002-02-28 03:14:18 +0000 | [diff] [blame] | 152 | } {1 {wrong number of arguments to function min()}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 153 | do_test select1-2.7 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 154 | set v [catch {execsql {SELECT Min(f1) FROM test1}} msg] |
| 155 | lappend v $msg |
| 156 | } {0 11} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 157 | do_test select1-2.8 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 158 | set v [catch {execsql {SELECT MIN(f1,f2) FROM test1}} msg] |
| 159 | lappend v [lsort $msg] |
| 160 | } {0 {11 33}} |
drh | 832508b | 2002-03-02 17:04:07 +0000 | [diff] [blame] | 161 | do_test select1-2.8.1 { |
| 162 | execsql {SELECT coalesce(min(a),'xyzzy') FROM t3} |
drh | 9eb516c | 2004-07-18 20:52:32 +0000 | [diff] [blame] | 163 | } {11} |
drh | 832508b | 2002-03-02 17:04:07 +0000 | [diff] [blame] | 164 | do_test select1-2.8.2 { |
| 165 | execsql {SELECT min(coalesce(a,'xyzzy')) FROM t3} |
| 166 | } {11} |
| 167 | do_test select1-2.8.3 { |
| 168 | execsql {SELECT min(b), min(b) FROM t4} |
| 169 | } [list $long $long] |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 170 | do_test select1-2.9 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 171 | set v [catch {execsql {SELECT MAX(*) FROM test1}} msg] |
| 172 | lappend v $msg |
drh | fbc9908 | 2002-02-28 03:14:18 +0000 | [diff] [blame] | 173 | } {1 {wrong number of arguments to function MAX()}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 174 | do_test select1-2.10 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 175 | set v [catch {execsql {SELECT Max(f1) FROM test1}} msg] |
| 176 | lappend v $msg |
| 177 | } {0 33} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 178 | do_test select1-2.11 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 179 | set v [catch {execsql {SELECT max(f1,f2) FROM test1}} msg] |
| 180 | lappend v [lsort $msg] |
| 181 | } {0 {22 44}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 182 | do_test select1-2.12 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 183 | set v [catch {execsql {SELECT MAX(f1,f2)+1 FROM test1}} msg] |
| 184 | lappend v [lsort $msg] |
| 185 | } {0 {23 45}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 186 | do_test select1-2.13 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 187 | set v [catch {execsql {SELECT MAX(f1)+1 FROM test1}} msg] |
| 188 | lappend v $msg |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 189 | } {0 34} |
drh | 832508b | 2002-03-02 17:04:07 +0000 | [diff] [blame] | 190 | do_test select1-2.13.1 { |
| 191 | execsql {SELECT coalesce(max(a),'xyzzy') FROM t3} |
drh | 739105c | 2002-05-29 23:22:23 +0000 | [diff] [blame] | 192 | } {abc} |
drh | bb11351 | 2002-05-27 01:04:51 +0000 | [diff] [blame] | 193 | do_test select1-2.13.2 { |
drh | 832508b | 2002-03-02 17:04:07 +0000 | [diff] [blame] | 194 | execsql {SELECT max(coalesce(a,'xyzzy')) FROM t3} |
| 195 | } {xyzzy} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 196 | do_test select1-2.14 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 197 | set v [catch {execsql {SELECT SUM(*) FROM test1}} msg] |
| 198 | lappend v $msg |
drh | 89425d5 | 2002-02-28 03:04:48 +0000 | [diff] [blame] | 199 | } {1 {wrong number of arguments to function SUM()}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 200 | do_test select1-2.15 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 201 | set v [catch {execsql {SELECT Sum(f1) FROM test1}} msg] |
| 202 | lappend v $msg |
drh | 3d1d95e | 2005-09-08 10:37:01 +0000 | [diff] [blame] | 203 | } {0 44} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 204 | do_test select1-2.16 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 205 | set v [catch {execsql {SELECT sum(f1,f2) FROM test1}} msg] |
| 206 | lappend v $msg |
drh | 89425d5 | 2002-02-28 03:04:48 +0000 | [diff] [blame] | 207 | } {1 {wrong number of arguments to function sum()}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 208 | do_test select1-2.17 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 209 | set v [catch {execsql {SELECT SUM(f1)+1 FROM test1}} msg] |
| 210 | lappend v $msg |
drh | 3d1d95e | 2005-09-08 10:37:01 +0000 | [diff] [blame] | 211 | } {0 45} |
drh | 832508b | 2002-03-02 17:04:07 +0000 | [diff] [blame] | 212 | do_test select1-2.17.1 { |
| 213 | execsql {SELECT sum(a) FROM t3} |
drh | 29d7210 | 2006-02-09 22:13:41 +0000 | [diff] [blame] | 214 | } {44.0} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 215 | do_test select1-2.18 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 216 | set v [catch {execsql {SELECT XYZZY(f1) FROM test1}} msg] |
| 217 | lappend v $msg |
| 218 | } {1 {no such function: XYZZY}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 219 | do_test select1-2.19 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 220 | set v [catch {execsql {SELECT SUM(min(f1,f2)) FROM test1}} msg] |
| 221 | lappend v $msg |
drh | 3d1d95e | 2005-09-08 10:37:01 +0000 | [diff] [blame] | 222 | } {0 44} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 223 | do_test select1-2.20 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 224 | set v [catch {execsql {SELECT SUM(min(f1)) FROM test1}} msg] |
| 225 | lappend v $msg |
drh | 8e0a2f9 | 2002-02-23 23:45:45 +0000 | [diff] [blame] | 226 | } {1 {misuse of aggregate function min()}} |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 227 | |
drh | 36379e9 | 2007-07-23 22:51:15 +0000 | [diff] [blame] | 228 | # Ticket #2526 |
| 229 | # |
| 230 | do_test select1-2.21 { |
| 231 | catchsql { |
| 232 | SELECT min(f1) AS m FROM test1 GROUP BY f1 HAVING max(m+5)<10 |
| 233 | } |
| 234 | } {1 {misuse of aliased aggregate m}} |
| 235 | do_test select1-2.22 { |
| 236 | catchsql { |
| 237 | SELECT coalesce(min(f1)+5,11) AS m FROM test1 |
| 238 | GROUP BY f1 |
| 239 | HAVING max(m+5)<10 |
| 240 | } |
| 241 | } {1 {misuse of aliased aggregate m}} |
| 242 | do_test select1-2.23 { |
| 243 | execsql { |
| 244 | CREATE TABLE tkt2526(a,b,c PRIMARY KEY); |
| 245 | INSERT INTO tkt2526 VALUES('x','y',NULL); |
| 246 | INSERT INTO tkt2526 VALUES('x','z',NULL); |
| 247 | } |
| 248 | catchsql { |
| 249 | SELECT count(a) AS cn FROM tkt2526 GROUP BY a HAVING cn<max(cn) |
| 250 | } |
| 251 | } {1 {misuse of aliased aggregate cn}} |
| 252 | |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 253 | # WHERE clause expressions |
| 254 | # |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 255 | do_test select1-3.1 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 256 | set v [catch {execsql {SELECT f1 FROM test1 WHERE f1<11}} msg] |
| 257 | lappend v $msg |
| 258 | } {0 {}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 259 | do_test select1-3.2 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 260 | set v [catch {execsql {SELECT f1 FROM test1 WHERE f1<=11}} msg] |
| 261 | lappend v $msg |
| 262 | } {0 11} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 263 | do_test select1-3.3 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 264 | set v [catch {execsql {SELECT f1 FROM test1 WHERE f1=11}} msg] |
| 265 | lappend v $msg |
| 266 | } {0 11} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 267 | do_test select1-3.4 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 268 | set v [catch {execsql {SELECT f1 FROM test1 WHERE f1>=11}} msg] |
| 269 | lappend v [lsort $msg] |
| 270 | } {0 {11 33}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 271 | do_test select1-3.5 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 272 | set v [catch {execsql {SELECT f1 FROM test1 WHERE f1>11}} msg] |
| 273 | lappend v [lsort $msg] |
| 274 | } {0 33} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 275 | do_test select1-3.6 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 276 | set v [catch {execsql {SELECT f1 FROM test1 WHERE f1!=11}} msg] |
| 277 | lappend v [lsort $msg] |
| 278 | } {0 33} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 279 | do_test select1-3.7 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 280 | set v [catch {execsql {SELECT f1 FROM test1 WHERE min(f1,f2)!=11}} msg] |
| 281 | lappend v [lsort $msg] |
| 282 | } {0 33} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 283 | do_test select1-3.8 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 284 | set v [catch {execsql {SELECT f1 FROM test1 WHERE max(f1,f2)!=11}} msg] |
| 285 | lappend v [lsort $msg] |
| 286 | } {0 {11 33}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 287 | do_test select1-3.9 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 288 | set v [catch {execsql {SELECT f1 FROM test1 WHERE count(f1,f2)!=11}} msg] |
| 289 | lappend v $msg |
drh | 89425d5 | 2002-02-28 03:04:48 +0000 | [diff] [blame] | 290 | } {1 {wrong number of arguments to function count()}} |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 291 | |
| 292 | # ORDER BY expressions |
| 293 | # |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 294 | do_test select1-4.1 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 295 | set v [catch {execsql {SELECT f1 FROM test1 ORDER BY f1}} msg] |
| 296 | lappend v $msg |
| 297 | } {0 {11 33}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 298 | do_test select1-4.2 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 299 | set v [catch {execsql {SELECT f1 FROM test1 ORDER BY -f1}} msg] |
| 300 | lappend v $msg |
| 301 | } {0 {33 11}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 302 | do_test select1-4.3 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 303 | set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1,f2)}} msg] |
| 304 | lappend v $msg |
| 305 | } {0 {11 33}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 306 | do_test select1-4.4 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 307 | set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1)}} msg] |
| 308 | lappend v $msg |
drh | b7916a7 | 2009-05-27 10:31:29 +0000 | [diff] [blame] | 309 | } {1 {misuse of aggregate: min()}} |
drh | 18e87cf | 2006-04-11 14:16:21 +0000 | [diff] [blame] | 310 | |
| 311 | # The restriction not allowing constants in the ORDER BY clause |
| 312 | # has been removed. See ticket #1768 |
| 313 | #do_test select1-4.5 { |
| 314 | # catchsql { |
| 315 | # SELECT f1 FROM test1 ORDER BY 8.4; |
| 316 | # } |
| 317 | #} {1 {ORDER BY terms must not be non-integer constants}} |
| 318 | #do_test select1-4.6 { |
| 319 | # catchsql { |
| 320 | # SELECT f1 FROM test1 ORDER BY '8.4'; |
| 321 | # } |
| 322 | #} {1 {ORDER BY terms must not be non-integer constants}} |
| 323 | #do_test select1-4.7.1 { |
| 324 | # catchsql { |
| 325 | # SELECT f1 FROM test1 ORDER BY 'xyz'; |
| 326 | # } |
| 327 | #} {1 {ORDER BY terms must not be non-integer constants}} |
| 328 | #do_test select1-4.7.2 { |
| 329 | # catchsql { |
| 330 | # SELECT f1 FROM test1 ORDER BY -8.4; |
| 331 | # } |
| 332 | #} {1 {ORDER BY terms must not be non-integer constants}} |
| 333 | #do_test select1-4.7.3 { |
| 334 | # catchsql { |
| 335 | # SELECT f1 FROM test1 ORDER BY +8.4; |
| 336 | # } |
| 337 | #} {1 {ORDER BY terms must not be non-integer constants}} |
| 338 | #do_test select1-4.7.4 { |
| 339 | # catchsql { |
| 340 | # SELECT f1 FROM test1 ORDER BY 4294967296; -- constant larger than 32 bits |
| 341 | # } |
| 342 | #} {1 {ORDER BY terms must not be non-integer constants}} |
| 343 | |
drh | 9208643 | 2002-01-22 14:11:29 +0000 | [diff] [blame] | 344 | do_test select1-4.5 { |
drh | 18e87cf | 2006-04-11 14:16:21 +0000 | [diff] [blame] | 345 | execsql { |
| 346 | SELECT f1 FROM test1 ORDER BY 8.4 |
drh | 9208643 | 2002-01-22 14:11:29 +0000 | [diff] [blame] | 347 | } |
drh | 18e87cf | 2006-04-11 14:16:21 +0000 | [diff] [blame] | 348 | } {11 33} |
drh | e4de1fe | 2002-06-02 16:09:01 +0000 | [diff] [blame] | 349 | do_test select1-4.6 { |
drh | 18e87cf | 2006-04-11 14:16:21 +0000 | [diff] [blame] | 350 | execsql { |
| 351 | SELECT f1 FROM test1 ORDER BY '8.4' |
drh | e4de1fe | 2002-06-02 16:09:01 +0000 | [diff] [blame] | 352 | } |
drh | 18e87cf | 2006-04-11 14:16:21 +0000 | [diff] [blame] | 353 | } {11 33} |
| 354 | |
drh | e4de1fe | 2002-06-02 16:09:01 +0000 | [diff] [blame] | 355 | do_test select1-4.8 { |
| 356 | execsql { |
| 357 | CREATE TABLE t5(a,b); |
| 358 | INSERT INTO t5 VALUES(1,10); |
| 359 | INSERT INTO t5 VALUES(2,9); |
| 360 | SELECT * FROM t5 ORDER BY 1; |
| 361 | } |
| 362 | } {1 10 2 9} |
drh | 018d1a4 | 2005-01-15 01:52:31 +0000 | [diff] [blame] | 363 | do_test select1-4.9.1 { |
drh | e4de1fe | 2002-06-02 16:09:01 +0000 | [diff] [blame] | 364 | execsql { |
| 365 | SELECT * FROM t5 ORDER BY 2; |
| 366 | } |
| 367 | } {2 9 1 10} |
drh | 018d1a4 | 2005-01-15 01:52:31 +0000 | [diff] [blame] | 368 | do_test select1-4.9.2 { |
| 369 | execsql { |
| 370 | SELECT * FROM t5 ORDER BY +2; |
| 371 | } |
| 372 | } {2 9 1 10} |
| 373 | do_test select1-4.10.1 { |
drh | e4de1fe | 2002-06-02 16:09:01 +0000 | [diff] [blame] | 374 | catchsql { |
| 375 | SELECT * FROM t5 ORDER BY 3; |
| 376 | } |
danielk1977 | 01874bf | 2007-12-13 07:58:50 +0000 | [diff] [blame] | 377 | } {1 {1st ORDER BY term out of range - should be between 1 and 2}} |
drh | 018d1a4 | 2005-01-15 01:52:31 +0000 | [diff] [blame] | 378 | do_test select1-4.10.2 { |
| 379 | catchsql { |
| 380 | SELECT * FROM t5 ORDER BY -1; |
| 381 | } |
danielk1977 | 01874bf | 2007-12-13 07:58:50 +0000 | [diff] [blame] | 382 | } {1 {1st ORDER BY term out of range - should be between 1 and 2}} |
drh | e4de1fe | 2002-06-02 16:09:01 +0000 | [diff] [blame] | 383 | do_test select1-4.11 { |
| 384 | execsql { |
| 385 | INSERT INTO t5 VALUES(3,10); |
| 386 | SELECT * FROM t5 ORDER BY 2, 1 DESC; |
| 387 | } |
| 388 | } {2 9 3 10 1 10} |
| 389 | do_test select1-4.12 { |
| 390 | execsql { |
| 391 | SELECT * FROM t5 ORDER BY 1 DESC, b; |
| 392 | } |
| 393 | } {3 10 2 9 1 10} |
| 394 | do_test select1-4.13 { |
| 395 | execsql { |
| 396 | SELECT * FROM t5 ORDER BY b DESC, 1; |
| 397 | } |
| 398 | } {1 10 3 10 2 9} |
| 399 | |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 400 | |
| 401 | # ORDER BY ignored on an aggregate query |
| 402 | # |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 403 | do_test select1-5.1 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 404 | set v [catch {execsql {SELECT max(f1) FROM test1 ORDER BY f2}} msg] |
| 405 | lappend v $msg |
| 406 | } {0 33} |
| 407 | |
drh | 85e9e22 | 2008-07-15 00:27:34 +0000 | [diff] [blame] | 408 | execsql {CREATE TABLE test2(t1 text, t2 text)} |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 409 | execsql {INSERT INTO test2 VALUES('abc','xyz')} |
| 410 | |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 411 | # Check for column naming |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 412 | # |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 413 | do_test select1-6.1 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 414 | set v [catch {execsql2 {SELECT f1 FROM test1 ORDER BY f2}} msg] |
| 415 | lappend v $msg |
| 416 | } {0 {f1 11 f1 33}} |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 417 | do_test select1-6.1.1 { |
drh | afed086 | 2006-03-14 13:10:42 +0000 | [diff] [blame] | 418 | db eval {PRAGMA full_column_names=on} |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 419 | set v [catch {execsql2 {SELECT f1 FROM test1 ORDER BY f2}} msg] |
| 420 | lappend v $msg |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 421 | } {0 {test1.f1 11 test1.f1 33}} |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 422 | do_test select1-6.1.2 { |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 423 | set v [catch {execsql2 {SELECT f1 as 'f1' FROM test1 ORDER BY f2}} msg] |
| 424 | lappend v $msg |
| 425 | } {0 {f1 11 f1 33}} |
| 426 | do_test select1-6.1.3 { |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 427 | set v [catch {execsql2 {SELECT * FROM test1 WHERE f1==11}} msg] |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 428 | lappend v $msg |
drh | 79d5f63 | 2005-01-18 17:20:10 +0000 | [diff] [blame] | 429 | } {0 {f1 11 f2 22}} |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 430 | do_test select1-6.1.4 { |
drh | 98808ba | 2001-10-18 12:34:46 +0000 | [diff] [blame] | 431 | set v [catch {execsql2 {SELECT DISTINCT * FROM test1 WHERE f1==11}} msg] |
drh | afed086 | 2006-03-14 13:10:42 +0000 | [diff] [blame] | 432 | db eval {PRAGMA full_column_names=off} |
drh | 98808ba | 2001-10-18 12:34:46 +0000 | [diff] [blame] | 433 | lappend v $msg |
drh | 79d5f63 | 2005-01-18 17:20:10 +0000 | [diff] [blame] | 434 | } {0 {f1 11 f2 22}} |
drh | 98808ba | 2001-10-18 12:34:46 +0000 | [diff] [blame] | 435 | do_test select1-6.1.5 { |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 436 | set v [catch {execsql2 {SELECT * FROM test1 WHERE f1==11}} msg] |
| 437 | lappend v $msg |
| 438 | } {0 {f1 11 f2 22}} |
drh | 98808ba | 2001-10-18 12:34:46 +0000 | [diff] [blame] | 439 | do_test select1-6.1.6 { |
| 440 | set v [catch {execsql2 {SELECT DISTINCT * FROM test1 WHERE f1==11}} msg] |
| 441 | lappend v $msg |
| 442 | } {0 {f1 11 f2 22}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 443 | do_test select1-6.2 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 444 | set v [catch {execsql2 {SELECT f1 as xyzzy FROM test1 ORDER BY f2}} msg] |
| 445 | lappend v $msg |
| 446 | } {0 {xyzzy 11 xyzzy 33}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 447 | do_test select1-6.3 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 448 | set v [catch {execsql2 {SELECT f1 as "xyzzy" FROM test1 ORDER BY f2}} msg] |
| 449 | lappend v $msg |
| 450 | } {0 {xyzzy 11 xyzzy 33}} |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 451 | do_test select1-6.3.1 { |
| 452 | set v [catch {execsql2 {SELECT f1 as 'xyzzy ' FROM test1 ORDER BY f2}} msg] |
| 453 | lappend v $msg |
| 454 | } {0 {{xyzzy } 11 {xyzzy } 33}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 455 | do_test select1-6.4 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 456 | set v [catch {execsql2 {SELECT f1+F2 as xyzzy FROM test1 ORDER BY f2}} msg] |
| 457 | lappend v $msg |
| 458 | } {0 {xyzzy 33 xyzzy 77}} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 459 | do_test select1-6.4a { |
| 460 | set v [catch {execsql2 {SELECT f1+F2 FROM test1 ORDER BY f2}} msg] |
| 461 | lappend v $msg |
| 462 | } {0 {f1+F2 33 f1+F2 77}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 463 | do_test select1-6.5 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 464 | set v [catch {execsql2 {SELECT test1.f1+F2 FROM test1 ORDER BY f2}} msg] |
| 465 | lappend v $msg |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 466 | } {0 {test1.f1+F2 33 test1.f1+F2 77}} |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 467 | do_test select1-6.5.1 { |
| 468 | execsql2 {PRAGMA full_column_names=on} |
| 469 | set v [catch {execsql2 {SELECT test1.f1+F2 FROM test1 ORDER BY f2}} msg] |
| 470 | execsql2 {PRAGMA full_column_names=off} |
| 471 | lappend v $msg |
| 472 | } {0 {test1.f1+F2 33 test1.f1+F2 77}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 473 | do_test select1-6.6 { |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 474 | set v [catch {execsql2 {SELECT test1.f1+F2, t1 FROM test1, test2 |
| 475 | ORDER BY f2}} msg] |
| 476 | lappend v $msg |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 477 | } {0 {test1.f1+F2 33 t1 abc test1.f1+F2 77 t1 abc}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 478 | do_test select1-6.7 { |
drh | da9d6c4 | 2000-05-31 18:20:14 +0000 | [diff] [blame] | 479 | set v [catch {execsql2 {SELECT A.f1, t1 FROM test1 as A, test2 |
| 480 | ORDER BY f2}} msg] |
| 481 | lappend v $msg |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 482 | } {0 {f1 11 t1 abc f1 33 t1 abc}} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 483 | do_test select1-6.8 { |
drh | da9d6c4 | 2000-05-31 18:20:14 +0000 | [diff] [blame] | 484 | set v [catch {execsql2 {SELECT A.f1, f1 FROM test1 as A, test1 as B |
| 485 | ORDER BY f2}} msg] |
| 486 | lappend v $msg |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 487 | } {1 {ambiguous column name: f1}} |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 488 | do_test select1-6.8b { |
drh | da9d6c4 | 2000-05-31 18:20:14 +0000 | [diff] [blame] | 489 | set v [catch {execsql2 {SELECT A.f1, B.f1 FROM test1 as A, test1 as B |
| 490 | ORDER BY f2}} msg] |
| 491 | lappend v $msg |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 492 | } {1 {ambiguous column name: f2}} |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 493 | do_test select1-6.8c { |
| 494 | set v [catch {execsql2 {SELECT A.f1, f1 FROM test1 as A, test1 as A |
| 495 | ORDER BY f2}} msg] |
| 496 | lappend v $msg |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 497 | } {1 {ambiguous column name: A.f1}} |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 498 | do_test select1-6.9.1 { |
| 499 | set v [catch {execsql {SELECT A.f1, B.f1 FROM test1 as A, test1 as B |
| 500 | ORDER BY A.f1, B.f1}} msg] |
| 501 | lappend v $msg |
| 502 | } {0 {11 11 11 33 33 11 33 33}} |
| 503 | do_test select1-6.9.2 { |
drh | da9d6c4 | 2000-05-31 18:20:14 +0000 | [diff] [blame] | 504 | set v [catch {execsql2 {SELECT A.f1, B.f1 FROM test1 as A, test1 as B |
| 505 | ORDER BY A.f1, B.f1}} msg] |
| 506 | lappend v $msg |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 507 | } {0 {f1 11 f1 11 f1 33 f1 33 f1 11 f1 11 f1 33 f1 33}} |
danielk1977 | 27c7743 | 2004-11-22 13:35:41 +0000 | [diff] [blame] | 508 | |
drh | e49b146 | 2008-07-09 01:39:44 +0000 | [diff] [blame] | 509 | do_test select1-6.9.3 { |
| 510 | db eval { |
| 511 | PRAGMA short_column_names=OFF; |
| 512 | PRAGMA full_column_names=OFF; |
| 513 | } |
| 514 | execsql2 { |
| 515 | SELECT test1 . f1, test1 . f2 FROM test1 LIMIT 1 |
| 516 | } |
| 517 | } {{test1 . f1} 11 {test1 . f2} 22} |
| 518 | do_test select1-6.9.4 { |
| 519 | db eval { |
| 520 | PRAGMA short_column_names=OFF; |
| 521 | PRAGMA full_column_names=ON; |
| 522 | } |
| 523 | execsql2 { |
| 524 | SELECT test1 . f1, test1 . f2 FROM test1 LIMIT 1 |
| 525 | } |
| 526 | } {test1.f1 11 test1.f2 22} |
| 527 | do_test select1-6.9.5 { |
| 528 | db eval { |
| 529 | PRAGMA short_column_names=OFF; |
| 530 | PRAGMA full_column_names=ON; |
| 531 | } |
| 532 | execsql2 { |
| 533 | SELECT 123.45; |
| 534 | } |
| 535 | } {123.45 123.45} |
drh | 93a960a | 2008-07-10 00:32:42 +0000 | [diff] [blame] | 536 | do_test select1-6.9.6 { |
| 537 | execsql2 { |
| 538 | SELECT * FROM test1 a, test1 b LIMIT 1 |
| 539 | } |
| 540 | } {a.f1 11 a.f2 22 b.f1 11 b.f2 22} |
| 541 | do_test select1-6.9.7 { |
| 542 | set x [execsql2 { |
| 543 | SELECT * FROM test1 a, (select 5, 6) LIMIT 1 |
| 544 | }] |
| 545 | regsub -all {subquery_[0-9a-fA-F]+_} $x {subquery} x |
| 546 | set x |
| 547 | } {a.f1 11 a.f2 22 sqlite_subquery.5 5 sqlite_subquery.6 6} |
| 548 | do_test select1-6.9.8 { |
| 549 | set x [execsql2 { |
| 550 | SELECT * FROM test1 a, (select 5 AS x, 6 AS y) AS b LIMIT 1 |
| 551 | }] |
| 552 | regsub -all {subquery_[0-9a-fA-F]+_} $x {subquery} x |
| 553 | set x |
| 554 | } {a.f1 11 a.f2 22 b.x 5 b.y 6} |
drh | 85e9e22 | 2008-07-15 00:27:34 +0000 | [diff] [blame] | 555 | do_test select1-6.9.9 { |
| 556 | execsql2 { |
| 557 | SELECT a.f1, b.f2 FROM test1 a, test1 b LIMIT 1 |
| 558 | } |
| 559 | } {test1.f1 11 test1.f2 22} |
| 560 | do_test select1-6.9.10 { |
| 561 | execsql2 { |
| 562 | SELECT f1, t1 FROM test1, test2 LIMIT 1 |
| 563 | } |
| 564 | } {test1.f1 11 test2.t1 abc} |
| 565 | do_test select1-6.9.11 { |
| 566 | db eval { |
| 567 | PRAGMA short_column_names=ON; |
| 568 | PRAGMA full_column_names=ON; |
| 569 | } |
| 570 | execsql2 { |
| 571 | SELECT a.f1, b.f2 FROM test1 a, test1 b LIMIT 1 |
| 572 | } |
| 573 | } {test1.f1 11 test1.f2 22} |
| 574 | do_test select1-6.9.12 { |
| 575 | execsql2 { |
| 576 | SELECT f1, t1 FROM test1, test2 LIMIT 1 |
| 577 | } |
| 578 | } {test1.f1 11 test2.t1 abc} |
| 579 | do_test select1-6.9.13 { |
| 580 | db eval { |
| 581 | PRAGMA short_column_names=ON; |
| 582 | PRAGMA full_column_names=OFF; |
| 583 | } |
| 584 | execsql2 { |
| 585 | SELECT a.f1, b.f1 FROM test1 a, test1 b LIMIT 1 |
| 586 | } |
| 587 | } {f1 11 f1 11} |
| 588 | do_test select1-6.9.14 { |
| 589 | execsql2 { |
| 590 | SELECT f1, t1 FROM test1, test2 LIMIT 1 |
| 591 | } |
| 592 | } {f1 11 t1 abc} |
| 593 | do_test select1-6.9.15 { |
| 594 | db eval { |
| 595 | PRAGMA short_column_names=OFF; |
| 596 | PRAGMA full_column_names=ON; |
| 597 | } |
| 598 | execsql2 { |
| 599 | SELECT a.f1, b.f1 FROM test1 a, test1 b LIMIT 1 |
| 600 | } |
| 601 | } {test1.f1 11 test1.f1 11} |
| 602 | do_test select1-6.9.16 { |
| 603 | execsql2 { |
| 604 | SELECT f1, t1 FROM test1, test2 LIMIT 1 |
| 605 | } |
| 606 | } {test1.f1 11 test2.t1 abc} |
| 607 | |
drh | 93a960a | 2008-07-10 00:32:42 +0000 | [diff] [blame] | 608 | |
drh | e49b146 | 2008-07-09 01:39:44 +0000 | [diff] [blame] | 609 | db eval { |
| 610 | PRAGMA short_column_names=ON; |
| 611 | PRAGMA full_column_names=OFF; |
| 612 | } |
| 613 | |
danielk1977 | 27c7743 | 2004-11-22 13:35:41 +0000 | [diff] [blame] | 614 | ifcapable compound { |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 615 | do_test select1-6.10 { |
| 616 | set v [catch {execsql2 { |
| 617 | SELECT f1 FROM test1 UNION SELECT f2 FROM test1 |
| 618 | ORDER BY f2; |
| 619 | }} msg] |
| 620 | lappend v $msg |
drh | 9237825 | 2006-03-26 01:21:22 +0000 | [diff] [blame] | 621 | } {0 {f1 11 f1 22 f1 33 f1 44}} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 622 | do_test select1-6.11 { |
| 623 | set v [catch {execsql2 { |
| 624 | SELECT f1 FROM test1 UNION SELECT f2+100 FROM test1 |
drh | 4c77431 | 2007-12-08 21:10:20 +0000 | [diff] [blame] | 625 | ORDER BY f2+101; |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 626 | }} msg] |
| 627 | lappend v $msg |
danielk1977 | 01874bf | 2007-12-13 07:58:50 +0000 | [diff] [blame] | 628 | } {1 {1st ORDER BY term does not match any column in the result set}} |
drh | 94ccde5 | 2007-04-13 16:06:32 +0000 | [diff] [blame] | 629 | |
| 630 | # Ticket #2296 |
danielk1977 | de3e41e | 2008-08-04 03:51:24 +0000 | [diff] [blame] | 631 | ifcapable subquery&&compound { |
drh | 94ccde5 | 2007-04-13 16:06:32 +0000 | [diff] [blame] | 632 | do_test select1-6.20 { |
| 633 | execsql { |
| 634 | CREATE TABLE t6(a TEXT, b TEXT); |
| 635 | INSERT INTO t6 VALUES('a','0'); |
| 636 | INSERT INTO t6 VALUES('b','1'); |
| 637 | INSERT INTO t6 VALUES('c','2'); |
| 638 | INSERT INTO t6 VALUES('d','3'); |
| 639 | SELECT a FROM t6 WHERE b IN |
| 640 | (SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x |
| 641 | ORDER BY 1 LIMIT 1) |
| 642 | } |
| 643 | } {a} |
| 644 | do_test select1-6.21 { |
| 645 | execsql { |
| 646 | SELECT a FROM t6 WHERE b IN |
| 647 | (SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x |
| 648 | ORDER BY 1 DESC LIMIT 1) |
| 649 | } |
| 650 | } {d} |
| 651 | do_test select1-6.22 { |
| 652 | execsql { |
| 653 | SELECT a FROM t6 WHERE b IN |
| 654 | (SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x |
| 655 | ORDER BY b LIMIT 2) |
| 656 | ORDER BY a; |
| 657 | } |
| 658 | } {a b} |
| 659 | do_test select1-6.23 { |
| 660 | execsql { |
| 661 | SELECT a FROM t6 WHERE b IN |
| 662 | (SELECT b FROM t6 WHERE a<='b' UNION SELECT '3' AS x |
| 663 | ORDER BY x DESC LIMIT 2) |
| 664 | ORDER BY a; |
| 665 | } |
| 666 | } {b d} |
danielk1977 | 284f4ac | 2007-12-10 05:03:46 +0000 | [diff] [blame] | 667 | } |
drh | 94ccde5 | 2007-04-13 16:06:32 +0000 | [diff] [blame] | 668 | |
danielk1977 | 27c7743 | 2004-11-22 13:35:41 +0000 | [diff] [blame] | 669 | } ;#ifcapable compound |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 670 | |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 671 | do_test select1-7.1 { |
| 672 | set v [catch {execsql { |
| 673 | SELECT f1 FROM test1 WHERE f2=; |
| 674 | }} msg] |
| 675 | lappend v $msg |
| 676 | } {1 {near ";": syntax error}} |
danielk1977 | 27c7743 | 2004-11-22 13:35:41 +0000 | [diff] [blame] | 677 | ifcapable compound { |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 678 | do_test select1-7.2 { |
| 679 | set v [catch {execsql { |
| 680 | SELECT f1 FROM test1 UNION SELECT WHERE; |
| 681 | }} msg] |
| 682 | lappend v $msg |
| 683 | } {1 {near "WHERE": syntax error}} |
danielk1977 | 27c7743 | 2004-11-22 13:35:41 +0000 | [diff] [blame] | 684 | } ;# ifcapable compound |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 685 | do_test select1-7.3 { |
| 686 | set v [catch {execsql {SELECT f1 FROM test1 as 'hi', test2 as}} msg] |
| 687 | lappend v $msg |
| 688 | } {1 {near "as": syntax error}} |
| 689 | do_test select1-7.4 { |
| 690 | set v [catch {execsql { |
| 691 | SELECT f1 FROM test1 ORDER BY; |
| 692 | }} msg] |
| 693 | lappend v $msg |
| 694 | } {1 {near ";": syntax error}} |
| 695 | do_test select1-7.5 { |
| 696 | set v [catch {execsql { |
| 697 | SELECT f1 FROM test1 ORDER BY f1 desc, f2 where; |
| 698 | }} msg] |
| 699 | lappend v $msg |
| 700 | } {1 {near "where": syntax error}} |
| 701 | do_test select1-7.6 { |
| 702 | set v [catch {execsql { |
| 703 | SELECT count(f1,f2 FROM test1; |
| 704 | }} msg] |
| 705 | lappend v $msg |
| 706 | } {1 {near "FROM": syntax error}} |
| 707 | do_test select1-7.7 { |
| 708 | set v [catch {execsql { |
| 709 | SELECT count(f1,f2+) FROM test1; |
| 710 | }} msg] |
| 711 | lappend v $msg |
| 712 | } {1 {near ")": syntax error}} |
| 713 | do_test select1-7.8 { |
| 714 | set v [catch {execsql { |
| 715 | SELECT f1 FROM test1 ORDER BY f2, f1+; |
| 716 | }} msg] |
| 717 | lappend v $msg |
| 718 | } {1 {near ";": syntax error}} |
drh | 1592659 | 2007-04-06 15:02:13 +0000 | [diff] [blame] | 719 | do_test select1-7.9 { |
| 720 | catchsql { |
| 721 | SELECT f1 FROM test1 LIMIT 5+3 OFFSET 11 ORDER BY f2; |
| 722 | } |
| 723 | } {1 {near "ORDER": syntax error}} |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 724 | |
| 725 | do_test select1-8.1 { |
| 726 | execsql {SELECT f1 FROM test1 WHERE 4.3+2.4 OR 1 ORDER BY f1} |
| 727 | } {11 33} |
| 728 | do_test select1-8.2 { |
| 729 | execsql { |
| 730 | SELECT f1 FROM test1 WHERE ('x' || f1) BETWEEN 'x10' AND 'x20' |
| 731 | ORDER BY f1 |
| 732 | } |
| 733 | } {11} |
| 734 | do_test select1-8.3 { |
| 735 | execsql { |
| 736 | SELECT f1 FROM test1 WHERE 5-3==2 |
| 737 | ORDER BY f1 |
| 738 | } |
| 739 | } {11 33} |
danielk1977 | 8d05984 | 2004-05-12 11:24:02 +0000 | [diff] [blame] | 740 | |
| 741 | # TODO: This test is failing because f1 is now being loaded off the |
| 742 | # disk as a vdbe integer, not a string. Hence the value of f1/(f1-11) |
| 743 | # changes because of rounding. Disable the test for now. |
| 744 | if 0 { |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 745 | do_test select1-8.4 { |
| 746 | execsql { |
drh | bb11351 | 2002-05-27 01:04:51 +0000 | [diff] [blame] | 747 | SELECT coalesce(f1/(f1-11),'x'), |
| 748 | coalesce(min(f1/(f1-11),5),'y'), |
| 749 | coalesce(max(f1/(f1-33),6),'z') |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 750 | FROM test1 ORDER BY f1 |
| 751 | } |
drh | bb11351 | 2002-05-27 01:04:51 +0000 | [diff] [blame] | 752 | } {x y 6 1.5 1.5 z} |
danielk1977 | 8d05984 | 2004-05-12 11:24:02 +0000 | [diff] [blame] | 753 | } |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 754 | do_test select1-8.5 { |
| 755 | execsql { |
| 756 | SELECT min(1,2,3), -max(1,2,3) |
| 757 | FROM test1 ORDER BY f1 |
| 758 | } |
| 759 | } {1 -3 1 -3} |
| 760 | |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 761 | |
| 762 | # Check the behavior when the result set is empty |
| 763 | # |
danielk1977 | cbb18d2 | 2004-05-28 11:37:27 +0000 | [diff] [blame] | 764 | # SQLite v3 always sets r(*). |
| 765 | # |
| 766 | # do_test select1-9.1 { |
| 767 | # catch {unset r} |
| 768 | # set r(*) {} |
| 769 | # db eval {SELECT * FROM test1 WHERE f1<0} r {} |
| 770 | # set r(*) |
| 771 | # } {} |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 772 | do_test select1-9.2 { |
| 773 | execsql {PRAGMA empty_result_callbacks=on} |
danielk1977 | cbb18d2 | 2004-05-28 11:37:27 +0000 | [diff] [blame] | 774 | catch {unset r} |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 775 | set r(*) {} |
| 776 | db eval {SELECT * FROM test1 WHERE f1<0} r {} |
| 777 | set r(*) |
| 778 | } {f1 f2} |
danielk1977 | 3e8c37e | 2005-01-21 03:12:14 +0000 | [diff] [blame] | 779 | ifcapable subquery { |
| 780 | do_test select1-9.3 { |
| 781 | set r(*) {} |
| 782 | db eval {SELECT * FROM test1 WHERE f1<(select count(*) from test2)} r {} |
| 783 | set r(*) |
| 784 | } {f1 f2} |
| 785 | } |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 786 | do_test select1-9.4 { |
| 787 | set r(*) {} |
| 788 | db eval {SELECT * FROM test1 ORDER BY f1} r {} |
| 789 | set r(*) |
| 790 | } {f1 f2} |
| 791 | do_test select1-9.5 { |
| 792 | set r(*) {} |
| 793 | db eval {SELECT * FROM test1 WHERE f1<0 ORDER BY f1} r {} |
| 794 | set r(*) |
| 795 | } {f1 f2} |
| 796 | unset r |
| 797 | |
drh | a2e0004 | 2002-01-22 03:13:42 +0000 | [diff] [blame] | 798 | # Check for ORDER BY clauses that refer to an AS name in the column list |
| 799 | # |
| 800 | do_test select1-10.1 { |
| 801 | execsql { |
| 802 | SELECT f1 AS x FROM test1 ORDER BY x |
| 803 | } |
| 804 | } {11 33} |
| 805 | do_test select1-10.2 { |
| 806 | execsql { |
| 807 | SELECT f1 AS x FROM test1 ORDER BY -x |
| 808 | } |
| 809 | } {33 11} |
| 810 | do_test select1-10.3 { |
| 811 | execsql { |
| 812 | SELECT f1-23 AS x FROM test1 ORDER BY abs(x) |
| 813 | } |
| 814 | } {10 -12} |
| 815 | do_test select1-10.4 { |
| 816 | execsql { |
| 817 | SELECT f1-23 AS x FROM test1 ORDER BY -abs(x) |
| 818 | } |
| 819 | } {-12 10} |
| 820 | do_test select1-10.5 { |
| 821 | execsql { |
| 822 | SELECT f1-22 AS x, f2-22 as y FROM test1 |
| 823 | } |
| 824 | } {-11 0 11 22} |
| 825 | do_test select1-10.6 { |
| 826 | execsql { |
| 827 | SELECT f1-22 AS x, f2-22 as y FROM test1 WHERE x>0 AND y<50 |
| 828 | } |
| 829 | } {11 22} |
drh | 93a960a | 2008-07-10 00:32:42 +0000 | [diff] [blame] | 830 | do_test select1-10.7 { |
| 831 | execsql { |
| 832 | SELECT f1 COLLATE nocase AS x FROM test1 ORDER BY x |
| 833 | } |
| 834 | } {11 33} |
drh | a2e0004 | 2002-01-22 03:13:42 +0000 | [diff] [blame] | 835 | |
drh | 5447322 | 2002-04-04 02:10:55 +0000 | [diff] [blame] | 836 | # Check the ability to specify "TABLE.*" in the result set of a SELECT |
| 837 | # |
| 838 | do_test select1-11.1 { |
| 839 | execsql { |
| 840 | DELETE FROM t3; |
| 841 | DELETE FROM t4; |
| 842 | INSERT INTO t3 VALUES(1,2); |
| 843 | INSERT INTO t4 VALUES(3,4); |
| 844 | SELECT * FROM t3, t4; |
| 845 | } |
| 846 | } {1 2 3 4} |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 847 | do_test select1-11.2.1 { |
| 848 | execsql { |
| 849 | SELECT * FROM t3, t4; |
| 850 | } |
| 851 | } {1 2 3 4} |
| 852 | do_test select1-11.2.2 { |
drh | 5447322 | 2002-04-04 02:10:55 +0000 | [diff] [blame] | 853 | execsql2 { |
| 854 | SELECT * FROM t3, t4; |
| 855 | } |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 856 | } {a 3 b 4 a 3 b 4} |
drh | cf55b7a | 2004-07-20 01:45:19 +0000 | [diff] [blame] | 857 | do_test select1-11.4.1 { |
drh | 5447322 | 2002-04-04 02:10:55 +0000 | [diff] [blame] | 858 | execsql { |
| 859 | SELECT t3.*, t4.b FROM t3, t4; |
| 860 | } |
| 861 | } {1 2 4} |
drh | cf55b7a | 2004-07-20 01:45:19 +0000 | [diff] [blame] | 862 | do_test select1-11.4.2 { |
| 863 | execsql { |
| 864 | SELECT "t3".*, t4.b FROM t3, t4; |
| 865 | } |
| 866 | } {1 2 4} |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 867 | do_test select1-11.5.1 { |
drh | 5447322 | 2002-04-04 02:10:55 +0000 | [diff] [blame] | 868 | execsql2 { |
| 869 | SELECT t3.*, t4.b FROM t3, t4; |
| 870 | } |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 871 | } {a 1 b 4 b 4} |
drh | 5447322 | 2002-04-04 02:10:55 +0000 | [diff] [blame] | 872 | do_test select1-11.6 { |
| 873 | execsql2 { |
| 874 | SELECT x.*, y.b FROM t3 AS x, t4 AS y; |
| 875 | } |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 876 | } {a 1 b 4 b 4} |
drh | 5447322 | 2002-04-04 02:10:55 +0000 | [diff] [blame] | 877 | do_test select1-11.7 { |
| 878 | execsql { |
| 879 | SELECT t3.b, t4.* FROM t3, t4; |
| 880 | } |
| 881 | } {2 3 4} |
| 882 | do_test select1-11.8 { |
| 883 | execsql2 { |
| 884 | SELECT t3.b, t4.* FROM t3, t4; |
| 885 | } |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 886 | } {b 4 a 3 b 4} |
drh | 5447322 | 2002-04-04 02:10:55 +0000 | [diff] [blame] | 887 | do_test select1-11.9 { |
| 888 | execsql2 { |
| 889 | SELECT x.b, y.* FROM t3 AS x, t4 AS y; |
| 890 | } |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 891 | } {b 4 a 3 b 4} |
drh | 5447322 | 2002-04-04 02:10:55 +0000 | [diff] [blame] | 892 | do_test select1-11.10 { |
| 893 | catchsql { |
| 894 | SELECT t5.* FROM t3, t4; |
| 895 | } |
| 896 | } {1 {no such table: t5}} |
| 897 | do_test select1-11.11 { |
| 898 | catchsql { |
| 899 | SELECT t3.* FROM t3 AS x, t4; |
| 900 | } |
| 901 | } {1 {no such table: t3}} |
danielk1977 | 3e8c37e | 2005-01-21 03:12:14 +0000 | [diff] [blame] | 902 | ifcapable subquery { |
| 903 | do_test select1-11.12 { |
| 904 | execsql2 { |
| 905 | SELECT t3.* FROM t3, (SELECT max(a), max(b) FROM t4) |
| 906 | } |
| 907 | } {a 1 b 2} |
| 908 | do_test select1-11.13 { |
| 909 | execsql2 { |
| 910 | SELECT t3.* FROM (SELECT max(a), max(b) FROM t4), t3 |
| 911 | } |
| 912 | } {a 1 b 2} |
| 913 | do_test select1-11.14 { |
| 914 | execsql2 { |
| 915 | SELECT * FROM t3, (SELECT max(a), max(b) FROM t4) AS 'tx' |
| 916 | } |
| 917 | } {a 1 b 2 max(a) 3 max(b) 4} |
| 918 | do_test select1-11.15 { |
| 919 | execsql2 { |
| 920 | SELECT y.*, t3.* FROM t3, (SELECT max(a), max(b) FROM t4) AS y |
| 921 | } |
| 922 | } {max(a) 3 max(b) 4 a 1 b 2} |
| 923 | } |
drh | c754fa5 | 2002-05-27 03:25:51 +0000 | [diff] [blame] | 924 | do_test select1-11.16 { |
| 925 | execsql2 { |
| 926 | SELECT y.* FROM t3 as y, t4 as z |
| 927 | } |
drh | 47a6db2 | 2005-01-18 16:02:40 +0000 | [diff] [blame] | 928 | } {a 1 b 2} |
drh | a2e0004 | 2002-01-22 03:13:42 +0000 | [diff] [blame] | 929 | |
drh | bf3a4fa | 2002-04-06 13:57:42 +0000 | [diff] [blame] | 930 | # Tests of SELECT statements without a FROM clause. |
| 931 | # |
| 932 | do_test select1-12.1 { |
| 933 | execsql2 { |
| 934 | SELECT 1+2+3 |
| 935 | } |
| 936 | } {1+2+3 6} |
| 937 | do_test select1-12.2 { |
| 938 | execsql2 { |
| 939 | SELECT 1,'hello',2 |
| 940 | } |
| 941 | } {1 1 'hello' hello 2 2} |
| 942 | do_test select1-12.3 { |
| 943 | execsql2 { |
| 944 | SELECT 1 AS 'a','hello' AS 'b',2 AS 'c' |
| 945 | } |
| 946 | } {a 1 b hello c 2} |
| 947 | do_test select1-12.4 { |
| 948 | execsql { |
| 949 | DELETE FROM t3; |
| 950 | INSERT INTO t3 VALUES(1,2); |
danielk1977 | 27c7743 | 2004-11-22 13:35:41 +0000 | [diff] [blame] | 951 | } |
| 952 | } {} |
| 953 | |
| 954 | ifcapable compound { |
| 955 | do_test select1-12.5 { |
| 956 | execsql { |
drh | bf3a4fa | 2002-04-06 13:57:42 +0000 | [diff] [blame] | 957 | SELECT * FROM t3 UNION SELECT 3 AS 'a', 4 ORDER BY a; |
| 958 | } |
| 959 | } {1 2 3 4} |
danielk1977 | 27c7743 | 2004-11-22 13:35:41 +0000 | [diff] [blame] | 960 | |
| 961 | do_test select1-12.6 { |
drh | bf3a4fa | 2002-04-06 13:57:42 +0000 | [diff] [blame] | 962 | execsql { |
| 963 | SELECT 3, 4 UNION SELECT * FROM t3; |
| 964 | } |
| 965 | } {1 2 3 4} |
danielk1977 | 27c7743 | 2004-11-22 13:35:41 +0000 | [diff] [blame] | 966 | } ;# ifcapable compound |
| 967 | |
danielk1977 | 3e8c37e | 2005-01-21 03:12:14 +0000 | [diff] [blame] | 968 | ifcapable subquery { |
| 969 | do_test select1-12.7 { |
| 970 | execsql { |
| 971 | SELECT * FROM t3 WHERE a=(SELECT 1); |
| 972 | } |
| 973 | } {1 2} |
| 974 | do_test select1-12.8 { |
| 975 | execsql { |
| 976 | SELECT * FROM t3 WHERE a=(SELECT 2); |
| 977 | } |
| 978 | } {} |
| 979 | } |
danielk1977 | 27c7743 | 2004-11-22 13:35:41 +0000 | [diff] [blame] | 980 | |
danielk1977 | e61b9f4 | 2005-01-21 04:25:47 +0000 | [diff] [blame] | 981 | ifcapable {compound && subquery} { |
| 982 | do_test select1-12.9 { |
| 983 | execsql2 { |
| 984 | SELECT x FROM ( |
drh | 9237825 | 2006-03-26 01:21:22 +0000 | [diff] [blame] | 985 | SELECT a AS x, b AS y FROM t3 UNION SELECT a,b FROM t4 ORDER BY a,b |
danielk1977 | e61b9f4 | 2005-01-21 04:25:47 +0000 | [diff] [blame] | 986 | ) ORDER BY x; |
| 987 | } |
| 988 | } {x 1 x 3} |
| 989 | do_test select1-12.10 { |
| 990 | execsql2 { |
| 991 | SELECT z.x FROM ( |
drh | 9237825 | 2006-03-26 01:21:22 +0000 | [diff] [blame] | 992 | SELECT a AS x,b AS y FROM t3 UNION SELECT a, b FROM t4 ORDER BY a,b |
danielk1977 | e61b9f4 | 2005-01-21 04:25:47 +0000 | [diff] [blame] | 993 | ) AS 'z' ORDER BY x; |
| 994 | } |
| 995 | } {x 1 x 3} |
danielk1977 | 27c7743 | 2004-11-22 13:35:41 +0000 | [diff] [blame] | 996 | } ;# ifcapable compound |
drh | d5feede | 2002-05-08 21:46:14 +0000 | [diff] [blame] | 997 | |
danielk1977 | 13a68c3 | 2005-12-15 10:11:30 +0000 | [diff] [blame] | 998 | |
danielk1977 | 327bd59 | 2006-01-13 13:01:19 +0000 | [diff] [blame] | 999 | # Check for a VDBE stack growth problem that existed at one point. |
| 1000 | # |
danielk1977 | 1576cd9 | 2006-01-14 08:02:28 +0000 | [diff] [blame] | 1001 | ifcapable subquery { |
| 1002 | do_test select1-13.1 { |
danielk1977 | 327bd59 | 2006-01-13 13:01:19 +0000 | [diff] [blame] | 1003 | execsql { |
danielk1977 | 1576cd9 | 2006-01-14 08:02:28 +0000 | [diff] [blame] | 1004 | BEGIN; |
| 1005 | create TABLE abc(a, b, c, PRIMARY KEY(a, b)); |
| 1006 | INSERT INTO abc VALUES(1, 1, 1); |
danielk1977 | 327bd59 | 2006-01-13 13:01:19 +0000 | [diff] [blame] | 1007 | } |
danielk1977 | 1576cd9 | 2006-01-14 08:02:28 +0000 | [diff] [blame] | 1008 | for {set i 0} {$i<10} {incr i} { |
| 1009 | execsql { |
| 1010 | INSERT INTO abc SELECT a+(select max(a) FROM abc), |
| 1011 | b+(select max(a) FROM abc), c+(select max(a) FROM abc) FROM abc; |
| 1012 | } |
| 1013 | } |
| 1014 | execsql {COMMIT} |
| 1015 | |
| 1016 | # This used to seg-fault when the problem existed. |
| 1017 | execsql { |
| 1018 | SELECT count( |
| 1019 | (SELECT a FROM abc WHERE a = NULL AND b >= upper.c) |
| 1020 | ) FROM abc AS upper; |
| 1021 | } |
| 1022 | } {0} |
| 1023 | } |
danielk1977 | 327bd59 | 2006-01-13 13:01:19 +0000 | [diff] [blame] | 1024 | |
danielk1977 | a3f0659 | 2009-04-23 14:58:39 +0000 | [diff] [blame] | 1025 | foreach tab [db eval {SELECT name FROM sqlite_master WHERE type = 'table'}] { |
| 1026 | db eval "DROP TABLE $tab" |
| 1027 | } |
danielk1977 | f7b9d66 | 2008-06-23 18:49:43 +0000 | [diff] [blame] | 1028 | db close |
danielk1977 | f7b9d66 | 2008-06-23 18:49:43 +0000 | [diff] [blame] | 1029 | sqlite3 db test.db |
danielk1977 | a3f0659 | 2009-04-23 14:58:39 +0000 | [diff] [blame] | 1030 | |
danielk1977 | f7b9d66 | 2008-06-23 18:49:43 +0000 | [diff] [blame] | 1031 | do_test select1-14.1 { |
| 1032 | execsql { |
| 1033 | SELECT * FROM sqlite_master WHERE rowid>10; |
| 1034 | SELECT * FROM sqlite_master WHERE rowid=10; |
| 1035 | SELECT * FROM sqlite_master WHERE rowid<10; |
| 1036 | SELECT * FROM sqlite_master WHERE rowid<=10; |
| 1037 | SELECT * FROM sqlite_master WHERE rowid>=10; |
| 1038 | SELECT * FROM sqlite_master; |
| 1039 | } |
| 1040 | } {} |
| 1041 | do_test select1-14.2 { |
| 1042 | execsql { |
| 1043 | SELECT 10 IN (SELECT rowid FROM sqlite_master); |
| 1044 | } |
| 1045 | } {0} |
| 1046 | |
drh | 01e61ee | 2009-04-10 15:38:42 +0000 | [diff] [blame] | 1047 | if {[db one {PRAGMA locking_mode}]=="normal"} { |
| 1048 | # Check that ticket #3771 has been fixed. This test does not |
| 1049 | # work with locking_mode=EXCLUSIVE so disable in that case. |
| 1050 | # |
| 1051 | do_test select1-15.1 { |
| 1052 | execsql { |
| 1053 | CREATE TABLE t1(a); |
| 1054 | CREATE INDEX i1 ON t1(a); |
| 1055 | INSERT INTO t1 VALUES(1); |
| 1056 | INSERT INTO t1 VALUES(2); |
| 1057 | INSERT INTO t1 VALUES(3); |
| 1058 | } |
| 1059 | } {} |
| 1060 | do_test select1-15.2 { |
| 1061 | sqlite3 db2 test.db |
| 1062 | execsql { DROP INDEX i1 } db2 |
| 1063 | db2 close |
| 1064 | } {} |
| 1065 | do_test select1-15.3 { |
| 1066 | execsql { SELECT 2 IN (SELECT a FROM t1) } |
| 1067 | } {1} |
| 1068 | } |
| 1069 | |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 1070 | finish_test |