fts5simple3.test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # 2015 September 05
  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. source [file join [file dirname [info script]] fts5_common.tcl]
  13. set testprefix fts5simple3
  14. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  15. ifcapable !fts5 {
  16. finish_test
  17. return
  18. }
  19. fts5_aux_test_functions db
  20. do_execsql_test 1.0 {
  21. CREATE VIRTUAL TABLE t1 USING fts5(a, b, c, detail=col);
  22. INSERT INTO t1 VALUES('a', 'b', 'c');
  23. INSERT INTO t1 VALUES('x', 'x', 'x');
  24. }
  25. do_execsql_test 1.1 {
  26. SELECT rowid, fts5_test_collist(t1) FROM t1('a:a');
  27. } {1 0.0}
  28. do_execsql_test 1.2 {
  29. SELECT rowid, fts5_test_collist(t1) FROM t1('b:x');
  30. } {2 0.1}
  31. do_execsql_test 1.3 {
  32. SELECT rowid, fts5_test_collist(t1) FROM t1('b:a');
  33. } {}
  34. #-------------------------------------------------------------------------
  35. # Create detail=col and detail=full tables with 998 columns.
  36. #
  37. foreach_detail_mode $testprefix {
  38. if {[detail_is_none]} continue
  39. do_test 2.1 {
  40. execsql { DROP TABLE IF EXISTS t2 }
  41. set cols [list]
  42. set vals [list]
  43. for {set i 1} {$i <= 998} {incr i} {
  44. lappend cols "c$i"
  45. lappend vals "'val$i'"
  46. }
  47. execsql "CREATE VIRTUAL TABLE t2 USING fts5(detail=%DETAIL%,[join $cols ,])"
  48. } {}
  49. do_test 2.2 {
  50. execsql "INSERT INTO t2 VALUES([join $vals ,])"
  51. } {}
  52. foreach {tn q res} {
  53. 1 { c1:val1 } 1
  54. 2 { c300:val300 } 1
  55. 3 { c300:val1 } {}
  56. 4 { c1:val300 } {}
  57. } {
  58. do_execsql_test 2.3.$tn {
  59. SELECT rowid FROM t2($q)
  60. } $res
  61. }
  62. }
  63. do_execsql_test 3.0 {
  64. CREATE VIRTUAL TABLE x3 USING fts5(one);
  65. INSERT INTO x3 VALUES('a b c');
  66. INSERT INTO x3 VALUES('c b a');
  67. INSERT INTO x3 VALUES('o t t');
  68. SELECT * FROM x3('x OR y OR z');
  69. }
  70. #-------------------------------------------------------------------------
  71. # Test that a crash occuring when the second or subsequent tokens in a
  72. # phrase matched zero rows has been fixed.
  73. #
  74. do_execsql_test 4.0 {
  75. CREATE VIRTUAL TABLE t1 USING fts5(x);
  76. INSERT INTO t1 VALUES('ab');
  77. INSERT INTO t1 VALUES('cd');
  78. INSERT INTO t1 VALUES('ab cd');
  79. INSERT INTO t1 VALUES('ab cdXXX');
  80. INSERT INTO t1 VALUES('abXXX cd');
  81. }
  82. do_execsql_test 4.1 {
  83. SELECT * FROM t1('"ab cd" OR "ab cd" *');
  84. } {{ab cd} {ab cdXXX}}
  85. do_execsql_test 4.2 {
  86. SELECT * FROM t1('"xy zz" OR "ab cd" *');
  87. } {{ab cd} {ab cdXXX}}
  88. do_execsql_test 4.3 {
  89. SELECT * FROM t1('"xy zz" OR "xy zz" *');
  90. }
  91. do_execsql_test 4.4 {
  92. SELECT * FROM t1('"ab cd" OR "xy zz" *');
  93. } {{ab cd}}
  94. do_execsql_test 4.5 {
  95. CREATE VIRTUAL TABLE t2 USING fts5(x);
  96. INSERT INTO t2 VALUES('ab');
  97. INSERT INTO t2 VALUES('cd');
  98. INSERT INTO t2 VALUES('ef');
  99. }
  100. do_execsql_test 4.6 {
  101. SELECT * FROM t2('ab + xyz');
  102. }
  103. finish_test