AryaWu/sqlite
0
1# 2017 September 152#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# This file implements regression tests for SQLite library.12#13 14set testdir [file dirname $argv0]15source $testdir/tester.tcl16set testprefix mjournal17 18if {[permutation]=="inmemory_journal"} {19 finish_test20 return21}22 23# Test that nothing bad happens if a journal file contains a pointer to24# a master journal file that does not have a "-" in the name. At one point25# this was causing a segfault on unix.26#27do_execsql_test 1.0 {28 CREATE TABLE t1(a, b);29}30 31do_test 1.1 {32 forcedelete test.db2journal test.db-journal33 34 close [open test.db-journal w]35 36 hexio_write test.db-journal 0 746573742e6462326a6f75726e616c0037 hexio_write test.db-journal 16 0000001038 hexio_write test.db-journal 20 000005e139 hexio_write test.db-journal 24 d9d505f920a163d740 41 close [open test.db2journal w]42 hexio_write test.db2journal 0 abcd43} {2}44 45do_execsql_test 1.2 {46 SELECT * FROM t1;47}48 49do_test 1.3 {50 forcedelete test0db2journal test.db-journal51 close [open test.db-journal w]52 hexio_write test.db-journal 0 74657374306462326a6f75726e616c0053 hexio_write test.db-journal 16 0000001054 hexio_write test.db-journal 20 000005e355 hexio_write test.db-journal 24 d9d505f920a163d756 57 close [open test0db2journal w]58 hexio_write test0db2journal 0 abcd59} {2}60 61do_execsql_test 1.4 {62 SELECT * FROM t1;63}64 65# And now test that nothing bad happens if a master journal contains a66# pointer to a journal file that does not have a "-" in the name. 67#68do_test 1.5 {69 forcedelete test.db2-master test.db-journal test170 close [open test.db-journal w]71 hexio_write test.db-journal 0 746573742e6462322d6d61737465720072 hexio_write test.db-journal 16 0000001073 hexio_write test.db-journal 20 0000059f74 hexio_write test.db-journal 24 d9d505f920a163d775 76 close [open test.db2-master w]77 hexio_write test.db2-master 0 74657374310078 79 close [open test1 w]80 hexio_write test1 0 abcd81} {2}82 83do_execsql_test 1.6 {84 SELECT * FROM t1;85}86 87#-------------------------------------------------------------------------88# Check that master journals are not created if the transaction involves89# multiple temp files.90#91db close92testvfs tvfs93tvfs filter xOpen94tvfs script open_cb95set ::open ""96proc open_cb {method file arglist} {97 lappend ::open $file98}99 100proc contains_mj {} {101 foreach f $::open {102 set t [file tail $f]103 if {[string match *mj* $t]} { return 1 }104 }105 return 0106}107 108# Like [do_execsql_test], except that a boolean indicating whether or109# not a master journal file was opened ([file tail] contains "mj") or110# not. Example:111#112# do_hasmj_test 1.0 { SELECT 'a', 'b' } {0 a b}113#114proc do_hasmj_test {tn sql expected} {115 set ::open [list]116 uplevel [list do_test $tn [subst -nocommands {117 set res [execsql "$sql"]118 concat [contains_mj] [set res]119 }] [list {*}$expected]]120}121 122forcedelete test.db123forcedelete test.db2124forcedelete test.db3125sqlite3 db test.db -vfs tvfs126 127do_execsql_test 2.0 {128 ATTACH 'test.db2' AS dbfile;129 ATTACH '' AS dbtemp;130 ATTACH ':memory:' AS dbmem;131 132 CREATE TABLE t1(x);133 CREATE TABLE dbfile.t2(x);134 CREATE TABLE dbtemp.t3(x);135 CREATE TABLE dbmem.t4(x);136}137 138# Two real files.139do_hasmj_test 2.1 {140 BEGIN;141 INSERT INTO t1 VALUES(1);142 INSERT INTO t2 VALUES(1);143 COMMIT;144} {1}145 146# One real, one temp file.147do_hasmj_test 2.2 {148 BEGIN;149 INSERT INTO t1 VALUES(1);150 INSERT INTO t3 VALUES(1);151 COMMIT;152} {0}153 154# One file, one :memory: db.155do_hasmj_test 2.3 {156 BEGIN;157 INSERT INTO t1 VALUES(1);158 INSERT INTO t4 VALUES(1);159 COMMIT;160} {0}161 162finish_test163 