fts5faultI.test 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. # 2010 June 15
  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. source $testdir/malloc_common.tcl
  14. set testprefix fts5faultI
  15. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  16. ifcapable !fts5 {
  17. finish_test
  18. return
  19. }
  20. set ::testprefix fts5faultI
  21. do_execsql_test 1.0 {
  22. PRAGMA encoding = utf16;
  23. CREATE VIRTUAL TABLE t1 USING fts5(x, locale=1);
  24. INSERT INTO t1 VALUES('origintext unicode61 ascii porter trigram');
  25. }
  26. faultsim_save_and_close
  27. faultsim_restore_and_reopen
  28. do_faultsim_test 1 -faults oom* -prep {
  29. } -body {
  30. execsql {
  31. SELECT rowid FROM t1(fts5_locale('en_US', 'origintext'));
  32. }
  33. } -test {
  34. faultsim_test_result {0 1}
  35. }
  36. do_faultsim_test 2 -faults oom* -prep {
  37. faultsim_restore_and_reopen
  38. execsql {
  39. SELECT * FROM t1('ascii');
  40. }
  41. } -body {
  42. execsql {
  43. UPDATE t1 SET rowid=rowid+1;
  44. }
  45. } -test {
  46. faultsim_test_result {0 {}}
  47. }
  48. fts5_aux_test_functions db
  49. do_faultsim_test 3 -faults oom* -prep {
  50. } -body {
  51. execsql {
  52. SELECT fts5_columnlocale(t1, 0) FROM t1('unicode*');
  53. }
  54. } -test {
  55. faultsim_test_result {0 {{}}} {1 SQLITE_NOMEM}
  56. }
  57. #-------------------------------------------------------------------------
  58. reset_db
  59. do_execsql_test 4.0 {
  60. CREATE VIRTUAL TABLE w1 USING fts5(a);
  61. }
  62. faultsim_save_and_close
  63. do_faultsim_test 4 -faults oom* -prep {
  64. faultsim_restore_and_reopen
  65. execsql {
  66. BEGIN;
  67. INSERT INTO w1 VALUES('token token token');
  68. }
  69. } -body {
  70. execsql {
  71. INSERT INTO w1(w1, rank) VALUES('rank', 'bm25()');
  72. }
  73. } -test {
  74. faultsim_test_result {0 {}}
  75. }
  76. do_faultsim_test 5 -faults oom* -prep {
  77. faultsim_restore_and_reopen
  78. execsql {
  79. BEGIN;
  80. INSERT INTO w1 VALUES('one');
  81. SAVEPOINT one;
  82. INSERT INTO w1 VALUES('two');
  83. ROLLBACK TO one;
  84. }
  85. } -body {
  86. execsql {
  87. INSERT INTO w1 VALUES('string');
  88. }
  89. } -test {
  90. faultsim_test_result {0 {}}
  91. }
  92. #-------------------------------------------------------------------------
  93. reset_db
  94. do_execsql_test 5.0 {
  95. CREATE VIRTUAL TABLE w1 USING fts5(a);
  96. INSERT INTO w1 VALUES('one two three');
  97. }
  98. fts5_aux_test_functions db
  99. do_faultsim_test 5 -faults oom* -prep {
  100. } -body {
  101. execsql {
  102. SELECT fts5_test_insttoken(w1, 0, 0) FROM w1('two');
  103. }
  104. } -test {
  105. faultsim_test_result {0 two} {1 SQLITE_NOMEM}
  106. }
  107. #-------------------------------------------------------------------------
  108. reset_db
  109. do_execsql_test 6.0 {
  110. CREATE VIRTUAL TABLE w1 USING fts5(a);
  111. INSERT INTO w1 VALUES('one two three');
  112. }
  113. fts5_aux_test_functions db
  114. faultsim_save_and_close
  115. do_faultsim_test 6 -faults oom* -prep {
  116. faultsim_restore_and_reopen
  117. db eval {
  118. BEGIN;
  119. INSERT INTO w1 VALUES('four five six');
  120. SAVEPOINT abc;
  121. INSERT INTO w1 VALUES('seven eight nine');
  122. SAVEPOINT def;
  123. INSERT INTO w1 VALUES('ten eleven twelve');
  124. }
  125. } -body {
  126. execsql {
  127. RELEASE abc;
  128. }
  129. } -test {
  130. faultsim_test_result {0 {}}
  131. }
  132. #-------------------------------------------------------------------------
  133. reset_db
  134. do_execsql_test 7.0 {
  135. CREATE VIRTUAL TABLE w1 USING fts5(a);
  136. INSERT INTO w1 VALUES('one two three');
  137. INSERT INTO w1 VALUES('three two one');
  138. DELETE FROM w1_content WHERE rowid=1;
  139. }
  140. faultsim_save_and_close
  141. do_faultsim_test 7 -faults oom* -prep {
  142. faultsim_restore_and_reopen
  143. db eval { SELECT * FROM w1 }
  144. } -body {
  145. execsql {
  146. PRAGMA integrity_check;
  147. }
  148. } -test {
  149. }
  150. #-------------------------------------------------------------------------
  151. reset_db
  152. fts5_tclnum_register db
  153. fts5_aux_test_functions db
  154. do_execsql_test 8.0 {
  155. CREATE VIRTUAL TABLE ft USING fts5(
  156. x, tokenize = "tclnum query", detail=columns
  157. );
  158. INSERT INTO ft VALUES('one two three i ii iii');
  159. INSERT INTO ft VALUES('four five six iv v vi');
  160. INSERT INTO ft VALUES('eight nine ten viii ix x');
  161. } {}
  162. do_faultsim_test 8.1 -faults oom* -prep {
  163. } -body {
  164. execsql {
  165. SELECT fts5_test_collist (ft) FROM ft('one two');
  166. }
  167. } -test {
  168. faultsim_test_result {0 {{0.0 1.0}}} {1 {SQL logic error}} {1 SQLITE_NOMEM}
  169. }
  170. do_faultsim_test 8.2 -faults oom* -prep {
  171. } -body {
  172. execsql {
  173. SELECT rowid FROM ft('one two') ORDER BY rank;
  174. }
  175. } -test {
  176. faultsim_test_result {0 1} {1 {SQL logic error}} {1 SQLITE_NOMEM}
  177. }
  178. #-------------------------------------------------------------------------
  179. reset_db
  180. do_execsql_test 9.0 {
  181. CREATE VIRTUAL TABLE ft USING fts5(x);
  182. INSERT INTO ft VALUES('one two three i ii iii');
  183. INSERT INTO ft VALUES('four five six iv v vi');
  184. INSERT INTO ft VALUES('eight nine ten viii ix x');
  185. } {}
  186. faultsim_save_and_close
  187. do_faultsim_test 9.1 -faults oom* -prep {
  188. faultsim_restore_and_reopen
  189. } -body {
  190. execsql {
  191. UPDATE ft SET rowid=4 WHERE rowid=1
  192. }
  193. } -test {
  194. faultsim_test_result {0 {}}
  195. }
  196. do_faultsim_test 9.2 -faults oom* -prep {
  197. faultsim_restore_and_reopen
  198. } -body {
  199. execsql {
  200. SELECT rowid FROM ft WHERE x MATCH 'one AND two AND three'
  201. }
  202. } -test {
  203. faultsim_test_result {0 1}
  204. }
  205. #-------------------------------------------------------------------------
  206. reset_db
  207. do_execsql_test 10.0 {
  208. CREATE VIRTUAL TABLE ft USING fts5(x, locale=1);
  209. INSERT INTO ft VALUES(fts5_locale('hello', 'one two three i ii iii'));
  210. INSERT INTO ft VALUES('four five six iv v vi');
  211. INSERT INTO ft VALUES('eight nine ten viii ix x');
  212. } {}
  213. do_execsql_test 10.1 {
  214. SELECT fts5_get_locale(ft, 0) FROM ft WHERE x MATCH 'one AND two AND three'
  215. } {hello}
  216. faultsim_save_and_close
  217. do_faultsim_test 10.1 -faults oom* -prep {
  218. faultsim_restore_and_reopen
  219. } -body {
  220. execsql {
  221. SELECT fts5_get_locale(ft, 0) FROM ft WHERE x MATCH 'one AND two AND three'
  222. }
  223. } -test {
  224. faultsim_test_result {0 hello}
  225. }
  226. breakpoint
  227. faultsim_save_and_close
  228. do_faultsim_test 10.2 -faults oom-t* -prep {
  229. faultsim_restore_and_reopen
  230. } -body {
  231. execsql {
  232. INSERT INTO ft VALUES(zeroblob(10000));
  233. }
  234. } -test {
  235. faultsim_test_result {0 {}}
  236. }
  237. #-------------------------------------------------------------------------
  238. reset_db
  239. do_execsql_test 11.0 {
  240. CREATE VIRTUAL TABLE f1 USING fts5(content);
  241. CREATE TABLE g1(id, content);
  242. INSERT INTO g1 VALUES(30000, 'a b c');
  243. INSERT INTO g1 VALUES(40000, 'd e f');
  244. }
  245. faultsim_save_and_close
  246. do_faultsim_test 11 -faults oom* -prep {
  247. faultsim_restore_and_reopen
  248. } -body {
  249. execsql {
  250. INSERT INTO f1(rowid, content) SELECT id, content FROM g1;
  251. }
  252. } -test {
  253. faultsim_test_result {0 {}}
  254. }
  255. finish_test