1*f5778751Sdan# 2018 August 28 2*f5778751Sdan# 3*f5778751Sdan# The author disclaims copyright to this source code. In place of 4*f5778751Sdan# a legal notice, here is a blessing: 5*f5778751Sdan# 6*f5778751Sdan# May you do good and not evil. 7*f5778751Sdan# May you find forgiveness for yourself and forgive others. 8*f5778751Sdan# May you share freely, never taking more than you give. 9*f5778751Sdan# 10*f5778751Sdan#*********************************************************************** 11*f5778751Sdan# This file implements regression tests for SQLite library. The focus 12*f5778751Sdan# of this file is the sqlite3_snapshot_xxx() APIs. 13*f5778751Sdan# 14*f5778751Sdan 15*f5778751Sdanset testdir [file dirname $argv0] 16*f5778751Sdansource $testdir/tester.tcl 17*f5778751Sdanifcapable !snapshot {finish_test; return} 18*f5778751Sdanset testprefix snapshot4 19*f5778751Sdan 20*f5778751Sdan# This test does not work with the inmemory_journal permutation. The reason 21*f5778751Sdan# is that each connection opened as part of this permutation executes 22*f5778751Sdan# "PRAGMA journal_mode=memory", which fails if the database is in wal mode 23*f5778751Sdan# and there are one or more existing connections. 24*f5778751Sdanif {[permutation]=="inmemory_journal"} { 25*f5778751Sdan finish_test 26*f5778751Sdan return 27*f5778751Sdan} 28*f5778751Sdan 29*f5778751Sdansqlite3 db2 test.db 30*f5778751Sdan 31*f5778751Sdando_execsql_test 1.0 { 32*f5778751Sdan PRAGMA cache_size = 10; 33*f5778751Sdan CREATE TABLE t1(a, b); 34*f5778751Sdan INSERT INTO t1 VALUES(1, randomblob(400)); 35*f5778751Sdan PRAGMA journal_mode = wal; 36*f5778751Sdan WITH s(i) AS ( 37*f5778751Sdan SELECT 2 UNION ALL SELECT i+1 FROM s WHERE i<100 38*f5778751Sdan ) 39*f5778751Sdan INSERT INTO t1 SELECT i, randomblob(400) FROM s; 40*f5778751Sdan} {wal} 41*f5778751Sdan 42*f5778751Sdando_test 1.1 { 43*f5778751Sdan execsql { 44*f5778751Sdan BEGIN; 45*f5778751Sdan SELECT count(*) FROM t1; 46*f5778751Sdan } 47*f5778751Sdan} {100} 48*f5778751Sdan 49*f5778751Sdando_test 1.2 { 50*f5778751Sdan db2 eval { 51*f5778751Sdan SELECT count(*) FROM t1; 52*f5778751Sdan CREATE TABLE t2(x); 53*f5778751Sdan } 54*f5778751Sdan} {100} 55*f5778751Sdan 56*f5778751Sdando_test 1.3 { 57*f5778751Sdan set ::snap [sqlite3_snapshot_get_blob db main] 58*f5778751Sdan db2 eval { PRAGMA wal_checkpoint } 59*f5778751Sdan} {0 54 52} 60*f5778751Sdan 61*f5778751Sdando_test 1.4 { 62*f5778751Sdan execsql { 63*f5778751Sdan COMMIT; 64*f5778751Sdan SELECT * FROM sqlite_master; 65*f5778751Sdan BEGIN; 66*f5778751Sdan } 67*f5778751Sdan sqlite3_snapshot_open_blob db main $::snap 68*f5778751Sdan execsql { 69*f5778751Sdan SELECT count(*) FROM t1 70*f5778751Sdan } 71*f5778751Sdan} {100} 72*f5778751Sdan 73*f5778751Sdan 74*f5778751Sdanfinish_test 75