collate8.test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #
  2. # 2007 June 20
  3. #
  4. # The author disclaims copyright to this source code. In place of
  5. # a legal notice, here is a blessing:
  6. #
  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.
  10. #
  11. #***********************************************************************
  12. # This file implements regression tests for SQLite library. The
  13. # focus of this script is making sure collations pass through the
  14. # unary + operator.
  15. #
  16. # $Id: collate8.test,v 1.2 2008/08/25 12:14:09 drh Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. do_test collate8-1.1 {
  20. execsql {
  21. CREATE TABLE t1(a TEXT COLLATE nocase);
  22. INSERT INTO t1 VALUES('aaa');
  23. INSERT INTO t1 VALUES('BBB');
  24. INSERT INTO t1 VALUES('ccc');
  25. INSERT INTO t1 VALUES('DDD');
  26. SELECT a FROM t1 ORDER BY a;
  27. }
  28. } {aaa BBB ccc DDD}
  29. do_test collate8-1.2 {
  30. execsql {
  31. SELECT rowid FROM t1 WHERE a<'ccc' ORDER BY 1
  32. }
  33. } {1 2}
  34. do_test collate8-1.3 {
  35. execsql {
  36. SELECT rowid FROM t1 WHERE a<'ccc' COLLATE binary ORDER BY 1
  37. }
  38. } {1 2 4}
  39. do_test collate8-1.4 {
  40. execsql {
  41. SELECT rowid FROM t1 WHERE +a<'ccc' ORDER BY 1
  42. }
  43. } {1 2}
  44. do_test collate8-1.5 {
  45. execsql {
  46. SELECT a FROM t1 ORDER BY +a
  47. }
  48. } {aaa BBB ccc DDD}
  49. do_test collate8-1.11 {
  50. execsql {
  51. SELECT a AS x FROM t1 ORDER BY "x";
  52. }
  53. } {aaa BBB ccc DDD}
  54. do_test collate8-1.12 {
  55. execsql {
  56. SELECT a AS x FROM t1 WHERE x<'ccc' ORDER BY 1
  57. }
  58. } {aaa BBB}
  59. do_test collate8-1.13 {
  60. execsql {
  61. SELECT a AS x FROM t1 WHERE x<'ccc' COLLATE binary ORDER BY [x]
  62. }
  63. } {aaa BBB DDD}
  64. do_test collate8-1.14 {
  65. execsql {
  66. SELECT a AS x FROM t1 WHERE +x<'ccc' ORDER BY 1
  67. }
  68. } {aaa BBB}
  69. do_test collate8-1.15 {
  70. execsql {
  71. SELECT a AS x FROM t1 ORDER BY +x
  72. }
  73. } {aaa BBB ccc DDD}
  74. # When a result-set column is aliased into a WHERE clause, make sure the
  75. # collating sequence logic works correctly.
  76. #
  77. do_test collate8-2.1 {
  78. execsql {
  79. CREATE TABLE t2(a);
  80. INSERT INTO t2 VALUES('abc');
  81. INSERT INTO t2 VALUES('ABC');
  82. SELECT a AS x FROM t2 WHERE x='abc';
  83. }
  84. } {abc}
  85. do_test collate8-2.2 {
  86. execsql {
  87. SELECT a AS x FROM t2 WHERE x='abc' COLLATE nocase;
  88. }
  89. } {abc ABC}
  90. do_test collate8-2.3 {
  91. execsql {
  92. SELECT a AS x FROM t2 WHERE (x COLLATE nocase)='abc';
  93. }
  94. } {abc ABC}
  95. do_test collate8-2.4 {
  96. execsql {
  97. SELECT a COLLATE nocase AS x FROM t2 WHERE x='abc';
  98. }
  99. } {abc ABC}
  100. do_test collate8-2.5 {
  101. execsql {
  102. SELECT a COLLATE nocase AS x FROM t2 WHERE (x COLLATE binary)='abc';
  103. }
  104. } {abc}
  105. do_test collate8-2.6 {
  106. execsql {
  107. SELECT a COLLATE nocase AS x FROM t2 WHERE x='abc' COLLATE binary;
  108. }
  109. } {abc ABC}
  110. do_test collate8-2.7 {
  111. execsql {
  112. SELECT * FROM t2 WHERE (a COLLATE nocase)='abc' COLLATE binary;
  113. }
  114. } {abc ABC}
  115. do_test collate8-2.8 {
  116. execsql {
  117. SELECT a COLLATE nocase AS x FROM t2 WHERE 'abc'=x COLLATE binary;
  118. }
  119. } {abc}
  120. finish_test