interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / win32shm.test

79 lines · 2058 bytes Raw Blame History
1# 2026 October 5
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 script is the behaviour of wal databases on windows
13# when some other process has the *-shm file memory-mapped.
14#
15
16if {$tcl_platform(platform) ne "windows"} return
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20set testprefix win32shm
21
22ifcapable !wal {
23 finish_test
24 return
25}
26
27#-------------------------------------------------------------------------
28# Each test below simulates a abrupt exit by copying the db, *-wal and
29# *-shm files of an open wal database, then reopens the copy while an
30# external mapping is held on its *-shm file. Since the *-shm file cannot
31# be truncated while it is mapped, these test that recovery still runs and
32# all committed data is visible.
33#
34# 1.1-1.2: The *-shm file is current.
35#
36# 1.3-1.4: The *-shm file is out of date. If this file were trusted
37# instead of running recovery, row 4 would be lost.
38#
39do_execsql_test 1.0 {
40 PRAGMA journal_mode = wal;
41 CREATE TABLE t1(a, b);
42 INSERT INTO t1 VALUES(1, 'one');
43 INSERT INTO t1 VALUES(2, 'two');
44 INSERT INTO t1 VALUES(3, 'three');
45} {wal}
46
47do_test 1.1 {
48 db_save_and_close
49 db_restore
50 map_win32_file shmmap test.db-shm
51} {shmmap}
52
53sqlite3 db test.db
54do_execsql_test 1.2 {
55 SELECT * FROM t1
56} {1 one 2 two 3 three}
57
58shmmap destroy
59
60do_test 1.3 {
61 forcedelete bak-shm
62 forcecopy test.db-shm bak-shm
63 execsql {
64 INSERT INTO t1 VALUES(4, 'four');
65 }
66 db_save_and_close
67 db_restore
68 forcecopy bak-shm test.db-shm
69 map_win32_file shmmap test.db-shm
70} {shmmap}
71
72sqlite3 db test.db
73do_execsql_test 1.4 {
74 SELECT * FROM t1
75} {1 one 2 two 3 three 4 four}
76
77shmmap destroy
78
79finish_test