xref: /sqlite-3.40.0/test/pragma.test (revision 68928b6c)
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#
15838cce43Sdanielk1977# $Id: pragma.test,v 1.73 2009/01/12 14:01:45 danielk1977 Exp $
16cd61c281Sdrh
17cd61c281Sdrhset testdir [file dirname $argv0]
18cd61c281Sdrhsource $testdir/tester.tcl
19cd61c281Sdrh
20*68928b6cSdan# Do not use a codec for tests in this file, as the database file is
21*68928b6cSdan# manipulated directly using tcl scripts (using the [hexio_write] command).
22*68928b6cSdan#
23*68928b6cSdando_not_use_codec
24*68928b6cSdan
2591cf71b0Sdanielk1977# Test organization:
2691cf71b0Sdanielk1977#
2791cf71b0Sdanielk1977# pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
2891cf71b0Sdanielk1977# pragma-2.*: Test synchronous on attached db.
2991cf71b0Sdanielk1977# pragma-3.*: Test detection of table/index inconsistency by integrity_check.
3091cf71b0Sdanielk1977# pragma-4.*: Test cache_size and default_cache_size on attached db.
3191cf71b0Sdanielk1977# pragma-5.*: Test that pragma synchronous may not be used inside of a
3291cf71b0Sdanielk1977#             transaction.
33cc6bd383Sdanielk1977# pragma-6.*: Test schema-query pragmas.
34cc6bd383Sdanielk1977# pragma-7.*: Miscellaneous tests.
35cc6bd383Sdanielk1977# pragma-8.*: Test user_version and schema_version pragmas.
369a09a3caStpoindex# pragma-9.*: Test temp_store and temp_store_directory.
37cc6bd383Sdanielk1977# pragma-10.*: Test the count_changes pragma in the presence of triggers.
3848af65aeSdanielk1977# pragma-11.*: Test the collation_list pragma.
3959a93791Sdanielk1977# pragma-14.*: Test the page_count pragma.
408cf6c554Sdanielk1977# pragma-15.*: Test that the value set using the cache_size pragma is not
418cf6c554Sdanielk1977#              reset when the schema is reloaded.
42aebf413dSaswift# pragma-16.*: Test proxy locking
4391cf71b0Sdanielk1977#
4491cf71b0Sdanielk1977
4505a82983Sdrhifcapable !pragma {
4605a82983Sdrh  finish_test
4705a82983Sdrh  return
4805a82983Sdrh}
4905a82983Sdrh
50cd61c281Sdrh# Delete the preexisting database to avoid the special setup
51cd61c281Sdrh# that the "all.test" script does.
52cd61c281Sdrh#
53cd61c281Sdrhdb close
5425403650Sdrhfile delete test.db test.db-journal
5525403650Sdrhfile delete test3.db test3.db-journal
56dddca286Sdrhsqlite3 db test.db; set DB [sqlite3_connection_pointer db]
57cd61c281Sdrh
581e9daa6aSdrh
59c7b4a44cSdanielk1977ifcapable pager_pragmas {
601e9daa6aSdrhset DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}]
611e9daa6aSdrhset TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}]
62cd61c281Sdrhdo_test pragma-1.1 {
63cd61c281Sdrh  execsql {
64cd61c281Sdrh    PRAGMA cache_size;
65cd61c281Sdrh    PRAGMA default_cache_size;
66cd61c281Sdrh    PRAGMA synchronous;
67cd61c281Sdrh  }
681e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
69cd61c281Sdrhdo_test pragma-1.2 {
70cd61c281Sdrh  execsql {
71eb43e5c7Sdrh    PRAGMA synchronous=OFF;
72cd61c281Sdrh    PRAGMA cache_size=1234;
73cd61c281Sdrh    PRAGMA cache_size;
74cd61c281Sdrh    PRAGMA default_cache_size;
75cd61c281Sdrh    PRAGMA synchronous;
76cd61c281Sdrh  }
771e9daa6aSdrh} [list 1234 $DFLT_CACHE_SZ 0]
78cd61c281Sdrhdo_test pragma-1.3 {
79cd61c281Sdrh  db close
80ef4ac8f9Sdrh  sqlite3 db test.db
81cd61c281Sdrh  execsql {
82cd61c281Sdrh    PRAGMA cache_size;
83cd61c281Sdrh    PRAGMA default_cache_size;
84cd61c281Sdrh    PRAGMA synchronous;
85cd61c281Sdrh  }
861e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
87cd61c281Sdrhdo_test pragma-1.4 {
88cd61c281Sdrh  execsql {
89cd61c281Sdrh    PRAGMA synchronous=OFF;
90cd61c281Sdrh    PRAGMA cache_size;
91cd61c281Sdrh    PRAGMA default_cache_size;
92cd61c281Sdrh    PRAGMA synchronous;
93cd61c281Sdrh  }
941e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0]
95cd61c281Sdrhdo_test pragma-1.5 {
96cd61c281Sdrh  execsql {
97d2cb50b7Sdrh    PRAGMA cache_size=-4321;
98cd61c281Sdrh    PRAGMA cache_size;
99cd61c281Sdrh    PRAGMA default_cache_size;
100cd61c281Sdrh    PRAGMA synchronous;
101cd61c281Sdrh  }
1021e9daa6aSdrh} [list 4321 $DFLT_CACHE_SZ 0]
103cd61c281Sdrhdo_test pragma-1.6 {
104cd61c281Sdrh  execsql {
105cd61c281Sdrh    PRAGMA synchronous=ON;
106cd61c281Sdrh    PRAGMA cache_size;
107cd61c281Sdrh    PRAGMA default_cache_size;
108cd61c281Sdrh    PRAGMA synchronous;
109cd61c281Sdrh  }
1101e9daa6aSdrh} [list 4321 $DFLT_CACHE_SZ 1]
111cd61c281Sdrhdo_test pragma-1.7 {
112cd61c281Sdrh  db close
113ef4ac8f9Sdrh  sqlite3 db test.db
114cd61c281Sdrh  execsql {
115cd61c281Sdrh    PRAGMA cache_size;
116cd61c281Sdrh    PRAGMA default_cache_size;
117cd61c281Sdrh    PRAGMA synchronous;
118cd61c281Sdrh  }
1191e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
120cd61c281Sdrhdo_test pragma-1.8 {
121cd61c281Sdrh  execsql {
122d2cb50b7Sdrh    PRAGMA default_cache_size=-123;
123cd61c281Sdrh    PRAGMA cache_size;
124cd61c281Sdrh    PRAGMA default_cache_size;
125cd61c281Sdrh    PRAGMA synchronous;
126cd61c281Sdrh  }
12791cf71b0Sdanielk1977} {123 123 2}
128802d69a7Sdrhdo_test pragma-1.9.1 {
129cd61c281Sdrh  db close
130dddca286Sdrh  sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
131cd61c281Sdrh  execsql {
132cd61c281Sdrh    PRAGMA cache_size;
133cd61c281Sdrh    PRAGMA default_cache_size;
134cd61c281Sdrh    PRAGMA synchronous;
135cd61c281Sdrh  }
13691cf71b0Sdanielk1977} {123 123 2}
137802d69a7Sdrhifcapable vacuum {
138802d69a7Sdrh  do_test pragma-1.9.2 {
139802d69a7Sdrh    execsql {
140802d69a7Sdrh      VACUUM;
141802d69a7Sdrh      PRAGMA cache_size;
142802d69a7Sdrh      PRAGMA default_cache_size;
143802d69a7Sdrh      PRAGMA synchronous;
144802d69a7Sdrh    }
145802d69a7Sdrh  } {123 123 2}
146802d69a7Sdrh}
14791cf71b0Sdanielk1977do_test pragma-1.10 {
1485a38705eSdrh  execsql {
1494303feedSdrh    PRAGMA synchronous=NORMAL;
1504303feedSdrh    PRAGMA cache_size;
1514303feedSdrh    PRAGMA default_cache_size;
1524303feedSdrh    PRAGMA synchronous;
1534303feedSdrh  }
15491cf71b0Sdanielk1977} {123 123 1}
15591cf71b0Sdanielk1977do_test pragma-1.11 {
1564303feedSdrh  execsql {
1574303feedSdrh    PRAGMA synchronous=FULL;
1584303feedSdrh    PRAGMA cache_size;
1594303feedSdrh    PRAGMA default_cache_size;
1604303feedSdrh    PRAGMA synchronous;
1614303feedSdrh  }
16291cf71b0Sdanielk1977} {123 123 2}
16391cf71b0Sdanielk1977do_test pragma-1.12 {
1644303feedSdrh  db close
165dddca286Sdrh  sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
1664303feedSdrh  execsql {
1674303feedSdrh    PRAGMA cache_size;
1684303feedSdrh    PRAGMA default_cache_size;
1694303feedSdrh    PRAGMA synchronous;
1704303feedSdrh  }
17191cf71b0Sdanielk1977} {123 123 2}
17291cf71b0Sdanielk1977
1735260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition
1745260f7e9Sdrh# to keywords like "off" and "full".
1755260f7e9Sdrh#
1765260f7e9Sdrhdo_test pragma-1.13 {
1775260f7e9Sdrh  execsql {
1785260f7e9Sdrh    PRAGMA synchronous=0;
1795260f7e9Sdrh    PRAGMA synchronous;
1805260f7e9Sdrh  }
1815260f7e9Sdrh} {0}
1825260f7e9Sdrhdo_test pragma-1.14 {
1835260f7e9Sdrh  execsql {
1845260f7e9Sdrh    PRAGMA synchronous=2;
1855260f7e9Sdrh    PRAGMA synchronous;
1865260f7e9Sdrh  }
1875260f7e9Sdrh} {2}
188c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
1895260f7e9Sdrh
1905260f7e9Sdrh# Test turning "flag" pragmas on and off.
1915260f7e9Sdrh#
1926338c762Sdanielk1977ifcapable debug {
1936338c762Sdanielk1977  # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG
1946338c762Sdanielk1977  #
1955260f7e9Sdrh  do_test pragma-1.15 {
1965260f7e9Sdrh    execsql {
1975260f7e9Sdrh      PRAGMA vdbe_listing=YES;
1985260f7e9Sdrh      PRAGMA vdbe_listing;
1995260f7e9Sdrh    }
2005260f7e9Sdrh  } {1}
2015260f7e9Sdrh  do_test pragma-1.16 {
2025260f7e9Sdrh    execsql {
2035260f7e9Sdrh      PRAGMA vdbe_listing=NO;
2045260f7e9Sdrh      PRAGMA vdbe_listing;
2055260f7e9Sdrh    }
2065260f7e9Sdrh  } {0}
2076338c762Sdanielk1977}
2086338c762Sdanielk1977
2095260f7e9Sdrhdo_test pragma-1.17 {
2105260f7e9Sdrh  execsql {
2115260f7e9Sdrh    PRAGMA parser_trace=ON;
2125260f7e9Sdrh    PRAGMA parser_trace=OFF;
2135260f7e9Sdrh  }
2145260f7e9Sdrh} {}
2155260f7e9Sdrhdo_test pragma-1.18 {
2165260f7e9Sdrh  execsql {
2175260f7e9Sdrh    PRAGMA bogus = -1234;  -- Parsing of negative values
2185260f7e9Sdrh  }
2195260f7e9Sdrh} {}
2205260f7e9Sdrh
22191cf71b0Sdanielk1977# Test modifying the safety_level of an attached database.
2225a8f9374Sdanielk1977ifcapable pager_pragmas&&attach {
22391cf71b0Sdanielk1977  do_test pragma-2.1 {
22491cf71b0Sdanielk1977    file delete -force test2.db
22591cf71b0Sdanielk1977    file delete -force test2.db-journal
2264303feedSdrh    execsql {
22791cf71b0Sdanielk1977      ATTACH 'test2.db' AS aux;
2284303feedSdrh    }
22991cf71b0Sdanielk1977  } {}
23091cf71b0Sdanielk1977  do_test pragma-2.2 {
2314303feedSdrh    execsql {
23291cf71b0Sdanielk1977      pragma aux.synchronous;
2334303feedSdrh    }
23491cf71b0Sdanielk1977  } {2}
23591cf71b0Sdanielk1977  do_test pragma-2.3 {
23691cf71b0Sdanielk1977    execsql {
23791cf71b0Sdanielk1977      pragma aux.synchronous = OFF;
23891cf71b0Sdanielk1977      pragma aux.synchronous;
23991cf71b0Sdanielk1977      pragma synchronous;
24091cf71b0Sdanielk1977    }
24191cf71b0Sdanielk1977  } {0 2}
24291cf71b0Sdanielk1977  do_test pragma-2.4 {
24391cf71b0Sdanielk1977    execsql {
24491cf71b0Sdanielk1977      pragma aux.synchronous = ON;
24591cf71b0Sdanielk1977      pragma synchronous;
24691cf71b0Sdanielk1977      pragma aux.synchronous;
24791cf71b0Sdanielk1977    }
24891cf71b0Sdanielk1977  } {2 1}
249c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
2504303feedSdrh
251ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check
252ed717fe3Sdrh# pragma finds it.
253ed717fe3Sdrh#
25425d6543dSdrh# These tests won't work if the database is encrypted
25525d6543dSdrh#
256ed717fe3Sdrhdo_test pragma-3.1 {
2571e9daa6aSdrh  db close
2581e9daa6aSdrh  file delete -force test.db test.db-journal
2591e9daa6aSdrh  sqlite3 db test.db
260ed717fe3Sdrh  execsql {
2611e9daa6aSdrh    PRAGMA auto_vacuum=OFF;
262ed717fe3Sdrh    BEGIN;
263ed717fe3Sdrh    CREATE TABLE t2(a,b,c);
264ed717fe3Sdrh    CREATE INDEX i2 ON t2(a);
265ed717fe3Sdrh    INSERT INTO t2 VALUES(11,2,3);
266ed717fe3Sdrh    INSERT INTO t2 VALUES(22,3,4);
267ed717fe3Sdrh    COMMIT;
268ed717fe3Sdrh    SELECT rowid, * from t2;
269ed717fe3Sdrh  }
270ed717fe3Sdrh} {1 11 2 3 2 22 3 4}
2715a8f9374Sdanielk1977ifcapable attach {
27240e016e4Sdrh  if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
273ed717fe3Sdrh    do_test pragma-3.2 {
274bb8a279eSdrh      db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break
275bb8a279eSdrh      set pgsz [db eval {PRAGMA page_size}]
276bb8a279eSdrh      # overwrite the header on the rootpage of the index in order to
277bb8a279eSdrh      # make the index appear to be empty.
278bb8a279eSdrh      #
279bb8a279eSdrh      set offset [expr {$pgsz*($rootpage-1)}]
280bb8a279eSdrh      hexio_write test.db $offset 0a00000000040000000000
281bb8a279eSdrh      db close
282bb8a279eSdrh      sqlite3 db test.db
283ed717fe3Sdrh      execsql {PRAGMA integrity_check}
284bb8a279eSdrh    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
28591cf71b0Sdanielk1977    do_test pragma-3.3 {
2861dcdbc06Sdrh      execsql {PRAGMA integrity_check=1}
2871dcdbc06Sdrh    } {{rowid 1 missing from index i2}}
2881dcdbc06Sdrh    do_test pragma-3.4 {
28991cf71b0Sdanielk1977      execsql {
2901dcdbc06Sdrh        ATTACH DATABASE 'test.db' AS t2;
2911dcdbc06Sdrh        PRAGMA integrity_check
29291cf71b0Sdanielk1977      }
293bb8a279eSdrh    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
2941dcdbc06Sdrh    do_test pragma-3.5 {
2951dcdbc06Sdrh      execsql {
296bb8a279eSdrh        PRAGMA integrity_check=4
2971dcdbc06Sdrh      }
298bb8a279eSdrh    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}}
2991dcdbc06Sdrh    do_test pragma-3.6 {
3001dcdbc06Sdrh      execsql {
3011dcdbc06Sdrh        PRAGMA integrity_check=xyz
3021dcdbc06Sdrh      }
303bb8a279eSdrh    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
3041dcdbc06Sdrh    do_test pragma-3.7 {
3051dcdbc06Sdrh      execsql {
3061dcdbc06Sdrh        PRAGMA integrity_check=0
3071dcdbc06Sdrh      }
308bb8a279eSdrh    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
3091dcdbc06Sdrh
3101dcdbc06Sdrh    # Add additional corruption by appending unused pages to the end of
3111dcdbc06Sdrh    # the database file testerr.db
3121dcdbc06Sdrh    #
3131dcdbc06Sdrh    do_test pragma-3.8 {
3141dcdbc06Sdrh      execsql {DETACH t2}
3151dcdbc06Sdrh      file delete -force testerr.db testerr.db-journal
316e3d559adSdrh      set out [open testerr.db w]
317e3d559adSdrh      fconfigure $out -translation binary
318e3d559adSdrh      set in [open test.db r]
319e3d559adSdrh      fconfigure $in -translation binary
3201dcdbc06Sdrh      puts -nonewline $out [read $in]
3211dcdbc06Sdrh      seek $in 0
3221dcdbc06Sdrh      puts -nonewline $out [read $in]
3231dcdbc06Sdrh      close $in
3241dcdbc06Sdrh      close $out
325dd3cd977Sdrh      hexio_write testerr.db 28 00000000
3261dcdbc06Sdrh      execsql {REINDEX t2}
3271dcdbc06Sdrh      execsql {PRAGMA integrity_check}
3281dcdbc06Sdrh    } {ok}
32941c58b78Sdanielk1977    do_test pragma-3.8.1 {
33041c58b78Sdanielk1977      execsql {PRAGMA quick_check}
33141c58b78Sdanielk1977    } {ok}
3321dcdbc06Sdrh    do_test pragma-3.9 {
3331dcdbc06Sdrh      execsql {
3341dcdbc06Sdrh        ATTACH 'testerr.db' AS t2;
3351dcdbc06Sdrh        PRAGMA integrity_check
3361dcdbc06Sdrh      }
3371dcdbc06Sdrh    } {{*** in database t2 ***
3381dcdbc06SdrhPage 4 is never used
3391dcdbc06SdrhPage 5 is never used
340bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
3411dcdbc06Sdrh    do_test pragma-3.10 {
3421dcdbc06Sdrh      execsql {
3431dcdbc06Sdrh        PRAGMA integrity_check=1
3441dcdbc06Sdrh      }
3451dcdbc06Sdrh    } {{*** in database t2 ***
3461dcdbc06SdrhPage 4 is never used}}
3471dcdbc06Sdrh    do_test pragma-3.11 {
3481dcdbc06Sdrh      execsql {
3491dcdbc06Sdrh        PRAGMA integrity_check=5
3501dcdbc06Sdrh      }
3511dcdbc06Sdrh    } {{*** in database t2 ***
3521dcdbc06SdrhPage 4 is never used
3531dcdbc06SdrhPage 5 is never used
354bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2}}
3551dcdbc06Sdrh    do_test pragma-3.12 {
3561dcdbc06Sdrh      execsql {
3571dcdbc06Sdrh        PRAGMA integrity_check=4
3581dcdbc06Sdrh      }
3591dcdbc06Sdrh    } {{*** in database t2 ***
3601dcdbc06SdrhPage 4 is never used
3611dcdbc06SdrhPage 5 is never used
3621dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
3631dcdbc06Sdrh    do_test pragma-3.13 {
3641dcdbc06Sdrh      execsql {
3651dcdbc06Sdrh        PRAGMA integrity_check=3
3661dcdbc06Sdrh      }
3671dcdbc06Sdrh    } {{*** in database t2 ***
3681dcdbc06SdrhPage 4 is never used
3691dcdbc06SdrhPage 5 is never used
3701dcdbc06SdrhPage 6 is never used}}
3711dcdbc06Sdrh    do_test pragma-3.14 {
3721dcdbc06Sdrh      execsql {
3731dcdbc06Sdrh        PRAGMA integrity_check(2)
3741dcdbc06Sdrh      }
3751dcdbc06Sdrh    } {{*** in database t2 ***
3761dcdbc06SdrhPage 4 is never used
3771dcdbc06SdrhPage 5 is never used}}
3781dcdbc06Sdrh    do_test pragma-3.15 {
3791dcdbc06Sdrh      execsql {
3801dcdbc06Sdrh        ATTACH 'testerr.db' AS t3;
3811dcdbc06Sdrh        PRAGMA integrity_check
3821dcdbc06Sdrh      }
3831dcdbc06Sdrh    } {{*** in database t2 ***
3841dcdbc06SdrhPage 4 is never used
3851dcdbc06SdrhPage 5 is never used
386bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
3871dcdbc06SdrhPage 4 is never used
3881dcdbc06SdrhPage 5 is never used
389bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
3901dcdbc06Sdrh    do_test pragma-3.16 {
3911dcdbc06Sdrh      execsql {
392bb8a279eSdrh        PRAGMA integrity_check(10)
3931dcdbc06Sdrh      }
3941dcdbc06Sdrh    } {{*** in database t2 ***
3951dcdbc06SdrhPage 4 is never used
3961dcdbc06SdrhPage 5 is never used
397bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
3981dcdbc06SdrhPage 4 is never used
3991dcdbc06SdrhPage 5 is never used
4001dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
4011dcdbc06Sdrh    do_test pragma-3.17 {
4021dcdbc06Sdrh      execsql {
403bb8a279eSdrh        PRAGMA integrity_check=8
4041dcdbc06Sdrh      }
4051dcdbc06Sdrh    } {{*** in database t2 ***
4061dcdbc06SdrhPage 4 is never used
4071dcdbc06SdrhPage 5 is never used
408bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
4091dcdbc06SdrhPage 4 is never used
4101dcdbc06SdrhPage 5 is never used}}
4111dcdbc06Sdrh    do_test pragma-3.18 {
4121dcdbc06Sdrh      execsql {
4131dcdbc06Sdrh        PRAGMA integrity_check=4
4141dcdbc06Sdrh      }
4151dcdbc06Sdrh    } {{*** in database t2 ***
4161dcdbc06SdrhPage 4 is never used
4171dcdbc06SdrhPage 5 is never used
4181dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
4191dcdbc06Sdrh  }
420d2cb50b7Sdrh  do_test pragma-3.19 {
421d2cb50b7Sdrh    catch {db close}
422d2cb50b7Sdrh    file delete -force test.db test.db-journal
423d2cb50b7Sdrh    sqlite3 db test.db
424d2cb50b7Sdrh    db eval {PRAGMA integrity_check}
425d2cb50b7Sdrh  } {ok}
4265a8f9374Sdanielk1977}
427d2cb50b7Sdrh#exit
42891cf71b0Sdanielk1977
42991cf71b0Sdanielk1977# Test modifying the cache_size of an attached database.
4305a8f9374Sdanielk1977ifcapable pager_pragmas&&attach {
43191cf71b0Sdanielk1977do_test pragma-4.1 {
43291cf71b0Sdanielk1977  execsql {
4331e9daa6aSdrh    ATTACH 'test2.db' AS aux;
43491cf71b0Sdanielk1977    pragma aux.cache_size;
43591cf71b0Sdanielk1977    pragma aux.default_cache_size;
43691cf71b0Sdanielk1977  }
4371e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4381bdd9b57Sdrhdo_test pragma-4.2 {
4391bdd9b57Sdrh  execsql {
44091cf71b0Sdanielk1977    pragma aux.cache_size = 50;
44191cf71b0Sdanielk1977    pragma aux.cache_size;
44291cf71b0Sdanielk1977    pragma aux.default_cache_size;
4431bdd9b57Sdrh  }
4441e9daa6aSdrh} [list 50 $DFLT_CACHE_SZ]
4451bdd9b57Sdrhdo_test pragma-4.3 {
4461bdd9b57Sdrh  execsql {
44791cf71b0Sdanielk1977    pragma aux.default_cache_size = 456;
44891cf71b0Sdanielk1977    pragma aux.cache_size;
44991cf71b0Sdanielk1977    pragma aux.default_cache_size;
4501bdd9b57Sdrh  }
45191cf71b0Sdanielk1977} {456 456}
4521bdd9b57Sdrhdo_test pragma-4.4 {
4531bdd9b57Sdrh  execsql {
45491cf71b0Sdanielk1977    pragma cache_size;
45591cf71b0Sdanielk1977    pragma default_cache_size;
4561bdd9b57Sdrh  }
4571e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4581bdd9b57Sdrhdo_test pragma-4.5 {
4591bdd9b57Sdrh  execsql {
46091cf71b0Sdanielk1977    DETACH aux;
46191cf71b0Sdanielk1977    ATTACH 'test3.db' AS aux;
46291cf71b0Sdanielk1977    pragma aux.cache_size;
46391cf71b0Sdanielk1977    pragma aux.default_cache_size;
4641bdd9b57Sdrh  }
4651e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4661bdd9b57Sdrhdo_test pragma-4.6 {
4671bdd9b57Sdrh  execsql {
46891cf71b0Sdanielk1977    DETACH aux;
46991cf71b0Sdanielk1977    ATTACH 'test2.db' AS aux;
47091cf71b0Sdanielk1977    pragma aux.cache_size;
47191cf71b0Sdanielk1977    pragma aux.default_cache_size;
4721bdd9b57Sdrh  }
47391cf71b0Sdanielk1977} {456 456}
474c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
4751bdd9b57Sdrh
47691cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is
47791cf71b0Sdanielk1977# disallowed.
478c7b4a44cSdanielk1977ifcapable pager_pragmas {
47991cf71b0Sdanielk1977do_test pragma-5.0 {
4801bdd9b57Sdrh  execsql {
48191cf71b0Sdanielk1977    pragma synchronous;
4821bdd9b57Sdrh  }
48391cf71b0Sdanielk1977} {2}
48491cf71b0Sdanielk1977do_test pragma-5.1 {
4851bdd9b57Sdrh  catchsql {
4861bdd9b57Sdrh    BEGIN;
48791cf71b0Sdanielk1977    pragma synchronous = OFF;
4881bdd9b57Sdrh  }
48991cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}}
49091cf71b0Sdanielk1977do_test pragma-5.2 {
49191cf71b0Sdanielk1977  execsql {
49291cf71b0Sdanielk1977    pragma synchronous;
49391cf71b0Sdanielk1977  }
49491cf71b0Sdanielk1977} {2}
4955260f7e9Sdrhcatchsql {COMMIT;}
496c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
4975260f7e9Sdrh
4985260f7e9Sdrh# Test schema-query pragmas
4995260f7e9Sdrh#
50027188fb5Sdanielk1977ifcapable schema_pragmas {
5015a8f9374Sdanielk1977ifcapable tempdb&&attach {
5025260f7e9Sdrh  do_test pragma-6.1 {
503956bc92cSdrh    set res {}
50440e016e4Sdrh    execsql {SELECT * FROM sqlite_temp_master}
5055260f7e9Sdrh    foreach {idx name file} [execsql {pragma database_list}] {
5065260f7e9Sdrh      lappend res $idx $name
5075260f7e9Sdrh    }
5085260f7e9Sdrh    set res
509a71aa001Sdrh  } {0 main 1 temp 2 aux}
51053c0f748Sdanielk1977}
5115260f7e9Sdrhdo_test pragma-6.2 {
5125260f7e9Sdrh  execsql {
513d2cb50b7Sdrh    CREATE TABLE t2(a,b,c);
5145260f7e9Sdrh    pragma table_info(t2)
5155260f7e9Sdrh  }
516bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0}
517d2cb50b7Sdrhdo_test pragma-6.2.1 {
518d2cb50b7Sdrh  execsql {
519d2cb50b7Sdrh    pragma table_info;
520d2cb50b7Sdrh  }
521d2cb50b7Sdrh} {}
522736c7d4bSdrhdb nullvalue <<NULL>>
523417ec638Sdrhdo_test pragma-6.2.2 {
524417ec638Sdrh  execsql {
525736c7d4bSdrh    CREATE TABLE t5(
526736c7d4bSdrh      a TEXT DEFAULT CURRENT_TIMESTAMP,
527736c7d4bSdrh      b DEFAULT (5+3),
528736c7d4bSdrh      c TEXT,
529736c7d4bSdrh      d INTEGER DEFAULT NULL,
530736c7d4bSdrh      e TEXT DEFAULT ''
531736c7d4bSdrh    );
532417ec638Sdrh    PRAGMA table_info(t5);
533417ec638Sdrh  }
534736c7d4bSdrh} {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}
535736c7d4bSdrhdb nullvalue {}
5366bf89570Sdrhifcapable {foreignkey} {
537d2cb50b7Sdrh  do_test pragma-6.3.1 {
5385260f7e9Sdrh    execsql {
5395260f7e9Sdrh      CREATE TABLE t3(a int references t2(b), b UNIQUE);
5405260f7e9Sdrh      pragma foreign_key_list(t3);
5415260f7e9Sdrh    }
5421da40a38Sdan  } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE}
543d2cb50b7Sdrh  do_test pragma-6.3.2 {
544d2cb50b7Sdrh    execsql {
545d2cb50b7Sdrh      pragma foreign_key_list;
546d2cb50b7Sdrh    }
547d2cb50b7Sdrh  } {}
548d2cb50b7Sdrh  do_test pragma-6.3.3 {
549d2cb50b7Sdrh    execsql {
550d2cb50b7Sdrh      pragma foreign_key_list(t3_bogus);
551d2cb50b7Sdrh    }
552d2cb50b7Sdrh  } {}
553d2cb50b7Sdrh  do_test pragma-6.3.4 {
554d2cb50b7Sdrh    execsql {
555d2cb50b7Sdrh      pragma foreign_key_list(t5);
556d2cb50b7Sdrh    }
557d2cb50b7Sdrh  } {}
5585260f7e9Sdrh  do_test pragma-6.4 {
5595260f7e9Sdrh    execsql {
5605260f7e9Sdrh      pragma index_list(t3);
5615260f7e9Sdrh    }
5625260f7e9Sdrh  } {0 sqlite_autoindex_t3_1 1}
5636bf89570Sdrh}
5646bf89570Sdrhifcapable {!foreignkey} {
5656bf89570Sdrh  execsql {CREATE TABLE t3(a,b UNIQUE)}
5666bf89570Sdrh}
567d2cb50b7Sdrhdo_test pragma-6.5.1 {
5685260f7e9Sdrh  execsql {
5695260f7e9Sdrh    CREATE INDEX t3i1 ON t3(a,b);
5705260f7e9Sdrh    pragma index_info(t3i1);
5715260f7e9Sdrh  }
5725260f7e9Sdrh} {0 0 a 1 1 b}
573d2cb50b7Sdrhdo_test pragma-6.5.2 {
574d2cb50b7Sdrh  execsql {
575d2cb50b7Sdrh    pragma index_info(t3i1_bogus);
576d2cb50b7Sdrh  }
577d2cb50b7Sdrh} {}
578260d8a6aSdanielk1977
579260d8a6aSdanielk1977ifcapable tempdb {
580260d8a6aSdanielk1977  # Test for ticket #3320. When a temp table of the same name exists, make
581260d8a6aSdanielk1977  # sure the schema of the main table can still be queried using
582260d8a6aSdanielk1977  # "pragma table_info":
583260d8a6aSdanielk1977  do_test pragma-6.6.1 {
584260d8a6aSdanielk1977    execsql {
585260d8a6aSdanielk1977      CREATE TABLE trial(col_main);
586260d8a6aSdanielk1977      CREATE TEMP TABLE trial(col_temp);
587260d8a6aSdanielk1977    }
588260d8a6aSdanielk1977  } {}
589260d8a6aSdanielk1977  do_test pragma-6.6.2 {
590260d8a6aSdanielk1977    execsql {
591260d8a6aSdanielk1977      PRAGMA table_info(trial);
592260d8a6aSdanielk1977    }
593260d8a6aSdanielk1977  } {0 col_temp {} 0 {} 0}
594260d8a6aSdanielk1977  do_test pragma-6.6.3 {
595260d8a6aSdanielk1977    execsql {
596260d8a6aSdanielk1977      PRAGMA temp.table_info(trial);
597260d8a6aSdanielk1977    }
598260d8a6aSdanielk1977  } {0 col_temp {} 0 {} 0}
599260d8a6aSdanielk1977  do_test pragma-6.6.4 {
600260d8a6aSdanielk1977    execsql {
601260d8a6aSdanielk1977      PRAGMA main.table_info(trial);
602260d8a6aSdanielk1977    }
603260d8a6aSdanielk1977  } {0 col_main {} 0 {} 0}
604260d8a6aSdanielk1977}
605f96a3778Sdanielk1977
606f96a3778Sdanielk1977do_test pragma-6.7 {
607f96a3778Sdanielk1977  execsql {
608f96a3778Sdanielk1977    CREATE TABLE test_table(
609f96a3778Sdanielk1977      one INT NOT NULL DEFAULT -1,
610f96a3778Sdanielk1977      two text,
611f96a3778Sdanielk1977      three VARCHAR(45, 65) DEFAULT 'abcde',
612f96a3778Sdanielk1977      four REAL DEFAULT X'abcdef',
613f96a3778Sdanielk1977      five DEFAULT CURRENT_TIME
614f96a3778Sdanielk1977    );
615f96a3778Sdanielk1977    PRAGMA table_info(test_table);
616f96a3778Sdanielk1977  }
617f96a3778Sdanielk1977} [concat \
618f96a3778Sdanielk1977  {0 one INT 1 -1 0} \
619f96a3778Sdanielk1977  {1 two text 0 {} 0} \
620f96a3778Sdanielk1977  {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \
621f96a3778Sdanielk1977  {3 four REAL 0 X'abcdef' 0} \
622f96a3778Sdanielk1977  {4 five {} 0 CURRENT_TIME 0} \
623f96a3778Sdanielk1977]
62427188fb5Sdanielk1977} ;# ifcapable schema_pragmas
6255260f7e9Sdrh# Miscellaneous tests
6265260f7e9Sdrh#
62727188fb5Sdanielk1977ifcapable schema_pragmas {
628d2cb50b7Sdrhdo_test pragma-7.1.1 {
6295260f7e9Sdrh  # Make sure a pragma knows to read the schema if it needs to
6305260f7e9Sdrh  db close
6315260f7e9Sdrh  sqlite3 db test.db
6325260f7e9Sdrh  execsql {
6335260f7e9Sdrh    pragma index_list(t3);
6345260f7e9Sdrh  }
6355260f7e9Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1}
636d2cb50b7Sdrhdo_test pragma-7.1.2 {
637d2cb50b7Sdrh  execsql {
638d2cb50b7Sdrh    pragma index_list(t3_bogus);
639d2cb50b7Sdrh  }
640d2cb50b7Sdrh} {}
64127188fb5Sdanielk1977} ;# ifcapable schema_pragmas
6426c62608fSdrhifcapable {utf16} {
6435260f7e9Sdrh  do_test pragma-7.2 {
6445260f7e9Sdrh    db close
6455260f7e9Sdrh    sqlite3 db test.db
6465260f7e9Sdrh    catchsql {
6475260f7e9Sdrh      pragma encoding=bogus;
6485260f7e9Sdrh    }
6495260f7e9Sdrh  } {1 {unsupported encoding: bogus}}
6506c62608fSdrh}
65153c0f748Sdanielk1977ifcapable tempdb {
6525260f7e9Sdrh  do_test pragma-7.3 {
6535260f7e9Sdrh    db close
6545260f7e9Sdrh    sqlite3 db test.db
6555260f7e9Sdrh    execsql {
6565260f7e9Sdrh      pragma lock_status;
6575260f7e9Sdrh    }
6585260f7e9Sdrh  } {main unlocked temp closed}
65953c0f748Sdanielk1977} else {
66053c0f748Sdanielk1977  do_test pragma-7.3 {
66153c0f748Sdanielk1977    db close
66253c0f748Sdanielk1977    sqlite3 db test.db
66353c0f748Sdanielk1977    execsql {
66453c0f748Sdanielk1977      pragma lock_status;
66553c0f748Sdanielk1977    }
66653c0f748Sdanielk1977  } {main unlocked}
66753c0f748Sdanielk1977}
6685260f7e9Sdrh
6695260f7e9Sdrh
670dae2495bSdanielk1977#----------------------------------------------------------------------
671b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
672b92b70bbSdanielk1977# user_version" statements.
673dae2495bSdanielk1977#
674b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version
675b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version
676dae2495bSdanielk1977#
677dae2495bSdanielk1977
67811cf9fbcSdanielk1977ifcapable schema_version {
67911cf9fbcSdanielk1977
680b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the
681dae2495bSdanielk1977# same value.
682dae2495bSdanielk1977do_test pragma-8.1.1 {
683dae2495bSdanielk1977  execsql {
684b92b70bbSdanielk1977    PRAGMA schema_version = 105;
685dae2495bSdanielk1977  }
686dae2495bSdanielk1977} {}
687dae2495bSdanielk1977do_test pragma-8.1.2 {
68825403650Sdrh  execsql2 {
689b92b70bbSdanielk1977    PRAGMA schema_version;
690dae2495bSdanielk1977  }
69125403650Sdrh} {schema_version 105}
692dae2495bSdanielk1977do_test pragma-8.1.3 {
693dae2495bSdanielk1977  execsql {
694b92b70bbSdanielk1977    PRAGMA schema_version = 106;
695dae2495bSdanielk1977  }
696dae2495bSdanielk1977} {}
697dae2495bSdanielk1977do_test pragma-8.1.4 {
698dae2495bSdanielk1977  execsql {
699b92b70bbSdanielk1977    PRAGMA schema_version;
700dae2495bSdanielk1977  }
701dae2495bSdanielk1977} 106
702dae2495bSdanielk1977
703b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really
704b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version).
705dae2495bSdanielk1977do_test pragma-8.1.5 {
706dae2495bSdanielk1977  execsql {
707dae2495bSdanielk1977    CREATE TABLE t4(a, b, c);
708dae2495bSdanielk1977    INSERT INTO t4 VALUES(1, 2, 3);
709dae2495bSdanielk1977    SELECT * FROM t4;
710dae2495bSdanielk1977  }
711dae2495bSdanielk1977} {1 2 3}
712dae2495bSdanielk1977do_test pragma-8.1.6 {
713dae2495bSdanielk1977  execsql {
714b92b70bbSdanielk1977    PRAGMA schema_version;
715dae2495bSdanielk1977  }
716dae2495bSdanielk1977} 107
717dae2495bSdanielk1977
718dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the
719b92b70bbSdanielk1977# schema-version using the first connection forces the second connection
720dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions,
721dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query.
722dae2495bSdanielk1977do_test pragma-8.1.7 {
723dddca286Sdrh  sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
724dae2495bSdanielk1977  execsql {
725dae2495bSdanielk1977    SELECT * FROM t4;
726dae2495bSdanielk1977  } db2
727dae2495bSdanielk1977} {1 2 3}
728dae2495bSdanielk1977do_test pragma-8.1.8 {
729dae2495bSdanielk1977  execsql {
730b92b70bbSdanielk1977    PRAGMA schema_version = 108;
731dae2495bSdanielk1977  }
732dae2495bSdanielk1977} {}
733dae2495bSdanielk1977do_test pragma-8.1.9 {
734dae2495bSdanielk1977  set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
735dae2495bSdanielk1977  sqlite3_step $::STMT
736dae2495bSdanielk1977} SQLITE_ERROR
737dae2495bSdanielk1977do_test pragma-8.1.10 {
738dae2495bSdanielk1977  sqlite3_finalize $::STMT
739dae2495bSdanielk1977} SQLITE_SCHEMA
740dae2495bSdanielk1977
741b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database.
742dae2495bSdanielk1977file delete -force test2.db
743dae2495bSdanielk1977file delete -force test2.db-journal
7445a8f9374Sdanielk1977ifcapable attach {
745dae2495bSdanielk1977  do_test pragma-8.1.11 {
746dae2495bSdanielk1977    execsql {
747dae2495bSdanielk1977      ATTACH 'test2.db' AS aux;
748dae2495bSdanielk1977      CREATE TABLE aux.t1(a, b, c);
749b92b70bbSdanielk1977      PRAGMA aux.schema_version = 205;
750dae2495bSdanielk1977    }
751dae2495bSdanielk1977  } {}
752dae2495bSdanielk1977  do_test pragma-8.1.12 {
753dae2495bSdanielk1977    execsql {
754b92b70bbSdanielk1977      PRAGMA aux.schema_version;
755dae2495bSdanielk1977    }
756dae2495bSdanielk1977  } 205
7575a8f9374Sdanielk1977}
758dae2495bSdanielk1977do_test pragma-8.1.13 {
759dae2495bSdanielk1977  execsql {
760b92b70bbSdanielk1977    PRAGMA schema_version;
761dae2495bSdanielk1977  }
762dae2495bSdanielk1977} 108
763dae2495bSdanielk1977
764b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database
765dae2495bSdanielk1977# forces the second connection to reload the schema.
7665a8f9374Sdanielk1977ifcapable attach {
767dae2495bSdanielk1977  do_test pragma-8.1.14 {
768dddca286Sdrh    sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
769dae2495bSdanielk1977    execsql {
770dae2495bSdanielk1977      ATTACH 'test2.db' AS aux;
771dae2495bSdanielk1977      SELECT * FROM aux.t1;
772dae2495bSdanielk1977    } db2
773dae2495bSdanielk1977  } {}
774dae2495bSdanielk1977  do_test pragma-8.1.15 {
775dae2495bSdanielk1977    execsql {
776b92b70bbSdanielk1977      PRAGMA aux.schema_version = 206;
777dae2495bSdanielk1977    }
778dae2495bSdanielk1977  } {}
779dae2495bSdanielk1977  do_test pragma-8.1.16 {
780dae2495bSdanielk1977    set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]
781dae2495bSdanielk1977    sqlite3_step $::STMT
782dae2495bSdanielk1977  } SQLITE_ERROR
783dae2495bSdanielk1977  do_test pragma-8.1.17 {
784dae2495bSdanielk1977    sqlite3_finalize $::STMT
785dae2495bSdanielk1977  } SQLITE_SCHEMA
786dae2495bSdanielk1977  do_test pragma-8.1.18 {
787dae2495bSdanielk1977    db2 close
788dae2495bSdanielk1977  } {}
7895a8f9374Sdanielk1977}
790dae2495bSdanielk1977
791b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't
792b92b70bbSdanielk1977# accidentally manipulating the schema-version instead).
793dae2495bSdanielk1977do_test pragma-8.2.1 {
79425403650Sdrh  execsql2 {
795b92b70bbSdanielk1977    PRAGMA user_version;
796dae2495bSdanielk1977  }
79725403650Sdrh} {user_version 0}
798dae2495bSdanielk1977do_test pragma-8.2.2 {
799dae2495bSdanielk1977  execsql {
800b92b70bbSdanielk1977    PRAGMA user_version = 2;
801dae2495bSdanielk1977  }
802dae2495bSdanielk1977} {}
803802d69a7Sdrhdo_test pragma-8.2.3.1 {
80425403650Sdrh  execsql2 {
805b92b70bbSdanielk1977    PRAGMA user_version;
806dae2495bSdanielk1977  }
80725403650Sdrh} {user_version 2}
808802d69a7Sdrhdo_test pragma-8.2.3.2 {
809802d69a7Sdrh  db close
810802d69a7Sdrh  sqlite3 db test.db
811802d69a7Sdrh  execsql {
812802d69a7Sdrh    PRAGMA user_version;
813802d69a7Sdrh  }
814802d69a7Sdrh} {2}
815802d69a7Sdrhdo_test pragma-8.2.4.1 {
816dae2495bSdanielk1977  execsql {
817b92b70bbSdanielk1977    PRAGMA schema_version;
818dae2495bSdanielk1977  }
819dae2495bSdanielk1977} {108}
820802d69a7Sdrhifcapable vacuum {
821802d69a7Sdrh  do_test pragma-8.2.4.2 {
822802d69a7Sdrh    execsql {
823802d69a7Sdrh      VACUUM;
824802d69a7Sdrh      PRAGMA user_version;
825802d69a7Sdrh    }
826802d69a7Sdrh  } {2}
827802d69a7Sdrh  do_test pragma-8.2.4.3 {
828802d69a7Sdrh    execsql {
829802d69a7Sdrh      PRAGMA schema_version;
830802d69a7Sdrh    }
831802d69a7Sdrh  } {109}
832802d69a7Sdrh}
8335a8f9374Sdanielk1977
8345a8f9374Sdanielk1977ifcapable attach {
835802d69a7Sdrh  db eval {ATTACH 'test2.db' AS aux}
836dae2495bSdanielk1977
837b92b70bbSdanielk1977  # Check that the user-version in the auxilary database can be manipulated (
838dae2495bSdanielk1977  # and that we aren't accidentally manipulating the same in the main db).
839dae2495bSdanielk1977  do_test pragma-8.2.5 {
840dae2495bSdanielk1977    execsql {
841b92b70bbSdanielk1977      PRAGMA aux.user_version;
842dae2495bSdanielk1977    }
843dae2495bSdanielk1977  } {0}
844dae2495bSdanielk1977  do_test pragma-8.2.6 {
845dae2495bSdanielk1977    execsql {
846b92b70bbSdanielk1977      PRAGMA aux.user_version = 3;
847dae2495bSdanielk1977    }
848dae2495bSdanielk1977  } {}
849dae2495bSdanielk1977  do_test pragma-8.2.7 {
850dae2495bSdanielk1977    execsql {
851b92b70bbSdanielk1977      PRAGMA aux.user_version;
852dae2495bSdanielk1977    }
853dae2495bSdanielk1977  } {3}
854dae2495bSdanielk1977  do_test pragma-8.2.8 {
855dae2495bSdanielk1977    execsql {
856b92b70bbSdanielk1977      PRAGMA main.user_version;
857dae2495bSdanielk1977    }
858dae2495bSdanielk1977  } {2}
859dae2495bSdanielk1977
860b92b70bbSdanielk1977  # Now check that a ROLLBACK resets the user-version if it has been modified
861dae2495bSdanielk1977  # within a transaction.
862dae2495bSdanielk1977  do_test pragma-8.2.9 {
863dae2495bSdanielk1977    execsql {
864dae2495bSdanielk1977      BEGIN;
865b92b70bbSdanielk1977      PRAGMA aux.user_version = 10;
866b92b70bbSdanielk1977      PRAGMA user_version = 11;
867dae2495bSdanielk1977    }
868dae2495bSdanielk1977  } {}
869dae2495bSdanielk1977  do_test pragma-8.2.10 {
870dae2495bSdanielk1977    execsql {
871b92b70bbSdanielk1977      PRAGMA aux.user_version;
872dae2495bSdanielk1977    }
873dae2495bSdanielk1977  } {10}
874dae2495bSdanielk1977  do_test pragma-8.2.11 {
875dae2495bSdanielk1977    execsql {
876b92b70bbSdanielk1977      PRAGMA main.user_version;
877dae2495bSdanielk1977    }
878dae2495bSdanielk1977  } {11}
879dae2495bSdanielk1977  do_test pragma-8.2.12 {
880dae2495bSdanielk1977    execsql {
881dae2495bSdanielk1977      ROLLBACK;
882b92b70bbSdanielk1977      PRAGMA aux.user_version;
883dae2495bSdanielk1977    }
884dae2495bSdanielk1977  } {3}
885dae2495bSdanielk1977  do_test pragma-8.2.13 {
886dae2495bSdanielk1977    execsql {
887b92b70bbSdanielk1977      PRAGMA main.user_version;
888dae2495bSdanielk1977    }
889dae2495bSdanielk1977  } {2}
8905a8f9374Sdanielk1977}
891dae2495bSdanielk1977
892b92b70bbSdanielk1977# Try a negative value for the user-version
893dae2495bSdanielk1977do_test pragma-8.2.14 {
894dae2495bSdanielk1977  execsql {
895b92b70bbSdanielk1977    PRAGMA user_version = -450;
896dae2495bSdanielk1977  }
897dae2495bSdanielk1977} {}
898dae2495bSdanielk1977do_test pragma-8.2.15 {
899dae2495bSdanielk1977  execsql {
900b92b70bbSdanielk1977    PRAGMA user_version;
901dae2495bSdanielk1977  }
902dae2495bSdanielk1977} {-450}
903d9c847dcSdanielk1977} ; # ifcapable schema_version
904d9c847dcSdanielk1977
905d19744f3Sdrh# Check to see if TEMP_STORE is memory or disk.  Return strings
906d19744f3Sdrh# "memory" or "disk" as appropriate.
907d19744f3Sdrh#
908d19744f3Sdrhproc check_temp_store {} {
909d19744f3Sdrh  db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)}
910d19744f3Sdrh  db eval {PRAGMA database_list} {
911d19744f3Sdrh    if {$name=="temp"} {
91217b90b53Sdanielk1977      set bt [btree_from_db db 1]
91317b90b53Sdanielk1977      if {[btree_ismemdb $bt]} {
914d19744f3Sdrh        return "memory"
915d19744f3Sdrh      }
91617b90b53Sdanielk1977      return "disk"
917d19744f3Sdrh    }
918d19744f3Sdrh  }
919d19744f3Sdrh  return "unknown"
920d19744f3Sdrh}
921d19744f3Sdrh
9229a09a3caStpoindex
9239a09a3caStpoindex# Test temp_store and temp_store_directory pragmas
9249a09a3caStpoindex#
925268283bcSdrhifcapable pager_pragmas {
9269a09a3caStpoindexdo_test pragma-9.1 {
9279a09a3caStpoindex  db close
9289a09a3caStpoindex  sqlite3 db test.db
9299a09a3caStpoindex  execsql {
9309a09a3caStpoindex    PRAGMA temp_store;
9319a09a3caStpoindex  }
9329a09a3caStpoindex} {0}
933d19744f3Sdrhif {$TEMP_STORE<=1} {
934d19744f3Sdrh  do_test pragma-9.1.1 {
935d19744f3Sdrh    check_temp_store
936d19744f3Sdrh  } {disk}
937d19744f3Sdrh} else {
938d19744f3Sdrh  do_test pragma-9.1.1 {
939d19744f3Sdrh    check_temp_store
940d19744f3Sdrh  } {memory}
941d19744f3Sdrh}
942d19744f3Sdrh
9439a09a3caStpoindexdo_test pragma-9.2 {
944d19744f3Sdrh  db close
945d19744f3Sdrh  sqlite3 db test.db
9469a09a3caStpoindex  execsql {
9479a09a3caStpoindex    PRAGMA temp_store=file;
9489a09a3caStpoindex    PRAGMA temp_store;
9499a09a3caStpoindex  }
9509a09a3caStpoindex} {1}
951d19744f3Sdrhif {$TEMP_STORE==3} {
952d19744f3Sdrh  # When TEMP_STORE is 3, always use memory regardless of pragma settings.
953d19744f3Sdrh  do_test pragma-9.2.1 {
954d19744f3Sdrh    check_temp_store
955d19744f3Sdrh  } {memory}
956d19744f3Sdrh} else {
957d19744f3Sdrh  do_test pragma-9.2.1 {
958d19744f3Sdrh    check_temp_store
959d19744f3Sdrh  } {disk}
960d19744f3Sdrh}
961d19744f3Sdrh
9629a09a3caStpoindexdo_test pragma-9.3 {
963d19744f3Sdrh  db close
964d19744f3Sdrh  sqlite3 db test.db
9659a09a3caStpoindex  execsql {
9669a09a3caStpoindex    PRAGMA temp_store=memory;
9679a09a3caStpoindex    PRAGMA temp_store;
9689a09a3caStpoindex  }
9699a09a3caStpoindex} {2}
970d19744f3Sdrhif {$TEMP_STORE==0} {
971d19744f3Sdrh  # When TEMP_STORE is 0, always use the disk regardless of pragma settings.
972d19744f3Sdrh  do_test pragma-9.3.1 {
973d19744f3Sdrh    check_temp_store
974d19744f3Sdrh  } {disk}
975d19744f3Sdrh} else {
976d19744f3Sdrh  do_test pragma-9.3.1 {
977d19744f3Sdrh    check_temp_store
978d19744f3Sdrh  } {memory}
979d19744f3Sdrh}
980d19744f3Sdrh
9819a09a3caStpoindexdo_test pragma-9.4 {
9829a09a3caStpoindex  execsql {
9839a09a3caStpoindex    PRAGMA temp_store_directory;
9849a09a3caStpoindex  }
9859a09a3caStpoindex} {}
98678f82d1eSdrhifcapable wsd {
9879a09a3caStpoindex  do_test pragma-9.5 {
988181ddaa1Sdanielk1977    set pwd [string map {' ''} [file nativename [pwd]]]
989268283bcSdrh    execsql "
990268283bcSdrh      PRAGMA temp_store_directory='$pwd';
9919a09a3caStpoindex    "
9929a09a3caStpoindex  } {}
9939a09a3caStpoindex  do_test pragma-9.6 {
9949a09a3caStpoindex    execsql {
9959a09a3caStpoindex      PRAGMA temp_store_directory;
9969a09a3caStpoindex    }
997181ddaa1Sdanielk1977  } [list [file nativename [pwd]]]
9989a09a3caStpoindex  do_test pragma-9.7 {
999268283bcSdrh    catchsql {
10009a09a3caStpoindex      PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
10019a09a3caStpoindex    }
1002268283bcSdrh  } {1 {not a writable directory}}
10039a09a3caStpoindex  do_test pragma-9.8 {
10049a09a3caStpoindex    execsql {
10059a09a3caStpoindex      PRAGMA temp_store_directory='';
10069a09a3caStpoindex    }
10079a09a3caStpoindex  } {}
10081e9daa6aSdrh  if {![info exists TEMP_STORE] || $TEMP_STORE<=1} {
100953c0f748Sdanielk1977    ifcapable tempdb {
10109a09a3caStpoindex      do_test pragma-9.9 {
10119a09a3caStpoindex        execsql {
10129a09a3caStpoindex          PRAGMA temp_store_directory;
10139a09a3caStpoindex          PRAGMA temp_store=FILE;
10149a09a3caStpoindex          CREATE TEMP TABLE temp_store_directory_test(a integer);
10159a09a3caStpoindex          INSERT INTO temp_store_directory_test values (2);
10169a09a3caStpoindex          SELECT * FROM temp_store_directory_test;
10179a09a3caStpoindex        }
10189a09a3caStpoindex      } {2}
10199a09a3caStpoindex      do_test pragma-9.10 {
1020268283bcSdrh        catchsql "
1021268283bcSdrh          PRAGMA temp_store_directory='$pwd';
10229a09a3caStpoindex          SELECT * FROM temp_store_directory_test;
10239a09a3caStpoindex        "
1024268283bcSdrh      } {1 {no such table: temp_store_directory_test}}
10251e9daa6aSdrh    }
10261e9daa6aSdrh  }
102778f82d1eSdrh}
102895b289b6Sdanielk1977do_test pragma-9.11 {
102995b289b6Sdanielk1977  execsql {
103095b289b6Sdanielk1977    PRAGMA temp_store = 0;
103195b289b6Sdanielk1977    PRAGMA temp_store;
103295b289b6Sdanielk1977  }
103395b289b6Sdanielk1977} {0}
103495b289b6Sdanielk1977do_test pragma-9.12 {
103595b289b6Sdanielk1977  execsql {
103695b289b6Sdanielk1977    PRAGMA temp_store = 1;
103795b289b6Sdanielk1977    PRAGMA temp_store;
103895b289b6Sdanielk1977  }
103995b289b6Sdanielk1977} {1}
104095b289b6Sdanielk1977do_test pragma-9.13 {
104195b289b6Sdanielk1977  execsql {
104295b289b6Sdanielk1977    PRAGMA temp_store = 2;
104395b289b6Sdanielk1977    PRAGMA temp_store;
104495b289b6Sdanielk1977  }
104595b289b6Sdanielk1977} {2}
104695b289b6Sdanielk1977do_test pragma-9.14 {
104795b289b6Sdanielk1977  execsql {
104895b289b6Sdanielk1977    PRAGMA temp_store = 3;
104995b289b6Sdanielk1977    PRAGMA temp_store;
105095b289b6Sdanielk1977  }
105195b289b6Sdanielk1977} {0}
105295b289b6Sdanielk1977do_test pragma-9.15 {
105395b289b6Sdanielk1977  catchsql {
105495b289b6Sdanielk1977    BEGIN EXCLUSIVE;
105595b289b6Sdanielk1977    CREATE TEMP TABLE temp_table(t);
105695b289b6Sdanielk1977    INSERT INTO temp_table VALUES('valuable data');
105795b289b6Sdanielk1977    PRAGMA temp_store = 1;
105895b289b6Sdanielk1977  }
105995b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}}
106095b289b6Sdanielk1977do_test pragma-9.16 {
106195b289b6Sdanielk1977  execsql {
106295b289b6Sdanielk1977    SELECT * FROM temp_table;
106395b289b6Sdanielk1977    COMMIT;
106495b289b6Sdanielk1977  }
106595b289b6Sdanielk1977} {{valuable data}}
1066983e2309Sdanielk1977
1067983e2309Sdanielk1977do_test pragma-9.17 {
1068983e2309Sdanielk1977  execsql {
1069983e2309Sdanielk1977    INSERT INTO temp_table VALUES('valuable data II');
1070983e2309Sdanielk1977    SELECT * FROM temp_table;
1071983e2309Sdanielk1977  }
1072983e2309Sdanielk1977} {{valuable data} {valuable data II}}
1073983e2309Sdanielk1977
1074983e2309Sdanielk1977do_test pragma-9.18 {
1075983e2309Sdanielk1977  set rc [catch {
1076983e2309Sdanielk1977    db eval {SELECT t FROM temp_table} {
1077983e2309Sdanielk1977      execsql {pragma temp_store = 1}
1078983e2309Sdanielk1977    }
1079983e2309Sdanielk1977  } msg]
1080983e2309Sdanielk1977  list $rc $msg
1081983e2309Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}}
1082983e2309Sdanielk1977
1083268283bcSdrh} ;# ifcapable pager_pragmas
10849a09a3caStpoindex
1085cc6bd383Sdanielk1977ifcapable trigger {
1086cc6bd383Sdanielk1977
1087cc6bd383Sdanielk1977do_test pragma-10.0 {
1088cc6bd383Sdanielk1977  catchsql {
1089cc6bd383Sdanielk1977    DROP TABLE main.t1;
1090cc6bd383Sdanielk1977  }
1091cc6bd383Sdanielk1977  execsql {
1092cc6bd383Sdanielk1977    PRAGMA count_changes = 1;
1093cc6bd383Sdanielk1977
1094cc6bd383Sdanielk1977    CREATE TABLE t1(a PRIMARY KEY);
1095cc6bd383Sdanielk1977    CREATE TABLE t1_mirror(a);
1096cc6bd383Sdanielk1977    CREATE TABLE t1_mirror2(a);
1097cc6bd383Sdanielk1977    CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN
1098cc6bd383Sdanielk1977      INSERT INTO t1_mirror VALUES(new.a);
1099cc6bd383Sdanielk1977    END;
1100cc6bd383Sdanielk1977    CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
1101cc6bd383Sdanielk1977      INSERT INTO t1_mirror2 VALUES(new.a);
1102cc6bd383Sdanielk1977    END;
1103cc6bd383Sdanielk1977    CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
1104cc6bd383Sdanielk1977      UPDATE t1_mirror SET a = new.a WHERE a = old.a;
1105cc6bd383Sdanielk1977    END;
1106cc6bd383Sdanielk1977    CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
1107cc6bd383Sdanielk1977      UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;
1108cc6bd383Sdanielk1977    END;
1109cc6bd383Sdanielk1977    CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN
1110cc6bd383Sdanielk1977      DELETE FROM t1_mirror WHERE a = old.a;
1111cc6bd383Sdanielk1977    END;
1112cc6bd383Sdanielk1977    CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
1113cc6bd383Sdanielk1977      DELETE FROM t1_mirror2 WHERE a = old.a;
1114cc6bd383Sdanielk1977    END;
1115cc6bd383Sdanielk1977  }
1116cc6bd383Sdanielk1977} {}
1117cc6bd383Sdanielk1977
1118cc6bd383Sdanielk1977do_test pragma-10.1 {
1119cc6bd383Sdanielk1977  execsql {
1120cc6bd383Sdanielk1977    INSERT INTO t1 VALUES(randstr(10,10));
1121cc6bd383Sdanielk1977  }
1122cc6bd383Sdanielk1977} {1}
1123cc6bd383Sdanielk1977do_test pragma-10.2 {
1124cc6bd383Sdanielk1977  execsql {
1125cc6bd383Sdanielk1977    UPDATE t1 SET a = randstr(10,10);
1126cc6bd383Sdanielk1977  }
1127cc6bd383Sdanielk1977} {1}
1128cc6bd383Sdanielk1977do_test pragma-10.3 {
1129cc6bd383Sdanielk1977  execsql {
1130cc6bd383Sdanielk1977    DELETE FROM t1;
1131cc6bd383Sdanielk1977  }
1132cc6bd383Sdanielk1977} {1}
1133cc6bd383Sdanielk1977
1134cc6bd383Sdanielk1977} ;# ifcapable trigger
1135cc6bd383Sdanielk1977
113648af65aeSdanielk1977ifcapable schema_pragmas {
113748af65aeSdanielk1977  do_test pragma-11.1 {
113848af65aeSdanielk1977    execsql2 {
113948af65aeSdanielk1977      pragma collation_list;
114048af65aeSdanielk1977    }
11419b5adfa2Sdrh  } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY}
114248af65aeSdanielk1977  do_test pragma-11.2 {
114348af65aeSdanielk1977    db collate New_Collation blah...
114448af65aeSdanielk1977    execsql {
114548af65aeSdanielk1977      pragma collation_list;
114648af65aeSdanielk1977    }
11479b5adfa2Sdrh  } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY}
114848af65aeSdanielk1977}
114948af65aeSdanielk1977
1150ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb {
1151ddfb2f03Sdanielk1977  do_test pragma-12.1 {
1152ddfb2f03Sdanielk1977    sqlite3 db2 test.db
1153ddfb2f03Sdanielk1977    execsql {
1154ddfb2f03Sdanielk1977      PRAGMA temp.table_info('abc');
1155ddfb2f03Sdanielk1977    } db2
1156ddfb2f03Sdanielk1977  } {}
1157ddfb2f03Sdanielk1977  db2 close
1158ddfb2f03Sdanielk1977
1159ddfb2f03Sdanielk1977  do_test pragma-12.2 {
1160ddfb2f03Sdanielk1977    sqlite3 db2 test.db
1161ddfb2f03Sdanielk1977    execsql {
1162ddfb2f03Sdanielk1977      PRAGMA temp.default_cache_size = 200;
1163ddfb2f03Sdanielk1977      PRAGMA temp.default_cache_size;
1164ddfb2f03Sdanielk1977    } db2
1165ddfb2f03Sdanielk1977  } {200}
1166ddfb2f03Sdanielk1977  db2 close
1167ddfb2f03Sdanielk1977
1168ddfb2f03Sdanielk1977  do_test pragma-12.3 {
1169ddfb2f03Sdanielk1977    sqlite3 db2 test.db
1170ddfb2f03Sdanielk1977    execsql {
1171ddfb2f03Sdanielk1977      PRAGMA temp.cache_size = 400;
1172ddfb2f03Sdanielk1977      PRAGMA temp.cache_size;
1173ddfb2f03Sdanielk1977    } db2
1174ddfb2f03Sdanielk1977  } {400}
1175ddfb2f03Sdanielk1977  db2 close
1176ddfb2f03Sdanielk1977}
1177ddfb2f03Sdanielk1977
11784b2688abSdanielk1977ifcapable bloblit {
11794b2688abSdanielk1977
118005a82983Sdrhdo_test pragma-13.1 {
118105a82983Sdrh  execsql {
118205a82983Sdrh    DROP TABLE IF EXISTS t4;
118305a82983Sdrh    PRAGMA vdbe_trace=on;
118405a82983Sdrh    PRAGMA vdbe_listing=on;
118505a82983Sdrh    PRAGMA sql_trace=on;
118605a82983Sdrh    CREATE TABLE t4(a INTEGER PRIMARY KEY,b);
118705a82983Sdrh    INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789');
118805a82983Sdrh    INSERT INTO t4(b) VALUES(randstr(30,30));
118905a82983Sdrh    INSERT INTO t4(b) VALUES(1.23456);
119005a82983Sdrh    INSERT INTO t4(b) VALUES(NULL);
119105a82983Sdrh    INSERT INTO t4(b) VALUES(0);
119205a82983Sdrh    INSERT INTO t4(b) SELECT b||b||b||b FROM t4;
119305a82983Sdrh    SELECT * FROM t4;
119405a82983Sdrh  }
119505a82983Sdrh  execsql {
119605a82983Sdrh    PRAGMA vdbe_trace=off;
119705a82983Sdrh    PRAGMA vdbe_listing=off;
119805a82983Sdrh    PRAGMA sql_trace=off;
119905a82983Sdrh  }
120005a82983Sdrh} {}
120105a82983Sdrh
12024b2688abSdanielk1977} ;# ifcapable bloblit
12034b2688abSdanielk1977
120459a93791Sdanielk1977ifcapable pager_pragmas {
120559a93791Sdanielk1977  db close
120659a93791Sdanielk1977  file delete -force test.db
120759a93791Sdanielk1977  sqlite3 db test.db
120859a93791Sdanielk1977
120959a93791Sdanielk1977  do_test pragma-14.1 {
121059a93791Sdanielk1977    execsql { pragma auto_vacuum = 0 }
121159a93791Sdanielk1977    execsql { pragma page_count }
121259a93791Sdanielk1977  } {0}
121359a93791Sdanielk1977
121459a93791Sdanielk1977  do_test pragma-14.2 {
121559a93791Sdanielk1977    execsql {
121659a93791Sdanielk1977      CREATE TABLE abc(a, b, c);
121759a93791Sdanielk1977      PRAGMA page_count;
121859a93791Sdanielk1977    }
121959a93791Sdanielk1977  } {2}
122059a93791Sdanielk1977
122159a93791Sdanielk1977  do_test pragma-14.3 {
122259a93791Sdanielk1977    execsql {
122359a93791Sdanielk1977      BEGIN;
122459a93791Sdanielk1977      CREATE TABLE def(a, b, c);
122559a93791Sdanielk1977      PRAGMA page_count;
122659a93791Sdanielk1977    }
122759a93791Sdanielk1977  } {3}
122859a93791Sdanielk1977
122959a93791Sdanielk1977  do_test pragma-14.4 {
123059a93791Sdanielk1977    set page_size [db one {pragma page_size}]
123159a93791Sdanielk1977    expr [file size test.db] / $page_size
123259a93791Sdanielk1977  } {2}
123359a93791Sdanielk1977
123459a93791Sdanielk1977  do_test pragma-14.5 {
123559a93791Sdanielk1977    execsql {
123659a93791Sdanielk1977      ROLLBACK;
123759a93791Sdanielk1977      PRAGMA page_count;
123859a93791Sdanielk1977    }
123959a93791Sdanielk1977  } {2}
124059a93791Sdanielk1977
124159a93791Sdanielk1977  do_test pragma-14.6 {
124259a93791Sdanielk1977    file delete -force test2.db
124359a93791Sdanielk1977    sqlite3 db2 test2.db
124459a93791Sdanielk1977    execsql {
124559a93791Sdanielk1977      PRAGMA auto_vacuum = 0;
124659a93791Sdanielk1977      CREATE TABLE t1(a, b, c);
124759a93791Sdanielk1977      CREATE TABLE t2(a, b, c);
124859a93791Sdanielk1977      CREATE TABLE t3(a, b, c);
124959a93791Sdanielk1977      CREATE TABLE t4(a, b, c);
125059a93791Sdanielk1977    } db2
125159a93791Sdanielk1977    db2 close
125259a93791Sdanielk1977    execsql {
125359a93791Sdanielk1977      ATTACH 'test2.db' AS aux;
125459a93791Sdanielk1977      PRAGMA aux.page_count;
125559a93791Sdanielk1977    }
125659a93791Sdanielk1977  } {5}
125759a93791Sdanielk1977}
125859a93791Sdanielk1977
12598cf6c554Sdanielk1977# Test that the value set using the cache_size pragma is not reset when the
12608cf6c554Sdanielk1977# schema is reloaded.
12618cf6c554Sdanielk1977#
12628cf6c554Sdanielk1977ifcapable pager_pragmas {
12638cf6c554Sdanielk1977  db close
12648cf6c554Sdanielk1977  sqlite3 db test.db
12658cf6c554Sdanielk1977  do_test pragma-15.1 {
12668cf6c554Sdanielk1977    execsql {
12678cf6c554Sdanielk1977      PRAGMA cache_size=59;
12688cf6c554Sdanielk1977      PRAGMA cache_size;
12698cf6c554Sdanielk1977    }
12708cf6c554Sdanielk1977  } {59}
12718cf6c554Sdanielk1977  do_test pragma-15.2 {
12728cf6c554Sdanielk1977    sqlite3 db2 test.db
12738cf6c554Sdanielk1977    execsql {
12748cf6c554Sdanielk1977      CREATE TABLE newtable(a, b, c);
12758cf6c554Sdanielk1977    } db2
12768cf6c554Sdanielk1977    db2 close
12778cf6c554Sdanielk1977  } {}
12788cf6c554Sdanielk1977  do_test pragma-15.3 {
12798cf6c554Sdanielk1977    # Evaluating this statement will cause the schema to be reloaded (because
12808cf6c554Sdanielk1977    # the schema was changed by another connection in pragma-15.2). At one
12818cf6c554Sdanielk1977    # point there was a bug that reset the cache_size to its default value
12828cf6c554Sdanielk1977    # when this happened.
12838cf6c554Sdanielk1977    execsql { SELECT * FROM sqlite_master }
12848cf6c554Sdanielk1977    execsql { PRAGMA cache_size }
12858cf6c554Sdanielk1977  } {59}
12868cf6c554Sdanielk1977}
12878cf6c554Sdanielk1977
12885558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests:
12895558a8a6Sdanielk1977sqlite3 dbX :memory:
12905558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""}
12915558a8a6Sdanielk1977dbX close
12925558a8a6Sdanielk1977
1293838cce43Sdanielk1977ifcapable lock_proxy_pragmas&&prefer_proxy_locking {
1294aebf413dSaswift  set sqlite_hostid_num 1
1295aebf413dSaswift
1296aebf413dSaswift  set using_proxy 0
1297aebf413dSaswift  foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
1298aebf413dSaswift    set using_proxy $value
1299aebf413dSaswift  }
1300aebf413dSaswift
1301aebf413dSaswift  # Test the lock_proxy_file pragmas.
1302aebf413dSaswift  #
1303aebf413dSaswift  db close
1304aebf413dSaswift  set env(SQLITE_FORCE_PROXY_LOCKING) "0"
1305aebf413dSaswift
1306aebf413dSaswift  sqlite3 db test.db
1307aebf413dSaswift  do_test pragma-16.1 {
1308aebf413dSaswift    execsql {
1309aebf413dSaswift      PRAGMA lock_proxy_file="mylittleproxy";
1310aebf413dSaswift      select * from sqlite_master;
1311aebf413dSaswift    }
1312aebf413dSaswift    execsql {
1313aebf413dSaswift      PRAGMA lock_proxy_file;
1314aebf413dSaswift    }
1315aebf413dSaswift  } {mylittleproxy}
1316aebf413dSaswift
1317aebf413dSaswift  do_test pragma-16.2 {
1318aebf413dSaswift    sqlite3 db2 test.db
1319aebf413dSaswift    execsql {
1320aebf413dSaswift      PRAGMA lock_proxy_file="mylittleproxy";
1321aebf413dSaswift    } db2
1322aebf413dSaswift  } {}
1323aebf413dSaswift
1324aebf413dSaswift  db2 close
1325aebf413dSaswift  do_test pragma-16.2.1 {
1326aebf413dSaswift    sqlite3 db2 test.db
1327aebf413dSaswift    execsql {
1328aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1329aebf413dSaswift      select * from sqlite_master;
1330aebf413dSaswift    } db2
1331aebf413dSaswift    execsql {
1332aebf413dSaswift      PRAGMA lock_proxy_file;
1333aebf413dSaswift    } db2
1334aebf413dSaswift  } {mylittleproxy}
1335aebf413dSaswift
1336aebf413dSaswift  db2 close
1337aebf413dSaswift  do_test pragma-16.3 {
1338aebf413dSaswift    sqlite3 db2 test.db
1339aebf413dSaswift    execsql {
1340aebf413dSaswift      PRAGMA lock_proxy_file="myotherproxy";
1341aebf413dSaswift    } db2
1342aebf413dSaswift    catchsql {
1343aebf413dSaswift      select * from sqlite_master;
1344aebf413dSaswift    } db2
1345aebf413dSaswift  } {1 {database is locked}}
1346aebf413dSaswift
1347aebf413dSaswift  do_test pragma-16.4 {
1348aebf413dSaswift    db2 close
1349aebf413dSaswift    db close
1350aebf413dSaswift    sqlite3 db2 test.db
1351aebf413dSaswift    execsql {
1352aebf413dSaswift      PRAGMA lock_proxy_file="myoriginalproxy";
1353aebf413dSaswift      PRAGMA lock_proxy_file="myotherproxy";
1354aebf413dSaswift      PRAGMA lock_proxy_file;
1355aebf413dSaswift    } db2
1356aebf413dSaswift  } {myotherproxy}
1357aebf413dSaswift
1358aebf413dSaswift  db2 close
1359aebf413dSaswift  set env(SQLITE_FORCE_PROXY_LOCKING) "1"
1360aebf413dSaswift  do_test pragma-16.5 {
1361aebf413dSaswift    sqlite3 db2 test.db
1362aebf413dSaswift    execsql {
1363aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1364aebf413dSaswift      PRAGMA lock_proxy_file;
1365aebf413dSaswift    } db2
1366aebf413dSaswift  } {myotherproxy}
1367aebf413dSaswift
1368aebf413dSaswift  do_test pragma-16.6 {
1369aebf413dSaswift    db2 close
1370aebf413dSaswift    sqlite3 db2 test2.db
1371aebf413dSaswift    set lockpath [execsql {
1372aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1373aebf413dSaswift      PRAGMA lock_proxy_file;
1374aebf413dSaswift    } db2]
1375aebf413dSaswift    string match "*test2.db:auto:" $lockpath
1376aebf413dSaswift  } {1}
1377aebf413dSaswift
1378aebf413dSaswift  set sqlite_hostid_num 2
1379aebf413dSaswift  do_test pragma-16.7 {
1380aebf413dSaswift    sqlite3 db test2.db
1381aebf413dSaswift    execsql {
1382aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1383aebf413dSaswift    }
1384aebf413dSaswift    catchsql {
1385aebf413dSaswift      select * from sqlite_master;
1386aebf413dSaswift    }
1387aebf413dSaswift  } {1 {database is locked}}
1388aebf413dSaswift  db close
1389aebf413dSaswift
1390aebf413dSaswift  do_test pragma-16.8 {
1391aebf413dSaswift    sqlite3 db test2.db
1392aebf413dSaswift    catchsql {
1393aebf413dSaswift      select * from sqlite_master;
1394aebf413dSaswift    }
1395aebf413dSaswift  } {1 {database is locked}}
1396aebf413dSaswift
1397aebf413dSaswift  db2 close
1398aebf413dSaswift  do_test pragma-16.8.1 {
1399aebf413dSaswift    execsql {
1400aebf413dSaswift      PRAGMA lock_proxy_file="yetanotherproxy";
1401aebf413dSaswift      PRAGMA lock_proxy_file;
1402aebf413dSaswift    }
1403aebf413dSaswift  } {yetanotherproxy}
1404aebf413dSaswift  do_test pragma-16.8.2 {
1405aebf413dSaswift    execsql {
1406aebf413dSaswift      create table mine(x);
1407aebf413dSaswift    }
1408aebf413dSaswift  } {}
1409aebf413dSaswift
1410aebf413dSaswift  db close
1411aebf413dSaswift  do_test pragma-16.9 {
1412aebf413dSaswift    sqlite3 db proxytest.db
1413aebf413dSaswift    set lockpath2 [execsql {
1414aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1415aebf413dSaswift      PRAGMA lock_proxy_file;
1416aebf413dSaswift    } db]
1417aebf413dSaswift    string match "*proxytest.db:auto:" $lockpath2
1418aebf413dSaswift  } {1}
1419aebf413dSaswift
1420aebf413dSaswift  set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy
1421aebf413dSaswift  set sqlite_hostid_num 0
1422aebf413dSaswift}
1423d2cb50b7Sdrh
1424d2cb50b7Sdrh# Parsing of auto_vacuum settings.
1425d2cb50b7Sdrh#
1426d2cb50b7Sdrhforeach {autovac_setting val} {
1427d2cb50b7Sdrh  0 0
1428d2cb50b7Sdrh  1 1
1429d2cb50b7Sdrh  2 2
1430d2cb50b7Sdrh  3 0
1431d2cb50b7Sdrh  -1 0
1432d2cb50b7Sdrh  none 0
1433d2cb50b7Sdrh  NONE 0
1434d2cb50b7Sdrh  NoNe 0
1435d2cb50b7Sdrh  full 1
1436d2cb50b7Sdrh  FULL 1
1437d2cb50b7Sdrh  incremental 2
1438d2cb50b7Sdrh  INCREMENTAL 2
1439d2cb50b7Sdrh  -1234 0
1440d2cb50b7Sdrh  1234 0
1441d2cb50b7Sdrh} {
1442d2cb50b7Sdrh  do_test pragma-17.1.$autovac_setting {
1443d2cb50b7Sdrh    catch {db close}
1444d2cb50b7Sdrh    sqlite3 db :memory:
1445d2cb50b7Sdrh    execsql "
1446d2cb50b7Sdrh      PRAGMA auto_vacuum=$::autovac_setting;
1447d2cb50b7Sdrh      PRAGMA auto_vacuum;
1448d2cb50b7Sdrh    "
1449d2cb50b7Sdrh  } $val
1450d2cb50b7Sdrh}
1451d2cb50b7Sdrh
1452d2cb50b7Sdrh# Parsing of temp_store settings.
1453d2cb50b7Sdrh#
1454d2cb50b7Sdrhforeach {temp_setting val} {
1455d2cb50b7Sdrh  0 0
1456d2cb50b7Sdrh  1 1
1457d2cb50b7Sdrh  2 2
1458d2cb50b7Sdrh  3 0
1459d2cb50b7Sdrh  -1 0
1460d2cb50b7Sdrh  file 1
1461d2cb50b7Sdrh  FILE 1
1462d2cb50b7Sdrh  fIlE 1
1463d2cb50b7Sdrh  memory 2
1464d2cb50b7Sdrh  MEMORY 2
1465d2cb50b7Sdrh  MeMoRy 2
1466d2cb50b7Sdrh} {
1467d2cb50b7Sdrh  do_test pragma-18.1.$temp_setting {
1468d2cb50b7Sdrh    catch {db close}
1469d2cb50b7Sdrh    sqlite3 db :memory:
1470d2cb50b7Sdrh    execsql "
1471d2cb50b7Sdrh      PRAGMA temp_store=$::temp_setting;
1472d2cb50b7Sdrh      PRAGMA temp_store=$::temp_setting;
1473d2cb50b7Sdrh      PRAGMA temp_store;
1474d2cb50b7Sdrh    "
1475d2cb50b7Sdrh  } $val
1476d2cb50b7Sdrh}
1477d2cb50b7Sdrh
1478cd61c281Sdrhfinish_test
1479