tkt-2a5629202f.test 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # 2012 April 19
  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. # The tests in this file were used while developing the SQLite 4 code.
  12. #
  13. set testdir [file dirname $argv0]
  14. source $testdir/tester.tcl
  15. set testprefix tkt-2a5629202f
  16. # This procedure executes the SQL. Then it checks to see if the OP_Sort
  17. # opcode was executed. If an OP_Sort did occur, then "sort" is appended
  18. # to the result. If no OP_Sort happened, then "nosort" is appended.
  19. #
  20. # This procedure is used to check to make sure sorting is or is not
  21. # occurring as expected.
  22. #
  23. proc cksort {sql} {
  24. set data [execsql $sql]
  25. if {[db status sort]} {set x sort} {set x nosort}
  26. lappend data $x
  27. return $data
  28. }
  29. do_execsql_test 1.1 {
  30. CREATE TABLE t8(b TEXT, c TEXT);
  31. INSERT INTO t8 VALUES('a', 'one');
  32. INSERT INTO t8 VALUES('b', 'two');
  33. INSERT INTO t8 VALUES(NULL, 'three');
  34. INSERT INTO t8 VALUES(NULL, 'four');
  35. }
  36. do_execsql_test 1.2 {
  37. SELECT coalesce(b, 'null') || '/' || c FROM t8 x ORDER BY x.b, x.c
  38. } {null/four null/three a/one b/two}
  39. do_execsql_test 1.3 {
  40. CREATE UNIQUE INDEX i1 ON t8(b);
  41. SELECT coalesce(b, 'null') || '/' || c FROM t8 x ORDER BY x.b, x.c
  42. } {null/four null/three a/one b/two}
  43. do_execsql_test 1.4 {
  44. DROP INDEX i1;
  45. CREATE UNIQUE INDEX i1 ON t8(b, c);
  46. SELECT coalesce(b, 'null') || '/' || c FROM t8 x ORDER BY x.b, x.c
  47. } {null/four null/three a/one b/two}
  48. #-------------------------------------------------------------------------
  49. #
  50. do_execsql_test 2.1 {
  51. CREATE TABLE t2(a, b NOT NULL, c);
  52. CREATE UNIQUE INDEX t2ab ON t2(a, b);
  53. CREATE UNIQUE INDEX t2ba ON t2(b, a);
  54. }
  55. do_test 2.2 {
  56. cksort { SELECT * FROM t2 WHERE a = 10 ORDER BY a, b, c }
  57. } {nosort}
  58. do_test 2.3 {
  59. cksort { SELECT * FROM t2 WHERE b = 10 ORDER BY a, b, c }
  60. } {sort}
  61. do_test 2.4 {
  62. cksort { SELECT * FROM t2 WHERE a IS NULL ORDER BY a, b, c }
  63. } {sort}
  64. finish_test