Add the "^" syntax from fts3/4 to fts5.
[sqlite.git] / test / mjournal.test
blobcf6ef5f7b5d268fa44570b00af9e9e4c6decf5a8
1 # 2017 September 15
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
16 set testprefix mjournal
18 # Test that nothing bad happens if a journal file contains a pointer to
19 # a master journal file that does not have a "-" in the name. At one point
20 # this was causing a segfault on unix.
22 do_execsql_test 1.0 {
23   CREATE TABLE t1(a, b);
26 do_test 1.1 {
27   forcedelete test.db2journal test.db-journal
29   close [open test.db-journal w]
30   
31   hexio_write test.db-journal 0 746573742e6462326a6f75726e616c00
32   hexio_write test.db-journal 16 00000010
33   hexio_write test.db-journal 20 000005e1
34   hexio_write test.db-journal 24 d9d505f920a163d7
36   close [open test.db2journal w]
37   hexio_write test.db2journal 0 abcd
38 } {2}
40 do_execsql_test 1.2 {
41   SELECT * FROM t1;
44 do_test 1.3 {
45   forcedelete test0db2journal test.db-journal
46   close [open test.db-journal w]
47   hexio_write test.db-journal 0 74657374306462326a6f75726e616c00
48   hexio_write test.db-journal 16 00000010
49   hexio_write test.db-journal 20 000005e3
50   hexio_write test.db-journal 24 d9d505f920a163d7
52   close [open test0db2journal w]
53   hexio_write test0db2journal 0 abcd
54 } {2}
56 do_execsql_test 1.4 {
57   SELECT * FROM t1;
60 # And now test that nothing bad happens if a master journal contains a
61 # pointer to a journal file that does not have a "-" in the name. 
63 do_test 1.5 {
64   forcedelete test.db2-master test.db-journal test1
65   close [open test.db-journal w]
66   hexio_write test.db-journal 0 746573742e6462322d6d617374657200
67   hexio_write test.db-journal 16 00000010
68   hexio_write test.db-journal 20 0000059f
69   hexio_write test.db-journal 24 d9d505f920a163d7
71   close [open test.db2-master w]
72   hexio_write test.db2-master 0 746573743100
74   close [open test1 w]
75   hexio_write test1 0 abcd
76 } {2}
78 do_execsql_test 1.6 {
79   SELECT * FROM t1;
82 #-------------------------------------------------------------------------
83 # Check that master journals are not created if the transaction involves
84 # multiple temp files.
86 db close
87 testvfs tvfs
88 tvfs filter xOpen
89 tvfs script open_cb
90 set ::open ""
91 proc open_cb {method file arglist} {
92   lappend ::open $file
95 proc contains_mj {} {
96   foreach f $::open {
97     set t [file tail $f]
98     if {[string match *mj* $t]} { return 1 }
99   }
100   return 0
103 # Like [do_execsql_test], except that a boolean indicating whether or
104 # not a master journal file was opened ([file tail] contains "mj") or
105 # not. Example:
107 #   do_hasmj_test 1.0 { SELECT 'a', 'b' } {0 a b}
109 proc do_hasmj_test {tn sql expected} {
110   set ::open [list]
111   uplevel [list do_test $tn [subst -nocommands {
112     set res [execsql "$sql"]
113     concat [contains_mj] [set res]
114   }] [list {*}$expected]]
117 forcedelete test.db
118 forcedelete test.db2
119 forcedelete test.db3
120 sqlite3 db test.db -vfs tvfs
122 do_execsql_test 2.0 {
123   ATTACH 'test.db2' AS dbfile;
124   ATTACH ''         AS dbtemp;
125   ATTACH ':memory:'  AS dbmem;
127   CREATE TABLE t1(x);
128   CREATE TABLE dbfile.t2(x);
129   CREATE TABLE dbtemp.t3(x);
130   CREATE TABLE dbmem.t4(x);
133 # Two real files.
134 do_hasmj_test 2.1 {
135   BEGIN;
136     INSERT INTO t1 VALUES(1);
137     INSERT INTO t2 VALUES(1);
138   COMMIT;
139 } {1}
141 # One real, one temp file.
142 do_hasmj_test 2.2 {
143   BEGIN;
144     INSERT INTO t1 VALUES(1);
145     INSERT INTO t3 VALUES(1);
146   COMMIT;
147 } {0}
149 # One file, one :memory: db.
150 do_hasmj_test 2.3 {
151   BEGIN;
152     INSERT INTO t1 VALUES(1);
153     INSERT INTO t4 VALUES(1);
154   COMMIT;
155 } {0}
157 finish_test