xref: /sqlite-3.40.0/test/pragma.test (revision 90ddb123)
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*90ddb123Sdrh# $Id: pragma.test,v 1.49 2007/01/27 14:04:13 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
49c7b4a44cSdanielk1977ifcapable pager_pragmas {
50cd61c281Sdrhdo_test pragma-1.1 {
51cd61c281Sdrh  execsql {
52cd61c281Sdrh    PRAGMA cache_size;
53cd61c281Sdrh    PRAGMA default_cache_size;
54cd61c281Sdrh    PRAGMA synchronous;
55cd61c281Sdrh  }
5691cf71b0Sdanielk1977} {2000 2000 2}
57cd61c281Sdrhdo_test pragma-1.2 {
58cd61c281Sdrh  execsql {
59eb43e5c7Sdrh    PRAGMA synchronous=OFF;
60cd61c281Sdrh    PRAGMA cache_size=1234;
61cd61c281Sdrh    PRAGMA cache_size;
62cd61c281Sdrh    PRAGMA default_cache_size;
63cd61c281Sdrh    PRAGMA synchronous;
64cd61c281Sdrh  }
65eb43e5c7Sdrh} {1234 2000 0}
66cd61c281Sdrhdo_test pragma-1.3 {
67cd61c281Sdrh  db close
68ef4ac8f9Sdrh  sqlite3 db test.db
69cd61c281Sdrh  execsql {
70cd61c281Sdrh    PRAGMA cache_size;
71cd61c281Sdrh    PRAGMA default_cache_size;
72cd61c281Sdrh    PRAGMA synchronous;
73cd61c281Sdrh  }
7491cf71b0Sdanielk1977} {2000 2000 2}
75cd61c281Sdrhdo_test pragma-1.4 {
76cd61c281Sdrh  execsql {
77cd61c281Sdrh    PRAGMA synchronous=OFF;
78cd61c281Sdrh    PRAGMA cache_size;
79cd61c281Sdrh    PRAGMA default_cache_size;
80cd61c281Sdrh    PRAGMA synchronous;
81cd61c281Sdrh  }
8291cf71b0Sdanielk1977} {2000 2000 0}
83cd61c281Sdrhdo_test pragma-1.5 {
84cd61c281Sdrh  execsql {
85cd61c281Sdrh    PRAGMA cache_size=4321;
86cd61c281Sdrh    PRAGMA cache_size;
87cd61c281Sdrh    PRAGMA default_cache_size;
88cd61c281Sdrh    PRAGMA synchronous;
89cd61c281Sdrh  }
9091cf71b0Sdanielk1977} {4321 2000 0}
91cd61c281Sdrhdo_test pragma-1.6 {
92cd61c281Sdrh  execsql {
93cd61c281Sdrh    PRAGMA synchronous=ON;
94cd61c281Sdrh    PRAGMA cache_size;
95cd61c281Sdrh    PRAGMA default_cache_size;
96cd61c281Sdrh    PRAGMA synchronous;
97cd61c281Sdrh  }
9891cf71b0Sdanielk1977} {4321 2000 1}
99cd61c281Sdrhdo_test pragma-1.7 {
100cd61c281Sdrh  db close
101ef4ac8f9Sdrh  sqlite3 db test.db
102cd61c281Sdrh  execsql {
103cd61c281Sdrh    PRAGMA cache_size;
104cd61c281Sdrh    PRAGMA default_cache_size;
105cd61c281Sdrh    PRAGMA synchronous;
106cd61c281Sdrh  }
10791cf71b0Sdanielk1977} {2000 2000 2}
108cd61c281Sdrhdo_test pragma-1.8 {
109cd61c281Sdrh  execsql {
110cd61c281Sdrh    PRAGMA default_cache_size=123;
111cd61c281Sdrh    PRAGMA cache_size;
112cd61c281Sdrh    PRAGMA default_cache_size;
113cd61c281Sdrh    PRAGMA synchronous;
114cd61c281Sdrh  }
11591cf71b0Sdanielk1977} {123 123 2}
116802d69a7Sdrhdo_test pragma-1.9.1 {
117cd61c281Sdrh  db close
118dddca286Sdrh  sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
119cd61c281Sdrh  execsql {
120cd61c281Sdrh    PRAGMA cache_size;
121cd61c281Sdrh    PRAGMA default_cache_size;
122cd61c281Sdrh    PRAGMA synchronous;
123cd61c281Sdrh  }
12491cf71b0Sdanielk1977} {123 123 2}
125802d69a7Sdrhifcapable vacuum {
126802d69a7Sdrh  do_test pragma-1.9.2 {
127802d69a7Sdrh    execsql {
128802d69a7Sdrh      VACUUM;
129802d69a7Sdrh      PRAGMA cache_size;
130802d69a7Sdrh      PRAGMA default_cache_size;
131802d69a7Sdrh      PRAGMA synchronous;
132802d69a7Sdrh    }
133802d69a7Sdrh  } {123 123 2}
134802d69a7Sdrh}
13591cf71b0Sdanielk1977do_test pragma-1.10 {
1365a38705eSdrh  execsql {
1374303feedSdrh    PRAGMA synchronous=NORMAL;
1384303feedSdrh    PRAGMA cache_size;
1394303feedSdrh    PRAGMA default_cache_size;
1404303feedSdrh    PRAGMA synchronous;
1414303feedSdrh  }
14291cf71b0Sdanielk1977} {123 123 1}
14391cf71b0Sdanielk1977do_test pragma-1.11 {
1444303feedSdrh  execsql {
1454303feedSdrh    PRAGMA synchronous=FULL;
1464303feedSdrh    PRAGMA cache_size;
1474303feedSdrh    PRAGMA default_cache_size;
1484303feedSdrh    PRAGMA synchronous;
1494303feedSdrh  }
15091cf71b0Sdanielk1977} {123 123 2}
15191cf71b0Sdanielk1977do_test pragma-1.12 {
1524303feedSdrh  db close
153dddca286Sdrh  sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
1544303feedSdrh  execsql {
1554303feedSdrh    PRAGMA cache_size;
1564303feedSdrh    PRAGMA default_cache_size;
1574303feedSdrh    PRAGMA synchronous;
1584303feedSdrh  }
15991cf71b0Sdanielk1977} {123 123 2}
16091cf71b0Sdanielk1977
1615260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition
1625260f7e9Sdrh# to keywords like "off" and "full".
1635260f7e9Sdrh#
1645260f7e9Sdrhdo_test pragma-1.13 {
1655260f7e9Sdrh  execsql {
1665260f7e9Sdrh    PRAGMA synchronous=0;
1675260f7e9Sdrh    PRAGMA synchronous;
1685260f7e9Sdrh  }
1695260f7e9Sdrh} {0}
1705260f7e9Sdrhdo_test pragma-1.14 {
1715260f7e9Sdrh  execsql {
1725260f7e9Sdrh    PRAGMA synchronous=2;
1735260f7e9Sdrh    PRAGMA synchronous;
1745260f7e9Sdrh  }
1755260f7e9Sdrh} {2}
176c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
1775260f7e9Sdrh
1785260f7e9Sdrh# Test turning "flag" pragmas on and off.
1795260f7e9Sdrh#
1805260f7e9Sdrhdo_test pragma-1.15 {
1815260f7e9Sdrh  execsql {
1825260f7e9Sdrh    PRAGMA vdbe_listing=YES;
1835260f7e9Sdrh    PRAGMA vdbe_listing;
1845260f7e9Sdrh  }
1855260f7e9Sdrh} {1}
1865260f7e9Sdrhdo_test pragma-1.16 {
1875260f7e9Sdrh  execsql {
1885260f7e9Sdrh    PRAGMA vdbe_listing=NO;
1895260f7e9Sdrh    PRAGMA vdbe_listing;
1905260f7e9Sdrh  }
1915260f7e9Sdrh} {0}
1925260f7e9Sdrhdo_test pragma-1.17 {
1935260f7e9Sdrh  execsql {
1945260f7e9Sdrh    PRAGMA parser_trace=ON;
1955260f7e9Sdrh    PRAGMA parser_trace=OFF;
1965260f7e9Sdrh  }
1975260f7e9Sdrh} {}
1985260f7e9Sdrhdo_test pragma-1.18 {
1995260f7e9Sdrh  execsql {
2005260f7e9Sdrh    PRAGMA bogus = -1234;  -- Parsing of negative values
2015260f7e9Sdrh  }
2025260f7e9Sdrh} {}
2035260f7e9Sdrh
20491cf71b0Sdanielk1977# Test modifying the safety_level of an attached database.
20591cf71b0Sdanielk1977do_test pragma-2.1 {
20691cf71b0Sdanielk1977  file delete -force test2.db
20791cf71b0Sdanielk1977  file delete -force test2.db-journal
2084303feedSdrh  execsql {
20991cf71b0Sdanielk1977    ATTACH 'test2.db' AS aux;
2104303feedSdrh  }
21191cf71b0Sdanielk1977} {}
212c7b4a44cSdanielk1977ifcapable pager_pragmas {
21391cf71b0Sdanielk1977do_test pragma-2.2 {
2144303feedSdrh  execsql {
21591cf71b0Sdanielk1977    pragma aux.synchronous;
2164303feedSdrh  }
21791cf71b0Sdanielk1977} {2}
21891cf71b0Sdanielk1977do_test pragma-2.3 {
21991cf71b0Sdanielk1977  execsql {
22091cf71b0Sdanielk1977    pragma aux.synchronous = OFF;
22191cf71b0Sdanielk1977    pragma aux.synchronous;
22291cf71b0Sdanielk1977    pragma synchronous;
22391cf71b0Sdanielk1977  }
22491cf71b0Sdanielk1977} {0 2}
22591cf71b0Sdanielk1977do_test pragma-2.4 {
22691cf71b0Sdanielk1977  execsql {
22791cf71b0Sdanielk1977    pragma aux.synchronous = ON;
22891cf71b0Sdanielk1977    pragma synchronous;
22991cf71b0Sdanielk1977    pragma aux.synchronous;
23091cf71b0Sdanielk1977  }
23191cf71b0Sdanielk1977} {2 1}
232c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
2334303feedSdrh
234ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check
235ed717fe3Sdrh# pragma finds it.
236ed717fe3Sdrh#
23725d6543dSdrh# These tests won't work if the database is encrypted
23825d6543dSdrh#
239ed717fe3Sdrhdo_test pragma-3.1 {
240ed717fe3Sdrh  execsql {
241ed717fe3Sdrh    BEGIN;
242ed717fe3Sdrh    CREATE TABLE t2(a,b,c);
243ed717fe3Sdrh    CREATE INDEX i2 ON t2(a);
244ed717fe3Sdrh    INSERT INTO t2 VALUES(11,2,3);
245ed717fe3Sdrh    INSERT INTO t2 VALUES(22,3,4);
246ed717fe3Sdrh    COMMIT;
247ed717fe3Sdrh    SELECT rowid, * from t2;
248ed717fe3Sdrh  }
249ed717fe3Sdrh} {1 11 2 3 2 22 3 4}
25040e016e4Sdrhif {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
251ed717fe3Sdrh  do_test pragma-3.2 {
252ed717fe3Sdrh    set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}]
25396fc5fe6Sdanielk1977    set db [btree_open test.db 100 0]
254ed717fe3Sdrh    btree_begin_transaction $db
255ed717fe3Sdrh    set c [btree_cursor $db $rootpage 1]
256ed717fe3Sdrh    btree_first $c
257ed717fe3Sdrh    btree_delete $c
258ed717fe3Sdrh    btree_commit $db
259ed717fe3Sdrh    btree_close $db
260ed717fe3Sdrh    execsql {PRAGMA integrity_check}
2614be295beSdrh  } {{rowid 1 missing from index i2} {wrong # of entries in index i2}}
26291cf71b0Sdanielk1977  do_test pragma-3.3 {
2631dcdbc06Sdrh    execsql {PRAGMA integrity_check=1}
2641dcdbc06Sdrh  } {{rowid 1 missing from index i2}}
2651dcdbc06Sdrh  do_test pragma-3.4 {
26691cf71b0Sdanielk1977    execsql {
2671dcdbc06Sdrh      ATTACH DATABASE 'test.db' AS t2;
2681dcdbc06Sdrh      PRAGMA integrity_check
26991cf71b0Sdanielk1977    }
2701dcdbc06Sdrh  } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
2711dcdbc06Sdrh  do_test pragma-3.5 {
2721dcdbc06Sdrh    execsql {
2731dcdbc06Sdrh      PRAGMA integrity_check=3
2741dcdbc06Sdrh    }
2751dcdbc06Sdrh  } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}}
2761dcdbc06Sdrh  do_test pragma-3.6 {
2771dcdbc06Sdrh    execsql {
2781dcdbc06Sdrh      PRAGMA integrity_check=xyz
2791dcdbc06Sdrh    }
2801dcdbc06Sdrh  } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
2811dcdbc06Sdrh  do_test pragma-3.7 {
2821dcdbc06Sdrh    execsql {
2831dcdbc06Sdrh      PRAGMA integrity_check=0
2841dcdbc06Sdrh    }
2851dcdbc06Sdrh  } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
2861dcdbc06Sdrh
2871dcdbc06Sdrh  # Add additional corruption by appending unused pages to the end of
2881dcdbc06Sdrh  # the database file testerr.db
2891dcdbc06Sdrh  #
2901dcdbc06Sdrh  do_test pragma-3.8 {
2911dcdbc06Sdrh    execsql {DETACH t2}
2921dcdbc06Sdrh    file delete -force testerr.db testerr.db-journal
2931dcdbc06Sdrh    set out [open testerr.db wb]
2941dcdbc06Sdrh    set in [open test.db rb]
2951dcdbc06Sdrh    puts -nonewline $out [read $in]
2961dcdbc06Sdrh    seek $in 0
2971dcdbc06Sdrh    puts -nonewline $out [read $in]
2981dcdbc06Sdrh    close $in
2991dcdbc06Sdrh    close $out
3001dcdbc06Sdrh    execsql {REINDEX t2}
3011dcdbc06Sdrh    execsql {PRAGMA integrity_check}
3021dcdbc06Sdrh  } {ok}
3031dcdbc06Sdrh  do_test pragma-3.9 {
3041dcdbc06Sdrh    execsql {
3051dcdbc06Sdrh      ATTACH 'testerr.db' AS t2;
3061dcdbc06Sdrh      PRAGMA integrity_check
3071dcdbc06Sdrh    }
3081dcdbc06Sdrh  } {{*** in database t2 ***
3091dcdbc06SdrhPage 4 is never used
3101dcdbc06SdrhPage 5 is never used
3111dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
3121dcdbc06Sdrh  do_test pragma-3.10 {
3131dcdbc06Sdrh    execsql {
3141dcdbc06Sdrh      PRAGMA integrity_check=1
3151dcdbc06Sdrh    }
3161dcdbc06Sdrh  } {{*** in database t2 ***
3171dcdbc06SdrhPage 4 is never used}}
3181dcdbc06Sdrh  do_test pragma-3.11 {
3191dcdbc06Sdrh    execsql {
3201dcdbc06Sdrh      PRAGMA integrity_check=5
3211dcdbc06Sdrh    }
3221dcdbc06Sdrh  } {{*** in database t2 ***
3231dcdbc06SdrhPage 4 is never used
3241dcdbc06SdrhPage 5 is never used
3251dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
3261dcdbc06Sdrh  do_test pragma-3.12 {
3271dcdbc06Sdrh    execsql {
3281dcdbc06Sdrh      PRAGMA integrity_check=4
3291dcdbc06Sdrh    }
3301dcdbc06Sdrh  } {{*** in database t2 ***
3311dcdbc06SdrhPage 4 is never used
3321dcdbc06SdrhPage 5 is never used
3331dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
3341dcdbc06Sdrh  do_test pragma-3.13 {
3351dcdbc06Sdrh    execsql {
3361dcdbc06Sdrh      PRAGMA integrity_check=3
3371dcdbc06Sdrh    }
3381dcdbc06Sdrh  } {{*** in database t2 ***
3391dcdbc06SdrhPage 4 is never used
3401dcdbc06SdrhPage 5 is never used
3411dcdbc06SdrhPage 6 is never used}}
3421dcdbc06Sdrh  do_test pragma-3.14 {
3431dcdbc06Sdrh    execsql {
3441dcdbc06Sdrh      PRAGMA integrity_check(2)
3451dcdbc06Sdrh    }
3461dcdbc06Sdrh  } {{*** in database t2 ***
3471dcdbc06SdrhPage 4 is never used
3481dcdbc06SdrhPage 5 is never used}}
3491dcdbc06Sdrh  do_test pragma-3.15 {
3501dcdbc06Sdrh    execsql {
3511dcdbc06Sdrh      ATTACH 'testerr.db' AS t3;
3521dcdbc06Sdrh      PRAGMA integrity_check
3531dcdbc06Sdrh    }
3541dcdbc06Sdrh  } {{*** in database t2 ***
3551dcdbc06SdrhPage 4 is never used
3561dcdbc06SdrhPage 5 is never used
3571dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
3581dcdbc06SdrhPage 4 is never used
3591dcdbc06SdrhPage 5 is never used
3601dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
3611dcdbc06Sdrh  do_test pragma-3.16 {
3621dcdbc06Sdrh    execsql {
3631dcdbc06Sdrh      PRAGMA integrity_check(9)
3641dcdbc06Sdrh    }
3651dcdbc06Sdrh  } {{*** in database t2 ***
3661dcdbc06SdrhPage 4 is never used
3671dcdbc06SdrhPage 5 is never used
3681dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
3691dcdbc06SdrhPage 4 is never used
3701dcdbc06SdrhPage 5 is never used
3711dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
3721dcdbc06Sdrh  do_test pragma-3.17 {
3731dcdbc06Sdrh    execsql {
3741dcdbc06Sdrh      PRAGMA integrity_check=7
3751dcdbc06Sdrh    }
3761dcdbc06Sdrh  } {{*** in database t2 ***
3771dcdbc06SdrhPage 4 is never used
3781dcdbc06SdrhPage 5 is never used
3791dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
3801dcdbc06SdrhPage 4 is never used
3811dcdbc06SdrhPage 5 is never used}}
3821dcdbc06Sdrh  do_test pragma-3.18 {
3831dcdbc06Sdrh    execsql {
3841dcdbc06Sdrh      PRAGMA integrity_check=4
3851dcdbc06Sdrh    }
3861dcdbc06Sdrh  } {{*** in database t2 ***
3871dcdbc06SdrhPage 4 is never used
3881dcdbc06SdrhPage 5 is never used
3891dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
3901dcdbc06Sdrh}
3911dcdbc06Sdrhdo_test pragma-3.99 {
3921dcdbc06Sdrh  catchsql {DETACH t3}
3931dcdbc06Sdrh  catchsql {DETACH t2}
3941dcdbc06Sdrh  catchsql {DROP INDEX i2}
395*90ddb123Sdrh  file delete -force testerr.db testerr.db-journal
3961dcdbc06Sdrh} {0 {}}
39791cf71b0Sdanielk1977
39891cf71b0Sdanielk1977# Test modifying the cache_size of an attached database.
399c7b4a44cSdanielk1977ifcapable pager_pragmas {
40091cf71b0Sdanielk1977do_test pragma-4.1 {
40191cf71b0Sdanielk1977  execsql {
40291cf71b0Sdanielk1977    pragma aux.cache_size;
40391cf71b0Sdanielk1977    pragma aux.default_cache_size;
40491cf71b0Sdanielk1977  }
40591cf71b0Sdanielk1977} {2000 2000}
4061bdd9b57Sdrhdo_test pragma-4.2 {
4071bdd9b57Sdrh  execsql {
40891cf71b0Sdanielk1977    pragma aux.cache_size = 50;
40991cf71b0Sdanielk1977    pragma aux.cache_size;
41091cf71b0Sdanielk1977    pragma aux.default_cache_size;
4111bdd9b57Sdrh  }
41291cf71b0Sdanielk1977} {50 2000}
4131bdd9b57Sdrhdo_test pragma-4.3 {
4141bdd9b57Sdrh  execsql {
41591cf71b0Sdanielk1977    pragma aux.default_cache_size = 456;
41691cf71b0Sdanielk1977    pragma aux.cache_size;
41791cf71b0Sdanielk1977    pragma aux.default_cache_size;
4181bdd9b57Sdrh  }
41991cf71b0Sdanielk1977} {456 456}
4201bdd9b57Sdrhdo_test pragma-4.4 {
4211bdd9b57Sdrh  execsql {
42291cf71b0Sdanielk1977    pragma cache_size;
42391cf71b0Sdanielk1977    pragma default_cache_size;
4241bdd9b57Sdrh  }
42591cf71b0Sdanielk1977} {123 123}
4261bdd9b57Sdrhdo_test pragma-4.5 {
4271bdd9b57Sdrh  execsql {
42891cf71b0Sdanielk1977    DETACH aux;
42991cf71b0Sdanielk1977    ATTACH 'test3.db' AS aux;
43091cf71b0Sdanielk1977    pragma aux.cache_size;
43191cf71b0Sdanielk1977    pragma aux.default_cache_size;
4321bdd9b57Sdrh  }
43391cf71b0Sdanielk1977} {2000 2000}
4341bdd9b57Sdrhdo_test pragma-4.6 {
4351bdd9b57Sdrh  execsql {
43691cf71b0Sdanielk1977    DETACH aux;
43791cf71b0Sdanielk1977    ATTACH 'test2.db' AS aux;
43891cf71b0Sdanielk1977    pragma aux.cache_size;
43991cf71b0Sdanielk1977    pragma aux.default_cache_size;
4401bdd9b57Sdrh  }
44191cf71b0Sdanielk1977} {456 456}
442c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
4431bdd9b57Sdrh
44491cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is
44591cf71b0Sdanielk1977# disallowed.
446c7b4a44cSdanielk1977ifcapable pager_pragmas {
44791cf71b0Sdanielk1977do_test pragma-5.0 {
4481bdd9b57Sdrh  execsql {
44991cf71b0Sdanielk1977    pragma synchronous;
4501bdd9b57Sdrh  }
45191cf71b0Sdanielk1977} {2}
45291cf71b0Sdanielk1977do_test pragma-5.1 {
4531bdd9b57Sdrh  catchsql {
4541bdd9b57Sdrh    BEGIN;
45591cf71b0Sdanielk1977    pragma synchronous = OFF;
4561bdd9b57Sdrh  }
45791cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}}
45891cf71b0Sdanielk1977do_test pragma-5.2 {
45991cf71b0Sdanielk1977  execsql {
46091cf71b0Sdanielk1977    pragma synchronous;
46191cf71b0Sdanielk1977  }
46291cf71b0Sdanielk1977} {2}
4635260f7e9Sdrhcatchsql {COMMIT;}
464c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
4655260f7e9Sdrh
4665260f7e9Sdrh# Test schema-query pragmas
4675260f7e9Sdrh#
46827188fb5Sdanielk1977ifcapable schema_pragmas {
46953c0f748Sdanielk1977ifcapable tempdb {
4705260f7e9Sdrh  do_test pragma-6.1 {
471956bc92cSdrh    set res {}
47240e016e4Sdrh    execsql {SELECT * FROM sqlite_temp_master}
4735260f7e9Sdrh    foreach {idx name file} [execsql {pragma database_list}] {
4745260f7e9Sdrh      lappend res $idx $name
4755260f7e9Sdrh    }
4765260f7e9Sdrh    set res
477a71aa001Sdrh  } {0 main 1 temp 2 aux}
47853c0f748Sdanielk1977}
4795260f7e9Sdrhdo_test pragma-6.2 {
4805260f7e9Sdrh  execsql {
4815260f7e9Sdrh    pragma table_info(t2)
4825260f7e9Sdrh  }
483bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0}
484736c7d4bSdrhdb nullvalue <<NULL>>
485417ec638Sdrhdo_test pragma-6.2.2 {
486417ec638Sdrh  execsql {
487736c7d4bSdrh    CREATE TABLE t5(
488736c7d4bSdrh      a TEXT DEFAULT CURRENT_TIMESTAMP,
489736c7d4bSdrh      b DEFAULT (5+3),
490736c7d4bSdrh      c TEXT,
491736c7d4bSdrh      d INTEGER DEFAULT NULL,
492736c7d4bSdrh      e TEXT DEFAULT ''
493736c7d4bSdrh    );
494417ec638Sdrh    PRAGMA table_info(t5);
495417ec638Sdrh  }
496736c7d4bSdrh} {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}
497736c7d4bSdrhdb nullvalue {}
4986bf89570Sdrhifcapable {foreignkey} {
4995260f7e9Sdrh  do_test pragma-6.3 {
5005260f7e9Sdrh    execsql {
5015260f7e9Sdrh      CREATE TABLE t3(a int references t2(b), b UNIQUE);
5025260f7e9Sdrh      pragma foreign_key_list(t3);
5035260f7e9Sdrh    }
5045260f7e9Sdrh  } {0 0 t2 a b}
5055260f7e9Sdrh  do_test pragma-6.4 {
5065260f7e9Sdrh    execsql {
5075260f7e9Sdrh      pragma index_list(t3);
5085260f7e9Sdrh    }
5095260f7e9Sdrh  } {0 sqlite_autoindex_t3_1 1}
5106bf89570Sdrh}
5116bf89570Sdrhifcapable {!foreignkey} {
5126bf89570Sdrh  execsql {CREATE TABLE t3(a,b UNIQUE)}
5136bf89570Sdrh}
5145260f7e9Sdrhdo_test pragma-6.5 {
5155260f7e9Sdrh  execsql {
5165260f7e9Sdrh    CREATE INDEX t3i1 ON t3(a,b);
5175260f7e9Sdrh    pragma index_info(t3i1);
5185260f7e9Sdrh  }
5195260f7e9Sdrh} {0 0 a 1 1 b}
52027188fb5Sdanielk1977} ;# ifcapable schema_pragmas
5215260f7e9Sdrh# Miscellaneous tests
5225260f7e9Sdrh#
52327188fb5Sdanielk1977ifcapable schema_pragmas {
5245260f7e9Sdrhdo_test pragma-7.1 {
5255260f7e9Sdrh  # Make sure a pragma knows to read the schema if it needs to
5265260f7e9Sdrh  db close
5275260f7e9Sdrh  sqlite3 db test.db
5285260f7e9Sdrh  execsql {
5295260f7e9Sdrh    pragma index_list(t3);
5305260f7e9Sdrh  }
5315260f7e9Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1}
53227188fb5Sdanielk1977} ;# ifcapable schema_pragmas
5336c62608fSdrhifcapable {utf16} {
5345260f7e9Sdrh  do_test pragma-7.2 {
5355260f7e9Sdrh    db close
5365260f7e9Sdrh    sqlite3 db test.db
5375260f7e9Sdrh    catchsql {
5385260f7e9Sdrh      pragma encoding=bogus;
5395260f7e9Sdrh    }
5405260f7e9Sdrh  } {1 {unsupported encoding: bogus}}
5416c62608fSdrh}
54253c0f748Sdanielk1977ifcapable tempdb {
5435260f7e9Sdrh  do_test pragma-7.3 {
5445260f7e9Sdrh    db close
5455260f7e9Sdrh    sqlite3 db test.db
5465260f7e9Sdrh    execsql {
5475260f7e9Sdrh      pragma lock_status;
5485260f7e9Sdrh    }
5495260f7e9Sdrh  } {main unlocked temp closed}
55053c0f748Sdanielk1977} else {
55153c0f748Sdanielk1977  do_test pragma-7.3 {
55253c0f748Sdanielk1977    db close
55353c0f748Sdanielk1977    sqlite3 db test.db
55453c0f748Sdanielk1977    execsql {
55553c0f748Sdanielk1977      pragma lock_status;
55653c0f748Sdanielk1977    }
55753c0f748Sdanielk1977  } {main unlocked}
55853c0f748Sdanielk1977}
5595260f7e9Sdrh
5605260f7e9Sdrh
561dae2495bSdanielk1977#----------------------------------------------------------------------
562b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
563b92b70bbSdanielk1977# user_version" statements.
564dae2495bSdanielk1977#
565b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version
566b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version
567dae2495bSdanielk1977#
568dae2495bSdanielk1977
56911cf9fbcSdanielk1977ifcapable schema_version {
57011cf9fbcSdanielk1977
571b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the
572dae2495bSdanielk1977# same value.
573dae2495bSdanielk1977do_test pragma-8.1.1 {
574dae2495bSdanielk1977  execsql {
575b92b70bbSdanielk1977    PRAGMA schema_version = 105;
576dae2495bSdanielk1977  }
577dae2495bSdanielk1977} {}
578dae2495bSdanielk1977do_test pragma-8.1.2 {
57925403650Sdrh  execsql2 {
580b92b70bbSdanielk1977    PRAGMA schema_version;
581dae2495bSdanielk1977  }
58225403650Sdrh} {schema_version 105}
583dae2495bSdanielk1977do_test pragma-8.1.3 {
584dae2495bSdanielk1977  execsql {
585b92b70bbSdanielk1977    PRAGMA schema_version = 106;
586dae2495bSdanielk1977  }
587dae2495bSdanielk1977} {}
588dae2495bSdanielk1977do_test pragma-8.1.4 {
589dae2495bSdanielk1977  execsql {
590b92b70bbSdanielk1977    PRAGMA schema_version;
591dae2495bSdanielk1977  }
592dae2495bSdanielk1977} 106
593dae2495bSdanielk1977
594b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really
595b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version).
596dae2495bSdanielk1977do_test pragma-8.1.5 {
597dae2495bSdanielk1977  execsql {
598dae2495bSdanielk1977    CREATE TABLE t4(a, b, c);
599dae2495bSdanielk1977    INSERT INTO t4 VALUES(1, 2, 3);
600dae2495bSdanielk1977    SELECT * FROM t4;
601dae2495bSdanielk1977  }
602dae2495bSdanielk1977} {1 2 3}
603dae2495bSdanielk1977do_test pragma-8.1.6 {
604dae2495bSdanielk1977  execsql {
605b92b70bbSdanielk1977    PRAGMA schema_version;
606dae2495bSdanielk1977  }
607dae2495bSdanielk1977} 107
608dae2495bSdanielk1977
609dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the
610b92b70bbSdanielk1977# schema-version using the first connection forces the second connection
611dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions,
612dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query.
613dae2495bSdanielk1977do_test pragma-8.1.7 {
614dddca286Sdrh  sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
615dae2495bSdanielk1977  execsql {
616dae2495bSdanielk1977    SELECT * FROM t4;
617dae2495bSdanielk1977  } db2
618dae2495bSdanielk1977} {1 2 3}
619dae2495bSdanielk1977do_test pragma-8.1.8 {
620dae2495bSdanielk1977  execsql {
621b92b70bbSdanielk1977    PRAGMA schema_version = 108;
622dae2495bSdanielk1977  }
623dae2495bSdanielk1977} {}
624dae2495bSdanielk1977do_test pragma-8.1.9 {
625dae2495bSdanielk1977  set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
626dae2495bSdanielk1977  sqlite3_step $::STMT
627dae2495bSdanielk1977} SQLITE_ERROR
628dae2495bSdanielk1977do_test pragma-8.1.10 {
629dae2495bSdanielk1977  sqlite3_finalize $::STMT
630dae2495bSdanielk1977} SQLITE_SCHEMA
631dae2495bSdanielk1977
632b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database.
633dae2495bSdanielk1977file delete -force test2.db
634dae2495bSdanielk1977file delete -force test2.db-journal
635dae2495bSdanielk1977do_test pragma-8.1.11 {
636dae2495bSdanielk1977  execsql {
637dae2495bSdanielk1977    ATTACH 'test2.db' AS aux;
638dae2495bSdanielk1977    CREATE TABLE aux.t1(a, b, c);
639b92b70bbSdanielk1977    PRAGMA aux.schema_version = 205;
640dae2495bSdanielk1977  }
641dae2495bSdanielk1977} {}
642dae2495bSdanielk1977do_test pragma-8.1.12 {
643dae2495bSdanielk1977  execsql {
644b92b70bbSdanielk1977    PRAGMA aux.schema_version;
645dae2495bSdanielk1977  }
646dae2495bSdanielk1977} 205
647dae2495bSdanielk1977do_test pragma-8.1.13 {
648dae2495bSdanielk1977  execsql {
649b92b70bbSdanielk1977    PRAGMA schema_version;
650dae2495bSdanielk1977  }
651dae2495bSdanielk1977} 108
652dae2495bSdanielk1977
653b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database
654dae2495bSdanielk1977# forces the second connection to reload the schema.
655dae2495bSdanielk1977do_test pragma-8.1.14 {
656dddca286Sdrh  sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
657dae2495bSdanielk1977  execsql {
658dae2495bSdanielk1977    ATTACH 'test2.db' AS aux;
659dae2495bSdanielk1977    SELECT * FROM aux.t1;
660dae2495bSdanielk1977  } db2
661dae2495bSdanielk1977} {}
662dae2495bSdanielk1977do_test pragma-8.1.15 {
663dae2495bSdanielk1977  execsql {
664b92b70bbSdanielk1977    PRAGMA aux.schema_version = 206;
665dae2495bSdanielk1977  }
666dae2495bSdanielk1977} {}
667dae2495bSdanielk1977do_test pragma-8.1.16 {
668dae2495bSdanielk1977  set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]
669dae2495bSdanielk1977  sqlite3_step $::STMT
670dae2495bSdanielk1977} SQLITE_ERROR
671dae2495bSdanielk1977do_test pragma-8.1.17 {
672dae2495bSdanielk1977  sqlite3_finalize $::STMT
673dae2495bSdanielk1977} SQLITE_SCHEMA
674dae2495bSdanielk1977do_test pragma-8.1.18 {
675dae2495bSdanielk1977  db2 close
676dae2495bSdanielk1977} {}
677dae2495bSdanielk1977
678b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't
679b92b70bbSdanielk1977# accidentally manipulating the schema-version instead).
680dae2495bSdanielk1977do_test pragma-8.2.1 {
68125403650Sdrh  execsql2 {
682b92b70bbSdanielk1977    PRAGMA user_version;
683dae2495bSdanielk1977  }
68425403650Sdrh} {user_version 0}
685dae2495bSdanielk1977do_test pragma-8.2.2 {
686dae2495bSdanielk1977  execsql {
687b92b70bbSdanielk1977    PRAGMA user_version = 2;
688dae2495bSdanielk1977  }
689dae2495bSdanielk1977} {}
690802d69a7Sdrhdo_test pragma-8.2.3.1 {
69125403650Sdrh  execsql2 {
692b92b70bbSdanielk1977    PRAGMA user_version;
693dae2495bSdanielk1977  }
69425403650Sdrh} {user_version 2}
695802d69a7Sdrhdo_test pragma-8.2.3.2 {
696802d69a7Sdrh  db close
697802d69a7Sdrh  sqlite3 db test.db
698802d69a7Sdrh  execsql {
699802d69a7Sdrh    PRAGMA user_version;
700802d69a7Sdrh  }
701802d69a7Sdrh} {2}
702802d69a7Sdrhdo_test pragma-8.2.4.1 {
703dae2495bSdanielk1977  execsql {
704b92b70bbSdanielk1977    PRAGMA schema_version;
705dae2495bSdanielk1977  }
706dae2495bSdanielk1977} {108}
707802d69a7Sdrhifcapable vacuum {
708802d69a7Sdrh  do_test pragma-8.2.4.2 {
709802d69a7Sdrh    execsql {
710802d69a7Sdrh      VACUUM;
711802d69a7Sdrh      PRAGMA user_version;
712802d69a7Sdrh    }
713802d69a7Sdrh  } {2}
714802d69a7Sdrh  do_test pragma-8.2.4.3 {
715802d69a7Sdrh    execsql {
716802d69a7Sdrh      PRAGMA schema_version;
717802d69a7Sdrh    }
718802d69a7Sdrh  } {109}
719802d69a7Sdrh}
720802d69a7Sdrhdb eval {ATTACH 'test2.db' AS aux}
721dae2495bSdanielk1977
722b92b70bbSdanielk1977# Check that the user-version in the auxilary database can be manipulated (
723dae2495bSdanielk1977# and that we aren't accidentally manipulating the same in the main db).
724dae2495bSdanielk1977do_test pragma-8.2.5 {
725dae2495bSdanielk1977  execsql {
726b92b70bbSdanielk1977    PRAGMA aux.user_version;
727dae2495bSdanielk1977  }
728dae2495bSdanielk1977} {0}
729dae2495bSdanielk1977do_test pragma-8.2.6 {
730dae2495bSdanielk1977  execsql {
731b92b70bbSdanielk1977    PRAGMA aux.user_version = 3;
732dae2495bSdanielk1977  }
733dae2495bSdanielk1977} {}
734dae2495bSdanielk1977do_test pragma-8.2.7 {
735dae2495bSdanielk1977  execsql {
736b92b70bbSdanielk1977    PRAGMA aux.user_version;
737dae2495bSdanielk1977  }
738dae2495bSdanielk1977} {3}
739dae2495bSdanielk1977do_test pragma-8.2.8 {
740dae2495bSdanielk1977  execsql {
741b92b70bbSdanielk1977    PRAGMA main.user_version;
742dae2495bSdanielk1977  }
743dae2495bSdanielk1977} {2}
744dae2495bSdanielk1977
745b92b70bbSdanielk1977# Now check that a ROLLBACK resets the user-version if it has been modified
746dae2495bSdanielk1977# within a transaction.
747dae2495bSdanielk1977do_test pragma-8.2.9 {
748dae2495bSdanielk1977  execsql {
749dae2495bSdanielk1977    BEGIN;
750b92b70bbSdanielk1977    PRAGMA aux.user_version = 10;
751b92b70bbSdanielk1977    PRAGMA user_version = 11;
752dae2495bSdanielk1977  }
753dae2495bSdanielk1977} {}
754dae2495bSdanielk1977do_test pragma-8.2.10 {
755dae2495bSdanielk1977  execsql {
756b92b70bbSdanielk1977    PRAGMA aux.user_version;
757dae2495bSdanielk1977  }
758dae2495bSdanielk1977} {10}
759dae2495bSdanielk1977do_test pragma-8.2.11 {
760dae2495bSdanielk1977  execsql {
761b92b70bbSdanielk1977    PRAGMA main.user_version;
762dae2495bSdanielk1977  }
763dae2495bSdanielk1977} {11}
764dae2495bSdanielk1977do_test pragma-8.2.12 {
765dae2495bSdanielk1977  execsql {
766dae2495bSdanielk1977    ROLLBACK;
767b92b70bbSdanielk1977    PRAGMA aux.user_version;
768dae2495bSdanielk1977  }
769dae2495bSdanielk1977} {3}
770dae2495bSdanielk1977do_test pragma-8.2.13 {
771dae2495bSdanielk1977  execsql {
772b92b70bbSdanielk1977    PRAGMA main.user_version;
773dae2495bSdanielk1977  }
774dae2495bSdanielk1977} {2}
775dae2495bSdanielk1977
776b92b70bbSdanielk1977# Try a negative value for the user-version
777dae2495bSdanielk1977do_test pragma-8.2.14 {
778dae2495bSdanielk1977  execsql {
779b92b70bbSdanielk1977    PRAGMA user_version = -450;
780dae2495bSdanielk1977  }
781dae2495bSdanielk1977} {}
782dae2495bSdanielk1977do_test pragma-8.2.15 {
783dae2495bSdanielk1977  execsql {
784b92b70bbSdanielk1977    PRAGMA user_version;
785dae2495bSdanielk1977  }
786dae2495bSdanielk1977} {-450}
787d9c847dcSdanielk1977} ; # ifcapable schema_version
788d9c847dcSdanielk1977
7899a09a3caStpoindex
7909a09a3caStpoindex# Test temp_store and temp_store_directory pragmas
7919a09a3caStpoindex#
792268283bcSdrhifcapable pager_pragmas {
7939a09a3caStpoindexdo_test pragma-9.1 {
7949a09a3caStpoindex  db close
7959a09a3caStpoindex  sqlite3 db test.db
7969a09a3caStpoindex  execsql {
7979a09a3caStpoindex    PRAGMA temp_store;
7989a09a3caStpoindex  }
7999a09a3caStpoindex} {0}
8009a09a3caStpoindexdo_test pragma-9.2 {
8019a09a3caStpoindex  execsql {
8029a09a3caStpoindex    PRAGMA temp_store=file;
8039a09a3caStpoindex    PRAGMA temp_store;
8049a09a3caStpoindex  }
8059a09a3caStpoindex} {1}
8069a09a3caStpoindexdo_test pragma-9.3 {
8079a09a3caStpoindex  execsql {
8089a09a3caStpoindex    PRAGMA temp_store=memory;
8099a09a3caStpoindex    PRAGMA temp_store;
8109a09a3caStpoindex  }
8119a09a3caStpoindex} {2}
8129a09a3caStpoindexdo_test pragma-9.4 {
8139a09a3caStpoindex  execsql {
8149a09a3caStpoindex    PRAGMA temp_store_directory;
8159a09a3caStpoindex  }
8169a09a3caStpoindex} {}
8179a09a3caStpoindexdo_test pragma-9.5 {
818268283bcSdrh  set pwd [string map {' ''} [pwd]]
819268283bcSdrh  execsql "
820268283bcSdrh    PRAGMA temp_store_directory='$pwd';
8219a09a3caStpoindex  "
8229a09a3caStpoindex} {}
8239a09a3caStpoindexdo_test pragma-9.6 {
8249a09a3caStpoindex  execsql {
8259a09a3caStpoindex    PRAGMA temp_store_directory;
8269a09a3caStpoindex  }
8271941a3e8Sdrh} [list [pwd]]
8289a09a3caStpoindexdo_test pragma-9.7 {
829268283bcSdrh  catchsql {
8309a09a3caStpoindex    PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
8319a09a3caStpoindex  }
832268283bcSdrh} {1 {not a writable directory}}
8339a09a3caStpoindexdo_test pragma-9.8 {
8349a09a3caStpoindex  execsql {
8359a09a3caStpoindex    PRAGMA temp_store_directory='';
8369a09a3caStpoindex  }
8379a09a3caStpoindex} {}
83853c0f748Sdanielk1977ifcapable tempdb {
8399a09a3caStpoindex  do_test pragma-9.9 {
8409a09a3caStpoindex    execsql {
8419a09a3caStpoindex      PRAGMA temp_store_directory;
8429a09a3caStpoindex      PRAGMA temp_store=FILE;
8439a09a3caStpoindex      CREATE TEMP TABLE temp_store_directory_test(a integer);
8449a09a3caStpoindex      INSERT INTO temp_store_directory_test values (2);
8459a09a3caStpoindex      SELECT * FROM temp_store_directory_test;
8469a09a3caStpoindex    }
8479a09a3caStpoindex  } {2}
84853c0f748Sdanielk1977}
8499a09a3caStpoindexdo_test pragma-9.10 {
850268283bcSdrh  catchsql "
851268283bcSdrh    PRAGMA temp_store_directory='$pwd';
8529a09a3caStpoindex    SELECT * FROM temp_store_directory_test;
8539a09a3caStpoindex  "
854268283bcSdrh} {1 {no such table: temp_store_directory_test}}
855268283bcSdrh} ;# ifcapable pager_pragmas
8569a09a3caStpoindex
857cc6bd383Sdanielk1977ifcapable trigger {
858cc6bd383Sdanielk1977
859cc6bd383Sdanielk1977do_test pragma-10.0 {
860cc6bd383Sdanielk1977  catchsql {
861cc6bd383Sdanielk1977    DROP TABLE main.t1;
862cc6bd383Sdanielk1977  }
863cc6bd383Sdanielk1977  execsql {
864cc6bd383Sdanielk1977    PRAGMA count_changes = 1;
865cc6bd383Sdanielk1977
866cc6bd383Sdanielk1977    CREATE TABLE t1(a PRIMARY KEY);
867cc6bd383Sdanielk1977    CREATE TABLE t1_mirror(a);
868cc6bd383Sdanielk1977    CREATE TABLE t1_mirror2(a);
869cc6bd383Sdanielk1977    CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN
870cc6bd383Sdanielk1977      INSERT INTO t1_mirror VALUES(new.a);
871cc6bd383Sdanielk1977    END;
872cc6bd383Sdanielk1977    CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
873cc6bd383Sdanielk1977      INSERT INTO t1_mirror2 VALUES(new.a);
874cc6bd383Sdanielk1977    END;
875cc6bd383Sdanielk1977    CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
876cc6bd383Sdanielk1977      UPDATE t1_mirror SET a = new.a WHERE a = old.a;
877cc6bd383Sdanielk1977    END;
878cc6bd383Sdanielk1977    CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
879cc6bd383Sdanielk1977      UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;
880cc6bd383Sdanielk1977    END;
881cc6bd383Sdanielk1977    CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN
882cc6bd383Sdanielk1977      DELETE FROM t1_mirror WHERE a = old.a;
883cc6bd383Sdanielk1977    END;
884cc6bd383Sdanielk1977    CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
885cc6bd383Sdanielk1977      DELETE FROM t1_mirror2 WHERE a = old.a;
886cc6bd383Sdanielk1977    END;
887cc6bd383Sdanielk1977  }
888cc6bd383Sdanielk1977} {}
889cc6bd383Sdanielk1977
890cc6bd383Sdanielk1977do_test pragma-10.1 {
891cc6bd383Sdanielk1977  execsql {
892cc6bd383Sdanielk1977    INSERT INTO t1 VALUES(randstr(10,10));
893cc6bd383Sdanielk1977  }
894cc6bd383Sdanielk1977} {1}
895cc6bd383Sdanielk1977do_test pragma-10.2 {
896cc6bd383Sdanielk1977  execsql {
897cc6bd383Sdanielk1977    UPDATE t1 SET a = randstr(10,10);
898cc6bd383Sdanielk1977  }
899cc6bd383Sdanielk1977} {1}
900cc6bd383Sdanielk1977do_test pragma-10.3 {
901cc6bd383Sdanielk1977  execsql {
902cc6bd383Sdanielk1977    DELETE FROM t1;
903cc6bd383Sdanielk1977  }
904cc6bd383Sdanielk1977} {1}
905cc6bd383Sdanielk1977
906cc6bd383Sdanielk1977} ;# ifcapable trigger
907cc6bd383Sdanielk1977
90848af65aeSdanielk1977ifcapable schema_pragmas {
90948af65aeSdanielk1977  do_test pragma-11.1 {
91048af65aeSdanielk1977    execsql2 {
91148af65aeSdanielk1977      pragma collation_list;
91248af65aeSdanielk1977    }
91348af65aeSdanielk1977  } {seq 0 name NOCASE seq 1 name BINARY}
91448af65aeSdanielk1977  do_test pragma-11.2 {
91548af65aeSdanielk1977    db collate New_Collation blah...
91648af65aeSdanielk1977    execsql {
91748af65aeSdanielk1977      pragma collation_list;
91848af65aeSdanielk1977    }
91948af65aeSdanielk1977  } {0 New_Collation 1 NOCASE 2 BINARY}
92048af65aeSdanielk1977}
92148af65aeSdanielk1977
922ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb {
923ddfb2f03Sdanielk1977  do_test pragma-12.1 {
924ddfb2f03Sdanielk1977    sqlite3 db2 test.db
925ddfb2f03Sdanielk1977    execsql {
926ddfb2f03Sdanielk1977      PRAGMA temp.table_info('abc');
927ddfb2f03Sdanielk1977    } db2
928ddfb2f03Sdanielk1977  } {}
929ddfb2f03Sdanielk1977  db2 close
930ddfb2f03Sdanielk1977
931ddfb2f03Sdanielk1977  do_test pragma-12.2 {
932ddfb2f03Sdanielk1977    sqlite3 db2 test.db
933ddfb2f03Sdanielk1977    execsql {
934ddfb2f03Sdanielk1977      PRAGMA temp.default_cache_size = 200;
935ddfb2f03Sdanielk1977      PRAGMA temp.default_cache_size;
936ddfb2f03Sdanielk1977    } db2
937ddfb2f03Sdanielk1977  } {200}
938ddfb2f03Sdanielk1977  db2 close
939ddfb2f03Sdanielk1977
940ddfb2f03Sdanielk1977  do_test pragma-12.3 {
941ddfb2f03Sdanielk1977    sqlite3 db2 test.db
942ddfb2f03Sdanielk1977    execsql {
943ddfb2f03Sdanielk1977      PRAGMA temp.cache_size = 400;
944ddfb2f03Sdanielk1977      PRAGMA temp.cache_size;
945ddfb2f03Sdanielk1977    } db2
946ddfb2f03Sdanielk1977  } {400}
947ddfb2f03Sdanielk1977  db2 close
948ddfb2f03Sdanielk1977}
949ddfb2f03Sdanielk1977
9504b2688abSdanielk1977ifcapable bloblit {
9514b2688abSdanielk1977
95205a82983Sdrhdo_test pragma-13.1 {
95305a82983Sdrh  execsql {
95405a82983Sdrh    DROP TABLE IF EXISTS t4;
95505a82983Sdrh    PRAGMA vdbe_trace=on;
95605a82983Sdrh    PRAGMA vdbe_listing=on;
95705a82983Sdrh    PRAGMA sql_trace=on;
95805a82983Sdrh    CREATE TABLE t4(a INTEGER PRIMARY KEY,b);
95905a82983Sdrh    INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789');
96005a82983Sdrh    INSERT INTO t4(b) VALUES(randstr(30,30));
96105a82983Sdrh    INSERT INTO t4(b) VALUES(1.23456);
96205a82983Sdrh    INSERT INTO t4(b) VALUES(NULL);
96305a82983Sdrh    INSERT INTO t4(b) VALUES(0);
96405a82983Sdrh    INSERT INTO t4(b) SELECT b||b||b||b FROM t4;
96505a82983Sdrh    SELECT * FROM t4;
96605a82983Sdrh  }
96705a82983Sdrh  execsql {
96805a82983Sdrh    PRAGMA vdbe_trace=off;
96905a82983Sdrh    PRAGMA vdbe_listing=off;
97005a82983Sdrh    PRAGMA sql_trace=off;
97105a82983Sdrh  }
97205a82983Sdrh} {}
97305a82983Sdrh
9744b2688abSdanielk1977} ;# ifcapable bloblit
9754b2688abSdanielk1977
9765558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests:
9775558a8a6Sdanielk1977sqlite3 dbX :memory:
9785558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""}
9795558a8a6Sdanielk1977dbX close
9805558a8a6Sdanielk1977
981cd61c281Sdrhfinish_test
982