xref: /sqlite-3.40.0/test/wal8.test (revision 7aa3ebee)
1# 2012 February 28
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library.  The
12# focus of this file is testing the operation of the library in
13# "PRAGMA journal_mode=WAL" mode.
14#
15# Specifically, it tests the case where a connection opens an empty
16# file. Then, another connection opens the same file and initializes
17# the connection as a WAL database. Following this, the first connection
18# executes a "PRAGMA page_size = XXX" command to set its expected page
19# size, and then queries the database.
20#
21# This is an unusual case, as normally SQLite is able to glean the page
22# size from the database file as soon as it is opened (even before the
23# first read transaction is executed), and the "PRAGMA page_size = XXX"
24# is a no-op.
25#
26set testdir [file dirname $argv0]
27source $testdir/tester.tcl
28set ::testprefix wal8
29ifcapable !wal {finish_test ; return }
30
31db close
32forcedelete test.db test.db-wal
33
34sqlite3 db test.db
35sqlite3 db2 test.db
36
37do_test 1.0 {
38  execsql {
39    PRAGMA journal_mode = wal;
40    CREATE TABLE t1(a, b);
41    INSERT INTO t1 VALUES(1, 2);
42  } db2
43} {wal}
44
45do_catchsql_test 1.1 {
46  PRAGMA page_size = 4096;
47  VACUUM;
48} {0 {}}
49
50db close
51db2 close
52forcedelete test.db test.db-wal
53
54sqlite3 db test.db
55sqlite3 db2 test.db
56
57do_test 2.0 {
58  execsql {
59    CREATE TABLE t1(a, b);
60    INSERT INTO t1 VALUES(1, 2);
61    PRAGMA journal_mode = wal;
62  } db2
63} {wal}
64
65do_catchsql_test 2.1 {
66  PRAGMA page_size = 4096;
67  VACUUM;
68} {0 {}}
69
70db close
71db2 close
72forcedelete test.db test.db-wal
73
74sqlite3 db test.db
75sqlite3 db2 test.db
76
77do_test 3.0 {
78  execsql {
79    PRAGMA journal_mode = wal;
80    CREATE TABLE t1(a, b);
81    INSERT INTO t1 VALUES(1, 2);
82  } db2
83} {wal}
84
85do_execsql_test 3.1 {
86  PRAGMA page_size = 4096;
87  SELECT name FROM sqlite_master;
88} {t1}
89
90finish_test
91