summaryrefslogtreecommitdiffstats
path: root/test/tkt-2d1a5c67d.test
blob: 1f797686bf066325c9b6bb274606581c669064bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# 2011 May 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. Specifically,
# it tests that ticket [2d1a5c67dfc2363e44f29d9bbd57f7331851390a] has
# been resolved.
#
# 
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix tkt-2d1a5c67d

ifcapable {!vtab || !incrblob} {finish_test; return}
if {[wal_is_capable]==0} {finish_test; return}

for {set ii 1} {$ii<=10} {incr ii} {
  do_test tkt-2d1a5c67d.1.$ii {
    db close
    forcedelete test.db test.db-wal
    sqlite3 db test.db
    db eval "PRAGMA cache_size=$::ii"
    db eval {
      PRAGMA journal_mode=WAL;
      CREATE TABLE t1(a,b);
      CREATE INDEX t1b ON t1(b);
      CREATE TABLE t2(x,y UNIQUE);
      INSERT INTO t2 VALUES(3,4);
      BEGIN;
      INSERT INTO t1(a,b) VALUES(1,2);
      SELECT 'A', * FROM t2 WHERE y=4;
      SELECT 'B', * FROM t1;
      COMMIT;
      SELECT 'C', * FROM t1;
    }
  } {wal A 3 4 B 1 2 C 1 2}
}

db close
forcedelete test.db test.db-wal
sqlite3 db test.db
load_static_extension db wholenumber
db eval {
  PRAGMA journal_mode=WAL;
  CREATE TABLE t1(a,b);
  CREATE INDEX t1b ON t1(b);
  CREATE TABLE t2(x,y);
  CREATE VIRTUAL TABLE nums USING wholenumber;
  INSERT INTO t2 SELECT value, randomblob(1000) FROM nums
                 WHERE value BETWEEN 1 AND 1000;
}

for {set ii 1} {$ii<=10} {incr ii} {
  do_test tkt-2d1a5c67d.2.$ii {
    db eval "PRAGMA cache_size=$::ii"
    db eval {
      DELETE FROM t1;
      BEGIN;
      INSERT INTO t1(a,b) VALUES(1,2);
      SELECT sum(length(y)) FROM t2;
      COMMIT;
      SELECT * FROM t1;
    }
  } {1000000 1 2}
}

db close
sqlite3 db test.db


do_execsql_test 3.1 {
  PRAGMA cache_size = 10;
  CREATE TABLE t3(a INTEGER PRIMARY KEY, b);
  CREATE TABLE t4(a);
}

do_execsql_test 3.2 {
  INSERT INTO t3 VALUES(NULL, randomblob(500));
  INSERT INTO t3 SELECT NULL, b||b FROM t3;     -- 2
  INSERT INTO t3 SELECT NULL, b||b FROM t3;     -- 4
  INSERT INTO t3 SELECT NULL, b||b FROM t3;     -- 8
  INSERT INTO t3 SELECT NULL, b||b FROM t3;     -- 16
  INSERT INTO t3 SELECT NULL, b||b FROM t3;     -- 32
  INSERT INTO t3 SELECT NULL, b||b FROM t3;     -- 64
  INSERT INTO t3 SELECT NULL, b||b FROM t3;     -- 128
}

do_execsql_test 3.3 {
  BEGIN;
    INSERT INTO t4 VALUES('xyz');
}

do_test 3.4 {
  set blobs [list]
  for {set i 1} {$i<100} {incr i} {
    set b [db incrblob -readonly t3 b $i]
    read $b
    lappend blobs $b
  }

  execsql COMMIT
  execsql { SELECT * FROM t4 WHERE a = 'xyz' }
} {xyz}

do_test 3.5 {
  foreach b $blobs { close $b }
  execsql { SELECT * FROM t4 WHERE a = 'xyz' }
} {xyz}

# Check that recovery works on the WAL file.
#
forcedelete test.db2-wal test.db2
do_test 3.6 {
  copy_file test.db-wal test.db2-wal
  copy_file test.db test.db2
  sqlite3 db2 test.db2
  execsql { SELECT * FROM t4 WHERE a = 'xyz' } db2
} {xyz}

finish_test