fts5prefix2.test 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # 2020 Dec 3
  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 contains tests focused on prefix indexes.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5prefix2
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. foreach p {3 2 1} {
  22. reset_db
  23. do_execsql_test 1.$p.0 "
  24. CREATE VIRTUAL TABLE t1 USING fts5(xyz, prefix=$p);
  25. "
  26. do_execsql_test 1.$p.1 {
  27. INSERT INTO t1 VALUES
  28. ('May you do good and not evil.'),
  29. ('May you find forgiveness for yourself and forgive others.'),
  30. ('May you share freely, never taking more than you give f.');
  31. }
  32. do_execsql_test 1.$p.2 {
  33. SELECT highlight(t1, 0, '[', ']') FROM t1('f*');
  34. } {
  35. {May you [find] [forgiveness] [for] yourself and [forgive] others.}
  36. {May you share [freely], never taking more than you give [f].}
  37. }
  38. }
  39. do_execsql_test 2.0 {
  40. CREATE VIRTUAL TABLE t2 USING fts5(one, prefix=3);
  41. INSERT INTO t2 VALUES('top');
  42. INSERT INTO t2 VALUES('to');
  43. INSERT INTO t2 VALUES('tommy');
  44. }
  45. do_execsql_test 2.1 {
  46. SELECT * FROM t2('to*');
  47. } {top to tommy}
  48. #-------------------------------------------------------------------------
  49. foreach {tn newrowid} {
  50. 1 122
  51. 2 123
  52. 3 124
  53. } {
  54. reset_db
  55. do_execsql_test 3.$tn.0 {
  56. CREATE VIRTUAL TABLE t12 USING fts5(x);
  57. INSERT INTO t12(rowid, x) VALUES(123, 'wwww');
  58. }
  59. do_execsql_test 3.$tn.1 {
  60. BEGIN;
  61. DELETE FROM t12 WHERE rowid=123;
  62. SELECT * FROM t12('wwww*');
  63. INSERT INTO t12(rowid, x) VALUES($newrowid, 'wwww');
  64. SELECT * FROM t12('wwww*');
  65. END;
  66. } {wwww}
  67. do_execsql_test 3.$tn.2 {
  68. INSERT INTO t12(t12) VALUES('integrity-check');
  69. }
  70. do_execsql_test 3.$tn.3 {
  71. SELECT rowid FROM t12('wwww*');
  72. } $newrowid
  73. }
  74. finish_test
  75. finish_test