mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Add the "PRAGMA wal_autocheckpoint" command. Rename "PRAGMA checkpoint" to "PRAGMA wal_checkpoint".
FossilOrigin-Name: 714e5947264571386f966aa8fcdd5607b5832238
This commit is contained in:
@ -11,6 +11,10 @@
|
||||
# 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.
|
||||
#
|
||||
# More specifically, this file contains regression tests for the
|
||||
# sqlite3_wal_hook() mechanism, including the sqlite3_wal_autocheckpoint()
|
||||
# and "PRAGMA wal_autocheckpoint" convenience interfaces.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@ -18,27 +22,27 @@ source $testdir/tester.tcl
|
||||
|
||||
ifcapable !wal {finish_test ; return }
|
||||
|
||||
proc sqlite3_wal {args} {
|
||||
eval sqlite3 $args
|
||||
[lindex $args 0] eval {
|
||||
PRAGMA journal_mode = wal;
|
||||
PRAGMA synchronous = normal;
|
||||
PRAGMA page_size = 1024;
|
||||
}
|
||||
proc log_file_size {nFrame pgsz} {
|
||||
expr {12 + ($pgsz+16)*$nFrame}
|
||||
}
|
||||
sqlite3_wal db test.db
|
||||
db wal_hook wal_hook
|
||||
|
||||
set ::wal_hook [list]
|
||||
proc wal_hook {zDb nEntry} {
|
||||
lappend ::wal_hook $zDb $nEntry
|
||||
return 0
|
||||
}
|
||||
db wal_hook wal_hook
|
||||
|
||||
do_test walhook-1.1 {
|
||||
execsql { CREATE TABLE t1(i PRIMARY KEY, j) }
|
||||
execsql {
|
||||
PRAGMA page_size = 1024;
|
||||
PRAGMA journal_mode = wal;
|
||||
PRAGMA synchronous = normal;
|
||||
CREATE TABLE t1(i PRIMARY KEY, j);
|
||||
}
|
||||
set ::wal_hook
|
||||
} {main 3}
|
||||
|
||||
do_test walhook-1.2 {
|
||||
set ::wal_hook [list]
|
||||
execsql { INSERT INTO t1 VALUES(1, 'one') }
|
||||
@ -49,10 +53,9 @@ do_test walhook-1.3 {
|
||||
execsql { INSERT INTO t1 VALUES(2, 'two') }
|
||||
file size test.db
|
||||
} [expr 3*1024]
|
||||
|
||||
do_test walhook-1.4 {
|
||||
proc wal_hook {zDb nEntry} {
|
||||
execsql { PRAGMA checkpoint }
|
||||
execsql { PRAGMA wal_checkpoint }
|
||||
return 0
|
||||
}
|
||||
execsql { CREATE TABLE t2(a, b) }
|
||||
@ -60,15 +63,49 @@ do_test walhook-1.4 {
|
||||
} [expr 4*1024]
|
||||
|
||||
do_test walhook-1.5 {
|
||||
sqlite3_wal db2 test.db
|
||||
proc wal_hook {zDb nEntry} {
|
||||
execsql { PRAGMA checkpoint } db2
|
||||
sqlite3 db2 test.db
|
||||
proc wal_hook {zDb nEntry} {
|
||||
execsql { PRAGMA wal_checkpoint } db2
|
||||
return 0
|
||||
}
|
||||
execsql { CREATE TABLE t3(a PRIMARY KEY, b) }
|
||||
file size test.db
|
||||
} [expr 6*1024]
|
||||
|
||||
db2 close
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_test walhook-2.1 {
|
||||
execsql { PRAGMA synchronous = NORMAL }
|
||||
execsql { PRAGMA wal_autocheckpoint }
|
||||
} {1000}
|
||||
do_test walhook-2.2 {
|
||||
execsql { PRAGMA wal_autocheckpoint = 10}
|
||||
} {10}
|
||||
do_test walhook-2.3 {
|
||||
execsql { PRAGMA wal_autocheckpoint }
|
||||
} {10}
|
||||
|
||||
#
|
||||
# The database connection is configured with "PRAGMA wal_autocheckpoint = 10".
|
||||
# Check that transactions are written to the log file until it contains at
|
||||
# least 10 frames, then the database is checkpointed. Subsequent transactions
|
||||
# are written into the start of the log file.
|
||||
#
|
||||
foreach {tn sql dbpages logpages} {
|
||||
4 "CREATE TABLE t4(x PRIMARY KEY, y)" 6 3
|
||||
5 "INSERT INTO t4 VALUES(1, 'one')" 6 5
|
||||
6 "INSERT INTO t4 VALUES(2, 'two')" 6 7
|
||||
7 "INSERT INTO t4 VALUES(3, 'three')" 6 9
|
||||
8 "INSERT INTO t4 VALUES(4, 'four')" 8 11
|
||||
9 "INSERT INTO t4 VALUES(5, 'five')" 8 11
|
||||
} {
|
||||
do_test walhook-2.$tn {
|
||||
execsql $sql
|
||||
list [file size test.db] [file size test.db-wal]
|
||||
} [list [expr $dbpages*1024] [log_file_size $logpages 1024]]
|
||||
}
|
||||
|
||||
catch { db2 close }
|
||||
catch { db close }
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user