fts3comp1.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # 2011 January 27
  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 script is testing the FTS3 module.
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. ifcapable !fts3 { finish_test ; return }
  17. set ::testprefix fts3comp1
  18. # Create a pretend compression system.
  19. #
  20. # Each time the [zip] function is called, an entry is added to the ::strings
  21. # array mapping from an integer key to the string argument to zip. The key
  22. # is returned. Later on, when the key is passed to [unzip], the original
  23. # string is retrieved from the ::strings array and returned.
  24. #
  25. set next_x 0
  26. proc zip {x} {
  27. incr ::next_x
  28. set ::strings($::next_x) $x
  29. return $::next_x
  30. }
  31. proc unzip {x} {
  32. return $::strings($x)
  33. }
  34. foreach {tn zip unzip} {
  35. 1 zip unzip
  36. 2 {z.i.p!!} {un "zip"}
  37. } {
  38. set next_x 0
  39. catch {db close}
  40. forcedelete test.db
  41. sqlite3 db test.db
  42. db func $zip zip
  43. db func $unzip unzip
  44. # Create a table that uses zip/unzip. Check that content inserted into
  45. # the table can be read back (using a full-scan query). Check that the
  46. # underlying %_content table contains the compressed (integer) values.
  47. #
  48. do_execsql_test 1.$tn.0 "
  49. CREATE VIRTUAL TABLE t1 USING fts4(
  50. a, b,
  51. compress='$zip', uncompress='$unzip'
  52. );
  53. "
  54. do_execsql_test 1.$tn.1 {
  55. INSERT INTO t1 VALUES('one two three', 'two four six');
  56. SELECT a, b FROM t1;
  57. } {{one two three} {two four six}}
  58. do_execsql_test 1.$tn.2 {
  59. SELECT c0a, c1b FROM t1_content;
  60. } {1 2}
  61. # Insert another row and check that it can be read back. Also that the
  62. # %_content table still contains all compressed content. This time, try
  63. # full-text index and by-docid queries too.
  64. #
  65. do_execsql_test 1.$tn.3 {
  66. INSERT INTO t1 VALUES('three six nine', 'four eight twelve');
  67. SELECT a, b FROM t1;
  68. } {{one two three} {two four six} {three six nine} {four eight twelve}}
  69. do_execsql_test 1.$tn.4 {
  70. SELECT c0a, c1b FROM t1_content;
  71. } {1 2 3 4}
  72. do_execsql_test 1.$tn.5 {
  73. SELECT a, b FROM t1 WHERE docid = 2
  74. } {{three six nine} {four eight twelve}}
  75. do_execsql_test 1.$tn.6 {
  76. SELECT a, b FROM t1 WHERE t1 MATCH 'two'
  77. } {{one two three} {two four six}}
  78. # Delete a row and check that the full-text index is correctly updated.
  79. # Inspect the full-text index using an fts4aux table.
  80. #
  81. do_execsql_test 1.$tn.7 {
  82. CREATE VIRTUAL TABLE terms USING fts4aux(t1);
  83. SELECT term, documents, occurrences FROM terms WHERE col = '*';
  84. } {
  85. eight 1 1 four 2 2 nine 1 1 one 1 1
  86. six 2 2 three 2 2 twelve 1 1 two 1 2
  87. }
  88. do_execsql_test 1.$tn.8 {
  89. DELETE FROM t1 WHERE docid = 1;
  90. SELECT term, documents, occurrences FROM terms WHERE col = '*';
  91. } {
  92. eight 1 1 four 1 1 nine 1 1
  93. six 1 1 three 1 1 twelve 1 1
  94. }
  95. do_execsql_test 1.$tn.9 { SELECT c0a, c1b FROM t1_content } {3 4}
  96. }
  97. # Test that is an error to specify just one of compress and uncompress.
  98. #
  99. do_catchsql_test 2.1 {
  100. CREATE VIRTUAL TABLE t2 USING fts4(x, compress=zip)
  101. } {1 {missing uncompress parameter in fts4 constructor}}
  102. do_catchsql_test 2.2 {
  103. CREATE VIRTUAL TABLE t2 USING fts4(x, uncompress=unzip)
  104. } {1 {missing compress parameter in fts4 constructor}}
  105. finish_test