tkt-cbd054fa6b.test 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # 2010 March 25
  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. #
  12. # This file implements tests to verify that ticket [cbd054fa6b] has been
  13. # fixed.
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. ifcapable !stat4&&!stat3 {
  18. finish_test
  19. return
  20. }
  21. proc s {blob} {
  22. set ret ""
  23. binary scan $blob c* bytes
  24. foreach b $bytes {
  25. set t [binary format c $b]
  26. if {[string is print $t]} {
  27. append ret $t
  28. } else {
  29. append ret .
  30. }
  31. }
  32. return $ret
  33. }
  34. db function s s
  35. do_test tkt-cbd05-1.1 {
  36. db eval {
  37. CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT UNIQUE NOT NULL);
  38. CREATE INDEX t1_x ON t1(b);
  39. INSERT INTO t1 VALUES (NULL, '');
  40. INSERT INTO t1 VALUES (NULL, 'A');
  41. INSERT INTO t1 VALUES (NULL, 'B');
  42. INSERT INTO t1 VALUES (NULL, 'C');
  43. INSERT INTO t1 VALUES (NULL, 'D');
  44. INSERT INTO t1 VALUES (NULL, 'E');
  45. INSERT INTO t1 VALUES (NULL, 'F');
  46. INSERT INTO t1 VALUES (NULL, 'G');
  47. INSERT INTO t1 VALUES (NULL, 'H');
  48. INSERT INTO t1 VALUES (NULL, 'I');
  49. SELECT count(*) FROM t1;
  50. }
  51. } {10}
  52. do_test tkt-cbd05-1.2 {
  53. db eval { ANALYZE; }
  54. ifcapable stat4 {
  55. db eval {
  56. PRAGMA writable_schema = 1;
  57. CREATE VIEW vvv AS
  58. SELECT tbl,idx,neq,nlt,ndlt,test_extract(sample,0) AS sample
  59. FROM sqlite_stat4;
  60. PRAGMA writable_schema = 0;
  61. }
  62. } else {
  63. db eval {
  64. CREATE VIEW vvv AS
  65. SELECT tbl,idx,neq,nlt,ndlt,sample FROM sqlite_stat3;
  66. }
  67. }
  68. } {}
  69. do_test tkt-cbd05-1.3 {
  70. execsql {
  71. SELECT tbl,idx,group_concat(s(sample),' ')
  72. FROM vvv
  73. WHERE idx = 't1_x'
  74. GROUP BY tbl,idx
  75. }
  76. } {t1 t1_x { A B C D E F G H I}}
  77. do_test tkt-cbd05-2.1 {
  78. db eval {
  79. DROP TABLE t1;
  80. CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB UNIQUE NOT NULL);
  81. CREATE INDEX t1_x ON t1(b);
  82. INSERT INTO t1 VALUES(NULL, X'');
  83. INSERT INTO t1 VALUES(NULL, X'41');
  84. INSERT INTO t1 VALUES(NULL, X'42');
  85. INSERT INTO t1 VALUES(NULL, X'43');
  86. INSERT INTO t1 VALUES(NULL, X'44');
  87. INSERT INTO t1 VALUES(NULL, X'45');
  88. INSERT INTO t1 VALUES(NULL, X'46');
  89. INSERT INTO t1 VALUES(NULL, X'47');
  90. INSERT INTO t1 VALUES(NULL, X'48');
  91. INSERT INTO t1 VALUES(NULL, X'49');
  92. SELECT count(*) FROM t1;
  93. }
  94. } {10}
  95. do_test tkt-cbd05-2.2 {
  96. db eval {
  97. ANALYZE;
  98. }
  99. } {}
  100. do_test tkt-cbd05-2.3 {
  101. execsql {
  102. SELECT tbl,idx,group_concat(s(sample),' ')
  103. FROM vvv
  104. WHERE idx = 't1_x'
  105. GROUP BY tbl,idx
  106. }
  107. } {t1 t1_x { A B C D E F G H I}}
  108. finish_test