1e36281fcSdan# 2022 July 06 2e36281fcSdan# 3e36281fcSdan# The author disclaims copyright to this source code. In place of 4e36281fcSdan# a legal notice, here is a blessing: 5e36281fcSdan# 6e36281fcSdan# May you do good and not evil. 7e36281fcSdan# May you find forgiveness for yourself and forgive others. 8e36281fcSdan# May you share freely, never taking more than you give. 9e36281fcSdan# 10e36281fcSdan#*********************************************************************** 11e36281fcSdan# 12e36281fcSdan 13e36281fcSdanset testdir [file dirname $argv0] 14e36281fcSdansource $testdir/tester.tcl 15e36281fcSdansource $testdir/lock_common.tcl 16e36281fcSdansource $testdir/malloc_common.tcl 17e36281fcSdan 18e36281fcSdanif {[permutation] == "inmemory_journal"} { 19e36281fcSdan finish_test 20e36281fcSdan return 21e36281fcSdan} 22e36281fcSdan 23*afe76819Sdanifcapable !vtab { 24*afe76819Sdan finish_test 25*afe76819Sdan return 26*afe76819Sdan} 27*afe76819Sdan 28e36281fcSdanset testprefix dbpagefault 29e36281fcSdan 30e36281fcSdanfaultsim_save_and_close 31e36281fcSdando_faultsim_test 1 -prep { 32e36281fcSdan faultsim_restore_and_reopen 33e36281fcSdan execsql { ATTACH 'test.db2' AS aux; } 34e36281fcSdan} -body { 35e36281fcSdan execsql { 36e36281fcSdan CREATE VIRTUAL TABLE t1 USING sqlite_dbpage(); 37e36281fcSdan } 38e36281fcSdan} -test { 39e36281fcSdan execsql { PRAGMA journal_mode = off } 40e36281fcSdan faultsim_test_result {0 {}} 41e36281fcSdan} 42e36281fcSdan 43e36281fcSdando_faultsim_test 2 -prep { 44e36281fcSdan sqlite3 db "xyz.db" -vfs memdb 45e36281fcSdan execsql { ATTACH 'test.db2' AS aux; } 46e36281fcSdan} -body { 47e36281fcSdan execsql { 48e36281fcSdan CREATE VIRTUAL TABLE t1 USING sqlite_dbpage(); 49e36281fcSdan INSERT INTO t1 DEFAULT VALUES; 50e36281fcSdan } 51e36281fcSdan} -test { 52e36281fcSdan execsql { PRAGMA journal_mode = off } 53e36281fcSdan faultsim_test_result {1 {no such schema}} {1 {SQL logic error}} 54e36281fcSdan} 55e36281fcSdan 56f56291edSdanreset_db 57f56291edSdando_execsql_test 3.0 { 58f56291edSdan CREATE TABLE x1(z, b); 59f56291edSdan CREATE TRIGGER BEFORE INSERT ON x1 BEGIN 60f56291edSdan DELETE FROM sqlite_dbpage WHERE pgno=100; 61f56291edSdan UPDATE sqlite_dbpage SET data=null WHERE pgno=100; 62f56291edSdan END; 63f56291edSdan} 64f56291edSdan 65f53c0a0dSdan# This test case no longer works, as it is no longer possible to use 66f53c0a0dSdan# virtual table sqlite_dbpage from within a trigger. 67f53c0a0dSdan# 68f53c0a0dSdando_execsql_test 3.1 { 69f53c0a0dSdan PRAGMA trusted_schema = 1; 70f56291edSdan} 71f53c0a0dSdando_catchsql_test 3.2 { 72f53c0a0dSdan PRAGMA trusted_schema = 1; 73f53c0a0dSdan INSERT INTO x1 DEFAULT VALUES; 74f53c0a0dSdan} {1 {unsafe use of virtual table "sqlite_dbpage"}} 75f53c0a0dSdan#do_faultsim_test 3 -prep { 76f53c0a0dSdan# catch { db close } 77f53c0a0dSdan# sqlite3 db test.db 78f53c0a0dSdan# execsql { PRAGMA trusted_schema = 1 } 79f53c0a0dSdan#} -body { 80f53c0a0dSdan# execsql { INSERT INTO x1 DEFAULT VALUES; } 81f53c0a0dSdan#} -test { 82f53c0a0dSdan# faultsim_test_result {0 {}} 83f53c0a0dSdan#} 84f56291edSdan 85f56291edSdan 86e36281fcSdanfinish_test 87f56291edSdan 88f56291edSdan 89