summaryrefslogtreecommitdiffstats
path: root/test/collate2.test
blob: 281aa35709c8fef99f84a76603a5959fd82209cb (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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
#
# 2001 September 15
#
# 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 page cache subsystem.
#
# $Id: collate2.test,v 1.6 2008/08/20 16:35:10 drh Exp $

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

set ::testprefix collate2

#
# Tests are organised as follows:
#
# collate2-1.* WHERE <expr> expressions (sqliteExprIfTrue).
# collate2-2.* WHERE NOT <expr> expressions (sqliteExprIfFalse).
# collate2-3.* SELECT <expr> expressions (sqliteExprCode).
# collate2-4.* Precedence of collation/data types in binary comparisons
# collate2-5.* JOIN syntax.
#

# Create a collation type BACKWARDS for use in testing. This collation type
# is similar to the built-in TEXT collation type except the order of
# characters in each string is reversed before the comparison is performed.
db collate BACKWARDS backwards_collate
proc backwards_collate {a b} {
  set ra {};
  set rb {}
  foreach c [split $a {}] { set ra $c$ra }
  foreach c [split $b {}] { set rb $c$rb }
  return [string compare $ra $rb]
}

# The following values are used in these tests:
# NULL   aa ab ba bb   aA aB bA bB   Aa Ab Ba Bb   AA AB BA BB 
#
# The collation orders for each of the tested collation types are:
#
# BINARY:    NULL  AA AB Aa Ab  BA BB Ba Bb  aA aB aa ab  bA bB ba bb 
# NOCASE:    NULL  aa aA Aa AA  ab aB Ab AB  ba bA Ba BA  bb bB Bb BB 
# BACKWARDS: NULL  AA BA aA bA  AB BB aB bB  Aa Ba aa ba  Ab Bb ab bb 
#
# These tests verify that the default collation type for a column is used
# for comparison operators (<, >, <=, >=, =) involving that column and 
# an expression that is not a column with a default collation type.
# 
# The collation sequences BINARY and NOCASE are built-in, the BACKWARDS
# collation sequence is implemented by the TCL proc backwards_collate
# above.
#
do_test collate2-1.0 {
  execsql {
    CREATE TABLE collate2t1(
      a COLLATE BINARY, 
      b COLLATE NOCASE, 
      c COLLATE BACKWARDS
    );
    INSERT INTO collate2t1 VALUES( NULL, NULL, NULL );

    INSERT INTO collate2t1 VALUES( 'aa', 'aa', 'aa' );
    INSERT INTO collate2t1 VALUES( 'ab', 'ab', 'ab' );
    INSERT INTO collate2t1 VALUES( 'ba', 'ba', 'ba' );
    INSERT INTO collate2t1 VALUES( 'bb', 'bb', 'bb' );

    INSERT INTO collate2t1 VALUES( 'aA', 'aA', 'aA' );
    INSERT INTO collate2t1 VALUES( 'aB', 'aB', 'aB' );
    INSERT INTO collate2t1 VALUES( 'bA', 'bA', 'bA' );
    INSERT INTO collate2t1 VALUES( 'bB', 'bB', 'bB' );

    INSERT INTO collate2t1 VALUES( 'Aa', 'Aa', 'Aa' );
    INSERT INTO collate2t1 VALUES( 'Ab', 'Ab', 'Ab' );
    INSERT INTO collate2t1 VALUES( 'Ba', 'Ba', 'Ba' );
    INSERT INTO collate2t1 VALUES( 'Bb', 'Bb', 'Bb' );

    INSERT INTO collate2t1 VALUES( 'AA', 'AA', 'AA' );
    INSERT INTO collate2t1 VALUES( 'AB', 'AB', 'AB' );
    INSERT INTO collate2t1 VALUES( 'BA', 'BA', 'BA' );
    INSERT INTO collate2t1 VALUES( 'BB', 'BB', 'BB' );
  }
  if {[info exists collate_test_use_index]} { 
    execsql {
      CREATE INDEX collate2t1_i1 ON collate2t1(a);
      CREATE INDEX collate2t1_i2 ON collate2t1(b);
      CREATE INDEX collate2t1_i3 ON collate2t1(c);
    }
  }
} {}
do_test collate2-1.1 {
  execsql {
    SELECT a FROM collate2t1 WHERE a > 'aa' ORDER BY 1;
  }
} {ab bA bB ba bb}
do_test collate2-1.1.1 {
  execsql {
    SELECT a FROM collate2t1 WHERE a COLLATE binary > 'aa' ORDER BY 1;
  }
} {ab bA bB ba bb}
do_test collate2-1.1.2 {
  execsql {
    SELECT a FROM collate2t1 WHERE b COLLATE binary > 'aa' ORDER BY 1;
  }
} {ab bA bB ba bb}
do_test collate2-1.1.3 {
  execsql {
    SELECT a FROM collate2t1 WHERE c COLLATE binary > 'aa' ORDER BY 1;
  }
} {ab bA bB ba bb}
do_test collate2-1.2 {
  execsql {
    SELECT b FROM collate2t1 WHERE b > 'aa' ORDER BY 1, oid;
  }
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.2.1 {
  execsql {
    SELECT b FROM collate2t1 WHERE a COLLATE nocase > 'aa'
     ORDER BY 1, oid;
  }
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.2.2 {
  execsql {
    SELECT b FROM collate2t1 WHERE b COLLATE nocase > 'aa'
     ORDER BY 1, oid;
  }
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.2.3 {
  execsql {
    SELECT b FROM collate2t1 WHERE c COLLATE nocase > 'aa'
     ORDER BY 1, oid;
  }
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.2.4 {
  execsql {
    SELECT b FROM collate2t1 WHERE b > 'aa' ORDER BY +b;
  }
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.2.5 {
  execsql {
    SELECT b FROM collate2t1 WHERE a COLLATE nocase > 'aa' ORDER BY +b;
  }
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.2.6 {
  execsql {
    SELECT b FROM collate2t1 WHERE b COLLATE nocase > 'aa' ORDER BY +b;
  }
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.2.7 {
  execsql {
    SELECT b FROM collate2t1 WHERE c COLLATE nocase > 'aa' ORDER BY +b;
  }
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.3 {
  execsql {
    SELECT c FROM collate2t1 WHERE c > 'aa' ORDER BY 1;
  }
} {ba Ab Bb ab bb}
do_test collate2-1.3.1 {
  execsql {
    SELECT c FROM collate2t1 WHERE a COLLATE backwards > 'aa'
    ORDER BY 1;
  }
} {ba Ab Bb ab bb}
do_test collate2-1.3.2 {
  execsql {
    SELECT c FROM collate2t1 WHERE b COLLATE backwards > 'aa'
    ORDER BY 1;
  }
} {ba Ab Bb ab bb}
do_test collate2-1.3.3 {
  execsql {
    SELECT c FROM collate2t1 WHERE c COLLATE backwards > 'aa'
    ORDER BY 1;
  }
} {ba Ab Bb ab bb}
do_test collate2-1.4 {
  execsql {
    SELECT a FROM collate2t1 WHERE a < 'aa' ORDER BY 1;
  }
} {AA AB Aa Ab BA BB Ba Bb aA aB}
do_test collate2-1.5 {
  execsql {
    SELECT b FROM collate2t1 WHERE b < 'aa' ORDER BY 1, oid;
  }
} {}
do_test collate2-1.5.1 {
  execsql {
    SELECT b FROM collate2t1 WHERE b < 'aa' ORDER BY +b;
  }
} {}
do_test collate2-1.6 {
  execsql {
    SELECT c FROM collate2t1 WHERE c < 'aa' ORDER BY 1;
  }
} {AA BA aA bA AB BB aB bB Aa Ba}
do_test collate2-1.7 {
  execsql {
    SELECT a FROM collate2t1 WHERE a = 'aa';
  }
} {aa}
do_test collate2-1.8 {
  execsql {
    SELECT b FROM collate2t1 WHERE b = 'aa' ORDER BY oid;
  }
} {aa aA Aa AA}
do_test collate2-1.9 {
  execsql {
    SELECT c FROM collate2t1 WHERE c = 'aa';
  }
} {aa}
do_test collate2-1.10 {
  execsql {
    SELECT a FROM collate2t1 WHERE a >= 'aa' ORDER BY 1;
  }
} {aa ab bA bB ba bb}
do_test collate2-1.11 {
  execsql {
    SELECT b FROM collate2t1 WHERE b >= 'aa' ORDER BY 1, oid;
  }
} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.12 {
  execsql {
    SELECT c FROM collate2t1 WHERE c >= 'aa' ORDER BY 1;
  }
} {aa ba Ab Bb ab bb}
do_test collate2-1.13 {
  execsql {
    SELECT a FROM collate2t1 WHERE a <= 'aa' ORDER BY 1;
  }
} {AA AB Aa Ab BA BB Ba Bb aA aB aa}
do_test collate2-1.14 {
  execsql {
    SELECT b FROM collate2t1 WHERE b <= 'aa' ORDER BY 1, oid;
  }
} {aa aA Aa AA}
do_test collate2-1.15 {
  execsql {
    SELECT c FROM collate2t1 WHERE c <= 'aa' ORDER BY 1;
  }
} {AA BA aA bA AB BB aB bB Aa Ba aa}
do_test collate2-1.16 {
  execsql {
    SELECT a FROM collate2t1 WHERE a BETWEEN 'Aa' AND 'Bb' ORDER BY 1;
  }
} {Aa Ab BA BB Ba Bb}
do_test collate2-1.17 {
  execsql {
    SELECT b FROM collate2t1 WHERE b BETWEEN 'Aa' AND 'Bb' ORDER BY 1, oid;
  }
} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.17.1 {
  execsql {
    SELECT b FROM collate2t1 WHERE b BETWEEN 'Aa' AND 'Bb' ORDER BY +b;
  }
} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-1.18 {
  execsql {
    SELECT c FROM collate2t1 WHERE c BETWEEN 'Aa' AND 'Bb' ORDER BY 1;
  }
} {Aa Ba aa ba Ab Bb}
do_test collate2-1.19 {
  execsql {
    SELECT a FROM collate2t1 WHERE 
      CASE a WHEN 'aa' THEN 1 ELSE 0 END
        ORDER BY 1, oid;
  }
} {aa}
do_test collate2-1.20 {
  execsql {
    SELECT b FROM collate2t1 WHERE 
      CASE b WHEN 'aa' THEN 1 ELSE 0 END
        ORDER BY 1, oid;
  }
} {aa aA Aa AA}
do_test collate2-1.21 {
  execsql {
    SELECT c FROM collate2t1 WHERE 
      CASE c WHEN 'aa' THEN 1 ELSE 0 END
        ORDER BY 1, oid;
  }
} {aa}

ifcapable subquery {
  do_test collate2-1.22 {
    execsql {
      SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb') ORDER BY 1, oid;
    }
  } {aa bb}
  do_test collate2-1.23 {
    execsql {
      SELECT b FROM collate2t1 WHERE b IN ('aa', 'bb') ORDER BY 1, oid;
    }
  } {aa aA Aa AA bb bB Bb BB}
  do_test collate2-1.24 {
    execsql {
      SELECT c FROM collate2t1 WHERE c IN ('aa', 'bb') ORDER BY 1, oid;
    }
  } {aa bb}
  do_test collate2-1.25 {
    execsql {
      SELECT a FROM collate2t1 
        WHERE a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
    }
  } {aa bb}
  do_test collate2-1.26 {
    execsql {
      SELECT b FROM collate2t1 
        WHERE b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
    }
  } {aa bb aA bB Aa Bb AA BB}
  do_test collate2-1.27 {
    execsql {
      SELECT c FROM collate2t1 
        WHERE c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
    }
  } {aa bb}
} ;# ifcapable subquery

do_test collate2-2.1 {
  execsql {
    SELECT a FROM collate2t1 WHERE NOT a > 'aa' ORDER BY 1;
  }
} {AA AB Aa Ab BA BB Ba Bb aA aB aa}
do_test collate2-2.2 {
  execsql {
    SELECT b FROM collate2t1 WHERE NOT b > 'aa' ORDER BY 1, oid;
  }
} {aa aA Aa AA}
do_test collate2-2.3 {
  execsql {
    SELECT c FROM collate2t1 WHERE NOT c > 'aa' ORDER BY 1;
  }
} {AA BA aA bA AB BB aB bB Aa Ba aa}
do_test collate2-2.4 {
  execsql {
    SELECT a FROM collate2t1 WHERE NOT a < 'aa' ORDER BY 1;
  }
} {aa ab bA bB ba bb}
do_test collate2-2.5 {
  execsql {
    SELECT b FROM collate2t1 WHERE NOT b < 'aa' ORDER BY 1, oid;
  }
} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-2.6 {
  execsql {
    SELECT c FROM collate2t1 WHERE NOT c < 'aa' ORDER BY 1;
  }
} {aa ba Ab Bb ab bb}
do_test collate2-2.7 {
  execsql {
    SELECT a FROM collate2t1 WHERE NOT a = 'aa';
  }
} {ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
do_test collate2-2.8 {
  execsql {
    SELECT b FROM collate2t1 WHERE NOT b = 'aa';
  }
} {ab ba bb aB bA bB Ab Ba Bb AB BA BB}
do_test collate2-2.9 {
  execsql {
    SELECT c FROM collate2t1 WHERE NOT c = 'aa';
  }
} {ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
do_test collate2-2.10 {
  execsql {
    SELECT a FROM collate2t1 WHERE NOT a >= 'aa' ORDER BY 1;
  }
} {AA AB Aa Ab BA BB Ba Bb aA aB}
do_test collate2-2.11 {
  execsql {
    SELECT b FROM collate2t1 WHERE NOT b >= 'aa' ORDER BY 1, oid;
  }
} {}
do_test collate2-2.12 {
  execsql {
    SELECT c FROM collate2t1 WHERE NOT c >= 'aa' ORDER BY 1;
  }
} {AA BA aA bA AB BB aB bB Aa Ba}
do_test collate2-2.13 {
  execsql {
    SELECT a FROM collate2t1 WHERE NOT a <= 'aa' ORDER BY 1;
  }
} {ab bA bB ba bb}
do_test collate2-2.14 {
  execsql {
    SELECT b FROM collate2t1 WHERE NOT b <= 'aa' ORDER BY 1, oid;
  }
} {ab aB Ab AB ba bA Ba BA bb bB Bb BB}
do_test collate2-2.15 {
  execsql {
    SELECT c FROM collate2t1 WHERE NOT c <= 'aa' ORDER BY 1;
  }
} {ba Ab Bb ab bb}
do_test collate2-2.16 {
  execsql {
    SELECT a FROM collate2t1 WHERE a NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1;
  }
} {AA AB aA aB aa ab bA bB ba bb}
do_test collate2-2.17 {
  execsql {
    SELECT b FROM collate2t1 WHERE b NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1, oid;
  }
} {}
do_test collate2-2.18 {
  execsql {
    SELECT c FROM collate2t1 WHERE c NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1;
  }
} {AA BA aA bA AB BB aB bB ab bb}
do_test collate2-2.19 {
  execsql {
    SELECT a FROM collate2t1 WHERE NOT CASE a WHEN 'aa' THEN 1 ELSE 0 END;
  }
} {{} ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
do_test collate2-2.20 {
  execsql {
    SELECT b FROM collate2t1 WHERE NOT CASE b WHEN 'aa' THEN 1 ELSE 0 END;
  }
} {{} ab ba bb aB bA bB Ab Ba Bb AB BA BB}
do_test collate2-2.21 {
  execsql {
    SELECT c FROM collate2t1 WHERE NOT CASE c WHEN 'aa' THEN 1 ELSE 0 END;
  }
} {{} ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB}

ifcapable subquery {
  do_test collate2-2.22 {
    execsql {
      SELECT a FROM collate2t1 WHERE NOT a IN ('aa', 'bb');
    }
  } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
  do_test collate2-2.23 {
    execsql {
      SELECT b FROM collate2t1 WHERE NOT b IN ('aa', 'bb');
    }
  } {ab ba aB bA Ab Ba AB BA}
  do_test collate2-2.24 {
    execsql {
      SELECT c FROM collate2t1 WHERE NOT c IN ('aa', 'bb');
    }
  } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
  do_test collate2-2.25 {
    execsql {
      SELECT a FROM collate2t1 
        WHERE NOT a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
    }
  } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
  do_test collate2-2.26 {
    execsql {
      SELECT b FROM collate2t1 
        WHERE NOT b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
    }
  } {ab ba aB bA Ab Ba AB BA}
  do_test collate2-2.27 {
    execsql {
      SELECT c FROM collate2t1 
        WHERE NOT c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb'));
    }
  } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB}
}

do_test collate2-3.1 {
  execsql {
    SELECT a > 'aa' FROM collate2t1;
  }
} {{} 0 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0}
do_test collate2-3.2 {
  execsql {
    SELECT b > 'aa' FROM collate2t1;
  }
} {{} 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1}
do_test collate2-3.3 {
  execsql {
    SELECT c > 'aa' FROM collate2t1;
  }
} {{} 0 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0}
do_test collate2-3.4 {
  execsql {
    SELECT a < 'aa' FROM collate2t1;
  }
} {{} 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1}
do_test collate2-3.5 {
  execsql {
    SELECT b < 'aa' FROM collate2t1;
  }
} {{} 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
do_test collate2-3.6 {
  execsql {
    SELECT c < 'aa' FROM collate2t1;
  }
} {{} 0 0 0 0 1 1 1 1 1 0 1 0 1 1 1 1}
do_test collate2-3.7 {
  execsql {
    SELECT a = 'aa' FROM collate2t1;
  }
} {{} 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
do_test collate2-3.8 {
  execsql {
    SELECT b = 'aa' FROM collate2t1;
  }
} {{} 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0}
do_test collate2-3.9 {
  execsql {
    SELECT c = 'aa' FROM collate2t1;
  }
} {{} 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
do_test collate2-3.10 {
  execsql {
    SELECT a <= 'aa' FROM collate2t1;
  }
} {{} 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1}
do_test collate2-3.11 {
  execsql {
    SELECT b <= 'aa' FROM collate2t1;
  }
} {{} 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0}
do_test collate2-3.12 {
  execsql {
    SELECT c <= 'aa' FROM collate2t1;
  }
} {{} 1 0 0 0 1 1 1 1 1 0 1 0 1 1 1 1}
do_test collate2-3.13 {
  execsql {
    SELECT a >= 'aa' FROM collate2t1;
  }
} {{} 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0}
do_test collate2-3.14 {
  execsql {
    SELECT b >= 'aa' FROM collate2t1;
  }
} {{} 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
do_test collate2-3.15 {
  execsql {
    SELECT c >= 'aa' FROM collate2t1;
  }
} {{} 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0}
do_test collate2-3.16 {
  execsql {
    SELECT a BETWEEN 'Aa' AND 'Bb' FROM collate2t1;
  }
} {{} 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1}
do_test collate2-3.17 {
  execsql {
    SELECT b BETWEEN 'Aa' AND 'Bb' FROM collate2t1;
  }
} {{} 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
do_test collate2-3.18 {
  execsql {
    SELECT c BETWEEN 'Aa' AND 'Bb' FROM collate2t1;
  }
} {{} 1 0 1 0 0 0 0 0 1 1 1 1 0 0 0 0}
do_test collate2-3.19 {
  execsql {
    SELECT CASE a WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1;
  }
} {0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
do_test collate2-3.20 {
  execsql {
    SELECT CASE b WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1;
  }
} {0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0}
do_test collate2-3.21 {
  execsql {
    SELECT CASE c WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1;
  }
} {0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}

ifcapable subquery {
  do_test collate2-3.22 {
    execsql {
      SELECT a IN ('aa', 'bb') FROM collate2t1;
    }
  } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0}
  do_test collate2-3.23 {
    execsql {
      SELECT b IN ('aa', 'bb') FROM collate2t1;
    }
  } {{} 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1}
  do_test collate2-3.24 {
    execsql {
      SELECT c IN ('aa', 'bb') FROM collate2t1;
    }
  } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0}
  do_test collate2-3.25 {
    execsql {
      SELECT a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')) 
        FROM collate2t1;
    }
  } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0}
  do_test collate2-3.26 {
    execsql {
      SELECT b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')) 
        FROM collate2t1;
    }
  } {{} 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1}
  do_test collate2-3.27 {
    execsql {
      SELECT c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')) 
        FROM collate2t1;
    }
  } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0}
}

do_test collate2-4.0 {
  execsql {
    CREATE TABLE collate2t2(b COLLATE binary);
    CREATE TABLE collate2t3(b text);
    INSERT INTO collate2t2 VALUES('aa');
    INSERT INTO collate2t3 VALUES('aa');
  }
} {}

# Test that when both sides of a binary comparison operator have
# default collation types, the collate type for the leftmost term
# is used.
do_test collate2-4.1 {
  execsql {
    SELECT collate2t1.a FROM collate2t1, collate2t2 
      WHERE collate2t1.b = collate2t2.b;
  }
} {aa aA Aa AA}
do_test collate2-4.2 {
  execsql {
    SELECT collate2t1.a FROM collate2t1, collate2t2 
      WHERE collate2t2.b = collate2t1.b;
  }
} {aa}

# Test that when one side has a default collation type and the other
# does not, the collation type is used.
do_test collate2-4.3 {
  execsql {
    SELECT collate2t1.a FROM collate2t1, collate2t3 
      WHERE collate2t1.b = collate2t3.b||''
      ORDER BY +collate2t1.a DESC;
  }
} {aa aA Aa AA}
do_test collate2-4.4 {
  execsql {
    SELECT collate2t1.a FROM collate2t1, collate2t3 
      WHERE collate2t3.b||'' = collate2t1.b
      ORDER BY +collate2t1.a DESC;
  }
} {aa aA Aa AA}

do_test collate2-4.5 {
  execsql {
    DROP TABLE collate2t3;
  }
} {}

#
# Test that the default collation types are used when the JOIN syntax
# is used in place of a WHERE clause.
#
# SQLite transforms the JOIN syntax into a WHERE clause internally, so
# the focus of these tests is to ensure that the table on the left-hand-side
# of the join determines the collation type used. 
#
do_test collate2-5.0 {
  execsql {
    SELECT collate2t1.b FROM collate2t1 JOIN collate2t2 USING (b);
  }
} {aa aA Aa AA}
do_test collate2-5.1 {
  execsql {
    SELECT collate2t1.b FROM collate2t2 JOIN collate2t1 USING (b);
  }
} {aa}
do_test collate2-5.2 {
  execsql {
    SELECT collate2t1.b FROM collate2t1 NATURAL JOIN collate2t2;
  }
} {aa aA Aa AA}
do_test collate2-5.3 {
  execsql {
    SELECT collate2t1.b FROM collate2t2 NATURAL JOIN collate2t1;
  }
} {aa}
do_test collate2-5.4.1 {
  execsql {
    SELECT collate2t2.b FROM collate2t1 LEFT JOIN collate2t2 USING (b) order by collate2t1.oid;
  }
} {{} aa {} {} {} aa {} {} {} aa {} {} {} aa {} {} {}}
do_test collate2-5.4.2 {
  execsql {
    SELECT collate2t2.b FROM collate2t2 RIGHT JOIN collate2t1 ON collate2t1.b=collate2t2.b
     ORDER BY collate2t1.oid;
  }
} {{} aa {} {} {} aa {} {} {} aa {} {} {} aa {} {} {}}
do_test collate2-5.4.3 {
  execsql {
    SELECT collate2t2.b FROM collate2t1 LEFT JOIN collate2t2 ON collate2t2.b=collate2t1.b
     ORDER BY collate2t1.oid;
  }
} {{} aa {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}}
do_test collate2-5.5.1 {
  execsql {
    SELECT collate2t1.b, collate2t2.b FROM collate2t2 LEFT OUTER JOIN collate2t1 USING (b);
  }
} {aa aa}
do_test collate2-5.5.2 {
  execsql {
    SELECT collate2t1.b, collate2t2.b
      FROM collate2t1 RIGHT JOIN collate2t2 ON collate2t2.b=collate2t1.b
  }
} {aa aa}

do_execsql_test 6.1 {
  CREATE TABLE t1(x);
  INSERT INTO t1 VALUES('b');
  INSERT INTO t1 VALUES('B');
}
do_execsql_test 6.2 {
  SELECT * FROM t1 WHERE x COLLATE nocase BETWEEN 'a' AND 'c';
} {b B}
do_execsql_test 6.3 {
  SELECT * FROM t1 WHERE x BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase;
} {b B}
do_execsql_test 6.4 {
  SELECT * FROM t1 
  WHERE x COLLATE nocase BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase;
} {b B}
do_execsql_test 6.5 {
  SELECT * FROM t1 WHERE +x COLLATE nocase BETWEEN 'a' AND 'c';
} {b B}
do_execsql_test 6.6 {
  SELECT * FROM t1 WHERE +x BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase;
} {b B}
do_execsql_test 6.7 {
  SELECT * FROM t1 
  WHERE +x COLLATE nocase BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase;
} {b B}

finish_test