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. The focus
12 # of this file is the sqlite3_snapshot_xxx() APIs.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 ifcapable !snapshot {finish_test; return}
18 set testprefix snapshot3
20 # This test does not work with the inmemory_journal permutation. The reason
21 # is that each connection opened as part of this permutation executes
22 # "PRAGMA journal_mode=memory", which fails if the database is in wal mode
23 # and there are one or more existing connections.
24 if {[permutation]=="inmemory_journal"} {
29 #-------------------------------------------------------------------------
30 # This block of tests verifies that it is not possible to wrap the wal
31 # file - using a writer or a "PRAGMA wal_checkpoint = TRUNCATE" - while
32 # there is an open snapshot transaction (transaction opened using
33 # sqlite3_snapshot_open()).
37 PRAGMA journal_mode = wal;
38 INSERT INTO t1 VALUES(1);
39 INSERT INTO t1 VALUES(2);
40 INSERT INTO t1 VALUES(3);
41 INSERT INTO t1 VALUES(4);
48 execsql {SELECT * FROM sqlite_master} db2
49 execsql {SELECT * FROM sqlite_master} db3
51 db2 trans { set snap [sqlite3_snapshot_get_blob db2 main] }
52 db2 eval { SELECT * FROM t1 }
57 sqlite3_snapshot_open_blob db2 main $snap
58 db2 eval { SELECT * FROM t1 }
63 execsql { PRAGMA wal_checkpoint }
66 sqlite3_snapshot_open_blob db2 main $snap
67 db2 eval { SELECT * FROM t1 }
70 set sz [file size test.db-wal]
72 execsql { PRAGMA wal_checkpoint = truncate }
78 list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
82 db3 eval { SELECT * FROM t1; END }
86 db2 eval { SELECT * FROM t1; END }
90 execsql { PRAGMA wal_checkpoint = truncate }
96 list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
97 } {1 SQLITE_ERROR_SNAPSHOT}