xref: /sqlite-3.40.0/test/pragma.test (revision ef4ac8f9)
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*ef4ac8f9Sdrh# $Id: pragma.test,v 1.13 2004/06/19 00:16:31 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
25*ef4ac8f9Sdrhset DB [sqlite3 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
46*ef4ac8f9Sdrh  sqlite3 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
83*ef4ac8f9Sdrh  sqlite3 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
111*ef4ac8f9Sdrh  set ::DB [sqlite3 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 {
1214303feedSdrh    PRAGMA synchronous=NORMAL;
1224303feedSdrh    PRAGMA cache_size;
1234303feedSdrh    PRAGMA default_cache_size;
1244303feedSdrh    PRAGMA synchronous;
1254303feedSdrh    PRAGMA default_synchronous;
1264303feedSdrh  }
1274303feedSdrh} {123 123 1 0}
1284303feedSdrhdo_test pragma-1.12 {
1294303feedSdrh  execsql {
1304303feedSdrh    PRAGMA synchronous=FULL;
1314303feedSdrh    PRAGMA cache_size;
1324303feedSdrh    PRAGMA default_cache_size;
1334303feedSdrh    PRAGMA synchronous;
1344303feedSdrh    PRAGMA default_synchronous;
1354303feedSdrh  }
1364303feedSdrh} {123 123 2 0}
1374303feedSdrhdo_test pragma-1.13 {
1384303feedSdrh  db close
139*ef4ac8f9Sdrh  set ::DB [sqlite3 db test.db]
1404303feedSdrh  execsql {
1414303feedSdrh    PRAGMA cache_size;
1424303feedSdrh    PRAGMA default_cache_size;
1434303feedSdrh    PRAGMA synchronous;
1444303feedSdrh    PRAGMA default_synchronous;
1454303feedSdrh  }
1464303feedSdrh} {123 123 0 0}
1474303feedSdrhdo_test pragma-1.14 {
1484303feedSdrh  execsql {
1494303feedSdrh    PRAGMA default_synchronous=FULL;
1504303feedSdrh    PRAGMA cache_size;
1514303feedSdrh    PRAGMA default_cache_size;
1524303feedSdrh    PRAGMA synchronous;
1534303feedSdrh    PRAGMA default_synchronous;
1544303feedSdrh  }
1554303feedSdrh} {123 123 2 2}
1564303feedSdrhdo_test pragma-1.15 {
1574303feedSdrh  db close
158*ef4ac8f9Sdrh  set ::DB [sqlite3 db test.db]
1594303feedSdrh  execsql {
1604303feedSdrh    PRAGMA cache_size;
1614303feedSdrh    PRAGMA default_cache_size;
1624303feedSdrh    PRAGMA synchronous;
1634303feedSdrh    PRAGMA default_synchronous;
1644303feedSdrh  }
1654303feedSdrh} {123 123 2 2}
1664303feedSdrh
167ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check
168ed717fe3Sdrh# pragma finds it.
169ed717fe3Sdrh#
170*ef4ac8f9Sdrhif {![sqlite3 -has-codec]} {
171ed717fe3Sdrhdo_test pragma-3.1 {
172ed717fe3Sdrh  execsql {
173ed717fe3Sdrh    BEGIN;
174ed717fe3Sdrh    CREATE TABLE t2(a,b,c);
175ed717fe3Sdrh    CREATE INDEX i2 ON t2(a);
176ed717fe3Sdrh    INSERT INTO t2 VALUES(11,2,3);
177ed717fe3Sdrh    INSERT INTO t2 VALUES(22,3,4);
178ed717fe3Sdrh    COMMIT;
179ed717fe3Sdrh    SELECT rowid, * from t2;
180ed717fe3Sdrh  }
181ed717fe3Sdrh} {1 11 2 3 2 22 3 4}
182ed717fe3Sdrhdo_test pragma-3.2 {
183ed717fe3Sdrh  set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}]
18496fc5fe6Sdanielk1977  set db [btree_open test.db 100 0]
185ed717fe3Sdrh  btree_begin_transaction $db
186ed717fe3Sdrh  set c [btree_cursor $db $rootpage 1]
187ed717fe3Sdrh  btree_first $c
188ed717fe3Sdrh  btree_delete $c
189ed717fe3Sdrh  btree_commit $db
190ed717fe3Sdrh  btree_close $db
191ed717fe3Sdrh  execsql {PRAGMA integrity_check}
1924be295beSdrh} {{rowid 1 missing from index i2} {wrong # of entries in index i2}}
1939eb9e26bSdrh}; # endif has-codec
1945a38705eSdrh
1951bdd9b57Sdrh# Test the temp_store and default_temp_store pragmas
1961bdd9b57Sdrh#
1971bdd9b57Sdrhdo_test pragma-4.2 {
1981bdd9b57Sdrh  execsql {
1991bdd9b57Sdrh    PRAGMA temp_store='default';
2001bdd9b57Sdrh    PRAGMA temp_store;
2011bdd9b57Sdrh  }
2021bdd9b57Sdrh} {0}
2031bdd9b57Sdrhdo_test pragma-4.3 {
2041bdd9b57Sdrh  execsql {
2051bdd9b57Sdrh    PRAGMA temp_store='file';
2061bdd9b57Sdrh    PRAGMA temp_store;
2071bdd9b57Sdrh  }
2081bdd9b57Sdrh} {1}
2091bdd9b57Sdrhdo_test pragma-4.4 {
2101bdd9b57Sdrh  execsql {
2111bdd9b57Sdrh    PRAGMA temp_store='memory';
2121bdd9b57Sdrh    PRAGMA temp_store;
2131bdd9b57Sdrh  }
2141bdd9b57Sdrh} {2}
2151bdd9b57Sdrhdo_test pragma-4.5 {
2161bdd9b57Sdrh  execsql {
2171bdd9b57Sdrh    PRAGMA default_temp_store='default';
2181bdd9b57Sdrh    PRAGMA default_temp_store;
2191bdd9b57Sdrh  }
2201bdd9b57Sdrh} {0}
2211bdd9b57Sdrhdo_test pragma-4.6 {
2221bdd9b57Sdrh  execsql {
2231bdd9b57Sdrh    PRAGMA temp_store;
2241bdd9b57Sdrh  }
2251bdd9b57Sdrh} {2}
2261bdd9b57Sdrhdo_test pragma-4.7 {
2271bdd9b57Sdrh  db close
228*ef4ac8f9Sdrh  sqlite3 db test.db
2291bdd9b57Sdrh  execsql {
2301bdd9b57Sdrh    PRAGMA temp_store;
2311bdd9b57Sdrh  }
2321bdd9b57Sdrh} {0}
2331bdd9b57Sdrhdo_test pragma-4.8 {
2341bdd9b57Sdrh  execsql {
2351bdd9b57Sdrh    PRAGMA default_temp_store;
2361bdd9b57Sdrh  }
2371bdd9b57Sdrh} {0}
2381bdd9b57Sdrhdo_test pragma-4.9 {
2391bdd9b57Sdrh  execsql {
2401bdd9b57Sdrh    PRAGMA default_temp_store='file';
2411bdd9b57Sdrh    PRAGMA default_temp_store;
2421bdd9b57Sdrh  }
2431bdd9b57Sdrh} {1}
2441bdd9b57Sdrhdo_test pragma-4.10 {
2451bdd9b57Sdrh  execsql {
2461bdd9b57Sdrh    PRAGMA temp_store;
2471bdd9b57Sdrh  }
2481bdd9b57Sdrh} {0}
2491bdd9b57Sdrhdo_test pragma-4.11 {
2501bdd9b57Sdrh  db close
251*ef4ac8f9Sdrh  sqlite3 db test.db
2521bdd9b57Sdrh  execsql {
2531bdd9b57Sdrh    PRAGMA temp_store;
2541bdd9b57Sdrh  }
2551bdd9b57Sdrh} {1}
2561bdd9b57Sdrhdo_test pragma-4.12 {
2571bdd9b57Sdrh  execsql {
2581bdd9b57Sdrh    PRAGMA default_temp_store;
2591bdd9b57Sdrh  }
2601bdd9b57Sdrh} {1}
2611bdd9b57Sdrhdo_test pragma-4.13 {
2621bdd9b57Sdrh  execsql {
2631bdd9b57Sdrh    PRAGMA default_temp_store='memory';
2641bdd9b57Sdrh    PRAGMA default_temp_store;
2651bdd9b57Sdrh  }
2661bdd9b57Sdrh} {2}
2671bdd9b57Sdrhdo_test pragma-4.14 {
2681bdd9b57Sdrh  execsql {
2691bdd9b57Sdrh    PRAGMA temp_store;
2701bdd9b57Sdrh  }
2711bdd9b57Sdrh} {1}
2721bdd9b57Sdrhdo_test pragma-4.15 {
2731bdd9b57Sdrh  db close
274*ef4ac8f9Sdrh  sqlite3 db test.db
2751bdd9b57Sdrh  execsql {
2761bdd9b57Sdrh    PRAGMA temp_store;
2771bdd9b57Sdrh  }
2781bdd9b57Sdrh} {2}
2791bdd9b57Sdrhdo_test pragma-4.16 {
2801bdd9b57Sdrh  execsql {
2811bdd9b57Sdrh    PRAGMA default_temp_store;
2821bdd9b57Sdrh  }
2831bdd9b57Sdrh} {2}
2841bdd9b57Sdrhdo_test pragma-4.17 {
2851bdd9b57Sdrh  execsql {
2861bdd9b57Sdrh    PRAGMA temp_store='file';
2871bdd9b57Sdrh    PRAGMA temp_store
2881bdd9b57Sdrh  }
2891bdd9b57Sdrh} {1}
2901bdd9b57Sdrhdo_test pragma-4.18 {
2911bdd9b57Sdrh  execsql {
2921bdd9b57Sdrh    PRAGMA default_temp_store
2931bdd9b57Sdrh  }
2941bdd9b57Sdrh} {2}
2951bdd9b57Sdrhdo_test pragma-4.19 {
2961bdd9b57Sdrh  db close
297*ef4ac8f9Sdrh  sqlite3 db test.db
2981bdd9b57Sdrh  execsql {
2991bdd9b57Sdrh    PRAGMA temp_store
3001bdd9b57Sdrh  }
3011bdd9b57Sdrh} {2}
3021bdd9b57Sdrh
3031bdd9b57Sdrh# Changing the TEMP_STORE deletes any existing temporary tables
3041bdd9b57Sdrh#
3051bdd9b57Sdrhdo_test pragma-4.20 {
3061bdd9b57Sdrh  execsql {SELECT name FROM sqlite_temp_master}
3071bdd9b57Sdrh} {}
3081bdd9b57Sdrhdo_test pragma-4.21 {
3091bdd9b57Sdrh  execsql {
3101bdd9b57Sdrh    CREATE TEMP TABLE test1(a,b,c);
3111bdd9b57Sdrh    SELECT name FROM sqlite_temp_master;
3121bdd9b57Sdrh  }
3131bdd9b57Sdrh} {test1}
3141bdd9b57Sdrhdo_test pragma-4.22 {
3151bdd9b57Sdrh  execsql {
3161bdd9b57Sdrh    PRAGMA temp_store='file';
3171bdd9b57Sdrh    SELECT name FROM sqlite_temp_master;
3181bdd9b57Sdrh  }
3191bdd9b57Sdrh} {}
3201bdd9b57Sdrhdo_test pragma-4.23 {
3211bdd9b57Sdrh  execsql {
3221bdd9b57Sdrh    CREATE TEMP TABLE test1(a,b,c);
3231bdd9b57Sdrh    SELECT name FROM sqlite_temp_master;
3241bdd9b57Sdrh  }
3251bdd9b57Sdrh} {test1}
3261bdd9b57Sdrhdo_test pragma-4.24 {
3271bdd9b57Sdrh  execsql {
3281bdd9b57Sdrh    PRAGMA temp_store='memory';
3291bdd9b57Sdrh    SELECT name FROM sqlite_temp_master;
3301bdd9b57Sdrh  }
3311bdd9b57Sdrh} {}
3321bdd9b57Sdrhdo_test pragma-4.25 {
3331bdd9b57Sdrh  catchsql {
3341bdd9b57Sdrh    BEGIN;
3351bdd9b57Sdrh    PRAGMA temp_store='default';
3361bdd9b57Sdrh    COMMIT;
3371bdd9b57Sdrh  }
3381bdd9b57Sdrh} {1 {temporary storage cannot be changed from within a transaction}}
3391bdd9b57Sdrhcatchsql {COMMIT}
3401bdd9b57Sdrh
341cd61c281Sdrhfinish_test
342