sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / fts5 / test / fts5faultF.test
| 1 | # 2023 July 20 |
| 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 is focused on OOM errors. Particularly those that may occur |
| 13 | # when using contentless_delete=1 databases. |
| 14 | # |
| 15 | |
| 16 | source [file join [file dirname [info script]] fts5_common.tcl] |
| 17 | source $testdir/malloc_common.tcl |
| 18 | set testprefix fts5faultF |
| 19 | |
| 20 | # If SQLITE_ENABLE_FTS5 is not defined, omit this file. |
| 21 | ifcapable !fts5 { |
| 22 | finish_test |
| 23 | return |
| 24 | } |
| 25 | |
| 26 | faultsim_save_and_close |
| 27 | do_faultsim_test 1 -prep { |
| 28 | faultsim_restore_and_reopen |
| 29 | } -body { |
| 30 | execsql { |
| 31 | CREATE VIRTUAL TABLE t1 USING fts5(x, y, content=, contentless_delete=1) |
| 32 | } |
| 33 | } -test { |
| 34 | faultsim_test_result {0 {}} {1 {vtable constructor failed: t1}} |
| 35 | } |
| 36 | |
| 37 | reset_db |
| 38 | do_execsql_test 2.0 { |
| 39 | CREATE VIRTUAL TABLE t1 USING fts5(doc, content=, contentless_delete=1); |
| 40 | BEGIN; |
| 41 | INSERT INTO t1(rowid, doc) VALUES(1, 'a b c d'); |
| 42 | INSERT INTO t1(rowid, doc) VALUES(2, 'a b c d'); |
| 43 | INSERT INTO t1(rowid, doc) VALUES(3, 'a b c d'); |
| 44 | INSERT INTO t1(rowid, doc) VALUES(4, 'a b c d'); |
| 45 | COMMIT; |
| 46 | DELETE FROM t1 WHERE rowid IN (2, 4); |
| 47 | } |
| 48 | |
| 49 | do_faultsim_test 2 -prep { |
| 50 | sqlite3 db test.db |
| 51 | execsql { SELECT rowid FROM t1 } |
| 52 | } -body { |
| 53 | execsql { |
| 54 | SELECT rowid FROM t1('b c'); |
| 55 | } |
| 56 | } -test { |
| 57 | faultsim_test_result {0 {1 3}} |
| 58 | } |
| 59 | |
| 60 | #------------------------------------------------------------------------- |
| 61 | reset_db |
| 62 | do_execsql_test 3.0 { |
| 63 | CREATE VIRTUAL TABLE t1 USING fts5(doc, content=, contentless_delete=1); |
| 64 | BEGIN; |
| 65 | INSERT INTO t1(rowid, doc) VALUES(1, 'a b c d'); |
| 66 | INSERT INTO t1(rowid, doc) VALUES(2, 'a b c d'); |
| 67 | INSERT INTO t1(rowid, doc) VALUES(3, 'a b c d'); |
| 68 | INSERT INTO t1(rowid, doc) VALUES(4, 'a b c d'); |
| 69 | COMMIT; |
| 70 | } |
| 71 | |
| 72 | faultsim_save_and_close |
| 73 | do_faultsim_test 3 -prep { |
| 74 | faultsim_restore_and_reopen |
| 75 | execsql { SELECT rowid FROM t1 } |
| 76 | } -body { |
| 77 | execsql { |
| 78 | INSERT INTO t1(rowid, doc) VALUES(5, 'a b c d'); |
| 79 | } |
| 80 | } -test { |
| 81 | faultsim_test_result {0 {}} |
| 82 | } |
| 83 | |
| 84 | #------------------------------------------------------------------------- |
| 85 | reset_db |
| 86 | do_execsql_test 4.0 { |
| 87 | CREATE VIRTUAL TABLE t1 USING fts5(doc, content=, contentless_delete=1); |
| 88 | INSERT INTO t1(t1, rank) VALUES('pgsz', 64); |
| 89 | WITH s(i) AS ( |
| 90 | SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000 |
| 91 | ) |
| 92 | INSERT INTO t1(rowid, doc) SELECT i, 'a b c d' FROM s; |
| 93 | } |
| 94 | |
| 95 | do_execsql_test 4.1 { DELETE FROM t1 WHERE rowid <= 25 } |
| 96 | |
| 97 | faultsim_save_and_close |
| 98 | do_faultsim_test 4 -faults oom-t* -prep { |
| 99 | faultsim_restore_and_reopen |
| 100 | execsql { SELECT rowid FROM t1 } |
| 101 | } -body { |
| 102 | execsql { |
| 103 | DELETE FROM t1 WHERE rowid < 100 |
| 104 | } |
| 105 | } -test { |
| 106 | faultsim_test_result {0 {}} |
| 107 | } |
| 108 | |
| 109 | |
| 110 | finish_test |
| 111 |