forked from sqlite/sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapshot3.test
138 lines (115 loc) · 3.28 KB
/
snapshot3.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# 2016 September 23
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The focus
# of this file is the sqlite3_snapshot_xxx() APIs.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !snapshot {finish_test; return}
set testprefix snapshot3
# This test does not work with the inmemory_journal permutation. The reason
# is that each connection opened as part of this permutation executes
# "PRAGMA journal_mode=memory", which fails if the database is in wal mode
# and there are one or more existing connections.
if {[permutation]=="inmemory_journal"} {
finish_test
return
}
#-------------------------------------------------------------------------
# This block of tests verifies that it is not possible to wrap the wal
# file - using a writer or a "PRAGMA wal_checkpoint = TRUNCATE" - while
# there is an open snapshot transaction (transaction opened using
# sqlite3_snapshot_open()).
#
do_execsql_test 1.0 {
CREATE TABLE t1(y);
PRAGMA journal_mode = wal;
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES(2);
INSERT INTO t1 VALUES(3);
INSERT INTO t1 VALUES(4);
} {wal}
do_test 1.1 {
sqlite3 db2 test.db
sqlite3 db3 test.db
execsql {SELECT * FROM sqlite_master} db2
execsql {SELECT * FROM sqlite_master} db3
db2 trans { set snap [sqlite3_snapshot_get_blob db2 main] }
db2 eval { SELECT * FROM t1 }
} {1 2 3 4}
do_test 1.2 {
execsql BEGIN db2
sqlite3_snapshot_open_blob db2 main $snap
db2 eval { SELECT * FROM t1 }
} {1 2 3 4}
do_test 1.2 {
execsql END db2
execsql { PRAGMA wal_checkpoint }
execsql BEGIN db2
sqlite3_snapshot_open_blob db2 main $snap
db2 eval { SELECT * FROM t1 }
} {1 2 3 4}
set sz [file size test.db-wal]
do_test 1.3 {
execsql { PRAGMA wal_checkpoint = truncate }
file size test.db-wal
} $sz
do_test 1.4 {
execsql BEGIN db3
list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
} {0 {}}
do_test 1.5 {
db3 eval { SELECT * FROM t1; END }
} {1 2 3 4}
do_test 1.6 {
db2 eval { SELECT * FROM t1; END }
} {1 2 3 4}
do_test 1.7 {
execsql { PRAGMA wal_checkpoint = truncate }
file size test.db-wal
} 0
do_test 1.8 {
execsql BEGIN db3
list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
} {1 SQLITE_ERROR_SNAPSHOT}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
PRAGMA journal_mode = wal;
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES(3, 4);
} {wal}
sqlite3 db2 test.db
sqlite3 db3 test.db
do_execsql_test -db db2 2.0.1 {
SELECT * FROM t1
} {1 2 3 4}
do_execsql_test -db db3 2.0.2 {
SELECT * FROM t1
} {1 2 3 4}
do_execsql_test -db db2 2.2 {
PRAGMA wal_checkpoint;
} {0 4 4}
do_test 2.1 {
db eval { BEGIN }
set snap [sqlite3_snapshot_get db main]
set {} {}
} {}
do_execsql_test -db db2 2.3 {
INSERT INTO t1 VALUES(5, 6);
} {}
do_test 2.2 {
execsql { BEGIN } db3
sqlite3_snapshot_open db3 main $snap
} {}
sqlite3_snapshot_free $snap
finish_test