CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
dbpagefault.test113 linesDownload Raw Back to test
1# 2022 July 062#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/lock_common.tcl16source $testdir/malloc_common.tcl17 18if {[permutation] == "inmemory_journal"} {19  finish_test20  return21}22 23ifcapable !vtab {24  finish_test25  return26}27 28set testprefix dbpagefault29 30faultsim_save_and_close31do_faultsim_test 1 -prep {32  faultsim_restore_and_reopen33  execsql { ATTACH 'test.db2' AS aux; }34} -body {35  execsql { 36    CREATE VIRTUAL TABLE t1 USING sqlite_dbpage();37  }38} -test {39  execsql { PRAGMA journal_mode = off }40  faultsim_test_result {0 {}} 41}42 43do_faultsim_test 2 -prep {44  sqlite3 db "xyz.db" -vfs memdb45  execsql { ATTACH 'test.db2' AS aux; }46} -body {47  execsql { 48    CREATE VIRTUAL TABLE t1 USING sqlite_dbpage();49    UPDATE t1 SET data=zeroblob(1024) WHERE pgno=1 AND schema='aux';50  }51} -test {52  execsql { PRAGMA journal_mode = off }53  faultsim_test_result {0 {}} {1 {no such schema}}  {1 {SQL logic error}} {1 {unable to open a temporary database file for storing temporary tables}}54}55 56reset_db57do_execsql_test 3.0 {58  CREATE TABLE x1(z, b);59  CREATE TRIGGER BEFORE INSERT ON x1 BEGIN60    DELETE FROM sqlite_dbpage WHERE pgno=100;61    UPDATE sqlite_dbpage SET data=null WHERE pgno=100;62  END;63}64 65# This test case no longer works, as it is no longer possible to use66# virtual table sqlite_dbpage from within a trigger.67#68do_execsql_test 3.1 {69  PRAGMA trusted_schema = 1;70}71do_catchsql_test 3.2 {72  PRAGMA trusted_schema = 1;73  INSERT INTO x1 DEFAULT VALUES;74} {1 {unsafe use of virtual table "sqlite_dbpage"}}75#do_faultsim_test 3 -prep {76#  catch { db close }77#  sqlite3 db test.db78#  execsql { PRAGMA trusted_schema = 1 }79#} -body {80#  execsql { INSERT INTO x1 DEFAULT VALUES; }81#} -test {82#  faultsim_test_result {0 {}}83#}84 85reset_db86forcedelete test.db287do_execsql_test 4.0 {88  CREATE TABLE t1(x);89  INSERT INTO t1 VALUES('one');90  CREATE TABLE t2(x);91  INSERT INTO t2 VALUES('two');92  ATTACH 'test.db2' AS aux;93  CREATE TABLE aux.x1(x);94}95 96set pgno [db one {SELECT max(rootpage) FROM sqlite_schema}]97 98faultsim_save_and_close99do_faultsim_test 4 -prep {100  faultsim_restore_and_reopen101  execsql { ATTACH 'test.db2' AS aux; }102} -body {103  execsql { 104    UPDATE sqlite_dbpage SET data = (105      SELECT data FROM sqlite_dbpage WHERE pgno=($pgno-1)106    ) WHERE pgno = $pgno;107  }108} -test {109  faultsim_test_result {0 {}} {1 {unable to open a temporary database file for storing temporary tables}}110}111 112finish_test113