fts5update.test 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # 2016 Jan 16
  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 FTS5 module.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5update
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. set docs {
  22. "eight zero iv eight 7" "ix one 8 one three ii one"
  23. "1 9 9 three viii" "5 zero ii 6 nine ix 3"
  24. "3 zero 5 2 seven nine" "two eight viii eight 1"
  25. "4 six two 5 9 vii" "viii ii four 8 i i iv"
  26. "vii 0 iv seven 7 viii" "five 1 nine vi seven"
  27. "1 zero zero iii 1" "one one six 6 nine seven"
  28. "one v 4 zero 4 iii ii" "2 3 eight six ix"
  29. "six iv 7 three 5" "ix zero 0 8 ii 7 3"
  30. "four six nine 2 vii 3" "five viii 5 8 0 7"
  31. }
  32. foreach_detail_mode $::testprefix {
  33. do_execsql_test 1.0 {
  34. CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=%DETAIL%);
  35. } {}
  36. do_test 1.1 {
  37. foreach {a b} $docs {
  38. execsql {INSERT INTO t1 VALUES($a, $b)}
  39. }
  40. } {}
  41. proc update {iRowid iA iB} {
  42. set a [lindex $::docs $iA]
  43. set b [lindex $::docs $iB]
  44. execsql { UPDATE t1 SET a=$a, b=$b WHERE rowid=$iRowid }
  45. }
  46. set nDoc [llength $::docs]
  47. foreach n {1 5 10 50 100} {
  48. do_test 1.2.$n {
  49. execsql BEGIN
  50. for {set i 1} {$i <= 1000} {incr i} {
  51. set iRowid [expr {int(rand() * ($nDoc/2)) + 1}]
  52. set iA [expr {int(rand() * $nDoc)}]
  53. set iB [expr {int(rand() * $nDoc)}]
  54. update $iRowid $iA $iB
  55. if {($i % $n)==0} {
  56. execsql { COMMIT; BEGIN }
  57. }
  58. if {($i % $n)==100} {
  59. execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
  60. }
  61. }
  62. execsql COMMIT
  63. execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
  64. } {}
  65. }
  66. do_execsql_test 1.3 {
  67. UPDATE t1 SET a=a AND b=b;
  68. INSERT INTO t1(t1) VALUES('integrity-check');
  69. }
  70. do_test 1.4 {
  71. execsql { INSERT INTO t1(t1, rank) VALUES('pgsz', 32) }
  72. for {set i 0} {$i < 50} {incr i} {
  73. execsql { UPDATE t1 SET a=a AND b=b }
  74. execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
  75. }
  76. } {}
  77. #-------------------------------------------------------------------------
  78. # Lots of deletes/inserts of the same document with the same rowid.
  79. #
  80. do_execsql_test 2.0 {
  81. CREATE VIRTUAL TABLE x2 USING fts5(x, detail=%DETAIL%);
  82. INSERT INTO x2(x2, rank) VALUES('crisismerge', 2);
  83. INSERT INTO x2 VALUES('a b c');
  84. INSERT INTO x2 VALUES('a b c');
  85. }
  86. do_test 2.1 {
  87. for {set i 0} {$i < 1000} {incr i} {
  88. execsql { DELETE FROM x2 WHERE rowid = 2 }
  89. execsql { INSERT INTO x2(rowid, x) VALUES(2, 'a b c') }
  90. }
  91. } {}
  92. do_execsql_test 2.1.integrity {
  93. INSERT INTO x2(x2) VALUES('integrity-check');
  94. }
  95. do_test 2.2 {
  96. for {set i 0} {$i < 1000} {incr i} {
  97. execsql { UPDATE x2 SET x=x WHERE rowid=2 }
  98. }
  99. } {}
  100. do_execsql_test 2.2.integrity {
  101. INSERT INTO x2(x2) VALUES('integrity-check');
  102. }
  103. #-------------------------------------------------------------------------
  104. #
  105. do_execsql_test 3.0 {
  106. CREATE VIRTUAL TABLE x3 USING fts5(x, detail=%DETAIL%);
  107. INSERT INTO x3 VALUES('one');
  108. INSERT INTO x3 VALUES('two');
  109. INSERT INTO x3 VALUES('one');
  110. INSERT INTO x3 VALUES('two');
  111. INSERT INTO x3 VALUES('one');
  112. }
  113. do_test 3.1 {
  114. db eval { SELECT * FROM x3('one') } {
  115. db eval {
  116. INSERT INTO x3(x3) VALUES('optimize');
  117. }
  118. }
  119. } {}
  120. do_execsql_test 4.0 {
  121. CREATE VIRTUAL TABLE x4 USING fts5(a, detail=%DETAIL%);
  122. INSERT INTO x4 VALUES('one two three');
  123. INSERT INTO x4(rowid, a) VALUES('2', 'one two three');
  124. INSERT INTO x4(rowid, a) VALUES('3.0', 'one two three');
  125. }
  126. do_catchsql_test 4.1 {
  127. INSERT INTO x4(rowid, a) VALUES('four', 'one two three');
  128. } {1 {datatype mismatch}}
  129. do_catchsql_test 4.2 {
  130. UPDATE x4 SET rowid = 'four' WHERE rowid=1;
  131. } {1 {datatype mismatch}}
  132. }
  133. reset_db
  134. do_catchsql_test 4.0 { CREATE VIRTUAL TABLE t1 USING fts5(a,b,c); } {0 {}}
  135. do_catchsql_test 4.1 { DELETE FROM t1 WHERE t1 MATCH 'f*'; } {0 {}}
  136. finish_test