blob: 4dca202b1cfc4a2f03f4608d254b8c67881ab01a (
plain)
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
|
# 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}
finish_test
|