whereA.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # 2009 February 23
  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 SQLite library. The
  12. # focus of this file is testing the reverse_select_order pragma.
  13. #
  14. # $Id: whereA.test,v 1.3 2009/06/10 19:33:29 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. do_test whereA-1.1 {
  18. db eval {
  19. CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE, c);
  20. INSERT INTO t1 VALUES(1,2,3);
  21. INSERT INTO t1 values(2,'hello','world');
  22. INSERT INTO t1 VALUES(3,4.53,NULL);
  23. SELECT * FROM t1
  24. }
  25. } {1 2 3 2 hello world 3 4.53 {}}
  26. do_test whereA-1.2 {
  27. db eval {
  28. PRAGMA reverse_unordered_selects=1;
  29. SELECT * FROM t1;
  30. }
  31. } {3 4.53 {} 2 hello world 1 2 3}
  32. do_test whereA-1.3 {
  33. db close
  34. sqlite3 db test.db
  35. db eval {
  36. PRAGMA reverse_unordered_selects=1;
  37. SELECT * FROM t1;
  38. }
  39. } {3 4.53 {} 2 hello world 1 2 3}
  40. do_test whereA-1.4 {
  41. db close
  42. sqlite3 db test.db
  43. db eval {
  44. PRAGMA reverse_unordered_selects=1;
  45. SELECT * FROM t1 ORDER BY rowid;
  46. }
  47. } {1 2 3 2 hello world 3 4.53 {}}
  48. do_test whereA-1.5 {
  49. db eval {
  50. VACUUM;
  51. SELECT * FROM t1 ORDER BY rowid;
  52. }
  53. } {1 2 3 2 hello world 3 4.53 {}}
  54. do_test whereA-1.6 {
  55. db eval {
  56. PRAGMA reverse_unordered_selects;
  57. }
  58. } {1}
  59. do_test whereA-1.7 {
  60. db close
  61. sqlite3 db test.db
  62. db eval {
  63. PRAGMA reverse_unordered_selects=1;
  64. VACUUM;
  65. SELECT * FROM t1;
  66. }
  67. } {3 4.53 {} 2 hello world 1 2 3}
  68. do_execsql_test whereA-1.8 {
  69. SELECT * FROM t1 WHERE b=2 AND a IS NULL;
  70. } {}
  71. do_execsql_test whereA-1.9 {
  72. SELECT * FROM t1 WHERE b=2 AND a IS NOT NULL;
  73. } {1 2 3}
  74. do_test whereA-2.1 {
  75. db eval {
  76. PRAGMA reverse_unordered_selects=0;
  77. SELECT * FROM t1 WHERE a>0;
  78. }
  79. } {1 2 3 2 hello world 3 4.53 {}}
  80. do_test whereA-2.2 {
  81. db eval {
  82. PRAGMA reverse_unordered_selects=1;
  83. SELECT * FROM t1 WHERE a>0;
  84. }
  85. } {3 4.53 {} 2 hello world 1 2 3}
  86. do_test whereA-2.3 {
  87. db eval {
  88. PRAGMA reverse_unordered_selects=1;
  89. SELECT * FROM t1 WHERE a>0 ORDER BY rowid;
  90. }
  91. } {1 2 3 2 hello world 3 4.53 {}}
  92. do_test whereA-3.1 {
  93. db eval {
  94. PRAGMA reverse_unordered_selects=0;
  95. SELECT * FROM t1 WHERE b>0;
  96. }
  97. } {1 2 3 3 4.53 {} 2 hello world}
  98. do_test whereA-3.2 {
  99. db eval {
  100. PRAGMA reverse_unordered_selects=1;
  101. SELECT * FROM t1 WHERE b>0;
  102. }
  103. } {2 hello world 3 4.53 {} 1 2 3}
  104. do_test whereA-3.3 {
  105. db eval {
  106. PRAGMA reverse_unordered_selects=1;
  107. SELECT * FROM t1 WHERE b>0 ORDER BY b;
  108. }
  109. } {1 2 3 3 4.53 {} 2 hello world}
  110. do_test whereA-4.1 {
  111. db eval {
  112. CREATE TABLE t2(x);
  113. INSERT INTO t2 VALUES(1);
  114. INSERT INTO t2 VALUES(2);
  115. SELECT x FROM t2;
  116. }
  117. } {2 1}
  118. # Do an SQL statement. Append the search count to the end of the result.
  119. #
  120. proc count sql {
  121. set ::sqlite_sort_count 0
  122. return [concat [execsql $sql] $::sqlite_sort_count]
  123. }
  124. do_test whereA-4.2 { ;# Ticket #3904
  125. db eval {
  126. CREATE INDEX t2x ON t2(x);
  127. }
  128. count {
  129. SELECT x FROM t2;
  130. }
  131. } {2 1 0}
  132. do_test whereA-4.3 {
  133. count {
  134. SELECT x FROM t2 ORDER BY x;
  135. }
  136. } {1 2 0}
  137. do_test whereA-4.4 {
  138. count {
  139. SELECT x FROM t2 ORDER BY x DESC;
  140. }
  141. } {2 1 0}
  142. do_test whereA-4.5 {
  143. db eval {DROP INDEX t2x;}
  144. count {
  145. SELECT x FROM t2 ORDER BY x;
  146. }
  147. } {1 2 1}
  148. do_test whereA-4.6 {
  149. count {
  150. SELECT x FROM t2 ORDER BY x DESC;
  151. }
  152. } {2 1 1}
  153. finish_test