1cd61c281Sdrh# 2002 March 6 2cd61c281Sdrh# 3cd61c281Sdrh# The author disclaims copyright to this source code. In place of 4cd61c281Sdrh# a legal notice, here is a blessing: 5cd61c281Sdrh# 6cd61c281Sdrh# May you do good and not evil. 7cd61c281Sdrh# May you find forgiveness for yourself and forgive others. 8cd61c281Sdrh# May you share freely, never taking more than you give. 9cd61c281Sdrh# 10cd61c281Sdrh#*********************************************************************** 11cd61c281Sdrh# This file implements regression tests for SQLite library. 12cd61c281Sdrh# 13cd61c281Sdrh# This file implements tests for the PRAGMA command. 14cd61c281Sdrh# 15*4303feedSdrh# $Id: pragma.test,v 1.4 2003/02/15 23:09:17 drh Exp $ 16cd61c281Sdrh 17cd61c281Sdrhset testdir [file dirname $argv0] 18cd61c281Sdrhsource $testdir/tester.tcl 19cd61c281Sdrh 20cd61c281Sdrh# Delete the preexisting database to avoid the special setup 21cd61c281Sdrh# that the "all.test" script does. 22cd61c281Sdrh# 23cd61c281Sdrhdb close 24cd61c281Sdrhfile delete test.db 255a38705eSdrhset DB [sqlite db test.db] 26cd61c281Sdrh 27cd61c281Sdrhdo_test pragma-1.1 { 28cd61c281Sdrh execsql { 29cd61c281Sdrh PRAGMA cache_size; 30cd61c281Sdrh PRAGMA default_cache_size; 31cd61c281Sdrh PRAGMA synchronous; 32cd61c281Sdrh PRAGMA default_synchronous; 33cd61c281Sdrh } 34cd61c281Sdrh} {2000 2000 1 1} 35cd61c281Sdrhdo_test pragma-1.2 { 36cd61c281Sdrh execsql { 37cd61c281Sdrh PRAGMA cache_size=1234; 38cd61c281Sdrh PRAGMA cache_size; 39cd61c281Sdrh PRAGMA default_cache_size; 40cd61c281Sdrh PRAGMA synchronous; 41cd61c281Sdrh PRAGMA default_synchronous; 42cd61c281Sdrh } 43cd61c281Sdrh} {1234 2000 1 1} 44cd61c281Sdrhdo_test pragma-1.3 { 45cd61c281Sdrh db close 46cd61c281Sdrh sqlite db test.db 47cd61c281Sdrh execsql { 48cd61c281Sdrh PRAGMA cache_size; 49cd61c281Sdrh PRAGMA default_cache_size; 50cd61c281Sdrh PRAGMA synchronous; 51cd61c281Sdrh PRAGMA default_synchronous; 52cd61c281Sdrh } 53cd61c281Sdrh} {2000 2000 1 1} 54cd61c281Sdrhdo_test pragma-1.4 { 55cd61c281Sdrh execsql { 56cd61c281Sdrh PRAGMA synchronous=OFF; 57cd61c281Sdrh PRAGMA cache_size; 58cd61c281Sdrh PRAGMA default_cache_size; 59cd61c281Sdrh PRAGMA synchronous; 60cd61c281Sdrh PRAGMA default_synchronous; 61cd61c281Sdrh } 62cd61c281Sdrh} {2000 2000 0 1} 63cd61c281Sdrhdo_test pragma-1.5 { 64cd61c281Sdrh execsql { 65cd61c281Sdrh PRAGMA cache_size=4321; 66cd61c281Sdrh PRAGMA cache_size; 67cd61c281Sdrh PRAGMA default_cache_size; 68cd61c281Sdrh PRAGMA synchronous; 69cd61c281Sdrh PRAGMA default_synchronous; 70cd61c281Sdrh } 71cd61c281Sdrh} {4321 2000 0 1} 72cd61c281Sdrhdo_test pragma-1.6 { 73cd61c281Sdrh execsql { 74cd61c281Sdrh PRAGMA synchronous=ON; 75cd61c281Sdrh PRAGMA cache_size; 76cd61c281Sdrh PRAGMA default_cache_size; 77cd61c281Sdrh PRAGMA synchronous; 78cd61c281Sdrh PRAGMA default_synchronous; 79cd61c281Sdrh } 80cd61c281Sdrh} {4321 2000 1 1} 81cd61c281Sdrhdo_test pragma-1.7 { 82cd61c281Sdrh db close 83cd61c281Sdrh sqlite db test.db 84cd61c281Sdrh execsql { 85cd61c281Sdrh PRAGMA cache_size; 86cd61c281Sdrh PRAGMA default_cache_size; 87cd61c281Sdrh PRAGMA synchronous; 88cd61c281Sdrh PRAGMA default_synchronous; 89cd61c281Sdrh } 90cd61c281Sdrh} {2000 2000 1 1} 91cd61c281Sdrhdo_test pragma-1.8 { 92cd61c281Sdrh execsql { 93cd61c281Sdrh PRAGMA default_synchronous=OFF; 94cd61c281Sdrh PRAGMA cache_size; 95cd61c281Sdrh PRAGMA default_cache_size; 96cd61c281Sdrh PRAGMA synchronous; 97cd61c281Sdrh PRAGMA default_synchronous; 98cd61c281Sdrh } 99cd61c281Sdrh} {2000 2000 0 0} 100cd61c281Sdrhdo_test pragma-1.9 { 101cd61c281Sdrh execsql { 102cd61c281Sdrh PRAGMA default_cache_size=123; 103cd61c281Sdrh PRAGMA cache_size; 104cd61c281Sdrh PRAGMA default_cache_size; 105cd61c281Sdrh PRAGMA synchronous; 106cd61c281Sdrh PRAGMA default_synchronous; 107cd61c281Sdrh } 108cd61c281Sdrh} {123 123 0 0} 109cd61c281Sdrhdo_test pragma-1.10 { 110cd61c281Sdrh db close 1115a38705eSdrh set ::DB [sqlite db test.db] 112cd61c281Sdrh execsql { 113cd61c281Sdrh PRAGMA cache_size; 114cd61c281Sdrh PRAGMA default_cache_size; 115cd61c281Sdrh PRAGMA synchronous; 116cd61c281Sdrh PRAGMA default_synchronous; 117cd61c281Sdrh } 118cd61c281Sdrh} {123 123 0 0} 1195a38705eSdrhdo_test pragma-1.11 { 1205a38705eSdrh execsql { 121*4303feedSdrh PRAGMA synchronous=NORMAL; 122*4303feedSdrh PRAGMA cache_size; 123*4303feedSdrh PRAGMA default_cache_size; 124*4303feedSdrh PRAGMA synchronous; 125*4303feedSdrh PRAGMA default_synchronous; 126*4303feedSdrh } 127*4303feedSdrh} {123 123 1 0} 128*4303feedSdrhdo_test pragma-1.12 { 129*4303feedSdrh execsql { 130*4303feedSdrh PRAGMA synchronous=FULL; 131*4303feedSdrh PRAGMA cache_size; 132*4303feedSdrh PRAGMA default_cache_size; 133*4303feedSdrh PRAGMA synchronous; 134*4303feedSdrh PRAGMA default_synchronous; 135*4303feedSdrh } 136*4303feedSdrh} {123 123 2 0} 137*4303feedSdrhdo_test pragma-1.13 { 138*4303feedSdrh db close 139*4303feedSdrh set ::DB [sqlite db test.db] 140*4303feedSdrh execsql { 141*4303feedSdrh PRAGMA cache_size; 142*4303feedSdrh PRAGMA default_cache_size; 143*4303feedSdrh PRAGMA synchronous; 144*4303feedSdrh PRAGMA default_synchronous; 145*4303feedSdrh } 146*4303feedSdrh} {123 123 0 0} 147*4303feedSdrhdo_test pragma-1.14 { 148*4303feedSdrh execsql { 149*4303feedSdrh PRAGMA default_synchronous=FULL; 150*4303feedSdrh PRAGMA cache_size; 151*4303feedSdrh PRAGMA default_cache_size; 152*4303feedSdrh PRAGMA synchronous; 153*4303feedSdrh PRAGMA default_synchronous; 154*4303feedSdrh } 155*4303feedSdrh} {123 123 2 2} 156*4303feedSdrhdo_test pragma-1.15 { 157*4303feedSdrh db close 158*4303feedSdrh set ::DB [sqlite db test.db] 159*4303feedSdrh execsql { 160*4303feedSdrh PRAGMA cache_size; 161*4303feedSdrh PRAGMA default_cache_size; 162*4303feedSdrh PRAGMA synchronous; 163*4303feedSdrh PRAGMA default_synchronous; 164*4303feedSdrh } 165*4303feedSdrh} {123 123 2 2} 166*4303feedSdrh 167*4303feedSdrhdo_test pragma-2.1 { 168*4303feedSdrh execsql { 1695a38705eSdrh PRAGMA show_datatypes=on; 1705a38705eSdrh PRAGMA empty_result_callbacks=off; 1715a38705eSdrh } 1725a38705eSdrh sqlite_datatypes $::DB {SELECT * FROM sqlite_master} 1735a38705eSdrh} {} 174*4303feedSdrhdo_test pragma-2.2 { 1755a38705eSdrh execsql { 1765a38705eSdrh PRAGMA empty_result_callbacks=on; 1775a38705eSdrh } 1785a38705eSdrh sqlite_datatypes $::DB {SELECT * FROM sqlite_master} 179fcb78a49Sdrh} {text text text integer text} 180*4303feedSdrhdo_test pragma-2.3 { 1815a38705eSdrh execsql { 1825a38705eSdrh CREATE TABLE t1( 1835a38705eSdrh a INTEGER, 1845a38705eSdrh b TEXT, 1855a38705eSdrh c WHATEVER, 1865a38705eSdrh d CLOB, 1875a38705eSdrh e BLOB, 1885a38705eSdrh f VARCHAR(123), 1895a38705eSdrh g nVaRcHaR(432) 1905a38705eSdrh ); 1915a38705eSdrh } 1925a38705eSdrh sqlite_datatypes $::DB {SELECT * FROM t1} 193fcb78a49Sdrh} {INTEGER TEXT WHATEVER CLOB BLOB VARCHAR(123) nVaRcHaR(432)} 194*4303feedSdrhdo_test pragma-2.4 { 1955a38705eSdrh sqlite_datatypes $::DB { 1965a38705eSdrh SELECT 1, 'hello', NULL 1975a38705eSdrh } 1985a38705eSdrh} {NUMERIC TEXT TEXT} 199*4303feedSdrhdo_test pragma-2.5 { 2005a38705eSdrh sqlite_datatypes $::DB { 2015a38705eSdrh SELECT 1+2 AS X, 'hello' || 5 AS Y, NULL AS Z 2025a38705eSdrh } 2035a38705eSdrh} {NUMERIC TEXT TEXT} 204*4303feedSdrhdo_test pragma-2.6 { 205fcb78a49Sdrh execsql { 206fcb78a49Sdrh CREATE VIEW v1 AS SELECT a+b, b||c, * FROM t1; 207fcb78a49Sdrh } 208fcb78a49Sdrh sqlite_datatypes $::DB {SELECT * FROM v1} 209fcb78a49Sdrh} {NUMERIC TEXT INTEGER TEXT WHATEVER CLOB BLOB VARCHAR(123) nVaRcHaR(432)} 210*4303feedSdrhdo_test pragma-2.7 { 211fcb78a49Sdrh sqlite_datatypes $::DB { 212fcb78a49Sdrh SELECT d,e FROM t1 UNION SELECT a,c FROM t1 213fcb78a49Sdrh } 214fcb78a49Sdrh} {INTEGER WHATEVER} 215*4303feedSdrhdo_test pragma-2.8 { 216fcb78a49Sdrh sqlite_datatypes $::DB { 217fcb78a49Sdrh SELECT d,e FROM t1 EXCEPT SELECT c,e FROM t1 218fcb78a49Sdrh } 219fcb78a49Sdrh} {WHATEVER BLOB} 220*4303feedSdrhdo_test pragma-2.9 { 221fcb78a49Sdrh sqlite_datatypes $::DB { 222fcb78a49Sdrh SELECT d,e FROM t1 INTERSECT SELECT c,e FROM t1 223fcb78a49Sdrh } 224fcb78a49Sdrh} {WHATEVER BLOB} 225*4303feedSdrhdo_test pragma-2.10 { 226fcb78a49Sdrh sqlite_datatypes $::DB { 227fcb78a49Sdrh SELECT d,e FROM t1 INTERSECT SELECT c,e FROM v1 228fcb78a49Sdrh } 229fcb78a49Sdrh} {WHATEVER BLOB} 230fcb78a49Sdrh 2315a38705eSdrh 2325a38705eSdrh 233cd61c281Sdrhfinish_test 234