OLD | NEW |
(Empty) | |
| 1 # 2009 February 23 |
| 2 # |
| 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: |
| 5 # |
| 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. |
| 9 # |
| 10 #*********************************************************************** |
| 11 # This file implements regression tests for SQLite library. The |
| 12 # focus of this file is testing the reverse_select_order pragma. |
| 13 # |
| 14 # $Id: whereA.test,v 1.3 2009/06/10 19:33:29 drh Exp $ |
| 15 |
| 16 set testdir [file dirname $argv0] |
| 17 source $testdir/tester.tcl |
| 18 |
| 19 do_test whereA-1.1 { |
| 20 db eval { |
| 21 CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE, c); |
| 22 INSERT INTO t1 VALUES(1,2,3); |
| 23 INSERT INTO t1 values(2,'hello','world'); |
| 24 INSERT INTO t1 VALUES(3,4.53,NULL); |
| 25 SELECT * FROM t1 |
| 26 } |
| 27 } {1 2 3 2 hello world 3 4.53 {}} |
| 28 do_test whereA-1.2 { |
| 29 db eval { |
| 30 PRAGMA reverse_unordered_selects=1; |
| 31 SELECT * FROM t1; |
| 32 } |
| 33 } {3 4.53 {} 2 hello world 1 2 3} |
| 34 |
| 35 do_test whereA-1.3 { |
| 36 db close |
| 37 sqlite3 db test.db |
| 38 db eval { |
| 39 PRAGMA reverse_unordered_selects=1; |
| 40 SELECT * FROM t1; |
| 41 } |
| 42 } {3 4.53 {} 2 hello world 1 2 3} |
| 43 do_test whereA-1.4 { |
| 44 db close |
| 45 sqlite3 db test.db |
| 46 db eval { |
| 47 PRAGMA reverse_unordered_selects=1; |
| 48 SELECT * FROM t1 ORDER BY rowid; |
| 49 } |
| 50 } {1 2 3 2 hello world 3 4.53 {}} |
| 51 do_test whereA-1.5 { |
| 52 db eval { |
| 53 VACUUM; |
| 54 SELECT * FROM t1 ORDER BY rowid; |
| 55 } |
| 56 } {1 2 3 2 hello world 3 4.53 {}} |
| 57 do_test whereA-1.6 { |
| 58 db eval { |
| 59 PRAGMA reverse_unordered_selects; |
| 60 } |
| 61 } {1} |
| 62 do_test whereA-1.7 { |
| 63 db close |
| 64 sqlite3 db test.db |
| 65 db eval { |
| 66 PRAGMA reverse_unordered_selects=1; |
| 67 VACUUM; |
| 68 SELECT * FROM t1; |
| 69 } |
| 70 } {3 4.53 {} 2 hello world 1 2 3} |
| 71 do_execsql_test whereA-1.8 { |
| 72 SELECT * FROM t1 WHERE b=2 AND a IS NULL; |
| 73 } {} |
| 74 do_execsql_test whereA-1.9 { |
| 75 SELECT * FROM t1 WHERE b=2 AND a IS NOT NULL; |
| 76 } {1 2 3} |
| 77 |
| 78 do_test whereA-2.1 { |
| 79 db eval { |
| 80 PRAGMA reverse_unordered_selects=0; |
| 81 SELECT * FROM t1 WHERE a>0; |
| 82 } |
| 83 } {1 2 3 2 hello world 3 4.53 {}} |
| 84 do_test whereA-2.2 { |
| 85 db eval { |
| 86 PRAGMA reverse_unordered_selects=1; |
| 87 SELECT * FROM t1 WHERE a>0; |
| 88 } |
| 89 } {3 4.53 {} 2 hello world 1 2 3} |
| 90 |
| 91 do_test whereA-2.3 { |
| 92 db eval { |
| 93 PRAGMA reverse_unordered_selects=1; |
| 94 SELECT * FROM t1 WHERE a>0 ORDER BY rowid; |
| 95 } |
| 96 } {1 2 3 2 hello world 3 4.53 {}} |
| 97 |
| 98 do_test whereA-3.1 { |
| 99 db eval { |
| 100 PRAGMA reverse_unordered_selects=0; |
| 101 SELECT * FROM t1 WHERE b>0; |
| 102 } |
| 103 } {1 2 3 3 4.53 {} 2 hello world} |
| 104 do_test whereA-3.2 { |
| 105 db eval { |
| 106 PRAGMA reverse_unordered_selects=1; |
| 107 SELECT * FROM t1 WHERE b>0; |
| 108 } |
| 109 } {2 hello world 3 4.53 {} 1 2 3} |
| 110 do_test whereA-3.3 { |
| 111 db eval { |
| 112 PRAGMA reverse_unordered_selects=1; |
| 113 SELECT * FROM t1 WHERE b>0 ORDER BY b; |
| 114 } |
| 115 } {1 2 3 3 4.53 {} 2 hello world} |
| 116 |
| 117 do_test whereA-4.1 { |
| 118 db eval { |
| 119 CREATE TABLE t2(x); |
| 120 INSERT INTO t2 VALUES(1); |
| 121 INSERT INTO t2 VALUES(2); |
| 122 SELECT x FROM t2; |
| 123 } |
| 124 } {2 1} |
| 125 # Do an SQL statement. Append the search count to the end of the result. |
| 126 # |
| 127 proc count sql { |
| 128 set ::sqlite_sort_count 0 |
| 129 return [concat [execsql $sql] $::sqlite_sort_count] |
| 130 } |
| 131 do_test whereA-4.2 { ;# Ticket #3904 |
| 132 db eval { |
| 133 CREATE INDEX t2x ON t2(x); |
| 134 } |
| 135 count { |
| 136 SELECT x FROM t2; |
| 137 } |
| 138 } {2 1 0} |
| 139 do_test whereA-4.3 { |
| 140 count { |
| 141 SELECT x FROM t2 ORDER BY x; |
| 142 } |
| 143 } {1 2 0} |
| 144 do_test whereA-4.4 { |
| 145 count { |
| 146 SELECT x FROM t2 ORDER BY x DESC; |
| 147 } |
| 148 } {2 1 0} |
| 149 do_test whereA-4.5 { |
| 150 db eval {DROP INDEX t2x;} |
| 151 count { |
| 152 SELECT x FROM t2 ORDER BY x; |
| 153 } |
| 154 } {1 2 1} |
| 155 do_test whereA-4.6 { |
| 156 count { |
| 157 SELECT x FROM t2 ORDER BY x DESC; |
| 158 } |
| 159 } {2 1 1} |
| 160 |
| 161 |
| 162 finish_test |
OLD | NEW |