17e09fe0bSdrh# 27e09fe0bSdrh# 2007 June 20 37e09fe0bSdrh# 47e09fe0bSdrh# The author disclaims copyright to this source code. In place of 57e09fe0bSdrh# a legal notice, here is a blessing: 67e09fe0bSdrh# 77e09fe0bSdrh# May you do good and not evil. 87e09fe0bSdrh# May you find forgiveness for yourself and forgive others. 97e09fe0bSdrh# May you share freely, never taking more than you give. 107e09fe0bSdrh# 117e09fe0bSdrh#*********************************************************************** 127e09fe0bSdrh# This file implements regression tests for SQLite library. The 137e09fe0bSdrh# focus of this script is making sure collations pass through the 147e09fe0bSdrh# unary + operator. 157e09fe0bSdrh# 16*2308ed38Sdrh# 2015-02-09: Added tests to make sure COLLATE passes through function 17*2308ed38Sdrh# calls. Ticket [ca0d20b6cdddec5e81b8d66f89c46a5583b5f6f6]. 18*2308ed38Sdrh# 197e09fe0bSdrh 207e09fe0bSdrhset testdir [file dirname $argv0] 217e09fe0bSdrhsource $testdir/tester.tcl 227e09fe0bSdrh 237e09fe0bSdrhdo_test collate8-1.1 { 247e09fe0bSdrh execsql { 257e09fe0bSdrh CREATE TABLE t1(a TEXT COLLATE nocase); 267e09fe0bSdrh INSERT INTO t1 VALUES('aaa'); 277e09fe0bSdrh INSERT INTO t1 VALUES('BBB'); 287e09fe0bSdrh INSERT INTO t1 VALUES('ccc'); 297e09fe0bSdrh INSERT INTO t1 VALUES('DDD'); 307e09fe0bSdrh SELECT a FROM t1 ORDER BY a; 317e09fe0bSdrh } 327e09fe0bSdrh} {aaa BBB ccc DDD} 337e09fe0bSdrhdo_test collate8-1.2 { 347e09fe0bSdrh execsql { 357e09fe0bSdrh SELECT rowid FROM t1 WHERE a<'ccc' ORDER BY 1 367e09fe0bSdrh } 377e09fe0bSdrh} {1 2} 387e09fe0bSdrhdo_test collate8-1.3 { 397e09fe0bSdrh execsql { 407e09fe0bSdrh SELECT rowid FROM t1 WHERE a<'ccc' COLLATE binary ORDER BY 1 417e09fe0bSdrh } 427e09fe0bSdrh} {1 2 4} 437e09fe0bSdrhdo_test collate8-1.4 { 447e09fe0bSdrh execsql { 457e09fe0bSdrh SELECT rowid FROM t1 WHERE +a<'ccc' ORDER BY 1 467e09fe0bSdrh } 477e09fe0bSdrh} {1 2} 487e09fe0bSdrhdo_test collate8-1.5 { 497e09fe0bSdrh execsql { 507e09fe0bSdrh SELECT a FROM t1 ORDER BY +a 517e09fe0bSdrh } 527e09fe0bSdrh} {aaa BBB ccc DDD} 53f436620eSdrhdo_test collate8-1.11 { 54f436620eSdrh execsql { 55f436620eSdrh SELECT a AS x FROM t1 ORDER BY "x"; 56f436620eSdrh } 57f436620eSdrh} {aaa BBB ccc DDD} 58f436620eSdrhdo_test collate8-1.12 { 59f436620eSdrh execsql { 60f436620eSdrh SELECT a AS x FROM t1 WHERE x<'ccc' ORDER BY 1 61f436620eSdrh } 62f436620eSdrh} {aaa BBB} 63f436620eSdrhdo_test collate8-1.13 { 64f436620eSdrh execsql { 65f436620eSdrh SELECT a AS x FROM t1 WHERE x<'ccc' COLLATE binary ORDER BY [x] 66f436620eSdrh } 67f436620eSdrh} {aaa BBB DDD} 68f436620eSdrhdo_test collate8-1.14 { 69f436620eSdrh execsql { 70f436620eSdrh SELECT a AS x FROM t1 WHERE +x<'ccc' ORDER BY 1 71f436620eSdrh } 72f436620eSdrh} {aaa BBB} 73f436620eSdrhdo_test collate8-1.15 { 74f436620eSdrh execsql { 75f436620eSdrh SELECT a AS x FROM t1 ORDER BY +x 76f436620eSdrh } 77f436620eSdrh} {aaa BBB ccc DDD} 78f436620eSdrh 79f436620eSdrh 80f436620eSdrh# When a result-set column is aliased into a WHERE clause, make sure the 81f436620eSdrh# collating sequence logic works correctly. 82f436620eSdrh# 83f436620eSdrhdo_test collate8-2.1 { 84f436620eSdrh execsql { 85f436620eSdrh CREATE TABLE t2(a); 86f436620eSdrh INSERT INTO t2 VALUES('abc'); 87f436620eSdrh INSERT INTO t2 VALUES('ABC'); 88f436620eSdrh SELECT a AS x FROM t2 WHERE x='abc'; 89f436620eSdrh } 90f436620eSdrh} {abc} 91f436620eSdrhdo_test collate8-2.2 { 92f436620eSdrh execsql { 93f436620eSdrh SELECT a AS x FROM t2 WHERE x='abc' COLLATE nocase; 94f436620eSdrh } 95f436620eSdrh} {abc ABC} 96f436620eSdrhdo_test collate8-2.3 { 97f436620eSdrh execsql { 98f436620eSdrh SELECT a AS x FROM t2 WHERE (x COLLATE nocase)='abc'; 99f436620eSdrh } 100f436620eSdrh} {abc ABC} 101f436620eSdrhdo_test collate8-2.4 { 102f436620eSdrh execsql { 103f436620eSdrh SELECT a COLLATE nocase AS x FROM t2 WHERE x='abc'; 104f436620eSdrh } 105f436620eSdrh} {abc ABC} 106f436620eSdrhdo_test collate8-2.5 { 107f436620eSdrh execsql { 108f436620eSdrh SELECT a COLLATE nocase AS x FROM t2 WHERE (x COLLATE binary)='abc'; 109f436620eSdrh } 110f436620eSdrh} {abc} 111f436620eSdrhdo_test collate8-2.6 { 112f436620eSdrh execsql { 113f436620eSdrh SELECT a COLLATE nocase AS x FROM t2 WHERE x='abc' COLLATE binary; 114f436620eSdrh } 115f436620eSdrh} {abc ABC} 116f436620eSdrhdo_test collate8-2.7 { 117f436620eSdrh execsql { 118f436620eSdrh SELECT * FROM t2 WHERE (a COLLATE nocase)='abc' COLLATE binary; 119f436620eSdrh } 120f436620eSdrh} {abc ABC} 121f436620eSdrhdo_test collate8-2.8 { 122f436620eSdrh execsql { 123f436620eSdrh SELECT a COLLATE nocase AS x FROM t2 WHERE 'abc'=x COLLATE binary; 124f436620eSdrh } 125f436620eSdrh} {abc} 1267e09fe0bSdrh 127*2308ed38Sdrh# Make sure the COLLATE operator perculates up through function calls 128*2308ed38Sdrh# and other Expr structures that use the Expr.x.pList field. 129*2308ed38Sdrh# 130*2308ed38Sdrhdo_execsql_test collate8-3.1 { 131*2308ed38Sdrh SELECT 'abc'==('ABC'||'') COLLATE nocase; 132*2308ed38Sdrh SELECT 'abc'==('ABC'||'' COLLATE nocase); 133*2308ed38Sdrh SELECT 'abc'==('ABC'||('' COLLATE nocase)); 134*2308ed38Sdrh SELECT 'abc'==('ABC'||upper('' COLLATE nocase)); 135*2308ed38Sdrh} {1 1 1 1} 136*2308ed38Sdrhdo_execsql_test collate8-3.2 { 137*2308ed38Sdrh SELECT 'abc'==('ABC'||max('' COLLATE nocase,'' COLLATE binary)); 138*2308ed38Sdrh} {1} 139*2308ed38Sdrh 140*2308ed38Sdrh# The COLLATE binary is on the left and so takes precedence 141*2308ed38Sdrhdo_execsql_test collate8-3.3 { 142*2308ed38Sdrh SELECT 'abc'==('ABC'||max('' COLLATE binary,'' COLLATE nocase)); 143*2308ed38Sdrh} {0} 144*2308ed38Sdrh 145*2308ed38Sdrhdo_execsql_test collate8-3.4 { 146*2308ed38Sdrh SELECT 'abc'==('ABC'||CASE WHEN 1-1=2 THEN '' COLLATE nocase 147*2308ed38Sdrh ELSE '' COLLATE binary END); 148*2308ed38Sdrh SELECT 'abc'==('ABC'||CASE WHEN 1+1=2 THEN '' COLLATE nocase 149*2308ed38Sdrh ELSE '' COLLATE binary END); 150*2308ed38Sdrh} {1 1} 151*2308ed38Sdrhdo_execsql_test collate8-3.5 { 152*2308ed38Sdrh SELECT 'abc'==('ABC'||CASE WHEN 1=2 THEN '' COLLATE binary 153*2308ed38Sdrh ELSE '' COLLATE nocase END); 154*2308ed38Sdrh} {0} 155*2308ed38Sdrh 156*2308ed38Sdrh 1577e09fe0bSdrhfinish_test 158