xref: /sqlite-3.40.0/test/pragma.test (revision 1e9daa6a)
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*1e9daa6aSdrh# $Id: pragma.test,v 1.53 2007/04/06 21:42:22 drh Exp $
16cd61c281Sdrh
17cd61c281Sdrhset testdir [file dirname $argv0]
18cd61c281Sdrhsource $testdir/tester.tcl
19cd61c281Sdrh
2091cf71b0Sdanielk1977# Test organization:
2191cf71b0Sdanielk1977#
2291cf71b0Sdanielk1977# pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
2391cf71b0Sdanielk1977# pragma-2.*: Test synchronous on attached db.
2491cf71b0Sdanielk1977# pragma-3.*: Test detection of table/index inconsistency by integrity_check.
2591cf71b0Sdanielk1977# pragma-4.*: Test cache_size and default_cache_size on attached db.
2691cf71b0Sdanielk1977# pragma-5.*: Test that pragma synchronous may not be used inside of a
2791cf71b0Sdanielk1977#             transaction.
28cc6bd383Sdanielk1977# pragma-6.*: Test schema-query pragmas.
29cc6bd383Sdanielk1977# pragma-7.*: Miscellaneous tests.
30cc6bd383Sdanielk1977# pragma-8.*: Test user_version and schema_version pragmas.
319a09a3caStpoindex# pragma-9.*: Test temp_store and temp_store_directory.
32cc6bd383Sdanielk1977# pragma-10.*: Test the count_changes pragma in the presence of triggers.
3348af65aeSdanielk1977# pragma-11.*: Test the collation_list pragma.
3491cf71b0Sdanielk1977#
3591cf71b0Sdanielk1977
3605a82983Sdrhifcapable !pragma {
3705a82983Sdrh  finish_test
3805a82983Sdrh  return
3905a82983Sdrh}
4005a82983Sdrh
41cd61c281Sdrh# Delete the preexisting database to avoid the special setup
42cd61c281Sdrh# that the "all.test" script does.
43cd61c281Sdrh#
44cd61c281Sdrhdb close
4525403650Sdrhfile delete test.db test.db-journal
4625403650Sdrhfile delete test3.db test3.db-journal
47dddca286Sdrhsqlite3 db test.db; set DB [sqlite3_connection_pointer db]
48cd61c281Sdrh
49*1e9daa6aSdrh
50c7b4a44cSdanielk1977ifcapable pager_pragmas {
51*1e9daa6aSdrhset DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}]
52*1e9daa6aSdrhset TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}]
53cd61c281Sdrhdo_test pragma-1.1 {
54cd61c281Sdrh  execsql {
55cd61c281Sdrh    PRAGMA cache_size;
56cd61c281Sdrh    PRAGMA default_cache_size;
57cd61c281Sdrh    PRAGMA synchronous;
58cd61c281Sdrh  }
59*1e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
60cd61c281Sdrhdo_test pragma-1.2 {
61cd61c281Sdrh  execsql {
62eb43e5c7Sdrh    PRAGMA synchronous=OFF;
63cd61c281Sdrh    PRAGMA cache_size=1234;
64cd61c281Sdrh    PRAGMA cache_size;
65cd61c281Sdrh    PRAGMA default_cache_size;
66cd61c281Sdrh    PRAGMA synchronous;
67cd61c281Sdrh  }
68*1e9daa6aSdrh} [list 1234 $DFLT_CACHE_SZ 0]
69cd61c281Sdrhdo_test pragma-1.3 {
70cd61c281Sdrh  db close
71ef4ac8f9Sdrh  sqlite3 db test.db
72cd61c281Sdrh  execsql {
73cd61c281Sdrh    PRAGMA cache_size;
74cd61c281Sdrh    PRAGMA default_cache_size;
75cd61c281Sdrh    PRAGMA synchronous;
76cd61c281Sdrh  }
77*1e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
78cd61c281Sdrhdo_test pragma-1.4 {
79cd61c281Sdrh  execsql {
80cd61c281Sdrh    PRAGMA synchronous=OFF;
81cd61c281Sdrh    PRAGMA cache_size;
82cd61c281Sdrh    PRAGMA default_cache_size;
83cd61c281Sdrh    PRAGMA synchronous;
84cd61c281Sdrh  }
85*1e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0]
86cd61c281Sdrhdo_test pragma-1.5 {
87cd61c281Sdrh  execsql {
88cd61c281Sdrh    PRAGMA cache_size=4321;
89cd61c281Sdrh    PRAGMA cache_size;
90cd61c281Sdrh    PRAGMA default_cache_size;
91cd61c281Sdrh    PRAGMA synchronous;
92cd61c281Sdrh  }
93*1e9daa6aSdrh} [list 4321 $DFLT_CACHE_SZ 0]
94cd61c281Sdrhdo_test pragma-1.6 {
95cd61c281Sdrh  execsql {
96cd61c281Sdrh    PRAGMA synchronous=ON;
97cd61c281Sdrh    PRAGMA cache_size;
98cd61c281Sdrh    PRAGMA default_cache_size;
99cd61c281Sdrh    PRAGMA synchronous;
100cd61c281Sdrh  }
101*1e9daa6aSdrh} [list 4321 $DFLT_CACHE_SZ 1]
102cd61c281Sdrhdo_test pragma-1.7 {
103cd61c281Sdrh  db close
104ef4ac8f9Sdrh  sqlite3 db test.db
105cd61c281Sdrh  execsql {
106cd61c281Sdrh    PRAGMA cache_size;
107cd61c281Sdrh    PRAGMA default_cache_size;
108cd61c281Sdrh    PRAGMA synchronous;
109cd61c281Sdrh  }
110*1e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
111cd61c281Sdrhdo_test pragma-1.8 {
112cd61c281Sdrh  execsql {
113cd61c281Sdrh    PRAGMA default_cache_size=123;
114cd61c281Sdrh    PRAGMA cache_size;
115cd61c281Sdrh    PRAGMA default_cache_size;
116cd61c281Sdrh    PRAGMA synchronous;
117cd61c281Sdrh  }
11891cf71b0Sdanielk1977} {123 123 2}
119802d69a7Sdrhdo_test pragma-1.9.1 {
120cd61c281Sdrh  db close
121dddca286Sdrh  sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
122cd61c281Sdrh  execsql {
123cd61c281Sdrh    PRAGMA cache_size;
124cd61c281Sdrh    PRAGMA default_cache_size;
125cd61c281Sdrh    PRAGMA synchronous;
126cd61c281Sdrh  }
12791cf71b0Sdanielk1977} {123 123 2}
128802d69a7Sdrhifcapable vacuum {
129802d69a7Sdrh  do_test pragma-1.9.2 {
130802d69a7Sdrh    execsql {
131802d69a7Sdrh      VACUUM;
132802d69a7Sdrh      PRAGMA cache_size;
133802d69a7Sdrh      PRAGMA default_cache_size;
134802d69a7Sdrh      PRAGMA synchronous;
135802d69a7Sdrh    }
136802d69a7Sdrh  } {123 123 2}
137802d69a7Sdrh}
13891cf71b0Sdanielk1977do_test pragma-1.10 {
1395a38705eSdrh  execsql {
1404303feedSdrh    PRAGMA synchronous=NORMAL;
1414303feedSdrh    PRAGMA cache_size;
1424303feedSdrh    PRAGMA default_cache_size;
1434303feedSdrh    PRAGMA synchronous;
1444303feedSdrh  }
14591cf71b0Sdanielk1977} {123 123 1}
14691cf71b0Sdanielk1977do_test pragma-1.11 {
1474303feedSdrh  execsql {
1484303feedSdrh    PRAGMA synchronous=FULL;
1494303feedSdrh    PRAGMA cache_size;
1504303feedSdrh    PRAGMA default_cache_size;
1514303feedSdrh    PRAGMA synchronous;
1524303feedSdrh  }
15391cf71b0Sdanielk1977} {123 123 2}
15491cf71b0Sdanielk1977do_test pragma-1.12 {
1554303feedSdrh  db close
156dddca286Sdrh  sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
1574303feedSdrh  execsql {
1584303feedSdrh    PRAGMA cache_size;
1594303feedSdrh    PRAGMA default_cache_size;
1604303feedSdrh    PRAGMA synchronous;
1614303feedSdrh  }
16291cf71b0Sdanielk1977} {123 123 2}
16391cf71b0Sdanielk1977
1645260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition
1655260f7e9Sdrh# to keywords like "off" and "full".
1665260f7e9Sdrh#
1675260f7e9Sdrhdo_test pragma-1.13 {
1685260f7e9Sdrh  execsql {
1695260f7e9Sdrh    PRAGMA synchronous=0;
1705260f7e9Sdrh    PRAGMA synchronous;
1715260f7e9Sdrh  }
1725260f7e9Sdrh} {0}
1735260f7e9Sdrhdo_test pragma-1.14 {
1745260f7e9Sdrh  execsql {
1755260f7e9Sdrh    PRAGMA synchronous=2;
1765260f7e9Sdrh    PRAGMA synchronous;
1775260f7e9Sdrh  }
1785260f7e9Sdrh} {2}
179c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
1805260f7e9Sdrh
1815260f7e9Sdrh# Test turning "flag" pragmas on and off.
1825260f7e9Sdrh#
1835260f7e9Sdrhdo_test pragma-1.15 {
1845260f7e9Sdrh  execsql {
1855260f7e9Sdrh    PRAGMA vdbe_listing=YES;
1865260f7e9Sdrh    PRAGMA vdbe_listing;
1875260f7e9Sdrh  }
1885260f7e9Sdrh} {1}
1895260f7e9Sdrhdo_test pragma-1.16 {
1905260f7e9Sdrh  execsql {
1915260f7e9Sdrh    PRAGMA vdbe_listing=NO;
1925260f7e9Sdrh    PRAGMA vdbe_listing;
1935260f7e9Sdrh  }
1945260f7e9Sdrh} {0}
1955260f7e9Sdrhdo_test pragma-1.17 {
1965260f7e9Sdrh  execsql {
1975260f7e9Sdrh    PRAGMA parser_trace=ON;
1985260f7e9Sdrh    PRAGMA parser_trace=OFF;
1995260f7e9Sdrh  }
2005260f7e9Sdrh} {}
2015260f7e9Sdrhdo_test pragma-1.18 {
2025260f7e9Sdrh  execsql {
2035260f7e9Sdrh    PRAGMA bogus = -1234;  -- Parsing of negative values
2045260f7e9Sdrh  }
2055260f7e9Sdrh} {}
2065260f7e9Sdrh
20791cf71b0Sdanielk1977# Test modifying the safety_level of an attached database.
20891cf71b0Sdanielk1977do_test pragma-2.1 {
20991cf71b0Sdanielk1977  file delete -force test2.db
21091cf71b0Sdanielk1977  file delete -force test2.db-journal
2114303feedSdrh  execsql {
21291cf71b0Sdanielk1977    ATTACH 'test2.db' AS aux;
2134303feedSdrh  }
21491cf71b0Sdanielk1977} {}
215c7b4a44cSdanielk1977ifcapable pager_pragmas {
21691cf71b0Sdanielk1977do_test pragma-2.2 {
2174303feedSdrh  execsql {
21891cf71b0Sdanielk1977    pragma aux.synchronous;
2194303feedSdrh  }
22091cf71b0Sdanielk1977} {2}
22191cf71b0Sdanielk1977do_test pragma-2.3 {
22291cf71b0Sdanielk1977  execsql {
22391cf71b0Sdanielk1977    pragma aux.synchronous = OFF;
22491cf71b0Sdanielk1977    pragma aux.synchronous;
22591cf71b0Sdanielk1977    pragma synchronous;
22691cf71b0Sdanielk1977  }
22791cf71b0Sdanielk1977} {0 2}
22891cf71b0Sdanielk1977do_test pragma-2.4 {
22991cf71b0Sdanielk1977  execsql {
23091cf71b0Sdanielk1977    pragma aux.synchronous = ON;
23191cf71b0Sdanielk1977    pragma synchronous;
23291cf71b0Sdanielk1977    pragma aux.synchronous;
23391cf71b0Sdanielk1977  }
23491cf71b0Sdanielk1977} {2 1}
235c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
2364303feedSdrh
237ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check
238ed717fe3Sdrh# pragma finds it.
239ed717fe3Sdrh#
24025d6543dSdrh# These tests won't work if the database is encrypted
24125d6543dSdrh#
242ed717fe3Sdrhdo_test pragma-3.1 {
243*1e9daa6aSdrh  db close
244*1e9daa6aSdrh  file delete -force test.db test.db-journal
245*1e9daa6aSdrh  sqlite3 db test.db
246ed717fe3Sdrh  execsql {
247*1e9daa6aSdrh    PRAGMA auto_vacuum=OFF;
248ed717fe3Sdrh    BEGIN;
249ed717fe3Sdrh    CREATE TABLE t2(a,b,c);
250ed717fe3Sdrh    CREATE INDEX i2 ON t2(a);
251ed717fe3Sdrh    INSERT INTO t2 VALUES(11,2,3);
252ed717fe3Sdrh    INSERT INTO t2 VALUES(22,3,4);
253ed717fe3Sdrh    COMMIT;
254ed717fe3Sdrh    SELECT rowid, * from t2;
255ed717fe3Sdrh  }
256ed717fe3Sdrh} {1 11 2 3 2 22 3 4}
25740e016e4Sdrhif {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
258ed717fe3Sdrh  do_test pragma-3.2 {
259ed717fe3Sdrh    set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}]
26096fc5fe6Sdanielk1977    set db [btree_open test.db 100 0]
261ed717fe3Sdrh    btree_begin_transaction $db
262ed717fe3Sdrh    set c [btree_cursor $db $rootpage 1]
263ed717fe3Sdrh    btree_first $c
264ed717fe3Sdrh    btree_delete $c
265ed717fe3Sdrh    btree_commit $db
266ed717fe3Sdrh    btree_close $db
267ed717fe3Sdrh    execsql {PRAGMA integrity_check}
2684be295beSdrh  } {{rowid 1 missing from index i2} {wrong # of entries in index i2}}
26991cf71b0Sdanielk1977  do_test pragma-3.3 {
2701dcdbc06Sdrh    execsql {PRAGMA integrity_check=1}
2711dcdbc06Sdrh  } {{rowid 1 missing from index i2}}
2721dcdbc06Sdrh  do_test pragma-3.4 {
27391cf71b0Sdanielk1977    execsql {
2741dcdbc06Sdrh      ATTACH DATABASE 'test.db' AS t2;
2751dcdbc06Sdrh      PRAGMA integrity_check
27691cf71b0Sdanielk1977    }
2771dcdbc06Sdrh  } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
2781dcdbc06Sdrh  do_test pragma-3.5 {
2791dcdbc06Sdrh    execsql {
2801dcdbc06Sdrh      PRAGMA integrity_check=3
2811dcdbc06Sdrh    }
2821dcdbc06Sdrh  } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}}
2831dcdbc06Sdrh  do_test pragma-3.6 {
2841dcdbc06Sdrh    execsql {
2851dcdbc06Sdrh      PRAGMA integrity_check=xyz
2861dcdbc06Sdrh    }
2871dcdbc06Sdrh  } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
2881dcdbc06Sdrh  do_test pragma-3.7 {
2891dcdbc06Sdrh    execsql {
2901dcdbc06Sdrh      PRAGMA integrity_check=0
2911dcdbc06Sdrh    }
2921dcdbc06Sdrh  } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
2931dcdbc06Sdrh
2941dcdbc06Sdrh  # Add additional corruption by appending unused pages to the end of
2951dcdbc06Sdrh  # the database file testerr.db
2961dcdbc06Sdrh  #
2971dcdbc06Sdrh  do_test pragma-3.8 {
2981dcdbc06Sdrh    execsql {DETACH t2}
2991dcdbc06Sdrh    file delete -force testerr.db testerr.db-journal
300e3d559adSdrh    set out [open testerr.db w]
301e3d559adSdrh    fconfigure $out -translation binary
302e3d559adSdrh    set in [open test.db r]
303e3d559adSdrh    fconfigure $in -translation binary
3041dcdbc06Sdrh    puts -nonewline $out [read $in]
3051dcdbc06Sdrh    seek $in 0
3061dcdbc06Sdrh    puts -nonewline $out [read $in]
3071dcdbc06Sdrh    close $in
3081dcdbc06Sdrh    close $out
3091dcdbc06Sdrh    execsql {REINDEX t2}
3101dcdbc06Sdrh    execsql {PRAGMA integrity_check}
3111dcdbc06Sdrh  } {ok}
3121dcdbc06Sdrh  do_test pragma-3.9 {
3131dcdbc06Sdrh    execsql {
3141dcdbc06Sdrh      ATTACH 'testerr.db' AS t2;
3151dcdbc06Sdrh      PRAGMA integrity_check
3161dcdbc06Sdrh    }
3171dcdbc06Sdrh  } {{*** in database t2 ***
3181dcdbc06SdrhPage 4 is never used
3191dcdbc06SdrhPage 5 is never used
3201dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
3211dcdbc06Sdrh  do_test pragma-3.10 {
3221dcdbc06Sdrh    execsql {
3231dcdbc06Sdrh      PRAGMA integrity_check=1
3241dcdbc06Sdrh    }
3251dcdbc06Sdrh  } {{*** in database t2 ***
3261dcdbc06SdrhPage 4 is never used}}
3271dcdbc06Sdrh  do_test pragma-3.11 {
3281dcdbc06Sdrh    execsql {
3291dcdbc06Sdrh      PRAGMA integrity_check=5
3301dcdbc06Sdrh    }
3311dcdbc06Sdrh  } {{*** in database t2 ***
3321dcdbc06SdrhPage 4 is never used
3331dcdbc06SdrhPage 5 is never used
3341dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
3351dcdbc06Sdrh  do_test pragma-3.12 {
3361dcdbc06Sdrh    execsql {
3371dcdbc06Sdrh      PRAGMA integrity_check=4
3381dcdbc06Sdrh    }
3391dcdbc06Sdrh  } {{*** in database t2 ***
3401dcdbc06SdrhPage 4 is never used
3411dcdbc06SdrhPage 5 is never used
3421dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
3431dcdbc06Sdrh  do_test pragma-3.13 {
3441dcdbc06Sdrh    execsql {
3451dcdbc06Sdrh      PRAGMA integrity_check=3
3461dcdbc06Sdrh    }
3471dcdbc06Sdrh  } {{*** in database t2 ***
3481dcdbc06SdrhPage 4 is never used
3491dcdbc06SdrhPage 5 is never used
3501dcdbc06SdrhPage 6 is never used}}
3511dcdbc06Sdrh  do_test pragma-3.14 {
3521dcdbc06Sdrh    execsql {
3531dcdbc06Sdrh      PRAGMA integrity_check(2)
3541dcdbc06Sdrh    }
3551dcdbc06Sdrh  } {{*** in database t2 ***
3561dcdbc06SdrhPage 4 is never used
3571dcdbc06SdrhPage 5 is never used}}
3581dcdbc06Sdrh  do_test pragma-3.15 {
3591dcdbc06Sdrh    execsql {
3601dcdbc06Sdrh      ATTACH 'testerr.db' AS t3;
3611dcdbc06Sdrh      PRAGMA integrity_check
3621dcdbc06Sdrh    }
3631dcdbc06Sdrh  } {{*** in database t2 ***
3641dcdbc06SdrhPage 4 is never used
3651dcdbc06SdrhPage 5 is never used
3661dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
3671dcdbc06SdrhPage 4 is never used
3681dcdbc06SdrhPage 5 is never used
3691dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
3701dcdbc06Sdrh  do_test pragma-3.16 {
3711dcdbc06Sdrh    execsql {
3721dcdbc06Sdrh      PRAGMA integrity_check(9)
3731dcdbc06Sdrh    }
3741dcdbc06Sdrh  } {{*** in database t2 ***
3751dcdbc06SdrhPage 4 is never used
3761dcdbc06SdrhPage 5 is never used
3771dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
3781dcdbc06SdrhPage 4 is never used
3791dcdbc06SdrhPage 5 is never used
3801dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
3811dcdbc06Sdrh  do_test pragma-3.17 {
3821dcdbc06Sdrh    execsql {
3831dcdbc06Sdrh      PRAGMA integrity_check=7
3841dcdbc06Sdrh    }
3851dcdbc06Sdrh  } {{*** in database t2 ***
3861dcdbc06SdrhPage 4 is never used
3871dcdbc06SdrhPage 5 is never used
3881dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
3891dcdbc06SdrhPage 4 is never used
3901dcdbc06SdrhPage 5 is never used}}
3911dcdbc06Sdrh  do_test pragma-3.18 {
3921dcdbc06Sdrh    execsql {
3931dcdbc06Sdrh      PRAGMA integrity_check=4
3941dcdbc06Sdrh    }
3951dcdbc06Sdrh  } {{*** in database t2 ***
3961dcdbc06SdrhPage 4 is never used
3971dcdbc06SdrhPage 5 is never used
3981dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
3991dcdbc06Sdrh}
4001dcdbc06Sdrhdo_test pragma-3.99 {
4011dcdbc06Sdrh  catchsql {DETACH t3}
4021dcdbc06Sdrh  catchsql {DETACH t2}
40390ddb123Sdrh  file delete -force testerr.db testerr.db-journal
40405a6f4acSdrh  catchsql {DROP INDEX i2}
4051dcdbc06Sdrh} {0 {}}
40691cf71b0Sdanielk1977
40791cf71b0Sdanielk1977# Test modifying the cache_size of an attached database.
408c7b4a44cSdanielk1977ifcapable pager_pragmas {
40991cf71b0Sdanielk1977do_test pragma-4.1 {
41091cf71b0Sdanielk1977  execsql {
411*1e9daa6aSdrh    ATTACH 'test2.db' AS aux;
41291cf71b0Sdanielk1977    pragma aux.cache_size;
41391cf71b0Sdanielk1977    pragma aux.default_cache_size;
41491cf71b0Sdanielk1977  }
415*1e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4161bdd9b57Sdrhdo_test pragma-4.2 {
4171bdd9b57Sdrh  execsql {
41891cf71b0Sdanielk1977    pragma aux.cache_size = 50;
41991cf71b0Sdanielk1977    pragma aux.cache_size;
42091cf71b0Sdanielk1977    pragma aux.default_cache_size;
4211bdd9b57Sdrh  }
422*1e9daa6aSdrh} [list 50 $DFLT_CACHE_SZ]
4231bdd9b57Sdrhdo_test pragma-4.3 {
4241bdd9b57Sdrh  execsql {
42591cf71b0Sdanielk1977    pragma aux.default_cache_size = 456;
42691cf71b0Sdanielk1977    pragma aux.cache_size;
42791cf71b0Sdanielk1977    pragma aux.default_cache_size;
4281bdd9b57Sdrh  }
42991cf71b0Sdanielk1977} {456 456}
4301bdd9b57Sdrhdo_test pragma-4.4 {
4311bdd9b57Sdrh  execsql {
43291cf71b0Sdanielk1977    pragma cache_size;
43391cf71b0Sdanielk1977    pragma default_cache_size;
4341bdd9b57Sdrh  }
435*1e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4361bdd9b57Sdrhdo_test pragma-4.5 {
4371bdd9b57Sdrh  execsql {
43891cf71b0Sdanielk1977    DETACH aux;
43991cf71b0Sdanielk1977    ATTACH 'test3.db' AS aux;
44091cf71b0Sdanielk1977    pragma aux.cache_size;
44191cf71b0Sdanielk1977    pragma aux.default_cache_size;
4421bdd9b57Sdrh  }
443*1e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4441bdd9b57Sdrhdo_test pragma-4.6 {
4451bdd9b57Sdrh  execsql {
44691cf71b0Sdanielk1977    DETACH aux;
44791cf71b0Sdanielk1977    ATTACH 'test2.db' AS aux;
44891cf71b0Sdanielk1977    pragma aux.cache_size;
44991cf71b0Sdanielk1977    pragma aux.default_cache_size;
4501bdd9b57Sdrh  }
45191cf71b0Sdanielk1977} {456 456}
452c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
4531bdd9b57Sdrh
45491cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is
45591cf71b0Sdanielk1977# disallowed.
456c7b4a44cSdanielk1977ifcapable pager_pragmas {
45791cf71b0Sdanielk1977do_test pragma-5.0 {
4581bdd9b57Sdrh  execsql {
45991cf71b0Sdanielk1977    pragma synchronous;
4601bdd9b57Sdrh  }
46191cf71b0Sdanielk1977} {2}
46291cf71b0Sdanielk1977do_test pragma-5.1 {
4631bdd9b57Sdrh  catchsql {
4641bdd9b57Sdrh    BEGIN;
46591cf71b0Sdanielk1977    pragma synchronous = OFF;
4661bdd9b57Sdrh  }
46791cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}}
46891cf71b0Sdanielk1977do_test pragma-5.2 {
46991cf71b0Sdanielk1977  execsql {
47091cf71b0Sdanielk1977    pragma synchronous;
47191cf71b0Sdanielk1977  }
47291cf71b0Sdanielk1977} {2}
4735260f7e9Sdrhcatchsql {COMMIT;}
474c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
4755260f7e9Sdrh
4765260f7e9Sdrh# Test schema-query pragmas
4775260f7e9Sdrh#
47827188fb5Sdanielk1977ifcapable schema_pragmas {
47953c0f748Sdanielk1977ifcapable tempdb {
4805260f7e9Sdrh  do_test pragma-6.1 {
481956bc92cSdrh    set res {}
48240e016e4Sdrh    execsql {SELECT * FROM sqlite_temp_master}
4835260f7e9Sdrh    foreach {idx name file} [execsql {pragma database_list}] {
4845260f7e9Sdrh      lappend res $idx $name
4855260f7e9Sdrh    }
4865260f7e9Sdrh    set res
487a71aa001Sdrh  } {0 main 1 temp 2 aux}
48853c0f748Sdanielk1977}
4895260f7e9Sdrhdo_test pragma-6.2 {
4905260f7e9Sdrh  execsql {
4915260f7e9Sdrh    pragma table_info(t2)
4925260f7e9Sdrh  }
493bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0}
494736c7d4bSdrhdb nullvalue <<NULL>>
495417ec638Sdrhdo_test pragma-6.2.2 {
496417ec638Sdrh  execsql {
497736c7d4bSdrh    CREATE TABLE t5(
498736c7d4bSdrh      a TEXT DEFAULT CURRENT_TIMESTAMP,
499736c7d4bSdrh      b DEFAULT (5+3),
500736c7d4bSdrh      c TEXT,
501736c7d4bSdrh      d INTEGER DEFAULT NULL,
502736c7d4bSdrh      e TEXT DEFAULT ''
503736c7d4bSdrh    );
504417ec638Sdrh    PRAGMA table_info(t5);
505417ec638Sdrh  }
506736c7d4bSdrh} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0 2 c TEXT 0 <<NULL>> 0 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 0}
507736c7d4bSdrhdb nullvalue {}
5086bf89570Sdrhifcapable {foreignkey} {
5095260f7e9Sdrh  do_test pragma-6.3 {
5105260f7e9Sdrh    execsql {
5115260f7e9Sdrh      CREATE TABLE t3(a int references t2(b), b UNIQUE);
5125260f7e9Sdrh      pragma foreign_key_list(t3);
5135260f7e9Sdrh    }
5145260f7e9Sdrh  } {0 0 t2 a b}
5155260f7e9Sdrh  do_test pragma-6.4 {
5165260f7e9Sdrh    execsql {
5175260f7e9Sdrh      pragma index_list(t3);
5185260f7e9Sdrh    }
5195260f7e9Sdrh  } {0 sqlite_autoindex_t3_1 1}
5206bf89570Sdrh}
5216bf89570Sdrhifcapable {!foreignkey} {
5226bf89570Sdrh  execsql {CREATE TABLE t3(a,b UNIQUE)}
5236bf89570Sdrh}
5245260f7e9Sdrhdo_test pragma-6.5 {
5255260f7e9Sdrh  execsql {
5265260f7e9Sdrh    CREATE INDEX t3i1 ON t3(a,b);
5275260f7e9Sdrh    pragma index_info(t3i1);
5285260f7e9Sdrh  }
5295260f7e9Sdrh} {0 0 a 1 1 b}
53027188fb5Sdanielk1977} ;# ifcapable schema_pragmas
5315260f7e9Sdrh# Miscellaneous tests
5325260f7e9Sdrh#
53327188fb5Sdanielk1977ifcapable schema_pragmas {
5345260f7e9Sdrhdo_test pragma-7.1 {
5355260f7e9Sdrh  # Make sure a pragma knows to read the schema if it needs to
5365260f7e9Sdrh  db close
5375260f7e9Sdrh  sqlite3 db test.db
5385260f7e9Sdrh  execsql {
5395260f7e9Sdrh    pragma index_list(t3);
5405260f7e9Sdrh  }
5415260f7e9Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1}
54227188fb5Sdanielk1977} ;# ifcapable schema_pragmas
5436c62608fSdrhifcapable {utf16} {
5445260f7e9Sdrh  do_test pragma-7.2 {
5455260f7e9Sdrh    db close
5465260f7e9Sdrh    sqlite3 db test.db
5475260f7e9Sdrh    catchsql {
5485260f7e9Sdrh      pragma encoding=bogus;
5495260f7e9Sdrh    }
5505260f7e9Sdrh  } {1 {unsupported encoding: bogus}}
5516c62608fSdrh}
55253c0f748Sdanielk1977ifcapable tempdb {
5535260f7e9Sdrh  do_test pragma-7.3 {
5545260f7e9Sdrh    db close
5555260f7e9Sdrh    sqlite3 db test.db
5565260f7e9Sdrh    execsql {
5575260f7e9Sdrh      pragma lock_status;
5585260f7e9Sdrh    }
5595260f7e9Sdrh  } {main unlocked temp closed}
56053c0f748Sdanielk1977} else {
56153c0f748Sdanielk1977  do_test pragma-7.3 {
56253c0f748Sdanielk1977    db close
56353c0f748Sdanielk1977    sqlite3 db test.db
56453c0f748Sdanielk1977    execsql {
56553c0f748Sdanielk1977      pragma lock_status;
56653c0f748Sdanielk1977    }
56753c0f748Sdanielk1977  } {main unlocked}
56853c0f748Sdanielk1977}
5695260f7e9Sdrh
5705260f7e9Sdrh
571dae2495bSdanielk1977#----------------------------------------------------------------------
572b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
573b92b70bbSdanielk1977# user_version" statements.
574dae2495bSdanielk1977#
575b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version
576b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version
577dae2495bSdanielk1977#
578dae2495bSdanielk1977
57911cf9fbcSdanielk1977ifcapable schema_version {
58011cf9fbcSdanielk1977
581b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the
582dae2495bSdanielk1977# same value.
583dae2495bSdanielk1977do_test pragma-8.1.1 {
584dae2495bSdanielk1977  execsql {
585b92b70bbSdanielk1977    PRAGMA schema_version = 105;
586dae2495bSdanielk1977  }
587dae2495bSdanielk1977} {}
588dae2495bSdanielk1977do_test pragma-8.1.2 {
58925403650Sdrh  execsql2 {
590b92b70bbSdanielk1977    PRAGMA schema_version;
591dae2495bSdanielk1977  }
59225403650Sdrh} {schema_version 105}
593dae2495bSdanielk1977do_test pragma-8.1.3 {
594dae2495bSdanielk1977  execsql {
595b92b70bbSdanielk1977    PRAGMA schema_version = 106;
596dae2495bSdanielk1977  }
597dae2495bSdanielk1977} {}
598dae2495bSdanielk1977do_test pragma-8.1.4 {
599dae2495bSdanielk1977  execsql {
600b92b70bbSdanielk1977    PRAGMA schema_version;
601dae2495bSdanielk1977  }
602dae2495bSdanielk1977} 106
603dae2495bSdanielk1977
604b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really
605b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version).
606dae2495bSdanielk1977do_test pragma-8.1.5 {
607dae2495bSdanielk1977  execsql {
608dae2495bSdanielk1977    CREATE TABLE t4(a, b, c);
609dae2495bSdanielk1977    INSERT INTO t4 VALUES(1, 2, 3);
610dae2495bSdanielk1977    SELECT * FROM t4;
611dae2495bSdanielk1977  }
612dae2495bSdanielk1977} {1 2 3}
613dae2495bSdanielk1977do_test pragma-8.1.6 {
614dae2495bSdanielk1977  execsql {
615b92b70bbSdanielk1977    PRAGMA schema_version;
616dae2495bSdanielk1977  }
617dae2495bSdanielk1977} 107
618dae2495bSdanielk1977
619dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the
620b92b70bbSdanielk1977# schema-version using the first connection forces the second connection
621dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions,
622dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query.
623dae2495bSdanielk1977do_test pragma-8.1.7 {
624dddca286Sdrh  sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
625dae2495bSdanielk1977  execsql {
626dae2495bSdanielk1977    SELECT * FROM t4;
627dae2495bSdanielk1977  } db2
628dae2495bSdanielk1977} {1 2 3}
629dae2495bSdanielk1977do_test pragma-8.1.8 {
630dae2495bSdanielk1977  execsql {
631b92b70bbSdanielk1977    PRAGMA schema_version = 108;
632dae2495bSdanielk1977  }
633dae2495bSdanielk1977} {}
634dae2495bSdanielk1977do_test pragma-8.1.9 {
635dae2495bSdanielk1977  set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
636dae2495bSdanielk1977  sqlite3_step $::STMT
637dae2495bSdanielk1977} SQLITE_ERROR
638dae2495bSdanielk1977do_test pragma-8.1.10 {
639dae2495bSdanielk1977  sqlite3_finalize $::STMT
640dae2495bSdanielk1977} SQLITE_SCHEMA
641dae2495bSdanielk1977
642b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database.
643dae2495bSdanielk1977file delete -force test2.db
644dae2495bSdanielk1977file delete -force test2.db-journal
645dae2495bSdanielk1977do_test pragma-8.1.11 {
646dae2495bSdanielk1977  execsql {
647dae2495bSdanielk1977    ATTACH 'test2.db' AS aux;
648dae2495bSdanielk1977    CREATE TABLE aux.t1(a, b, c);
649b92b70bbSdanielk1977    PRAGMA aux.schema_version = 205;
650dae2495bSdanielk1977  }
651dae2495bSdanielk1977} {}
652dae2495bSdanielk1977do_test pragma-8.1.12 {
653dae2495bSdanielk1977  execsql {
654b92b70bbSdanielk1977    PRAGMA aux.schema_version;
655dae2495bSdanielk1977  }
656dae2495bSdanielk1977} 205
657dae2495bSdanielk1977do_test pragma-8.1.13 {
658dae2495bSdanielk1977  execsql {
659b92b70bbSdanielk1977    PRAGMA schema_version;
660dae2495bSdanielk1977  }
661dae2495bSdanielk1977} 108
662dae2495bSdanielk1977
663b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database
664dae2495bSdanielk1977# forces the second connection to reload the schema.
665dae2495bSdanielk1977do_test pragma-8.1.14 {
666dddca286Sdrh  sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
667dae2495bSdanielk1977  execsql {
668dae2495bSdanielk1977    ATTACH 'test2.db' AS aux;
669dae2495bSdanielk1977    SELECT * FROM aux.t1;
670dae2495bSdanielk1977  } db2
671dae2495bSdanielk1977} {}
672dae2495bSdanielk1977do_test pragma-8.1.15 {
673dae2495bSdanielk1977  execsql {
674b92b70bbSdanielk1977    PRAGMA aux.schema_version = 206;
675dae2495bSdanielk1977  }
676dae2495bSdanielk1977} {}
677dae2495bSdanielk1977do_test pragma-8.1.16 {
678dae2495bSdanielk1977  set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]
679dae2495bSdanielk1977  sqlite3_step $::STMT
680dae2495bSdanielk1977} SQLITE_ERROR
681dae2495bSdanielk1977do_test pragma-8.1.17 {
682dae2495bSdanielk1977  sqlite3_finalize $::STMT
683dae2495bSdanielk1977} SQLITE_SCHEMA
684dae2495bSdanielk1977do_test pragma-8.1.18 {
685dae2495bSdanielk1977  db2 close
686dae2495bSdanielk1977} {}
687dae2495bSdanielk1977
688b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't
689b92b70bbSdanielk1977# accidentally manipulating the schema-version instead).
690dae2495bSdanielk1977do_test pragma-8.2.1 {
69125403650Sdrh  execsql2 {
692b92b70bbSdanielk1977    PRAGMA user_version;
693dae2495bSdanielk1977  }
69425403650Sdrh} {user_version 0}
695dae2495bSdanielk1977do_test pragma-8.2.2 {
696dae2495bSdanielk1977  execsql {
697b92b70bbSdanielk1977    PRAGMA user_version = 2;
698dae2495bSdanielk1977  }
699dae2495bSdanielk1977} {}
700802d69a7Sdrhdo_test pragma-8.2.3.1 {
70125403650Sdrh  execsql2 {
702b92b70bbSdanielk1977    PRAGMA user_version;
703dae2495bSdanielk1977  }
70425403650Sdrh} {user_version 2}
705802d69a7Sdrhdo_test pragma-8.2.3.2 {
706802d69a7Sdrh  db close
707802d69a7Sdrh  sqlite3 db test.db
708802d69a7Sdrh  execsql {
709802d69a7Sdrh    PRAGMA user_version;
710802d69a7Sdrh  }
711802d69a7Sdrh} {2}
712802d69a7Sdrhdo_test pragma-8.2.4.1 {
713dae2495bSdanielk1977  execsql {
714b92b70bbSdanielk1977    PRAGMA schema_version;
715dae2495bSdanielk1977  }
716dae2495bSdanielk1977} {108}
717802d69a7Sdrhifcapable vacuum {
718802d69a7Sdrh  do_test pragma-8.2.4.2 {
719802d69a7Sdrh    execsql {
720802d69a7Sdrh      VACUUM;
721802d69a7Sdrh      PRAGMA user_version;
722802d69a7Sdrh    }
723802d69a7Sdrh  } {2}
724802d69a7Sdrh  do_test pragma-8.2.4.3 {
725802d69a7Sdrh    execsql {
726802d69a7Sdrh      PRAGMA schema_version;
727802d69a7Sdrh    }
728802d69a7Sdrh  } {109}
729802d69a7Sdrh}
730802d69a7Sdrhdb eval {ATTACH 'test2.db' AS aux}
731dae2495bSdanielk1977
732b92b70bbSdanielk1977# Check that the user-version in the auxilary database can be manipulated (
733dae2495bSdanielk1977# and that we aren't accidentally manipulating the same in the main db).
734dae2495bSdanielk1977do_test pragma-8.2.5 {
735dae2495bSdanielk1977  execsql {
736b92b70bbSdanielk1977    PRAGMA aux.user_version;
737dae2495bSdanielk1977  }
738dae2495bSdanielk1977} {0}
739dae2495bSdanielk1977do_test pragma-8.2.6 {
740dae2495bSdanielk1977  execsql {
741b92b70bbSdanielk1977    PRAGMA aux.user_version = 3;
742dae2495bSdanielk1977  }
743dae2495bSdanielk1977} {}
744dae2495bSdanielk1977do_test pragma-8.2.7 {
745dae2495bSdanielk1977  execsql {
746b92b70bbSdanielk1977    PRAGMA aux.user_version;
747dae2495bSdanielk1977  }
748dae2495bSdanielk1977} {3}
749dae2495bSdanielk1977do_test pragma-8.2.8 {
750dae2495bSdanielk1977  execsql {
751b92b70bbSdanielk1977    PRAGMA main.user_version;
752dae2495bSdanielk1977  }
753dae2495bSdanielk1977} {2}
754dae2495bSdanielk1977
755b92b70bbSdanielk1977# Now check that a ROLLBACK resets the user-version if it has been modified
756dae2495bSdanielk1977# within a transaction.
757dae2495bSdanielk1977do_test pragma-8.2.9 {
758dae2495bSdanielk1977  execsql {
759dae2495bSdanielk1977    BEGIN;
760b92b70bbSdanielk1977    PRAGMA aux.user_version = 10;
761b92b70bbSdanielk1977    PRAGMA user_version = 11;
762dae2495bSdanielk1977  }
763dae2495bSdanielk1977} {}
764dae2495bSdanielk1977do_test pragma-8.2.10 {
765dae2495bSdanielk1977  execsql {
766b92b70bbSdanielk1977    PRAGMA aux.user_version;
767dae2495bSdanielk1977  }
768dae2495bSdanielk1977} {10}
769dae2495bSdanielk1977do_test pragma-8.2.11 {
770dae2495bSdanielk1977  execsql {
771b92b70bbSdanielk1977    PRAGMA main.user_version;
772dae2495bSdanielk1977  }
773dae2495bSdanielk1977} {11}
774dae2495bSdanielk1977do_test pragma-8.2.12 {
775dae2495bSdanielk1977  execsql {
776dae2495bSdanielk1977    ROLLBACK;
777b92b70bbSdanielk1977    PRAGMA aux.user_version;
778dae2495bSdanielk1977  }
779dae2495bSdanielk1977} {3}
780dae2495bSdanielk1977do_test pragma-8.2.13 {
781dae2495bSdanielk1977  execsql {
782b92b70bbSdanielk1977    PRAGMA main.user_version;
783dae2495bSdanielk1977  }
784dae2495bSdanielk1977} {2}
785dae2495bSdanielk1977
786b92b70bbSdanielk1977# Try a negative value for the user-version
787dae2495bSdanielk1977do_test pragma-8.2.14 {
788dae2495bSdanielk1977  execsql {
789b92b70bbSdanielk1977    PRAGMA user_version = -450;
790dae2495bSdanielk1977  }
791dae2495bSdanielk1977} {}
792dae2495bSdanielk1977do_test pragma-8.2.15 {
793dae2495bSdanielk1977  execsql {
794b92b70bbSdanielk1977    PRAGMA user_version;
795dae2495bSdanielk1977  }
796dae2495bSdanielk1977} {-450}
797d9c847dcSdanielk1977} ; # ifcapable schema_version
798d9c847dcSdanielk1977
7999a09a3caStpoindex
8009a09a3caStpoindex# Test temp_store and temp_store_directory pragmas
8019a09a3caStpoindex#
802268283bcSdrhifcapable pager_pragmas {
8039a09a3caStpoindexdo_test pragma-9.1 {
8049a09a3caStpoindex  db close
8059a09a3caStpoindex  sqlite3 db test.db
8069a09a3caStpoindex  execsql {
8079a09a3caStpoindex    PRAGMA temp_store;
8089a09a3caStpoindex  }
8099a09a3caStpoindex} {0}
8109a09a3caStpoindexdo_test pragma-9.2 {
8119a09a3caStpoindex  execsql {
8129a09a3caStpoindex    PRAGMA temp_store=file;
8139a09a3caStpoindex    PRAGMA temp_store;
8149a09a3caStpoindex  }
8159a09a3caStpoindex} {1}
8169a09a3caStpoindexdo_test pragma-9.3 {
8179a09a3caStpoindex  execsql {
8189a09a3caStpoindex    PRAGMA temp_store=memory;
8199a09a3caStpoindex    PRAGMA temp_store;
8209a09a3caStpoindex  }
8219a09a3caStpoindex} {2}
8229a09a3caStpoindexdo_test pragma-9.4 {
8239a09a3caStpoindex  execsql {
8249a09a3caStpoindex    PRAGMA temp_store_directory;
8259a09a3caStpoindex  }
8269a09a3caStpoindex} {}
8279a09a3caStpoindexdo_test pragma-9.5 {
828268283bcSdrh  set pwd [string map {' ''} [pwd]]
829268283bcSdrh  execsql "
830268283bcSdrh    PRAGMA temp_store_directory='$pwd';
8319a09a3caStpoindex  "
8329a09a3caStpoindex} {}
8339a09a3caStpoindexdo_test pragma-9.6 {
8349a09a3caStpoindex  execsql {
8359a09a3caStpoindex    PRAGMA temp_store_directory;
8369a09a3caStpoindex  }
8371941a3e8Sdrh} [list [pwd]]
8389a09a3caStpoindexdo_test pragma-9.7 {
839268283bcSdrh  catchsql {
8409a09a3caStpoindex    PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
8419a09a3caStpoindex  }
842268283bcSdrh} {1 {not a writable directory}}
8439a09a3caStpoindexdo_test pragma-9.8 {
8449a09a3caStpoindex  execsql {
8459a09a3caStpoindex    PRAGMA temp_store_directory='';
8469a09a3caStpoindex  }
8479a09a3caStpoindex} {}
848*1e9daa6aSdrhif {![info exists TEMP_STORE] || $TEMP_STORE<=1} {
84953c0f748Sdanielk1977  ifcapable tempdb {
8509a09a3caStpoindex    do_test pragma-9.9 {
8519a09a3caStpoindex      execsql {
8529a09a3caStpoindex        PRAGMA temp_store_directory;
8539a09a3caStpoindex        PRAGMA temp_store=FILE;
8549a09a3caStpoindex        CREATE TEMP TABLE temp_store_directory_test(a integer);
8559a09a3caStpoindex        INSERT INTO temp_store_directory_test values (2);
8569a09a3caStpoindex        SELECT * FROM temp_store_directory_test;
8579a09a3caStpoindex      }
8589a09a3caStpoindex    } {2}
8599a09a3caStpoindex    do_test pragma-9.10 {
860268283bcSdrh      catchsql "
861268283bcSdrh        PRAGMA temp_store_directory='$pwd';
8629a09a3caStpoindex        SELECT * FROM temp_store_directory_test;
8639a09a3caStpoindex      "
864268283bcSdrh    } {1 {no such table: temp_store_directory_test}}
865*1e9daa6aSdrh  }
866*1e9daa6aSdrh}
86795b289b6Sdanielk1977do_test pragma-9.11 {
86895b289b6Sdanielk1977  execsql {
86995b289b6Sdanielk1977    PRAGMA temp_store = 0;
87095b289b6Sdanielk1977    PRAGMA temp_store;
87195b289b6Sdanielk1977  }
87295b289b6Sdanielk1977} {0}
87395b289b6Sdanielk1977do_test pragma-9.12 {
87495b289b6Sdanielk1977  execsql {
87595b289b6Sdanielk1977    PRAGMA temp_store = 1;
87695b289b6Sdanielk1977    PRAGMA temp_store;
87795b289b6Sdanielk1977  }
87895b289b6Sdanielk1977} {1}
87995b289b6Sdanielk1977do_test pragma-9.13 {
88095b289b6Sdanielk1977  execsql {
88195b289b6Sdanielk1977    PRAGMA temp_store = 2;
88295b289b6Sdanielk1977    PRAGMA temp_store;
88395b289b6Sdanielk1977  }
88495b289b6Sdanielk1977} {2}
88595b289b6Sdanielk1977do_test pragma-9.14 {
88695b289b6Sdanielk1977  execsql {
88795b289b6Sdanielk1977    PRAGMA temp_store = 3;
88895b289b6Sdanielk1977    PRAGMA temp_store;
88995b289b6Sdanielk1977  }
89095b289b6Sdanielk1977} {0}
89195b289b6Sdanielk1977breakpoint
89295b289b6Sdanielk1977do_test pragma-9.15 {
89395b289b6Sdanielk1977  catchsql {
89495b289b6Sdanielk1977    BEGIN EXCLUSIVE;
89595b289b6Sdanielk1977    CREATE TEMP TABLE temp_table(t);
89695b289b6Sdanielk1977    INSERT INTO temp_table VALUES('valuable data');
89795b289b6Sdanielk1977    PRAGMA temp_store = 1;
89895b289b6Sdanielk1977  }
89995b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}}
90095b289b6Sdanielk1977do_test pragma-9.16 {
90195b289b6Sdanielk1977  execsql {
90295b289b6Sdanielk1977    SELECT * FROM temp_table;
90395b289b6Sdanielk1977    COMMIT;
90495b289b6Sdanielk1977  }
90595b289b6Sdanielk1977} {{valuable data}}
906268283bcSdrh} ;# ifcapable pager_pragmas
9079a09a3caStpoindex
908cc6bd383Sdanielk1977ifcapable trigger {
909cc6bd383Sdanielk1977
910cc6bd383Sdanielk1977do_test pragma-10.0 {
911cc6bd383Sdanielk1977  catchsql {
912cc6bd383Sdanielk1977    DROP TABLE main.t1;
913cc6bd383Sdanielk1977  }
914cc6bd383Sdanielk1977  execsql {
915cc6bd383Sdanielk1977    PRAGMA count_changes = 1;
916cc6bd383Sdanielk1977
917cc6bd383Sdanielk1977    CREATE TABLE t1(a PRIMARY KEY);
918cc6bd383Sdanielk1977    CREATE TABLE t1_mirror(a);
919cc6bd383Sdanielk1977    CREATE TABLE t1_mirror2(a);
920cc6bd383Sdanielk1977    CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN
921cc6bd383Sdanielk1977      INSERT INTO t1_mirror VALUES(new.a);
922cc6bd383Sdanielk1977    END;
923cc6bd383Sdanielk1977    CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
924cc6bd383Sdanielk1977      INSERT INTO t1_mirror2 VALUES(new.a);
925cc6bd383Sdanielk1977    END;
926cc6bd383Sdanielk1977    CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
927cc6bd383Sdanielk1977      UPDATE t1_mirror SET a = new.a WHERE a = old.a;
928cc6bd383Sdanielk1977    END;
929cc6bd383Sdanielk1977    CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
930cc6bd383Sdanielk1977      UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;
931cc6bd383Sdanielk1977    END;
932cc6bd383Sdanielk1977    CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN
933cc6bd383Sdanielk1977      DELETE FROM t1_mirror WHERE a = old.a;
934cc6bd383Sdanielk1977    END;
935cc6bd383Sdanielk1977    CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
936cc6bd383Sdanielk1977      DELETE FROM t1_mirror2 WHERE a = old.a;
937cc6bd383Sdanielk1977    END;
938cc6bd383Sdanielk1977  }
939cc6bd383Sdanielk1977} {}
940cc6bd383Sdanielk1977
941cc6bd383Sdanielk1977do_test pragma-10.1 {
942cc6bd383Sdanielk1977  execsql {
943cc6bd383Sdanielk1977    INSERT INTO t1 VALUES(randstr(10,10));
944cc6bd383Sdanielk1977  }
945cc6bd383Sdanielk1977} {1}
946cc6bd383Sdanielk1977do_test pragma-10.2 {
947cc6bd383Sdanielk1977  execsql {
948cc6bd383Sdanielk1977    UPDATE t1 SET a = randstr(10,10);
949cc6bd383Sdanielk1977  }
950cc6bd383Sdanielk1977} {1}
951cc6bd383Sdanielk1977do_test pragma-10.3 {
952cc6bd383Sdanielk1977  execsql {
953cc6bd383Sdanielk1977    DELETE FROM t1;
954cc6bd383Sdanielk1977  }
955cc6bd383Sdanielk1977} {1}
956cc6bd383Sdanielk1977
957cc6bd383Sdanielk1977} ;# ifcapable trigger
958cc6bd383Sdanielk1977
95948af65aeSdanielk1977ifcapable schema_pragmas {
96048af65aeSdanielk1977  do_test pragma-11.1 {
96148af65aeSdanielk1977    execsql2 {
96248af65aeSdanielk1977      pragma collation_list;
96348af65aeSdanielk1977    }
96448af65aeSdanielk1977  } {seq 0 name NOCASE seq 1 name BINARY}
96548af65aeSdanielk1977  do_test pragma-11.2 {
96648af65aeSdanielk1977    db collate New_Collation blah...
96748af65aeSdanielk1977    execsql {
96848af65aeSdanielk1977      pragma collation_list;
96948af65aeSdanielk1977    }
97048af65aeSdanielk1977  } {0 New_Collation 1 NOCASE 2 BINARY}
97148af65aeSdanielk1977}
97248af65aeSdanielk1977
973ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb {
974ddfb2f03Sdanielk1977  do_test pragma-12.1 {
975ddfb2f03Sdanielk1977    sqlite3 db2 test.db
976ddfb2f03Sdanielk1977    execsql {
977ddfb2f03Sdanielk1977      PRAGMA temp.table_info('abc');
978ddfb2f03Sdanielk1977    } db2
979ddfb2f03Sdanielk1977  } {}
980ddfb2f03Sdanielk1977  db2 close
981ddfb2f03Sdanielk1977
982ddfb2f03Sdanielk1977  do_test pragma-12.2 {
983ddfb2f03Sdanielk1977    sqlite3 db2 test.db
984ddfb2f03Sdanielk1977    execsql {
985ddfb2f03Sdanielk1977      PRAGMA temp.default_cache_size = 200;
986ddfb2f03Sdanielk1977      PRAGMA temp.default_cache_size;
987ddfb2f03Sdanielk1977    } db2
988ddfb2f03Sdanielk1977  } {200}
989ddfb2f03Sdanielk1977  db2 close
990ddfb2f03Sdanielk1977
991ddfb2f03Sdanielk1977  do_test pragma-12.3 {
992ddfb2f03Sdanielk1977    sqlite3 db2 test.db
993ddfb2f03Sdanielk1977    execsql {
994ddfb2f03Sdanielk1977      PRAGMA temp.cache_size = 400;
995ddfb2f03Sdanielk1977      PRAGMA temp.cache_size;
996ddfb2f03Sdanielk1977    } db2
997ddfb2f03Sdanielk1977  } {400}
998ddfb2f03Sdanielk1977  db2 close
999ddfb2f03Sdanielk1977}
1000ddfb2f03Sdanielk1977
10014b2688abSdanielk1977ifcapable bloblit {
10024b2688abSdanielk1977
100305a82983Sdrhdo_test pragma-13.1 {
100405a82983Sdrh  execsql {
100505a82983Sdrh    DROP TABLE IF EXISTS t4;
100605a82983Sdrh    PRAGMA vdbe_trace=on;
100705a82983Sdrh    PRAGMA vdbe_listing=on;
100805a82983Sdrh    PRAGMA sql_trace=on;
100905a82983Sdrh    CREATE TABLE t4(a INTEGER PRIMARY KEY,b);
101005a82983Sdrh    INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789');
101105a82983Sdrh    INSERT INTO t4(b) VALUES(randstr(30,30));
101205a82983Sdrh    INSERT INTO t4(b) VALUES(1.23456);
101305a82983Sdrh    INSERT INTO t4(b) VALUES(NULL);
101405a82983Sdrh    INSERT INTO t4(b) VALUES(0);
101505a82983Sdrh    INSERT INTO t4(b) SELECT b||b||b||b FROM t4;
101605a82983Sdrh    SELECT * FROM t4;
101705a82983Sdrh  }
101805a82983Sdrh  execsql {
101905a82983Sdrh    PRAGMA vdbe_trace=off;
102005a82983Sdrh    PRAGMA vdbe_listing=off;
102105a82983Sdrh    PRAGMA sql_trace=off;
102205a82983Sdrh  }
102305a82983Sdrh} {}
102405a82983Sdrh
10254b2688abSdanielk1977} ;# ifcapable bloblit
10264b2688abSdanielk1977
10275558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests:
10285558a8a6Sdanielk1977sqlite3 dbX :memory:
10295558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""}
10305558a8a6Sdanielk1977dbX close
10315558a8a6Sdanielk1977
1032cd61c281Sdrhfinish_test
1033