CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
mmapfault.test77 linesDownload Raw Back to test
1# 2013-05-232#3# The author disclaims copyright to this source code.  In place of4# 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 13set testdir [file dirname $argv0]14source $testdir/tester.tcl15source $testdir/malloc_common.tcl16ifcapable !mmap {17  finish_test18  return19}20set testprefix mmapfault21 22set a_string_counter 123proc a_string {n} {24  global a_string_counter25  incr a_string_counter26  string range [string repeat "${a_string_counter}." $n] 1 $n27}28db func a_string a_string29 30do_test 1-pre {31  execsql {32    CREATE TABLE t1(a UNIQUE, b UNIQUE);33    INSERT INTO t1 VALUES(a_string(200), a_string(300));34    INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;35    INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;36  }37  faultsim_save_and_close38} {}39 40 41do_faultsim_test 1 -prep {42  faultsim_restore_and_reopen43  db func a_string a_string44  execsql {45    PRAGMA mmap_size = 1000000;46    PRAGMA cache_size = 5;47    BEGIN;48      INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;49      INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;50      INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;51      INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;52  }53} -body {54  execsql { INSERT INTO t1 VALUES(a_string(200), a_string(300)) }55} -test {56  faultsim_test_result {0 {}} 57 58  if {[sqlite3_get_autocommit db]} {59    sqlite3 db2 test.db60    set nRow [db2 one {SELECT count(*) FROM t1}]61    if {$nRow!=4} { error "Database content appears incorrect (1)" }62    db2 close63  }64 65  execsql { INSERT INTO t1 VALUES(a_string(201), a_string(301)) }66  set nRow [db one {SELECT count(*) FROM t1}]67  if {$nRow!=5 && $nRow!=66 && $nRow!=65} { 68    error "Database content appears incorrect (2) ($nRow)" 69  }70 71  catch { execsql COMMIT }72}73 74 75 76finish_test77