1
0

selectE.test 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # 2013-05-07
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. # This file implements regression tests for compound SELECT statements
  12. # that have ORDER BY clauses with collating sequences that differ
  13. # from the collating sequence used for comparison in the compound.
  14. #
  15. # Ticket 6709574d2a8d8b9be3a9cb1afbf4ff2de48ea4e7:
  16. # drh added on 2013-05-06 15:21:16:
  17. #
  18. # In the code shown below (which is intended to be run from the
  19. # sqlite3.exe command-line tool) the three SELECT statements should all
  20. # generate the same answer. But the third one does not. It is as if the
  21. # COLLATE clause on the ORDER BY somehow got pulled into the EXCEPT
  22. # operator. Note that the ".print" commands are instructions to the
  23. # sqlite3.exe shell program to output delimiter lines so that you can more
  24. # easily tell where the output of one query ends and the next query
  25. # begins.
  26. #
  27. # CREATE TABLE t1(a);
  28. # INSERT INTO t1 VALUES('abc'),('def');
  29. # CREATE TABLE t2(a);
  30. # INSERT INTO t2 VALUES('DEF');
  31. #
  32. # SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a;
  33. # .print -----
  34. # SELECT a FROM (SELECT a FROM t1 EXCEPT SELECT a FROM t2)
  35. # ORDER BY a COLLATE nocase;
  36. # .print -----
  37. # SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a COLLATE nocase;
  38. #
  39. # Bisecting shows that this problem was introduced in SQLite version 3.6.0
  40. # by check-in [8bbfa97837a74ef] on 2008-06-15.
  41. #
  42. set testdir [file dirname $argv0]
  43. source $testdir/tester.tcl
  44. do_test selectE-1.0 {
  45. db eval {
  46. CREATE TABLE t1(a);
  47. INSERT INTO t1 VALUES('abc'),('def'),('ghi');
  48. CREATE TABLE t2(a);
  49. INSERT INTO t2 VALUES('DEF'),('abc');
  50. CREATE TABLE t3(a);
  51. INSERT INTO t3 VALUES('def'),('jkl');
  52. SELECT a FROM t1 EXCEPT SELECT a FROM t2
  53. ORDER BY a COLLATE nocase;
  54. }
  55. } {def ghi}
  56. do_test selectE-1.1 {
  57. db eval {
  58. SELECT a FROM t2 EXCEPT SELECT a FROM t3
  59. ORDER BY a COLLATE nocase;
  60. }
  61. } {abc DEF}
  62. do_test selectE-1.2 {
  63. db eval {
  64. SELECT a FROM t2 EXCEPT SELECT a FROM t3
  65. ORDER BY a COLLATE binary;
  66. }
  67. } {DEF abc}
  68. do_test selectE-1.3 {
  69. db eval {
  70. SELECT a FROM t2 EXCEPT SELECT a FROM t3
  71. ORDER BY a;
  72. }
  73. } {DEF abc}
  74. do_test selectE-2.1 {
  75. db eval {
  76. DELETE FROM t2;
  77. DELETE FROM t3;
  78. INSERT INTO t2 VALUES('ABC'),('def'),('GHI'),('jkl');
  79. INSERT INTO t3 SELECT lower(a) FROM t2;
  80. SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
  81. ORDER BY 1
  82. }
  83. } {}
  84. do_test selectE-2.2 {
  85. db eval {
  86. SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
  87. ORDER BY 1 COLLATE binary
  88. }
  89. } {}
  90. finish_test