| 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 |
# |
| 26 |
set testdir [file dirname $argv0] |
| 27 |
source $testdir/tester.tcl |
| 28 |
set ::testprefix wal8 |
| 29 |
ifcapable !wal {finish_test ; return } |
| 30 |
do_not_use_codec |
| 31 |
|
| 32 |
db close |
| 33 |
forcedelete test.db test.db-wal |
| 34 |
|
| 35 |
sqlite3 db test.db |
| 36 |
sqlite3 db2 test.db |
| 37 |
|
| 38 |
do_test 1.0 { |
| 39 |
execsql { |
| 40 |
PRAGMA journal_mode = wal; |
| 41 |
CREATE TABLE t1(a, b); |
| 42 |
INSERT INTO t1 VALUES(1, 2); |
| 43 |
} db2 |
| 44 |
} {wal} |
| 45 |
|
| 46 |
do_catchsql_test 1.1 { |
| 47 |
PRAGMA page_size = 4096; |
| 48 |
VACUUM; |
| 49 |
} {0 {}} |
| 50 |
|
| 51 |
db close |
| 52 |
db2 close |
| 53 |
forcedelete test.db test.db-wal |
| 54 |
|
| 55 |
sqlite3 db test.db |
| 56 |
sqlite3 db2 test.db |
| 57 |
|
| 58 |
do_test 2.0 { |
| 59 |
execsql { |
| 60 |
CREATE TABLE t1(a, b); |
| 61 |
INSERT INTO t1 VALUES(1, 2); |
| 62 |
PRAGMA journal_mode = wal; |
| 63 |
} db2 |
| 64 |
} {wal} |
| 65 |
|
| 66 |
do_catchsql_test 2.1 { |
| 67 |
PRAGMA page_size = 4096; |
| 68 |
VACUUM; |
| 69 |
} {0 {}} |
| 70 |
|
| 71 |
db close |
| 72 |
db2 close |
| 73 |
forcedelete test.db test.db-wal |
| 74 |
|
| 75 |
sqlite3 db test.db |
| 76 |
sqlite3 db2 test.db |
| 77 |
|
| 78 |
do_test 3.0 { |
| 79 |
execsql { |
| 80 |
PRAGMA journal_mode = wal; |
| 81 |
CREATE TABLE t1(a, b); |
| 82 |
INSERT INTO t1 VALUES(1, 2); |
| 83 |
} db2 |
| 84 |
} {wal} |
| 85 |
|
| 86 |
do_execsql_test 3.1 { |
| 87 |
PRAGMA page_size = 4096; |
| 88 |
SELECT name FROM sqlite_master; |
| 89 |
} {t1} |
| 90 |
|
| 91 |
finish_test |