Fix a case where a corrupt stat4 record could go unrecognized due to integer overflow.
[sqlite.git] / test / vacuum6.test
blobf80ff7546295ffb74afdd3661feabd87a529d958
1 # 2016-08-19
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11
12 # This file implements a test for VACUUM on attached databases.
14 # TESTRUNNER: slow
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix vacuum6
20 # If the VACUUM statement is disabled in the current build, skip all
21 # the tests in this file.
23 ifcapable !vacuum {
24   finish_test
25   return
29 do_execsql_test 1.0 {
30   CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
31   INSERT INTO t1 VALUES(1, 1);
32 } {}
34 do_execsql_test 1.1 {
35   VACUUM
38 reset_db
39 do_execsql_test 1.2 {
40   CREATE TABLE t1(x,b);
41   CREATE INDEX x1 ON t1(x);
42   CREATE INDEX x2 ON t1(x);
43   CREATE INDEX x3 ON t1(x);
44   INSERT INTO t1 SELECT 2,'';
45   VACUUM;
48 #-------------------------------------------------------------------------
50 reset_db
51 foreach {tn sz} {1 400 2 4000 3 9999} {
52   reset_db
53   do_execsql_test 2.$tn.1 {
54     CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
55     WITH s(i) AS (
56         SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
57     )
58     INSERT INTO t1 SELECT i, randomblob($sz) FROM s;
59   }
61   do_execsql_test 2.$tn.2 {
62     vacuum;
63   }
65   do_execsql_test 2.$tn.3 {
66     PRAGMA integrity_check;
67   } {ok}
70 reset_db
71 do_execsql_test 3.0 {
72   PRAGMA page_size = 1024;
73   CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
74   INSERT INTO t1 VALUES(2, randomblob(1200));
75 } {}
76 do_execsql_test 3.1 {
77   PRAGMA page_size = 512;
78   VACUUM;
80 do_execsql_test 3.2 {
81   PRAGMA integrity_check
82 } {ok}
84 #-------------------------------------------------------------------------
86 reset_db
87 do_execsql_test 4.0 {
88   CREATE TABLE tx(a, b);
89   CREATE INDEX i1 ON tx(b);
90   WITH s(i) AS (
91       SELECT 8000 UNION ALL SELECT i+1 FROM s WHERE i<10000
92   )
93   INSERT INTO tx SELECT i, randomblob(i) FROM s;
95   SELECT sum(length(b)) FROM tx;
96 } {18009000}
97 foreach {tn pgsz av} {
98   1 2048   0
99   2 1024   1
100   3 65536  0
101   4 8192   1
102   5 512    0
103   6 4096   1
104 } {
105   do_execsql_test 4.1.$tn.1 "
106     PRAGMA page_size = $pgsz;
107     PRAGMA auto_vacuum = $av;
108   "
109   do_execsql_test 4.1.$tn.2 VACUUM
110   integrity_check 4.1.$tn.3
113 finish_test