gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/tkt3457.test (about) 1 # 2008 October 29 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 # This file implements regression tests for SQLite library. 12 # 13 # $Id: tkt3457.test,v 1.3 2009/06/26 07:12:07 danielk1977 Exp $ 14 15 set testdir [file dirname $argv0] 16 source $testdir/tester.tcl 17 18 if {$tcl_platform(platform) != "unix"} { 19 finish_test 20 return 21 } 22 if {[atomic_batch_write test.db]} { 23 finish_test 24 return 25 } 26 27 #----------------------------------------------------------------------- 28 # To roll back a hot-journal file, the application needs read and write 29 # permission on the journal file in question. The following tests test 30 # the outcome of trying to rollback a hot-journal file when this is not 31 # the case. 32 # 33 # tkt3457-1.2: Application has neither read, nor write permission on 34 # the hot-journal file. Result: SQLITE_CANTOPEN. 35 # 36 # tkt3457-1.3: Application has write but not read permission on 37 # the hot-journal file. Result: SQLITE_CANTOPEN. 38 # 39 # tkt3457-1.4: Application has read but not write permission on 40 # the hot-journal file. Result: SQLITE_CANTOPEN. 41 # 42 # tkt3457-1.5: Application has read/write permission on the hot-journal 43 # file. Result: SQLITE_OK. 44 # 45 do_test tkt3457-1.1 { 46 execsql { 47 CREATE TABLE t1(a, b, c); 48 INSERT INTO t1 VALUES(1, 2, 3); 49 BEGIN; 50 INSERT INTO t1 VALUES(4, 5, 6); 51 } 52 53 forcecopy test.db bak.db 54 forcecopy test.db-journal bak.db-journal 55 56 # Fix the first journal-header in the journal-file. Because the 57 # journal file has not yet been synced, the 8-byte magic string at the 58 # start of the first journal-header has not been written by SQLite. 59 # So write it now. 60 set fd [open bak.db-journal a+] 61 fconfigure $fd -encoding binary -translation binary 62 seek $fd 0 63 puts -nonewline $fd "\xd9\xd5\x05\xf9\x20\xa1\x63\xd7" 64 close $fd 65 66 execsql COMMIT 67 } {} 68 69 # Disable fchmod to make sure SQLite itself does not try to change the 70 # permission bits on us 71 # 72 catch { 73 test_syscall install fchmod 74 test_syscall fault 1 1 75 } 76 77 do_test tkt3457-1.2 { 78 forcecopy bak.db-journal test.db-journal 79 file attributes test.db-journal -permissions --------- 80 catchsql { SELECT * FROM t1 } 81 } {1 {unable to open database file}} 82 do_test tkt3457-1.3 { 83 forcecopy bak.db-journal test.db-journal 84 file attributes test.db-journal -permissions -w--w--w- 85 catchsql { SELECT * FROM t1 } 86 } {1 {unable to open database file}} 87 do_test tkt3457-1.4 { 88 forcecopy bak.db-journal test.db-journal 89 file attributes test.db-journal -permissions r--r--r-- 90 catchsql { SELECT * FROM t1 } 91 } {1 {unable to open database file}} 92 93 do_test tkt3457-1.5 { 94 forcecopy bak.db-journal test.db-journal 95 file attributes test.db-journal -permissions rw-rw-rw- 96 catchsql { SELECT * FROM t1 } 97 } {0 {1 2 3 4 5 6}} 98 99 # Reenable fchmod 100 catch { 101 test_syscall uninstall 102 test_syscall fault 0 0 103 } 104 105 finish_test