fts5columnsize.test 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # 2015 Jun 10
  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. # Tests focusing on fts5 tables with the columnsize=0 option.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5columnsize
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. #-------------------------------------------------------------------------
  22. # Check that the option can be parsed and that the %_docsize table is
  23. # only created if it is set to true.
  24. #
  25. foreach {tn outcome stmt} {
  26. 1 0 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=0) }
  27. 2 1 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=1) }
  28. 3 0 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize='0') }
  29. 4 1 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize='1') }
  30. 5 2 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize='') }
  31. 6 2 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=2) }
  32. 7 1 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=0, columnsize=1) }
  33. 8 1 { CREATE VIRTUAL TABLE t1 USING fts5(x) }
  34. 9 2 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=11) }
  35. } {
  36. execsql {
  37. DROP TABLE IF EXISTS t1;
  38. }
  39. if {$outcome==2} {
  40. do_catchsql_test 1.$tn.1 $stmt {1 {malformed columnsize=... directive}}
  41. } else {
  42. do_execsql_test 1.$tn.2 $stmt
  43. do_execsql_test 1.$tn.3 {
  44. SELECT count(*) FROM sqlite_master WHERE name = 't1_docsize'
  45. } $outcome
  46. }
  47. }
  48. #-------------------------------------------------------------------------
  49. # Run tests on a table with no %_content or %_docsize backing store.
  50. #
  51. do_execsql_test 2.0 {
  52. CREATE VIRTUAL TABLE t2 USING fts5(x, columnsize=0, content='');
  53. }
  54. do_catchsql_test 2.1 {
  55. INSERT INTO t2 VALUES('a b c d e f');
  56. } {1 {datatype mismatch}}
  57. do_execsql_test 2.2 {
  58. INSERT INTO t2(rowid, x) VALUES(1, 'c d e f');
  59. INSERT INTO t2(rowid, x) VALUES(2, 'c d e f g h');
  60. INSERT INTO t2(rowid, x) VALUES(3, 'a b c d e f g h');
  61. } {}
  62. do_execsql_test 2.3 {
  63. SELECT rowid FROM t2 WHERE t2 MATCH 'b'; SELECT '::';
  64. SELECT rowid FROM t2 WHERE t2 MATCH 'e'; SELECT '::';
  65. SELECT rowid FROM t2 WHERE t2 MATCH 'h';
  66. } {3 :: 1 2 3 :: 2 3}
  67. do_execsql_test 2.4 {
  68. INSERT INTO t2(t2, rowid, x) VALUES('delete', 2, 'c d e f g h');
  69. SELECT rowid FROM t2 WHERE t2 MATCH 'b'; SELECT '::';
  70. SELECT rowid FROM t2 WHERE t2 MATCH 'e'; SELECT '::';
  71. SELECT rowid FROM t2 WHERE t2 MATCH 'h';
  72. } {3 :: 1 3 :: 3}
  73. do_execsql_test 2.5 {
  74. INSERT INTO t2(t2) VALUES('delete-all');
  75. SELECT rowid FROM t2 WHERE t2 MATCH 'b'; SELECT '::';
  76. SELECT rowid FROM t2 WHERE t2 MATCH 'e'; SELECT '::';
  77. SELECT rowid FROM t2 WHERE t2 MATCH 'h';
  78. } {:: ::}
  79. do_execsql_test 2.6 {
  80. INSERT INTO t2(rowid, x) VALUES(1, 'o t t f');
  81. INSERT INTO t2(rowid, x) VALUES(2, 'f s s e');
  82. INSERT INTO t2(rowid, x) VALUES(3, 'n t e t');
  83. }
  84. do_catchsql_test 2.7.1 {
  85. SELECT rowid FROM t2
  86. } {1 {t2: table does not support scanning}}
  87. do_catchsql_test 2.7.2 {
  88. SELECT rowid FROM t2 WHERE rowid=2
  89. } {1 {t2: table does not support scanning}}
  90. do_catchsql_test 2.7.3 {
  91. SELECT rowid FROM t2 WHERE rowid BETWEEN 1 AND 3
  92. } {1 {t2: table does not support scanning}}
  93. do_execsql_test 2.X {
  94. DROP TABLE t2
  95. }
  96. #-------------------------------------------------------------------------
  97. # Test the xColumnSize() API
  98. #
  99. fts5_aux_test_functions db
  100. do_execsql_test 3.1.0 {
  101. CREATE VIRTUAL TABLE t3 USING fts5(x, y UNINDEXED, z, columnsize=0);
  102. INSERT INTO t3 VALUES('a a', 'b b b', 'c');
  103. INSERT INTO t3 VALUES('x a x', 'b b b y', '');
  104. }
  105. do_execsql_test 3.1.1 {
  106. SELECT rowid, fts5_test_columnsize(t3) FROM t3 WHERE t3 MATCH 'a'
  107. } {
  108. 1 {2 0 1} 2 {3 0 0}
  109. }
  110. do_execsql_test 3.1.2 {
  111. INSERT INTO t3 VALUES(NULL, NULL, 'a a a a');
  112. DELETE FROM t3 WHERE rowid = 1;
  113. SELECT rowid, fts5_test_columnsize(t3) FROM t3 WHERE t3 MATCH 'a'
  114. } {
  115. 2 {3 0 0} 3 {0 0 4}
  116. }
  117. do_execsql_test 3.2.0 {
  118. CREATE VIRTUAL TABLE t4 USING fts5(x, y UNINDEXED, z, columnsize=0, content='');
  119. INSERT INTO t4(rowid, x, y, z) VALUES(1, 'a a', 'b b b', 'c');
  120. INSERT INTO t4(rowid, x, y, z) VALUES(2, 'x a x', 'b b b y', '');
  121. }
  122. do_execsql_test 3.2.1 {
  123. SELECT rowid, fts5_test_columnsize(t4) FROM t4 WHERE t4 MATCH 'a'
  124. } {
  125. 1 {-1 0 -1} 2 {-1 0 -1}
  126. }
  127. #-------------------------------------------------------------------------
  128. # Test the integrity-check
  129. #
  130. do_execsql_test 4.1.1 {
  131. CREATE VIRTUAL TABLE t5 USING fts5(x, columnsize=0);
  132. INSERT INTO t5 VALUES('1 2 3 4');
  133. INSERT INTO t5 VALUES('2 4 6 8');
  134. }
  135. do_execsql_test 4.1.2 {
  136. INSERT INTO t5(t5) VALUES('integrity-check');
  137. }
  138. finish_test