mirror of https://github.com/sqlite/sqlite
96 lines
2.4 KiB
Plaintext
96 lines
2.4 KiB
Plaintext
# 2010 April 19
|
|
#
|
|
# 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 testing the operation of the library in
|
|
# "PRAGMA journal_mode=WAL" mode.
|
|
#
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
|
|
do_test walmode-1.1 {
|
|
set sqlite_sync_count 0
|
|
execsql { PRAGMA page_size = 1024 }
|
|
execsql { PRAGMA journal_mode = wal }
|
|
} {wal}
|
|
do_test walmode-1.2 {
|
|
file size test.db
|
|
} {1024}
|
|
do_test walmode-1.3 {
|
|
set sqlite_sync_count
|
|
} {4}
|
|
do_test walmode-1.4 {
|
|
file exists test.db-wal
|
|
} {0}
|
|
do_test walmode-1.5 {
|
|
execsql { CREATE TABLE t1(a, b) }
|
|
file size test.db
|
|
} {1024}
|
|
do_test walmode-1.6 {
|
|
file exists test.db-wal
|
|
} {1}
|
|
do_test walmode-1.7 {
|
|
db close
|
|
file exists test.db-wal
|
|
} {0}
|
|
|
|
# There is now a database file with the read and write versions set to 2
|
|
# in the file system. This file should default to WAL mode.
|
|
#
|
|
do_test walmode-2.1 {
|
|
sqlite3 db test.db
|
|
file exists test.db-wal
|
|
} {0}
|
|
do_test walmode-2.2 {
|
|
execsql { SELECT * FROM sqlite_master }
|
|
file exists test.db-wal
|
|
} {1}
|
|
do_test walmode-2.3 {
|
|
db close
|
|
file exists test.db-wal
|
|
} {0}
|
|
|
|
# If the first statement executed is "PRAGMA journal_mode = wal", and
|
|
# the file is already configured for WAL (read and write versions set
|
|
# to 2), then there should be no need to write the database. The
|
|
# statement should cause the client to connect to the log file.
|
|
#
|
|
set sqlite_sync_count 0
|
|
do_test walmode-3.1 {
|
|
sqlite3 db test.db
|
|
execsql { PRAGMA journal_mode = wal }
|
|
} {wal}
|
|
do_test walmode-3.2 {
|
|
list $sqlite_sync_count [file exists test.db-wal] [file size test.db-wal]
|
|
} {0 1 0}
|
|
|
|
do_test walmode-4.1 {
|
|
execsql { INSERT INTO t1 VALUES(1, 2) }
|
|
execsql { PRAGMA journal_mode = persist }
|
|
} {persist}
|
|
do_test walmode-4.2 {
|
|
list [file exists test.db-journal] [file exists test.db-wal]
|
|
} {1 0}
|
|
do_test walmode-4.3 {
|
|
execsql { SELECT * FROM t1 }
|
|
} {1 2}
|
|
do_test walmode-4.4 {
|
|
db close
|
|
sqlite3 db test.db
|
|
execsql { SELECT * FROM t1 }
|
|
} {1 2}
|
|
do_test walmode-4.5 {
|
|
list [file exists test.db-journal] [file exists test.db-wal]
|
|
} {1 0}
|
|
|
|
finish_test
|
|
|