15bb7ffe1Sdrh# 2004 September 2 25bb7ffe1Sdrh# 35bb7ffe1Sdrh# The author disclaims copyright to this source code. In place of 45bb7ffe1Sdrh# a legal notice, here is a blessing: 55bb7ffe1Sdrh# 65bb7ffe1Sdrh# May you do good and not evil. 75bb7ffe1Sdrh# May you find forgiveness for yourself and forgive others. 85bb7ffe1Sdrh# May you share freely, never taking more than you give. 95bb7ffe1Sdrh# 105bb7ffe1Sdrh#*********************************************************************** 115bb7ffe1Sdrh# This file implements regression tests for SQLite library. 125bb7ffe1Sdrh# This file implements tests for the page_size PRAGMA. 135bb7ffe1Sdrh# 147426f864Sdrh# $Id: pagesize.test,v 1.13 2008/08/26 21:07:27 drh Exp $ 155bb7ffe1Sdrh 165bb7ffe1Sdrh 175bb7ffe1Sdrhset testdir [file dirname $argv0] 185bb7ffe1Sdrhsource $testdir/tester.tcl 195bb7ffe1Sdrh 20c7b4a44cSdanielk1977# This test script depends entirely on "PRAGMA page_size". So if this 21c7b4a44cSdanielk1977# pragma is not available, omit the whole file. 22c7b4a44cSdanielk1977ifcapable !pager_pragmas { 23c7b4a44cSdanielk1977 finish_test 24c7b4a44cSdanielk1977 return 25c7b4a44cSdanielk1977} 26c7b4a44cSdanielk1977 275bb7ffe1Sdrhdo_test pagesize-1.1 { 285bb7ffe1Sdrh execsql {PRAGMA page_size} 295bb7ffe1Sdrh} 1024 306bf89570Sdrhifcapable {explain} { 315bb7ffe1Sdrh do_test pagesize-1.2 { 325bb7ffe1Sdrh catch {execsql {EXPLAIN PRAGMA page_size}} 335bb7ffe1Sdrh } 0 346bf89570Sdrh} 355bb7ffe1Sdrhdo_test pagesize-1.3 { 365bb7ffe1Sdrh execsql { 375bb7ffe1Sdrh CREATE TABLE t1(a); 385bb7ffe1Sdrh PRAGMA page_size=2048; 395bb7ffe1Sdrh PRAGMA page_size; 405bb7ffe1Sdrh } 415bb7ffe1Sdrh} 1024 42f2a611c9Sdrh 435bb7ffe1Sdrhdo_test pagesize-1.4 { 445bb7ffe1Sdrh db close 45fda06befSmistachkin forcedelete test.db 465bb7ffe1Sdrh sqlite3 db test.db 475bb7ffe1Sdrh execsql { 48f2a611c9Sdrh PRAGMA page_size=511; 495bb7ffe1Sdrh PRAGMA page_size; 505bb7ffe1Sdrh } 51f2a611c9Sdrh} 1024 525bb7ffe1Sdrhdo_test pagesize-1.5 { 53f2a611c9Sdrh execsql { 54f2a611c9Sdrh PRAGMA page_size=512; 55f2a611c9Sdrh PRAGMA page_size; 56f2a611c9Sdrh } 57f2a611c9Sdrh} 512 581e9daa6aSdrhif {![info exists SQLITE_MAX_PAGE_SIZE] || $SQLITE_MAX_PAGE_SIZE>=8192} { 59f2a611c9Sdrh do_test pagesize-1.6 { 60f2a611c9Sdrh execsql { 61f2a611c9Sdrh PRAGMA page_size=8192; 62f2a611c9Sdrh PRAGMA page_size; 63f2a611c9Sdrh } 64f2a611c9Sdrh } 8192 65f2a611c9Sdrh do_test pagesize-1.7 { 66f2a611c9Sdrh execsql { 67f2a611c9Sdrh PRAGMA page_size=65537; 68f2a611c9Sdrh PRAGMA page_size; 69f2a611c9Sdrh } 70f2a611c9Sdrh } 8192 7106f50217Sdrh do_test pagesize-1.8 { 7206f50217Sdrh execsql { 7306f50217Sdrh PRAGMA page_size=1234; 7406f50217Sdrh PRAGMA page_size 7506f50217Sdrh } 7606f50217Sdrh } 8192 771e9daa6aSdrh} 7806f50217Sdrhforeach PGSZ {512 2048 4096 8192} { 791e9daa6aSdrh if {[info exists SQLITE_MAX_PAGE_SIZE] 801e9daa6aSdrh && $SQLITE_MAX_PAGE_SIZE<$PGSZ} continue 813bdca9c9Sdanielk1977 ifcapable memorydb { 827426f864Sdrh do_test pagesize-2.$PGSZ.0.1 { 831c7880e5Sdrh db close 841c7880e5Sdrh sqlite3 db :memory: 851c7880e5Sdrh execsql "PRAGMA page_size=$PGSZ;" 861c7880e5Sdrh execsql {PRAGMA page_size} 877426f864Sdrh } $PGSZ 887426f864Sdrh do_test pagesize-2.$PGSZ.0.2 { 897426f864Sdrh execsql {CREATE TABLE t1(x UNIQUE, y UNIQUE, z UNIQUE)} 907426f864Sdrh execsql {PRAGMA page_size} 917426f864Sdrh } $PGSZ 927426f864Sdrh do_test pagesize-2.$PGSZ.0.3 { 937426f864Sdrh execsql { 947426f864Sdrh INSERT INTO t1 VALUES(1,2,3); 957426f864Sdrh INSERT INTO t1 VALUES(2,3,4); 967426f864Sdrh SELECT * FROM t1; 977426f864Sdrh } 987426f864Sdrh } {1 2 3 2 3 4} 993bdca9c9Sdanielk1977 } 100f2a611c9Sdrh do_test pagesize-2.$PGSZ.1 { 101f2a611c9Sdrh db close 102fda06befSmistachkin forcedelete test.db 103f2a611c9Sdrh sqlite3 db test.db 104f2a611c9Sdrh execsql "PRAGMA page_size=$PGSZ" 105f2a611c9Sdrh execsql { 106f2a611c9Sdrh CREATE TABLE t1(x); 107f2a611c9Sdrh PRAGMA page_size; 108f2a611c9Sdrh } 109f2a611c9Sdrh } $PGSZ 110f2a611c9Sdrh do_test pagesize-2.$PGSZ.2 { 1115bb7ffe1Sdrh db close 1125bb7ffe1Sdrh sqlite3 db test.db 1135bb7ffe1Sdrh execsql { 1145bb7ffe1Sdrh PRAGMA page_size 1155bb7ffe1Sdrh } 116f2a611c9Sdrh } $PGSZ 117f2a611c9Sdrh do_test pagesize-2.$PGSZ.3 { 1185bb7ffe1Sdrh file size test.db 11945901d62Sdanielk1977 } [expr {$PGSZ*($AUTOVACUUM?3:2)}] 120798da52cSdrh ifcapable {vacuum} { 121f2a611c9Sdrh do_test pagesize-2.$PGSZ.4 { 122f2a611c9Sdrh execsql {VACUUM} 123f2a611c9Sdrh } {} 124798da52cSdrh } 125f2a611c9Sdrh integrity_check pagesize-2.$PGSZ.5 126f2a611c9Sdrh do_test pagesize-2.$PGSZ.6 { 127f2a611c9Sdrh db close 128f2a611c9Sdrh sqlite3 db test.db 129f2a611c9Sdrh execsql {PRAGMA page_size} 130f2a611c9Sdrh } $PGSZ 131f2a611c9Sdrh do_test pagesize-2.$PGSZ.7 { 132f2a611c9Sdrh execsql { 133f2a611c9Sdrh INSERT INTO t1 VALUES(randstr(10,9000)); 134f2a611c9Sdrh INSERT INTO t1 VALUES(randstr(10,9000)); 135f2a611c9Sdrh INSERT INTO t1 VALUES(randstr(10,9000)); 136f2a611c9Sdrh BEGIN; 137f2a611c9Sdrh INSERT INTO t1 SELECT x||x FROM t1; 138f2a611c9Sdrh INSERT INTO t1 SELECT x||x FROM t1; 139f2a611c9Sdrh INSERT INTO t1 SELECT x||x FROM t1; 140f2a611c9Sdrh INSERT INTO t1 SELECT x||x FROM t1; 141f2a611c9Sdrh SELECT count(*) FROM t1; 142f2a611c9Sdrh } 143f2a611c9Sdrh } 48 144f2a611c9Sdrh do_test pagesize-2.$PGSZ.8 { 145f2a611c9Sdrh execsql { 146f2a611c9Sdrh ROLLBACK; 147f2a611c9Sdrh SELECT count(*) FROM t1; 148f2a611c9Sdrh } 149f2a611c9Sdrh } 3 150f2a611c9Sdrh integrity_check pagesize-2.$PGSZ.9 151f2a611c9Sdrh do_test pagesize-2.$PGSZ.10 { 152f2a611c9Sdrh db close 153f2a611c9Sdrh sqlite3 db test.db 154f2a611c9Sdrh execsql {PRAGMA page_size} 155f2a611c9Sdrh } $PGSZ 156f2a611c9Sdrh do_test pagesize-2.$PGSZ.11 { 157f2a611c9Sdrh execsql { 158f2a611c9Sdrh INSERT INTO t1 SELECT x||x FROM t1; 159f2a611c9Sdrh INSERT INTO t1 SELECT x||x FROM t1; 160f2a611c9Sdrh INSERT INTO t1 SELECT x||x FROM t1; 161f2a611c9Sdrh INSERT INTO t1 SELECT x||x FROM t1; 162f2a611c9Sdrh INSERT INTO t1 SELECT x||x FROM t1; 163f2a611c9Sdrh INSERT INTO t1 SELECT x||x FROM t1; 164f2a611c9Sdrh SELECT count(*) FROM t1; 165f2a611c9Sdrh } 166f2a611c9Sdrh } 192 167f2a611c9Sdrh do_test pagesize-2.$PGSZ.12 { 168f2a611c9Sdrh execsql { 169f2a611c9Sdrh BEGIN; 170f2a611c9Sdrh DELETE FROM t1 WHERE rowid%5!=0; 171f2a611c9Sdrh SELECT count(*) FROM t1; 172f2a611c9Sdrh } 173f2a611c9Sdrh } 38 174f2a611c9Sdrh do_test pagesize-2.$PGSZ.13 { 175f2a611c9Sdrh execsql { 176f2a611c9Sdrh ROLLBACK; 177f2a611c9Sdrh SELECT count(*) FROM t1; 178f2a611c9Sdrh } 179f2a611c9Sdrh } 192 180f2a611c9Sdrh integrity_check pagesize-2.$PGSZ.14 181f2a611c9Sdrh do_test pagesize-2.$PGSZ.15 { 182798da52cSdrh execsql {DELETE FROM t1 WHERE rowid%5!=0} 183798da52cSdrh ifcapable {vacuum} {execsql VACUUM} 184798da52cSdrh execsql {SELECT count(*) FROM t1} 185f2a611c9Sdrh } 38 186f2a611c9Sdrh do_test pagesize-2.$PGSZ.16 { 187798da52cSdrh execsql {DROP TABLE t1} 188798da52cSdrh ifcapable {vacuum} {execsql VACUUM} 189f2a611c9Sdrh } {} 190f2a611c9Sdrh integrity_check pagesize-2.$PGSZ.17 19110a76c90Sdrh 19210a76c90Sdrh db close 193fda06befSmistachkin forcedelete test.db 19410a76c90Sdrh sqlite3 db test.db 19510a76c90Sdrh do_test pagesize-2.$PGSZ.30 { 19610a76c90Sdrh execsql " 19710a76c90Sdrh CREATE TABLE t1(x); 19810a76c90Sdrh PRAGMA temp.page_size=$PGSZ; 19910a76c90Sdrh CREATE TEMP TABLE t2(y); 20010a76c90Sdrh PRAGMA main.page_size; 20110a76c90Sdrh PRAGMA temp.page_size; 20210a76c90Sdrh " 20310a76c90Sdrh } [list 1024 $PGSZ] 20410a76c90Sdrh 20510a76c90Sdrh db close 206fda06befSmistachkin forcedelete test.db 20710a76c90Sdrh sqlite3 db test.db 20810a76c90Sdrh do_test pagesize-2.$PGSZ.40 { 20910a76c90Sdrh execsql " 21010a76c90Sdrh PRAGMA page_size=$PGSZ; 21110a76c90Sdrh CREATE TABLE t1(x); 21210a76c90Sdrh CREATE TEMP TABLE t2(y); 21310a76c90Sdrh PRAGMA main.page_size; 21410a76c90Sdrh PRAGMA temp.page_size; 21510a76c90Sdrh " 21610a76c90Sdrh } [list $PGSZ $PGSZ] 217f2a611c9Sdrh} 2185bb7ffe1Sdrh 219*dd14ecbcSdanreset_db 220*dd14ecbcSdando_execsql_test pagesize-3.1 { 221*dd14ecbcSdan BEGIN; 222*dd14ecbcSdan SELECT * FROM sqlite_master; 223*dd14ecbcSdan PRAGMA page_size=2048; 224*dd14ecbcSdan PRAGMA main.page_size; 225*dd14ecbcSdan} {1024} 226*dd14ecbcSdando_execsql_test pagesize-3.2 { 227*dd14ecbcSdan CREATE TABLE t1(x); 228*dd14ecbcSdan COMMIT; 229*dd14ecbcSdan} 230*dd14ecbcSdando_execsql_test pagesize-3.3 { 231*dd14ecbcSdan BEGIN; 232*dd14ecbcSdan PRAGMA page_size = 2048; 233*dd14ecbcSdan COMMIT; 234*dd14ecbcSdan PRAGMA main.page_size; 235*dd14ecbcSdan} {1024} 236*dd14ecbcSdan 2375bb7ffe1Sdrhfinish_test 238