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 / test / fts3fault3.test
| 1 | # 2023 October 23 |
| 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 | |
| 13 | set testdir [file dirname $argv0] |
| 14 | source $testdir/tester.tcl |
| 15 | |
| 16 | set ::testprefix fts3fault |
| 17 | |
| 18 | # If SQLITE_ENABLE_FTS3 is not defined, omit this file. |
| 19 | ifcapable !fts3 { finish_test ; return } |
| 20 | |
| 21 | set ::TMPDBERROR [list 1 \ |
| 22 | {unable to open a temporary database file for storing temporary tables} |
| 23 | ] |
| 24 | |
| 25 | |
| 26 | # Test error handling in an "ALTER TABLE ... RENAME TO" statement on an |
| 27 | # FTS3 table. Specifically, test renaming the table within a transaction |
| 28 | # after it has been written to. |
| 29 | # |
| 30 | do_execsql_test 1.0 { |
| 31 | CREATE VIRTUAL TABLE t1 USING fts3(a); |
| 32 | INSERT INTO t1 VALUES('test renaming the table'); |
| 33 | INSERT INTO t1 VALUES(' after it has been written'); |
| 34 | INSERT INTO t1 VALUES(' actually other stuff instead'); |
| 35 | } |
| 36 | faultsim_save_and_close |
| 37 | do_faultsim_test 1 -faults oom* -prep { |
| 38 | faultsim_restore_and_reopen |
| 39 | execsql { |
| 40 | BEGIN; |
| 41 | DELETE FROM t1 WHERE rowid=2; |
| 42 | } |
| 43 | } -body { |
| 44 | execsql { |
| 45 | DELETE FROM t1; |
| 46 | } |
| 47 | } -test { |
| 48 | catchsql { COMMIT } |
| 49 | faultsim_integrity_check |
| 50 | faultsim_test_result {0 {}} |
| 51 | } |
| 52 | |
| 53 | #------------------------------------------------------------------- |
| 54 | reset_db |
| 55 | |
| 56 | do_execsql_test 2.0 { |
| 57 | BEGIN; |
| 58 | CREATE VIRTUAL TABLE t1 USING fts3(a); |
| 59 | WITH s(i) AS ( |
| 60 | SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50 |
| 61 | ) |
| 62 | INSERT INTO t1 SELECT 'abc def ghi jkl mno pqr' FROM s; |
| 63 | COMMIT; |
| 64 | } |
| 65 | |
| 66 | faultsim_save_and_close |
| 67 | do_faultsim_test 2 -faults oom-t* -prep { |
| 68 | faultsim_restore_and_reopen |
| 69 | execsql { |
| 70 | BEGIN; |
| 71 | CREATE TABLE x1(a PRIMARY KEY); |
| 72 | } |
| 73 | } -body { |
| 74 | execsql { |
| 75 | PRAGMA integrity_check; |
| 76 | } |
| 77 | } -test { |
| 78 | faultsim_test_result {0 ok} $::TMPDBERROR |
| 79 | } |
| 80 | |
| 81 | |
| 82 | finish_test |