summaryrefslogtreecommitdiff
path: root/test/collateA.test
blob: 3f7ebd9242fa7bfcc1270af3d5cb31051bcf464d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#
# 2008 January 20
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is the built-in RTRIM collating
# API.
#
# $Id: collateA.test,v 1.3 2008/04/15 04:02:41 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test collateA-1.1 {
  execsql {
    CREATE TABLE t1(
      a INTEGER PRIMARY KEY,
      b TEXT COLLATE BINARY,
      c TEXT COLLATE RTRIM
    );
    INSERT INTO t1 VALUES(1, 'abcde','abcde');
    INSERT INTO t1 VALUES(2, 'xyzzy ','xyzzy ');
    INSERT INTO t1 VALUES(3, 'xyzzy  ','xyzzy  ');
    INSERT INTO t1 VALUES(4, 'xyzzy   ','xyzzy   ');
    INSERT INTO t1 VALUES(5, '   ', '   ');
    INSERT INTO t1 VALUES(6, '', '');
    SELECT count(*) FROM t1;
  }
} {6}
do_test collateA-1.2 {
  execsql {SELECT a FROM t1 WHERE b='abcde     '}
} {}
do_test collateA-1.3 {
  execsql {SELECT a FROM t1 WHERE c='abcde     '}
} {1}
do_test collateA-1.4 {
  execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-1.5 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}
do_test collateA-1.6 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-1.7 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy  '}
} {2 3 4}
do_test collateA-1.8 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy   '}
} {2 3 4}
do_test collateA-1.9 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy    '}
} {2 3 4}
do_test collateA-1.10 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy                                  '}
} {2 3 4}
do_test collateA-1.11 {
  execsql {SELECT 'abc123'='abc123                         ' COLLATE RTRIM;}
} {1}
do_test collateA-1.12 {
  execsql {SELECT 'abc123                         '='abc123' COLLATE RTRIM;}
} {1}
do_test collateA-1.13 {
  execsql {SELECT '  '='' COLLATE RTRIM, '  '='' COLLATE BINARY, '  '=''}
} {1 0 0}
do_test collateA-1.14 {
  execsql {SELECT ''='  ' COLLATE RTRIM, ''='  ' COLLATE BINARY, ''='  '}
} {1 0 0}
do_test collateA-1.15 {
  execsql {SELECT '  '='      ' COLLATE RTRIM, '  '='        '}
} {1 0}
do_test collateA-1.16 {
  execsql {SELECT ''<>'  ' COLLATE RTRIM, ''<>'  ' COLLATE BINARY, ''<>'  '}
} {0 1 1}
do_test collateA-1.17 {
  execsql {SELECT a FROM t1 WHERE c='xyzz'}
} {}
do_test collateA-1.18 {
  execsql {SELECT a FROM t1 WHERE c='xyzzyy   '}
} {}
do_test collateA-1.19 {
  execsql {SELECT a FROM t1 WHERE c='xyzz   '}
} {}
do_test collateA-1.20 {
  execsql {SELECT a FROM t1 WHERE c='abcd   '}
} {}
do_test collateA-1.21 {
  execsql {SELECT a FROM t1 WHERE c='abcd'}
} {}
do_test collateA-1.22 {
  execsql {SELECT a FROM t1 WHERE c='abc'}
} {}
do_test collateA-1.23 {
  execsql {SELECT a FROM t1 WHERE c='abcdef    '}
} {}
do_test collateA-1.24 {
  execsql {SELECT a FROM t1 WHERE c=''}
} {5 6}
do_test collateA-1.25 {
  execsql {SELECT a FROM t1 WHERE c=' '}
} {5 6}
do_test collateA-1.26 {
  execsql {SELECT a FROM t1 WHERE c='                    '}
} {5 6}


do_test collateA-2.1 {
  execsql {
    CREATE INDEX i1b ON t1(b);
    CREATE INDEX i1c ON t1(c);
    PRAGMA integrity_check;
  }
} {ok}
do_test collateA-2.2 {
  execsql {SELECT a FROM t1 WHERE b='abcde     '}
} {}
do_test collateA-2.3 {
  execsql {SELECT a FROM t1 WHERE c='abcde     '}
} {1}
do_test collateA-2.4 {
  execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-2.5 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}
do_test collateA-2.6 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-2.7 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy  '}
} {2 3 4}
do_test collateA-2.8 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy   '}
} {2 3 4}
do_test collateA-2.9 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy    '}
} {2 3 4}
do_test collateA-2.10 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy                                  '}
} {2 3 4}
do_test collateA-2.17 {
  execsql {SELECT a FROM t1 WHERE c='xyzz'}
} {}
do_test collateA-2.18 {
  execsql {SELECT a FROM t1 WHERE c='xyzzyy   '}
} {}
do_test collateA-2.19 {
  execsql {SELECT a FROM t1 WHERE c='xyzz   '}
} {}
do_test collateA-2.20 {
  execsql {SELECT a FROM t1 WHERE c='abcd   '}
} {}
do_test collateA-2.21 {
  execsql {SELECT a FROM t1 WHERE c='abcd'}
} {}
do_test collateA-2.22 {
  execsql {SELECT a FROM t1 WHERE c='abc'}
} {}
do_test collateA-2.23 {
  execsql {SELECT a FROM t1 WHERE c='abcdef    '}
} {}
do_test collateA-2.24 {
  execsql {SELECT a FROM t1 WHERE c=''}
} {5 6}
do_test collateA-2.25 {
  execsql {SELECT a FROM t1 WHERE c=' '}
} {5 6}
do_test collateA-2.26 {
  execsql {SELECT a FROM t1 WHERE c='                    '}
} {5 6}


do_test collateA-3.1 {
  db close
  sqlite3 db test.db
  execsql {
    REINDEX;
    PRAGMA integrity_check;
  }
} {ok}
do_test collateA-3.2 {
  execsql {SELECT a FROM t1 WHERE b='abcde     '}
} {}
do_test collateA-3.3 {
  execsql {SELECT a FROM t1 WHERE c='abcde     '}
} {1}
do_test collateA-3.4 {
  execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-3.5 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}
do_test collateA-3.6 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-3.7 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy  '}
} {2 3 4}
do_test collateA-3.8 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy   '}
} {2 3 4}
do_test collateA-3.9 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy    '}
} {2 3 4}
do_test collateA-3.10 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy                                  '}
} {2 3 4}


finish_test