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 making sure that the names of collation
14 # sequences may be quoted using double quotes in SQL statements.
16 # $Id: collate9.test,v 1.2 2008/07/10 00:32:42 drh Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 proc reverse_sort {lhs rhs} {
22 return [string compare $rhs $lhs]
24 db collate "reverse sort" reverse_sort
26 # This procedure executes the SQL. Then it checks to see if the OP_Sort
27 # opcode was executed. If an OP_Sort did occur, then "sort" is appended
28 # to the result. If no OP_Sort happened, then "nosort" is appended.
30 # This procedure is used to check to make sure sorting is or is not
31 # occurring as expected.
34 set ::sqlite_sort_count 0
35 set data [execsql $sql]
36 if {$::sqlite_sort_count} {set x sort} {set x nosort}
43 # collate9-1.* - Test collation sequences attached to table columns
44 # collate9-2.* - Test collation sequences attached to expressions
45 # collate9-3.* - Test collation sequences attached to an index
46 # collate9-4.* - Test collation sequences as an argument to REINDEX
49 do_test collate9-1.1 {
51 CREATE TABLE xy(x COLLATE "reverse sort", y COLLATE binary);
52 INSERT INTO xy VALUES('one', 'one');
53 INSERT INTO xy VALUES('two', 'two');
54 INSERT INTO xy VALUES('three', 'three');
57 do_test collate9-1.2 {
59 SELECT x FROM xy ORDER BY x
62 do_test collate9-1.3 {
64 SELECT y FROM xy ORDER BY y
67 do_test collate9-1.4 {
69 SELECT x FROM xy ORDER BY x
71 } {two three one sort}
72 do_test collate9-1.5 {
74 CREATE INDEX xy_i ON xy(x)
77 do_test collate9-1.6 {
79 SELECT x FROM xy ORDER BY x
81 } {two three one nosort}
83 do_test collate9-2.1 {
85 SELECT x, x < 'seven' FROM xy ORDER BY x
87 } {two 1 three 1 one 0}
88 do_test collate9-2.2 {
90 SELECT y, y < 'seven' FROM xy ORDER BY x
92 } {two 0 three 0 one 1}
93 do_test collate9-2.3 {
95 SELECT y, y COLLATE "reverse sort" < 'seven' FROM xy ORDER BY x
97 } {two 1 three 1 one 0}
98 do_test collate9-2.4 {
100 SELECT y FROM xy ORDER BY y
103 do_test collate9-2.5 {
105 SELECT y FROM xy ORDER BY y COLLATE "reverse sort"
108 do_test collate9-2.6 {
110 SELECT y COLLATE "reverse sort" AS aaa FROM xy ORDER BY aaa
114 do_test collate9-3.1 {
116 CREATE INDEX xy_i2 ON xy(y COLLATE "reverse sort");
119 do_test collate9-3.2 {
121 SELECT y FROM xy ORDER BY y
123 } {one three two sort}
124 do_test collate9-3.3 {
126 SELECT y FROM xy ORDER BY y COLLATE "reverse sort"
128 } {two three one nosort}
129 do_test collate9-3.4 {
131 SELECT y AS aaa FROM xy ORDER BY aaa
133 } {one three two sort}
134 do_test collate9-3.5 {
136 SELECT y COLLATE "reverse sort" AS aaa FROM xy ORDER BY aaa
138 } {two three one nosort}
141 do_test collate9-4.1 {
143 REINDEX "reverse sort"
147 # Modify the "reverse sort" collation so that it now sorts in the same
149 proc reverse_sort {lhs rhs} {
150 return [string compare $lhs $rhs]
153 # The integrity check should now fail because the indexes created using
154 # "reverse sort" are no longer in sync with the collation sequence
156 do_test collate9-4.2 {
157 expr {"ok" eq [execsql { PRAGMA integrity_check }]}
160 do_test collate9-4.3 {
162 REINDEX "reverse sort"
166 # Integrity check should now pass.
167 do_test collate9-4.4 {
168 expr {"ok" eq [execsql { PRAGMA integrity_check }]}
171 do_test collate9-4.5 {
173 SELECT x FROM xy ORDER BY x COLLATE "reverse sort"
175 } {one three two nosort}