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