mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
148 lines
3.6 KiB
Plaintext
148 lines
3.6 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}
|
|
|
|
# Test that changing back to journal_mode=persist works.
|
|
#
|
|
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}
|
|
|
|
# Test that nothing goes wrong if a connection is prevented from changing
|
|
# from WAL to rollback mode because a second connection has the database
|
|
# open. Or from rollback to WAL.
|
|
#
|
|
do_test walmode-4.1 {
|
|
sqlite3 db2 test.db
|
|
execsql { PRAGMA main.journal_mode } db2
|
|
} {delete}
|
|
do_test walmode-4.2 {
|
|
execsql { PRAGMA main.journal_mode = wal } db
|
|
} {wal}
|
|
do_test walmode-4.3 {
|
|
execsql { SELECT * FROM t1 } db2
|
|
} {1 2}
|
|
do_test walmode-4.4 {
|
|
catchsql { PRAGMA journal_mode = delete } db
|
|
} {1 {database is locked}}
|
|
do_test walmode-4.5 {
|
|
execsql { PRAGMA main.journal_mode } db
|
|
} {wal}
|
|
do_test walmode-4.6 {
|
|
db2 close
|
|
execsql { PRAGMA journal_mode = delete } db
|
|
} {delete}
|
|
do_test walmode-4.7 {
|
|
execsql { PRAGMA main.journal_mode } db
|
|
} {delete}
|
|
do_test walmode-4.8 {
|
|
list [file exists test.db-journal] [file exists test.db-wal]
|
|
} {0 0}
|
|
do_test walmode-4.9 {
|
|
sqlite3 db2 test.db
|
|
execsql {
|
|
BEGIN;
|
|
SELECT * FROM t1;
|
|
} db2
|
|
} {1 2}
|
|
do_test walmode-4.11 {
|
|
execsql { PRAGMA main.journal_mode } db
|
|
} {delete}
|
|
do_test walmode-4.10 {
|
|
catchsql { PRAGMA main.journal_mode = wal } db
|
|
} {1 {database is locked}}
|
|
do_test walmode-4.11 {
|
|
execsql { PRAGMA main.journal_mode } db
|
|
} {delete}
|
|
|
|
|
|
catch { db close }
|
|
catch { db2 close }
|
|
finish_test
|
|
|