gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/ioerr6.test (about)

     1  # 2012 December 18
     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  source $testdir/malloc_common.tcl
    16  set ::testprefix ioerr6
    17  
    18  ifcapable !atomicwrite {
    19    puts "skipping tests - not compiled with SQLITE_ENABLE_ATOMIC_WRITE..."
    20    finish_test
    21    return
    22  }
    23  
    24  if {[permutation]=="inmemory_journal"} {
    25    # These tests will not work with in-memory journals (as persistent VFS
    26    # errors commencing after a transaction has started to write to the db
    27    # cannot be recovered from).
    28    finish_test
    29    return
    30  }
    31  
    32  faultsim_save_and_close
    33  
    34  do_test 1.1 {
    35    testvfs shmfault -default true
    36    shmfault devchar atomic
    37    sqlite3 db test.db
    38    execsql {
    39      CREATE TABLE t1(a, b);
    40      CREATE INDEX i1 ON t1(a, b);
    41      INSERT INTO t1 VALUES(1, 2);
    42      INSERT INTO t1 VALUES(2, 4);
    43      INSERT INTO t1 VALUES(3, 6);
    44      INSERT INTO t1 VALUES(4, 8);
    45    }
    46  
    47    # Cause the first call to xWrite() to fail with SQLITE_FULL.
    48    shmfault full 2 1
    49    catchsql { INSERT INTO t1 VALUES(5, 10) }
    50  } {1 {database or disk is full}}
    51  
    52  do_test 1.2 {
    53    execsql { PRAGMA integrity_check }
    54  } {ok}
    55  
    56  db close
    57  shmfault delete
    58  
    59  do_faultsim_test 2 -faults full* -prep {
    60    shmfault devchar atomic
    61    faultsim_restore
    62    sqlite3 db test.db
    63  } -body {
    64    db eval {
    65      CREATE TABLE t1(x PRIMARY KEY);
    66      INSERT INTO t1 VALUES('abc');
    67    }
    68  } -test {
    69    set res [db one { PRAGMA integrity_check }]
    70    if {$res != "ok"} {
    71      error "integrity check: $res"
    72    }
    73  }
    74  
    75  do_faultsim_test 3 -faults full* -prep {
    76    shmfault devchar atomic
    77    faultsim_restore
    78    sqlite3 db test.db
    79  } -body {
    80    db eval {
    81      CREATE TABLE t1(x);
    82      CREATE TABLE t2(x);
    83    }
    84  } -test {
    85    db eval { CREATE TABLE t3(x) }
    86    if {[db one { PRAGMA integrity_check }] != "ok"} {
    87      error "integrity check failed"
    88    }
    89  }
    90  
    91  finish_test