4 # The author disclaims copyright to this source code. In place of
5 # a legal notice, here is a blessing:
7 # May you do good and not evil.
8 # May you find forgiveness for yourself and forgive others.
9 # May you share freely, never taking more than you give.
11 #***********************************************************************
12 # This file implements regression tests for SQLite library. The
13 # focus of this script is collation sequences in concert with triggers.
15 # $Id: collate6.test,v 1.4 2007/07/30 14:40:48 danielk1977 Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # There are no tests in this file that will work without
23 ifcapable {!trigger} {
28 # Create a case-insensitive collation type NOCASE for use in testing.
29 # Normally, capital letters are less than their lower-case counterparts.
30 db collate NOCASE nocase_collate
31 proc nocase_collate {a b} {
32 return [string compare -nocase $a $b]
36 # Tests are organized as follows:
37 # collate6-1.* - triggers.
40 do_test collate6-1.0 {
42 CREATE TABLE collate6log(a, b);
43 CREATE TABLE collate6tab(a COLLATE NOCASE, b COLLATE BINARY);
47 # Test that the default collation sequence applies to new.* references
49 do_test collate6-1.1 {
51 CREATE TRIGGER collate6trig BEFORE INSERT ON collate6tab
52 WHEN new.a = 'a' BEGIN
53 INSERT INTO collate6log VALUES(new.a, new.b);
57 do_test collate6-1.2 {
59 INSERT INTO collate6tab VALUES('a', 'b');
60 SELECT * FROM collate6log;
63 do_test collate6-1.3 {
65 INSERT INTO collate6tab VALUES('A', 'B');
66 SELECT * FROM collate6log;
69 do_test collate6-1.4 {
71 DROP TRIGGER collate6trig;
72 DELETE FROM collate6log;
76 # Test that the default collation sequence applies to new.* references
77 # in the body of triggers.
78 do_test collate6-1.5 {
80 CREATE TRIGGER collate6trig BEFORE INSERT ON collate6tab BEGIN
81 INSERT INTO collate6log VALUES(new.a='a', new.b='b');
85 do_test collate6-1.6 {
87 INSERT INTO collate6tab VALUES('a', 'b');
88 SELECT * FROM collate6log;
91 do_test collate6-1.7 {
93 INSERT INTO collate6tab VALUES('A', 'B');
94 SELECT * FROM collate6log;
97 do_test collate6-1.8 {
99 DROP TRIGGER collate6trig;
100 DELETE FROM collate6log;
104 do_test collate6-1.9 {
106 DROP TABLE collate6tab;
110 # Test that an explicit collation sequence overrides an implicit
111 # one attached to a 'new' reference.
113 do_test collate6-2.1 {
115 CREATE TABLE abc(a COLLATE binary, b, c);
116 CREATE TABLE def(a, b, c);
117 CREATE TRIGGER abc_t1 AFTER INSERT ON abc BEGIN
118 INSERT INTO def SELECT * FROM abc WHERE a < new.a COLLATE nocase;
122 do_test collate6-2.2 {
124 INSERT INTO abc VALUES('One', 'Two', 'Three');
125 INSERT INTO abc VALUES('one', 'two', 'three');
129 do_test collate6-2.3 {
131 UPDATE abc SET a = 'four' WHERE a = 'one';
132 CREATE TRIGGER abc_t2 AFTER UPDATE ON abc BEGIN
133 INSERT INTO def SELECT * FROM abc WHERE a < new.a COLLATE nocase;
139 # At one point the 6-3.2 (but not 6-3.1) was causing an assert() to fail.
141 do_test collate6-3.1 {
143 SELECT 1 FROM sqlite_master WHERE name COLLATE nocase = 'hello';
146 do_test collate6-3.2 {
148 SELECT 1 FROM sqlite_master WHERE 'hello' = name COLLATE nocase;