xref: /sqlite-3.40.0/test/walshared.test (revision 9c5e1e40)
1a550f2deSdan# 2010 August 2
2a550f2deSdan#
3a550f2deSdan# The author disclaims copyright to this source code.  In place of
4a550f2deSdan# a legal notice, here is a blessing:
5a550f2deSdan#
6a550f2deSdan#    May you do good and not evil.
7a550f2deSdan#    May you find forgiveness for yourself and forgive others.
8a550f2deSdan#    May you share freely, never taking more than you give.
9a550f2deSdan#
10a550f2deSdan#***********************************************************************
11a550f2deSdan# This file implements regression tests for SQLite library.  The
12a550f2deSdan# focus of this file is testing the operation of the library in
13a550f2deSdan# "PRAGMA journal_mode=WAL" mode with shared-cache turned on.
14a550f2deSdan#
15a550f2deSdan
16a550f2deSdanset testdir [file dirname $argv0]
17a550f2deSdansource $testdir/tester.tcl
189091f775Sshaneh
19*9c5e1e40Sdrhifcapable !wal||!shared_cache {finish_test ; return }
209091f775Sshaneh
21a550f2deSdandb close
22a550f2deSdanset ::enable_shared_cache [sqlite3_enable_shared_cache 1]
23a550f2deSdan
24a550f2deSdansqlite3 db  test.db
25a550f2deSdansqlite3 db2 test.db
26a550f2deSdan
27a550f2deSdando_test walshared-1.0 {
28a550f2deSdan  execsql {
29a550f2deSdan    PRAGMA cache_size = 10;
30a550f2deSdan    PRAGMA journal_mode = WAL;
31a550f2deSdan    CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
32a550f2deSdan    INSERT INTO t1 VALUES(randomblob(100), randomblob(200));
33a550f2deSdan  }
34a550f2deSdan} {wal}
35a550f2deSdan
36a550f2deSdando_test walshared-1.1 {
37a550f2deSdan  execsql {
38a550f2deSdan    BEGIN;
39a550f2deSdan      INSERT INTO t1 VALUES(randomblob(100), randomblob(200));
40a550f2deSdan      INSERT INTO t1 SELECT randomblob(100), randomblob(200) FROM t1;
41a550f2deSdan      INSERT INTO t1 SELECT randomblob(100), randomblob(200) FROM t1;
42a550f2deSdan      INSERT INTO t1 SELECT randomblob(100), randomblob(200) FROM t1;
43a550f2deSdan  }
44a550f2deSdan} {}
45a550f2deSdan
46a550f2deSdando_test walshared-1.2 {
47a550f2deSdan  catchsql { PRAGMA wal_checkpoint }
48a550f2deSdan} {1 {database table is locked}}
49a550f2deSdan
50a550f2deSdando_test walshared-1.3 {
51a550f2deSdan  catchsql { PRAGMA wal_checkpoint } db2
52a550f2deSdan} {1 {database table is locked}}
53a550f2deSdan
54a550f2deSdando_test walshared-1.4 {
55a550f2deSdan  execsql { COMMIT }
56a550f2deSdan  execsql { PRAGMA integrity_check } db2
57a550f2deSdan} {ok}
58a550f2deSdan
59a550f2deSdan
60a550f2deSdan
61a550f2deSdansqlite3_enable_shared_cache $::enable_shared_cache
62a550f2deSdanfinish_test
63