xref: /sqlite-3.40.0/test/pagesize.test (revision 4dcbdbff)
1# 2004 September 2
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.
12# This file implements tests for the page_size PRAGMA.
13#
14# $Id: pagesize.test,v 1.10 2005/05/20 20:01:56 drh Exp $
15
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20# This test script depends entirely on "PRAGMA page_size". So if this
21# pragma is not available, omit the whole file.
22ifcapable !pager_pragmas {
23  finish_test
24  return
25}
26
27do_test pagesize-1.1 {
28  execsql {PRAGMA page_size}
29} 1024
30ifcapable {explain} {
31  do_test pagesize-1.2 {
32    catch {execsql {EXPLAIN PRAGMA page_size}}
33  } 0
34}
35do_test pagesize-1.3 {
36  execsql {
37    CREATE TABLE t1(a);
38    PRAGMA page_size=2048;
39    PRAGMA page_size;
40  }
41} 1024
42
43do_test pagesize-1.4 {
44  db close
45  file delete -force test.db
46  sqlite3 db test.db
47  execsql {
48    PRAGMA page_size=511;
49    PRAGMA page_size;
50  }
51} 1024
52do_test pagesize-1.5 {
53  execsql {
54    PRAGMA page_size=512;
55    PRAGMA page_size;
56  }
57} 512
58do_test pagesize-1.6 {
59  execsql {
60    PRAGMA page_size=8192;
61    PRAGMA page_size;
62  }
63} 8192
64do_test pagesize-1.7 {
65  execsql {
66    PRAGMA page_size=65537;
67    PRAGMA page_size;
68  }
69} 8192
70do_test pagesize-1.8 {
71  execsql {
72    PRAGMA page_size=1234;
73    PRAGMA page_size
74  }
75} 8192
76
77foreach PGSZ {512 2048 4096 8192} {
78  do_test pagesize-2.$PGSZ.0 {
79    db close
80    sqlite3 db :memory:
81    execsql "PRAGMA page_size=$PGSZ;"
82    execsql {PRAGMA page_size}
83  } 1024
84  do_test pagesize-2.$PGSZ.1 {
85    db close
86    file delete -force test.db
87    sqlite3 db test.db
88    execsql "PRAGMA page_size=$PGSZ"
89    execsql {
90      CREATE TABLE t1(x);
91      PRAGMA page_size;
92    }
93  } $PGSZ
94  do_test pagesize-2.$PGSZ.2 {
95    db close
96    sqlite3 db test.db
97    execsql {
98      PRAGMA page_size
99    }
100  } $PGSZ
101  do_test pagesize-2.$PGSZ.3 {
102    file size test.db
103  } [expr {$PGSZ*($AUTOVACUUM?3:2)}]
104  ifcapable {vacuum} {
105    do_test pagesize-2.$PGSZ.4 {
106      execsql {VACUUM}
107    } {}
108  }
109  integrity_check pagesize-2.$PGSZ.5
110  do_test pagesize-2.$PGSZ.6 {
111    db close
112    sqlite3 db test.db
113    execsql {PRAGMA page_size}
114  } $PGSZ
115  do_test pagesize-2.$PGSZ.7 {
116    execsql {
117      INSERT INTO t1 VALUES(randstr(10,9000));
118      INSERT INTO t1 VALUES(randstr(10,9000));
119      INSERT INTO t1 VALUES(randstr(10,9000));
120      BEGIN;
121      INSERT INTO t1 SELECT x||x FROM t1;
122      INSERT INTO t1 SELECT x||x FROM t1;
123      INSERT INTO t1 SELECT x||x FROM t1;
124      INSERT INTO t1 SELECT x||x FROM t1;
125      SELECT count(*) FROM t1;
126    }
127  } 48
128  do_test pagesize-2.$PGSZ.8 {
129    execsql {
130      ROLLBACK;
131      SELECT count(*) FROM t1;
132    }
133  } 3
134  integrity_check pagesize-2.$PGSZ.9
135  do_test pagesize-2.$PGSZ.10 {
136    db close
137    sqlite3 db test.db
138    execsql {PRAGMA page_size}
139  } $PGSZ
140  do_test pagesize-2.$PGSZ.11 {
141    execsql {
142      INSERT INTO t1 SELECT x||x FROM t1;
143      INSERT INTO t1 SELECT x||x FROM t1;
144      INSERT INTO t1 SELECT x||x FROM t1;
145      INSERT INTO t1 SELECT x||x FROM t1;
146      INSERT INTO t1 SELECT x||x FROM t1;
147      INSERT INTO t1 SELECT x||x FROM t1;
148      SELECT count(*) FROM t1;
149    }
150  } 192
151  do_test pagesize-2.$PGSZ.12 {
152    execsql {
153      BEGIN;
154      DELETE FROM t1 WHERE rowid%5!=0;
155      SELECT count(*) FROM t1;
156    }
157  } 38
158  do_test pagesize-2.$PGSZ.13 {
159    execsql {
160      ROLLBACK;
161      SELECT count(*) FROM t1;
162    }
163  } 192
164  integrity_check pagesize-2.$PGSZ.14
165  do_test pagesize-2.$PGSZ.15 {
166    execsql {DELETE FROM t1 WHERE rowid%5!=0}
167    ifcapable {vacuum} {execsql VACUUM}
168    execsql {SELECT count(*) FROM t1}
169  } 38
170  do_test pagesize-2.$PGSZ.16 {
171    execsql {DROP TABLE t1}
172    ifcapable {vacuum} {execsql VACUUM}
173  } {}
174  integrity_check pagesize-2.$PGSZ.17
175}
176
177finish_test
178