1 # 2008 October 13 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. Specifically, 12 # it tests that affinities and collation sequences are correctly applied 13 # in aggregate queries. 14 # 15 # $Id: tkt3493.test,v 1.2 2009/06/05 17:09:12 drh Exp $ 16 17 set testdir [file dirname $argv0] 18 source $testdir/tester.tcl 19 20 do_test tkt3493-1.1 { 21 execsql { 22 BEGIN; 23 CREATE TABLE A (id INTEGER PRIMARY KEY AUTOINCREMENT, val TEXT); 24 INSERT INTO A VALUES(1,'123'); 25 INSERT INTO A VALUES(2,'456'); 26 CREATE TABLE B (id INTEGER PRIMARY KEY AUTOINCREMENT, val TEXT); 27 INSERT INTO B VALUES(1,1); 28 INSERT INTO B VALUES(2,2); 29 CREATE TABLE A_B (B_id INTEGER NOT NULL, A_id INTEGER); 30 INSERT INTO A_B VALUES(1,1); 31 INSERT INTO A_B VALUES(2,2); 32 COMMIT; 33 } 34 } {} 35 do_test tkt3493-1.2 { 36 execsql { 37 SELECT 38 CASE 39 WHEN B.val = 1 THEN 'XYZ' 40 ELSE A.val 41 END AS Col1 42 FROM B 43 LEFT OUTER JOIN A_B ON B.id = A_B.B_id 44 LEFT OUTER JOIN A ON A.id = A_B.A_id 45 ORDER BY Col1 ASC; 46 } 47 } {456 XYZ} 48 do_test tkt3493-1.3 { 49 execsql { 50 SELECT DISTINCT 51 CASE 52 WHEN B.val = 1 THEN 'XYZ' 53 ELSE A.val 54 END AS Col1 55 FROM B 56 LEFT OUTER JOIN A_B ON B.id = A_B.B_id 57 LEFT OUTER JOIN A ON A.id = A_B.A_id 58 ORDER BY Col1 ASC; 59 } 60 } {456 XYZ} 61 do_test tkt3493-1.4 { 62 execsql { 63 SELECT b.val, CASE WHEN b.val = 1 THEN 'xyz' ELSE b.val END AS col1 FROM b; 64 } 65 } {1 xyz 2 2} 66 do_test tkt3493-1.5 { 67 execsql { 68 SELECT DISTINCT 69 b.val, 70 CASE WHEN b.val = 1 THEN 'xyz' ELSE b.val END AS col1 71 FROM b; 72 } 73 } {1 xyz 2 2} 74 do_test tkt3493-1.6 { 75 execsql { 76 SELECT DISTINCT 77 b.val, 78 CASE WHEN b.val = '1' THEN 'xyz' ELSE b.val END AS col1 79 FROM b; 80 } 81 } {1 xyz 2 2} 82 83 84 do_test tkt3493-2.1 { 85 execsql { 86 CREATE TABLE t1(a TEXT, b INT); 87 INSERT INTO t1 VALUES(123, 456); 88 } 89 } {} 90 do_test tkt3493-2.2.1 { 91 execsql { SELECT a=123 FROM t1 GROUP BY a } 92 } {1} 93 do_test tkt3493-2.2.2 { 94 execsql { SELECT a=123 FROM t1 } 95 } {1} 96 do_test tkt3493-2.2.3 { 97 execsql { SELECT a='123' FROM t1 } 98 } {1} 99 do_test tkt3493-2.2.4 { 100 execsql { SELECT count(*), a=123 FROM t1 } 101 } {1 1} 102 do_test tkt3493-2.2.5 { 103 execsql { SELECT count(*), +a=123 FROM t1 } 104 } {1 0} 105 do_test tkt3493-2.3.3 { 106 execsql { SELECT b='456' FROM t1 GROUP BY a } 107 } {1} 108 do_test tkt3493-2.3.1 { 109 execsql { SELECT b='456' FROM t1 GROUP BY b } 110 } {1} 111 do_test tkt3493-2.3.2 { 112 execsql { SELECT b='456' FROM t1 } 113 } {1} 114 do_test tkt3493-2.4.1 { 115 execsql { SELECT typeof(a), a FROM t1 GROUP BY a HAVING a=123 } 116 } {text 123} 117 do_test tkt3493-2.4.2 { 118 execsql { SELECT typeof(a), a FROM t1 GROUP BY b HAVING a=123 } 119 } {text 123} 120 do_test tkt3493-2.5.1 { 121 execsql { SELECT typeof(b), b FROM t1 GROUP BY a HAVING b='456' } 122 } {integer 456} 123 do_test tkt3493-2.5.2 { 124 execsql { SELECT typeof(b), b FROM t1 GROUP BY b HAVING b='456' } 125 } {integer 456} 126 127 do_test tkt3493-3.1 { 128 execsql { 129 CREATE TABLE t2(a COLLATE NOCASE, b COLLATE BINARY); 130 INSERT INTO t2 VALUES('aBc', 'DeF'); 131 } 132 } {} 133 do_test tkt3493-3.2.1 { 134 execsql { SELECT a='abc' FROM t2 GROUP BY a } 135 } {1} 136 do_test tkt3493-3.2.2 { 137 execsql { SELECT a='abc' FROM t2 } 138 } {1} 139 140 do_test tkt3493-3.3.1 { 141 execsql { SELECT a>b FROM t2 GROUP BY a, b} 142 } {0} 143 do_test tkt3493-3.3.2 { 144 execsql { SELECT a>b COLLATE BINARY FROM t2 GROUP BY a, b} 145 } {1} 146 do_test tkt3493-3.3.3 { 147 execsql { SELECT b>a FROM t2 GROUP BY a, b} 148 } {0} 149 do_test tkt3493-3.3.4 { 150 execsql { SELECT b>a COLLATE NOCASE FROM t2 GROUP BY a, b} 151 } {1} 152 153 finish_test 154