xref: /sqlite-3.40.0/test/pragma.test (revision 4ee09b4b)
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
195885e762Sdanset testprefix pragma
20cd61c281Sdrh
2168928b6cSdan# Do not use a codec for tests in this file, as the database file is
2268928b6cSdan# manipulated directly using tcl scripts (using the [hexio_write] command).
2368928b6cSdan#
2468928b6cSdando_not_use_codec
2568928b6cSdan
2691cf71b0Sdanielk1977# Test organization:
2791cf71b0Sdanielk1977#
2891cf71b0Sdanielk1977# pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
2991cf71b0Sdanielk1977# pragma-2.*: Test synchronous on attached db.
3091cf71b0Sdanielk1977# pragma-3.*: Test detection of table/index inconsistency by integrity_check.
3191cf71b0Sdanielk1977# pragma-4.*: Test cache_size and default_cache_size on attached db.
3291cf71b0Sdanielk1977# pragma-5.*: Test that pragma synchronous may not be used inside of a
3391cf71b0Sdanielk1977#             transaction.
34cc6bd383Sdanielk1977# pragma-6.*: Test schema-query pragmas.
35cc6bd383Sdanielk1977# pragma-7.*: Miscellaneous tests.
36cc6bd383Sdanielk1977# pragma-8.*: Test user_version and schema_version pragmas.
379a09a3caStpoindex# pragma-9.*: Test temp_store and temp_store_directory.
38cc6bd383Sdanielk1977# pragma-10.*: Test the count_changes pragma in the presence of triggers.
3948af65aeSdanielk1977# pragma-11.*: Test the collation_list pragma.
4059a93791Sdanielk1977# pragma-14.*: Test the page_count pragma.
418cf6c554Sdanielk1977# pragma-15.*: Test that the value set using the cache_size pragma is not
428cf6c554Sdanielk1977#              reset when the schema is reloaded.
43aebf413dSaswift# pragma-16.*: Test proxy locking
44a112d140Smistachkin# pragma-20.*: Test data_store_directory.
455885e762Sdan# pragma-22.*: Test that "PRAGMA [db].integrity_check" respects the "db"
465885e762Sdan#              directive - if it is present.
4791cf71b0Sdanielk1977#
4891cf71b0Sdanielk1977
4905a82983Sdrhifcapable !pragma {
5005a82983Sdrh  finish_test
5105a82983Sdrh  return
5205a82983Sdrh}
5305a82983Sdrh
54cd61c281Sdrh# Delete the preexisting database to avoid the special setup
55cd61c281Sdrh# that the "all.test" script does.
56cd61c281Sdrh#
57cd61c281Sdrhdb close
58fda06befSmistachkindelete_file test.db test.db-journal
59fda06befSmistachkindelete_file test3.db test3.db-journal
60dddca286Sdrhsqlite3 db test.db; set DB [sqlite3_connection_pointer db]
61cd61c281Sdrh
621e9daa6aSdrh
63c7b4a44cSdanielk1977ifcapable pager_pragmas {
641e9daa6aSdrhset DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}]
651e9daa6aSdrhset TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}]
66cd61c281Sdrhdo_test pragma-1.1 {
67cd61c281Sdrh  execsql {
68cd61c281Sdrh    PRAGMA cache_size;
69cd61c281Sdrh    PRAGMA default_cache_size;
70cd61c281Sdrh    PRAGMA synchronous;
71cd61c281Sdrh  }
721e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
73cd61c281Sdrhdo_test pragma-1.2 {
74cd61c281Sdrh  execsql {
75eb43e5c7Sdrh    PRAGMA synchronous=OFF;
76cd61c281Sdrh    PRAGMA cache_size=1234;
77cd61c281Sdrh    PRAGMA cache_size;
78cd61c281Sdrh    PRAGMA default_cache_size;
79cd61c281Sdrh    PRAGMA synchronous;
80cd61c281Sdrh  }
811e9daa6aSdrh} [list 1234 $DFLT_CACHE_SZ 0]
82cd61c281Sdrhdo_test pragma-1.3 {
83cd61c281Sdrh  db close
84ef4ac8f9Sdrh  sqlite3 db test.db
85cd61c281Sdrh  execsql {
86cd61c281Sdrh    PRAGMA cache_size;
87cd61c281Sdrh    PRAGMA default_cache_size;
88cd61c281Sdrh    PRAGMA synchronous;
89cd61c281Sdrh  }
901e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
91cd61c281Sdrhdo_test pragma-1.4 {
92cd61c281Sdrh  execsql {
93cd61c281Sdrh    PRAGMA synchronous=OFF;
94cd61c281Sdrh    PRAGMA cache_size;
95cd61c281Sdrh    PRAGMA default_cache_size;
96cd61c281Sdrh    PRAGMA synchronous;
97cd61c281Sdrh  }
981e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0]
99cd61c281Sdrhdo_test pragma-1.5 {
100cd61c281Sdrh  execsql {
101d2cb50b7Sdrh    PRAGMA cache_size=-4321;
102cd61c281Sdrh    PRAGMA cache_size;
103cd61c281Sdrh    PRAGMA default_cache_size;
104cd61c281Sdrh    PRAGMA synchronous;
105cd61c281Sdrh  }
1063b42abb3Sdrh} [list -4321 $DFLT_CACHE_SZ 0]
107cd61c281Sdrhdo_test pragma-1.6 {
108cd61c281Sdrh  execsql {
109cd61c281Sdrh    PRAGMA synchronous=ON;
110cd61c281Sdrh    PRAGMA cache_size;
111cd61c281Sdrh    PRAGMA default_cache_size;
112cd61c281Sdrh    PRAGMA synchronous;
113cd61c281Sdrh  }
1143b42abb3Sdrh} [list -4321 $DFLT_CACHE_SZ 1]
115cd61c281Sdrhdo_test pragma-1.7 {
116cd61c281Sdrh  db close
117ef4ac8f9Sdrh  sqlite3 db test.db
118cd61c281Sdrh  execsql {
119cd61c281Sdrh    PRAGMA cache_size;
120cd61c281Sdrh    PRAGMA default_cache_size;
121cd61c281Sdrh    PRAGMA synchronous;
122cd61c281Sdrh  }
1231e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
124cd61c281Sdrhdo_test pragma-1.8 {
125cd61c281Sdrh  execsql {
126d2cb50b7Sdrh    PRAGMA default_cache_size=-123;
127cd61c281Sdrh    PRAGMA cache_size;
128cd61c281Sdrh    PRAGMA default_cache_size;
129cd61c281Sdrh    PRAGMA synchronous;
130cd61c281Sdrh  }
13191cf71b0Sdanielk1977} {123 123 2}
132802d69a7Sdrhdo_test pragma-1.9.1 {
133cd61c281Sdrh  db close
134dddca286Sdrh  sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
135cd61c281Sdrh  execsql {
136cd61c281Sdrh    PRAGMA cache_size;
137cd61c281Sdrh    PRAGMA default_cache_size;
138cd61c281Sdrh    PRAGMA synchronous;
139cd61c281Sdrh  }
14091cf71b0Sdanielk1977} {123 123 2}
141802d69a7Sdrhifcapable vacuum {
142802d69a7Sdrh  do_test pragma-1.9.2 {
143802d69a7Sdrh    execsql {
144802d69a7Sdrh      VACUUM;
145802d69a7Sdrh      PRAGMA cache_size;
146802d69a7Sdrh      PRAGMA default_cache_size;
147802d69a7Sdrh      PRAGMA synchronous;
148802d69a7Sdrh    }
149802d69a7Sdrh  } {123 123 2}
150802d69a7Sdrh}
15191cf71b0Sdanielk1977do_test pragma-1.10 {
1525a38705eSdrh  execsql {
1534303feedSdrh    PRAGMA synchronous=NORMAL;
1544303feedSdrh    PRAGMA cache_size;
1554303feedSdrh    PRAGMA default_cache_size;
1564303feedSdrh    PRAGMA synchronous;
1574303feedSdrh  }
15891cf71b0Sdanielk1977} {123 123 1}
15991cf71b0Sdanielk1977do_test pragma-1.11 {
1604303feedSdrh  execsql {
1614303feedSdrh    PRAGMA synchronous=FULL;
1624303feedSdrh    PRAGMA cache_size;
1634303feedSdrh    PRAGMA default_cache_size;
1644303feedSdrh    PRAGMA synchronous;
1654303feedSdrh  }
16691cf71b0Sdanielk1977} {123 123 2}
16791cf71b0Sdanielk1977do_test pragma-1.12 {
1684303feedSdrh  db close
169dddca286Sdrh  sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
1704303feedSdrh  execsql {
1714303feedSdrh    PRAGMA cache_size;
1724303feedSdrh    PRAGMA default_cache_size;
1734303feedSdrh    PRAGMA synchronous;
1744303feedSdrh  }
17591cf71b0Sdanielk1977} {123 123 2}
17691cf71b0Sdanielk1977
1775260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition
1785260f7e9Sdrh# to keywords like "off" and "full".
1795260f7e9Sdrh#
1805260f7e9Sdrhdo_test pragma-1.13 {
1815260f7e9Sdrh  execsql {
1825260f7e9Sdrh    PRAGMA synchronous=0;
1835260f7e9Sdrh    PRAGMA synchronous;
1845260f7e9Sdrh  }
1855260f7e9Sdrh} {0}
1865260f7e9Sdrhdo_test pragma-1.14 {
1875260f7e9Sdrh  execsql {
1885260f7e9Sdrh    PRAGMA synchronous=2;
1895260f7e9Sdrh    PRAGMA synchronous;
1905260f7e9Sdrh  }
1915260f7e9Sdrh} {2}
192c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
1935260f7e9Sdrh
1945260f7e9Sdrh# Test turning "flag" pragmas on and off.
1955260f7e9Sdrh#
1966338c762Sdanielk1977ifcapable debug {
1976338c762Sdanielk1977  # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG
1986338c762Sdanielk1977  #
1995260f7e9Sdrh  do_test pragma-1.15 {
2005260f7e9Sdrh    execsql {
2015260f7e9Sdrh      PRAGMA vdbe_listing=YES;
2025260f7e9Sdrh      PRAGMA vdbe_listing;
2035260f7e9Sdrh    }
2045260f7e9Sdrh  } {1}
2055260f7e9Sdrh  do_test pragma-1.16 {
2065260f7e9Sdrh    execsql {
2075260f7e9Sdrh      PRAGMA vdbe_listing=NO;
2085260f7e9Sdrh      PRAGMA vdbe_listing;
2095260f7e9Sdrh    }
2105260f7e9Sdrh  } {0}
2116338c762Sdanielk1977}
2126338c762Sdanielk1977
2135260f7e9Sdrhdo_test pragma-1.17 {
2145260f7e9Sdrh  execsql {
2155260f7e9Sdrh    PRAGMA parser_trace=ON;
2165260f7e9Sdrh    PRAGMA parser_trace=OFF;
2175260f7e9Sdrh  }
2185260f7e9Sdrh} {}
2195260f7e9Sdrhdo_test pragma-1.18 {
2205260f7e9Sdrh  execsql {
2215260f7e9Sdrh    PRAGMA bogus = -1234;  -- Parsing of negative values
2225260f7e9Sdrh  }
2235260f7e9Sdrh} {}
2245260f7e9Sdrh
22591cf71b0Sdanielk1977# Test modifying the safety_level of an attached database.
2265a8f9374Sdanielk1977ifcapable pager_pragmas&&attach {
22791cf71b0Sdanielk1977  do_test pragma-2.1 {
228fda06befSmistachkin    forcedelete test2.db
229fda06befSmistachkin    forcedelete test2.db-journal
2304303feedSdrh    execsql {
23191cf71b0Sdanielk1977      ATTACH 'test2.db' AS aux;
2324303feedSdrh    }
23391cf71b0Sdanielk1977  } {}
23491cf71b0Sdanielk1977  do_test pragma-2.2 {
2354303feedSdrh    execsql {
23691cf71b0Sdanielk1977      pragma aux.synchronous;
2374303feedSdrh    }
23891cf71b0Sdanielk1977  } {2}
23991cf71b0Sdanielk1977  do_test pragma-2.3 {
24091cf71b0Sdanielk1977    execsql {
24191cf71b0Sdanielk1977      pragma aux.synchronous = OFF;
24291cf71b0Sdanielk1977      pragma aux.synchronous;
24391cf71b0Sdanielk1977      pragma synchronous;
24491cf71b0Sdanielk1977    }
24591cf71b0Sdanielk1977  } {0 2}
24691cf71b0Sdanielk1977  do_test pragma-2.4 {
24791cf71b0Sdanielk1977    execsql {
24891cf71b0Sdanielk1977      pragma aux.synchronous = ON;
24991cf71b0Sdanielk1977      pragma synchronous;
25091cf71b0Sdanielk1977      pragma aux.synchronous;
25191cf71b0Sdanielk1977    }
25291cf71b0Sdanielk1977  } {2 1}
253c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
2544303feedSdrh
255ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check
256ed717fe3Sdrh# pragma finds it.
257ed717fe3Sdrh#
25825d6543dSdrh# These tests won't work if the database is encrypted
25925d6543dSdrh#
260ed717fe3Sdrhdo_test pragma-3.1 {
2611e9daa6aSdrh  db close
262fda06befSmistachkin  forcedelete test.db test.db-journal
2631e9daa6aSdrh  sqlite3 db test.db
264ed717fe3Sdrh  execsql {
2651e9daa6aSdrh    PRAGMA auto_vacuum=OFF;
266ed717fe3Sdrh    BEGIN;
267ed717fe3Sdrh    CREATE TABLE t2(a,b,c);
268ed717fe3Sdrh    CREATE INDEX i2 ON t2(a);
269ed717fe3Sdrh    INSERT INTO t2 VALUES(11,2,3);
270ed717fe3Sdrh    INSERT INTO t2 VALUES(22,3,4);
271ed717fe3Sdrh    COMMIT;
272ed717fe3Sdrh    SELECT rowid, * from t2;
273ed717fe3Sdrh  }
274ed717fe3Sdrh} {1 11 2 3 2 22 3 4}
2755a8f9374Sdanielk1977ifcapable attach {
27640e016e4Sdrh  if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
277ed717fe3Sdrh    do_test pragma-3.2 {
278bb8a279eSdrh      db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break
279bb8a279eSdrh      set pgsz [db eval {PRAGMA page_size}]
280bb8a279eSdrh      # overwrite the header on the rootpage of the index in order to
281bb8a279eSdrh      # make the index appear to be empty.
282bb8a279eSdrh      #
283bb8a279eSdrh      set offset [expr {$pgsz*($rootpage-1)}]
284bb8a279eSdrh      hexio_write test.db $offset 0a00000000040000000000
285bb8a279eSdrh      db close
286bb8a279eSdrh      sqlite3 db test.db
287ed717fe3Sdrh      execsql {PRAGMA integrity_check}
288bb8a279eSdrh    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
28991cf71b0Sdanielk1977    do_test pragma-3.3 {
2901dcdbc06Sdrh      execsql {PRAGMA integrity_check=1}
2911dcdbc06Sdrh    } {{rowid 1 missing from index i2}}
2921dcdbc06Sdrh    do_test pragma-3.4 {
29391cf71b0Sdanielk1977      execsql {
2941dcdbc06Sdrh        ATTACH DATABASE 'test.db' AS t2;
2951dcdbc06Sdrh        PRAGMA integrity_check
29691cf71b0Sdanielk1977      }
297bb8a279eSdrh    } {{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}}
2981dcdbc06Sdrh    do_test pragma-3.5 {
2991dcdbc06Sdrh      execsql {
300bb8a279eSdrh        PRAGMA integrity_check=4
3011dcdbc06Sdrh      }
302bb8a279eSdrh    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}}
3031dcdbc06Sdrh    do_test pragma-3.6 {
3041dcdbc06Sdrh      execsql {
3051dcdbc06Sdrh        PRAGMA integrity_check=xyz
3061dcdbc06Sdrh      }
307bb8a279eSdrh    } {{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}}
3081dcdbc06Sdrh    do_test pragma-3.7 {
3091dcdbc06Sdrh      execsql {
3101dcdbc06Sdrh        PRAGMA integrity_check=0
3111dcdbc06Sdrh      }
312bb8a279eSdrh    } {{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}}
3131dcdbc06Sdrh
3141dcdbc06Sdrh    # Add additional corruption by appending unused pages to the end of
3151dcdbc06Sdrh    # the database file testerr.db
3161dcdbc06Sdrh    #
3171dcdbc06Sdrh    do_test pragma-3.8 {
3181dcdbc06Sdrh      execsql {DETACH t2}
319fda06befSmistachkin      forcedelete testerr.db testerr.db-journal
320e3d559adSdrh      set out [open testerr.db w]
321e3d559adSdrh      fconfigure $out -translation binary
322e3d559adSdrh      set in [open test.db r]
323e3d559adSdrh      fconfigure $in -translation binary
3241dcdbc06Sdrh      puts -nonewline $out [read $in]
3251dcdbc06Sdrh      seek $in 0
3261dcdbc06Sdrh      puts -nonewline $out [read $in]
3271dcdbc06Sdrh      close $in
3281dcdbc06Sdrh      close $out
329dd3cd977Sdrh      hexio_write testerr.db 28 00000000
3301dcdbc06Sdrh      execsql {REINDEX t2}
3311dcdbc06Sdrh      execsql {PRAGMA integrity_check}
3321dcdbc06Sdrh    } {ok}
33341c58b78Sdanielk1977    do_test pragma-3.8.1 {
33441c58b78Sdanielk1977      execsql {PRAGMA quick_check}
33541c58b78Sdanielk1977    } {ok}
3365d16a9a6Sdrh    do_test pragma-3.8.2 {
3375d16a9a6Sdrh      execsql {PRAGMA QUICK_CHECK}
3385d16a9a6Sdrh    } {ok}
3391dcdbc06Sdrh    do_test pragma-3.9 {
3401dcdbc06Sdrh      execsql {
3411dcdbc06Sdrh        ATTACH 'testerr.db' AS t2;
3421dcdbc06Sdrh        PRAGMA integrity_check
3431dcdbc06Sdrh      }
3441dcdbc06Sdrh    } {{*** in database t2 ***
3451dcdbc06SdrhPage 4 is never used
3461dcdbc06SdrhPage 5 is never used
347bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
3481dcdbc06Sdrh    do_test pragma-3.10 {
3491dcdbc06Sdrh      execsql {
3501dcdbc06Sdrh        PRAGMA integrity_check=1
3511dcdbc06Sdrh      }
3521dcdbc06Sdrh    } {{*** in database t2 ***
3531dcdbc06SdrhPage 4 is never used}}
3541dcdbc06Sdrh    do_test pragma-3.11 {
3551dcdbc06Sdrh      execsql {
3561dcdbc06Sdrh        PRAGMA integrity_check=5
3571dcdbc06Sdrh      }
3581dcdbc06Sdrh    } {{*** in database t2 ***
3591dcdbc06SdrhPage 4 is never used
3601dcdbc06SdrhPage 5 is never used
361bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2}}
3621dcdbc06Sdrh    do_test pragma-3.12 {
3631dcdbc06Sdrh      execsql {
3641dcdbc06Sdrh        PRAGMA integrity_check=4
3651dcdbc06Sdrh      }
3661dcdbc06Sdrh    } {{*** in database t2 ***
3671dcdbc06SdrhPage 4 is never used
3681dcdbc06SdrhPage 5 is never used
3691dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
3701dcdbc06Sdrh    do_test pragma-3.13 {
3711dcdbc06Sdrh      execsql {
3721dcdbc06Sdrh        PRAGMA integrity_check=3
3731dcdbc06Sdrh      }
3741dcdbc06Sdrh    } {{*** in database t2 ***
3751dcdbc06SdrhPage 4 is never used
3761dcdbc06SdrhPage 5 is never used
3771dcdbc06SdrhPage 6 is never used}}
3781dcdbc06Sdrh    do_test pragma-3.14 {
3791dcdbc06Sdrh      execsql {
3801dcdbc06Sdrh        PRAGMA integrity_check(2)
3811dcdbc06Sdrh      }
3821dcdbc06Sdrh    } {{*** in database t2 ***
3831dcdbc06SdrhPage 4 is never used
3841dcdbc06SdrhPage 5 is never used}}
3851dcdbc06Sdrh    do_test pragma-3.15 {
3861dcdbc06Sdrh      execsql {
3871dcdbc06Sdrh        ATTACH 'testerr.db' AS t3;
3881dcdbc06Sdrh        PRAGMA integrity_check
3891dcdbc06Sdrh      }
3901dcdbc06Sdrh    } {{*** in database t2 ***
3911dcdbc06SdrhPage 4 is never used
3921dcdbc06SdrhPage 5 is never used
393bb8a279eSdrhPage 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 ***
3941dcdbc06SdrhPage 4 is never used
3951dcdbc06SdrhPage 5 is never used
396bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
3971dcdbc06Sdrh    do_test pragma-3.16 {
3981dcdbc06Sdrh      execsql {
399bb8a279eSdrh        PRAGMA integrity_check(10)
4001dcdbc06Sdrh      }
4011dcdbc06Sdrh    } {{*** in database t2 ***
4021dcdbc06SdrhPage 4 is never used
4031dcdbc06SdrhPage 5 is never used
404bb8a279eSdrhPage 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 ***
4051dcdbc06SdrhPage 4 is never used
4061dcdbc06SdrhPage 5 is never used
4071dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
4081dcdbc06Sdrh    do_test pragma-3.17 {
4091dcdbc06Sdrh      execsql {
410bb8a279eSdrh        PRAGMA integrity_check=8
4111dcdbc06Sdrh      }
4121dcdbc06Sdrh    } {{*** in database t2 ***
4131dcdbc06SdrhPage 4 is never used
4141dcdbc06SdrhPage 5 is never used
415bb8a279eSdrhPage 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 ***
4161dcdbc06SdrhPage 4 is never used
4171dcdbc06SdrhPage 5 is never used}}
4181dcdbc06Sdrh    do_test pragma-3.18 {
4191dcdbc06Sdrh      execsql {
4201dcdbc06Sdrh        PRAGMA integrity_check=4
4211dcdbc06Sdrh      }
4221dcdbc06Sdrh    } {{*** in database t2 ***
4231dcdbc06SdrhPage 4 is never used
4241dcdbc06SdrhPage 5 is never used
4251dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}}
4261dcdbc06Sdrh  }
427d2cb50b7Sdrh  do_test pragma-3.19 {
428d2cb50b7Sdrh    catch {db close}
429fda06befSmistachkin    forcedelete test.db test.db-journal
430d2cb50b7Sdrh    sqlite3 db test.db
431d2cb50b7Sdrh    db eval {PRAGMA integrity_check}
432d2cb50b7Sdrh  } {ok}
4335a8f9374Sdanielk1977}
434d2cb50b7Sdrh#exit
43591cf71b0Sdanielk1977
43691cf71b0Sdanielk1977# Test modifying the cache_size of an attached database.
4375a8f9374Sdanielk1977ifcapable pager_pragmas&&attach {
43891cf71b0Sdanielk1977do_test pragma-4.1 {
43991cf71b0Sdanielk1977  execsql {
4401e9daa6aSdrh    ATTACH 'test2.db' AS aux;
44191cf71b0Sdanielk1977    pragma aux.cache_size;
44291cf71b0Sdanielk1977    pragma aux.default_cache_size;
44391cf71b0Sdanielk1977  }
4441e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4451bdd9b57Sdrhdo_test pragma-4.2 {
4461bdd9b57Sdrh  execsql {
44791cf71b0Sdanielk1977    pragma aux.cache_size = 50;
44891cf71b0Sdanielk1977    pragma aux.cache_size;
44991cf71b0Sdanielk1977    pragma aux.default_cache_size;
4501bdd9b57Sdrh  }
4511e9daa6aSdrh} [list 50 $DFLT_CACHE_SZ]
4521bdd9b57Sdrhdo_test pragma-4.3 {
4531bdd9b57Sdrh  execsql {
45491cf71b0Sdanielk1977    pragma aux.default_cache_size = 456;
45591cf71b0Sdanielk1977    pragma aux.cache_size;
45691cf71b0Sdanielk1977    pragma aux.default_cache_size;
4571bdd9b57Sdrh  }
45891cf71b0Sdanielk1977} {456 456}
4591bdd9b57Sdrhdo_test pragma-4.4 {
4601bdd9b57Sdrh  execsql {
46191cf71b0Sdanielk1977    pragma cache_size;
46291cf71b0Sdanielk1977    pragma default_cache_size;
4631bdd9b57Sdrh  }
4641e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4651bdd9b57Sdrhdo_test pragma-4.5 {
4661bdd9b57Sdrh  execsql {
46791cf71b0Sdanielk1977    DETACH aux;
46891cf71b0Sdanielk1977    ATTACH 'test3.db' AS aux;
46991cf71b0Sdanielk1977    pragma aux.cache_size;
47091cf71b0Sdanielk1977    pragma aux.default_cache_size;
4711bdd9b57Sdrh  }
4721e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4731bdd9b57Sdrhdo_test pragma-4.6 {
4741bdd9b57Sdrh  execsql {
47591cf71b0Sdanielk1977    DETACH aux;
47691cf71b0Sdanielk1977    ATTACH 'test2.db' AS aux;
47791cf71b0Sdanielk1977    pragma aux.cache_size;
47891cf71b0Sdanielk1977    pragma aux.default_cache_size;
4791bdd9b57Sdrh  }
48091cf71b0Sdanielk1977} {456 456}
481c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
4821bdd9b57Sdrh
48391cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is
48491cf71b0Sdanielk1977# disallowed.
485c7b4a44cSdanielk1977ifcapable pager_pragmas {
48691cf71b0Sdanielk1977do_test pragma-5.0 {
4871bdd9b57Sdrh  execsql {
48891cf71b0Sdanielk1977    pragma synchronous;
4891bdd9b57Sdrh  }
49091cf71b0Sdanielk1977} {2}
49191cf71b0Sdanielk1977do_test pragma-5.1 {
4921bdd9b57Sdrh  catchsql {
4931bdd9b57Sdrh    BEGIN;
49491cf71b0Sdanielk1977    pragma synchronous = OFF;
4951bdd9b57Sdrh  }
49691cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}}
49791cf71b0Sdanielk1977do_test pragma-5.2 {
49891cf71b0Sdanielk1977  execsql {
49991cf71b0Sdanielk1977    pragma synchronous;
50091cf71b0Sdanielk1977  }
50191cf71b0Sdanielk1977} {2}
5025260f7e9Sdrhcatchsql {COMMIT;}
503c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
5045260f7e9Sdrh
5055260f7e9Sdrh# Test schema-query pragmas
5065260f7e9Sdrh#
50727188fb5Sdanielk1977ifcapable schema_pragmas {
5085a8f9374Sdanielk1977ifcapable tempdb&&attach {
5095260f7e9Sdrh  do_test pragma-6.1 {
510956bc92cSdrh    set res {}
51140e016e4Sdrh    execsql {SELECT * FROM sqlite_temp_master}
5125260f7e9Sdrh    foreach {idx name file} [execsql {pragma database_list}] {
5135260f7e9Sdrh      lappend res $idx $name
5145260f7e9Sdrh    }
5155260f7e9Sdrh    set res
516a71aa001Sdrh  } {0 main 1 temp 2 aux}
51753c0f748Sdanielk1977}
5185260f7e9Sdrhdo_test pragma-6.2 {
5195260f7e9Sdrh  execsql {
520d2cb50b7Sdrh    CREATE TABLE t2(a,b,c);
5215260f7e9Sdrh    pragma table_info(t2)
5225260f7e9Sdrh  }
523bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0}
524d2cb50b7Sdrhdo_test pragma-6.2.1 {
525d2cb50b7Sdrh  execsql {
526d2cb50b7Sdrh    pragma table_info;
527d2cb50b7Sdrh  }
528d2cb50b7Sdrh} {}
529736c7d4bSdrhdb nullvalue <<NULL>>
530417ec638Sdrhdo_test pragma-6.2.2 {
531417ec638Sdrh  execsql {
532736c7d4bSdrh    CREATE TABLE t5(
533736c7d4bSdrh      a TEXT DEFAULT CURRENT_TIMESTAMP,
534736c7d4bSdrh      b DEFAULT (5+3),
535736c7d4bSdrh      c TEXT,
536736c7d4bSdrh      d INTEGER DEFAULT NULL,
537384b7fe2Sdrh      e TEXT DEFAULT '',
538384b7fe2Sdrh      UNIQUE(b,c,d),
539384b7fe2Sdrh      PRIMARY KEY(e,b,c)
540736c7d4bSdrh    );
541417ec638Sdrh    PRAGMA table_info(t5);
542417ec638Sdrh  }
543384b7fe2Sdrh} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 2 2 c TEXT 0 <<NULL>> 3 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 1}
544736c7d4bSdrhdb nullvalue {}
545384b7fe2Sdrhdo_test pragma-6.2.3 {
546384b7fe2Sdrh  execsql {
547384b7fe2Sdrh    CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c);
548384b7fe2Sdrh    pragma table_info(t2_3)
549384b7fe2Sdrh  }
550384b7fe2Sdrh} {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0}
5516bf89570Sdrhifcapable {foreignkey} {
552d2cb50b7Sdrh  do_test pragma-6.3.1 {
5535260f7e9Sdrh    execsql {
5545260f7e9Sdrh      CREATE TABLE t3(a int references t2(b), b UNIQUE);
5555260f7e9Sdrh      pragma foreign_key_list(t3);
5565260f7e9Sdrh    }
5571da40a38Sdan  } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE}
558d2cb50b7Sdrh  do_test pragma-6.3.2 {
559d2cb50b7Sdrh    execsql {
560d2cb50b7Sdrh      pragma foreign_key_list;
561d2cb50b7Sdrh    }
562d2cb50b7Sdrh  } {}
563d2cb50b7Sdrh  do_test pragma-6.3.3 {
564d2cb50b7Sdrh    execsql {
565d2cb50b7Sdrh      pragma foreign_key_list(t3_bogus);
566d2cb50b7Sdrh    }
567d2cb50b7Sdrh  } {}
568d2cb50b7Sdrh  do_test pragma-6.3.4 {
569d2cb50b7Sdrh    execsql {
570d2cb50b7Sdrh      pragma foreign_key_list(t5);
571d2cb50b7Sdrh    }
572d2cb50b7Sdrh  } {}
5735260f7e9Sdrh  do_test pragma-6.4 {
5745260f7e9Sdrh    execsql {
5755260f7e9Sdrh      pragma index_list(t3);
5765260f7e9Sdrh    }
5775260f7e9Sdrh  } {0 sqlite_autoindex_t3_1 1}
5786bf89570Sdrh}
5796bf89570Sdrhifcapable {!foreignkey} {
5806bf89570Sdrh  execsql {CREATE TABLE t3(a,b UNIQUE)}
5816bf89570Sdrh}
582d2cb50b7Sdrhdo_test pragma-6.5.1 {
5835260f7e9Sdrh  execsql {
5845260f7e9Sdrh    CREATE INDEX t3i1 ON t3(a,b);
5855260f7e9Sdrh    pragma index_info(t3i1);
5865260f7e9Sdrh  }
5875260f7e9Sdrh} {0 0 a 1 1 b}
588d2cb50b7Sdrhdo_test pragma-6.5.2 {
589d2cb50b7Sdrh  execsql {
590d2cb50b7Sdrh    pragma index_info(t3i1_bogus);
591d2cb50b7Sdrh  }
592d2cb50b7Sdrh} {}
593260d8a6aSdanielk1977
594260d8a6aSdanielk1977ifcapable tempdb {
595260d8a6aSdanielk1977  # Test for ticket #3320. When a temp table of the same name exists, make
596260d8a6aSdanielk1977  # sure the schema of the main table can still be queried using
597260d8a6aSdanielk1977  # "pragma table_info":
598260d8a6aSdanielk1977  do_test pragma-6.6.1 {
599260d8a6aSdanielk1977    execsql {
600260d8a6aSdanielk1977      CREATE TABLE trial(col_main);
601260d8a6aSdanielk1977      CREATE TEMP TABLE trial(col_temp);
602260d8a6aSdanielk1977    }
603260d8a6aSdanielk1977  } {}
604260d8a6aSdanielk1977  do_test pragma-6.6.2 {
605260d8a6aSdanielk1977    execsql {
606260d8a6aSdanielk1977      PRAGMA table_info(trial);
607260d8a6aSdanielk1977    }
608260d8a6aSdanielk1977  } {0 col_temp {} 0 {} 0}
609260d8a6aSdanielk1977  do_test pragma-6.6.3 {
610260d8a6aSdanielk1977    execsql {
611260d8a6aSdanielk1977      PRAGMA temp.table_info(trial);
612260d8a6aSdanielk1977    }
613260d8a6aSdanielk1977  } {0 col_temp {} 0 {} 0}
614260d8a6aSdanielk1977  do_test pragma-6.6.4 {
615260d8a6aSdanielk1977    execsql {
616260d8a6aSdanielk1977      PRAGMA main.table_info(trial);
617260d8a6aSdanielk1977    }
618260d8a6aSdanielk1977  } {0 col_main {} 0 {} 0}
619260d8a6aSdanielk1977}
620f96a3778Sdanielk1977
621f96a3778Sdanielk1977do_test pragma-6.7 {
622f96a3778Sdanielk1977  execsql {
623f96a3778Sdanielk1977    CREATE TABLE test_table(
624f96a3778Sdanielk1977      one INT NOT NULL DEFAULT -1,
625f96a3778Sdanielk1977      two text,
626f96a3778Sdanielk1977      three VARCHAR(45, 65) DEFAULT 'abcde',
627f96a3778Sdanielk1977      four REAL DEFAULT X'abcdef',
628f96a3778Sdanielk1977      five DEFAULT CURRENT_TIME
629f96a3778Sdanielk1977    );
630f96a3778Sdanielk1977    PRAGMA table_info(test_table);
631f96a3778Sdanielk1977  }
632f96a3778Sdanielk1977} [concat \
633f96a3778Sdanielk1977  {0 one INT 1 -1 0} \
634f96a3778Sdanielk1977  {1 two text 0 {} 0} \
635f96a3778Sdanielk1977  {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \
636f96a3778Sdanielk1977  {3 four REAL 0 X'abcdef' 0} \
637f96a3778Sdanielk1977  {4 five {} 0 CURRENT_TIME 0} \
638f96a3778Sdanielk1977]
63927188fb5Sdanielk1977} ;# ifcapable schema_pragmas
6405260f7e9Sdrh# Miscellaneous tests
6415260f7e9Sdrh#
64227188fb5Sdanielk1977ifcapable schema_pragmas {
643d2cb50b7Sdrhdo_test pragma-7.1.1 {
6445260f7e9Sdrh  # Make sure a pragma knows to read the schema if it needs to
6455260f7e9Sdrh  db close
6465260f7e9Sdrh  sqlite3 db test.db
6475260f7e9Sdrh  execsql {
6485260f7e9Sdrh    pragma index_list(t3);
6495260f7e9Sdrh  }
6505260f7e9Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1}
651d2cb50b7Sdrhdo_test pragma-7.1.2 {
652d2cb50b7Sdrh  execsql {
653d2cb50b7Sdrh    pragma index_list(t3_bogus);
654d2cb50b7Sdrh  }
655d2cb50b7Sdrh} {}
65627188fb5Sdanielk1977} ;# ifcapable schema_pragmas
6576c62608fSdrhifcapable {utf16} {
658cb354603Sdan  if {[permutation] == ""} {
6595260f7e9Sdrh    do_test pragma-7.2 {
6605260f7e9Sdrh      db close
6615260f7e9Sdrh      sqlite3 db test.db
6625260f7e9Sdrh      catchsql {
6635260f7e9Sdrh        pragma encoding=bogus;
6645260f7e9Sdrh      }
6655260f7e9Sdrh    } {1 {unsupported encoding: bogus}}
6666c62608fSdrh  }
667cb354603Sdan}
66853c0f748Sdanielk1977ifcapable tempdb {
6695260f7e9Sdrh  do_test pragma-7.3 {
6705260f7e9Sdrh    db close
6715260f7e9Sdrh    sqlite3 db test.db
6725260f7e9Sdrh    execsql {
6735260f7e9Sdrh      pragma lock_status;
6745260f7e9Sdrh    }
6755260f7e9Sdrh  } {main unlocked temp closed}
67653c0f748Sdanielk1977} else {
67753c0f748Sdanielk1977  do_test pragma-7.3 {
67853c0f748Sdanielk1977    db close
67953c0f748Sdanielk1977    sqlite3 db test.db
68053c0f748Sdanielk1977    execsql {
68153c0f748Sdanielk1977      pragma lock_status;
68253c0f748Sdanielk1977    }
68353c0f748Sdanielk1977  } {main unlocked}
68453c0f748Sdanielk1977}
6855260f7e9Sdrh
6865260f7e9Sdrh
687dae2495bSdanielk1977#----------------------------------------------------------------------
688b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
689b92b70bbSdanielk1977# user_version" statements.
690dae2495bSdanielk1977#
691b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version
692b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version
693dae2495bSdanielk1977#
694dae2495bSdanielk1977
69511cf9fbcSdanielk1977ifcapable schema_version {
69611cf9fbcSdanielk1977
697b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the
698dae2495bSdanielk1977# same value.
699dae2495bSdanielk1977do_test pragma-8.1.1 {
700dae2495bSdanielk1977  execsql {
701b92b70bbSdanielk1977    PRAGMA schema_version = 105;
702dae2495bSdanielk1977  }
703dae2495bSdanielk1977} {}
704dae2495bSdanielk1977do_test pragma-8.1.2 {
70525403650Sdrh  execsql2 {
706b92b70bbSdanielk1977    PRAGMA schema_version;
707dae2495bSdanielk1977  }
70825403650Sdrh} {schema_version 105}
709dae2495bSdanielk1977do_test pragma-8.1.3 {
710dae2495bSdanielk1977  execsql {
711b92b70bbSdanielk1977    PRAGMA schema_version = 106;
712dae2495bSdanielk1977  }
713dae2495bSdanielk1977} {}
714dae2495bSdanielk1977do_test pragma-8.1.4 {
715dae2495bSdanielk1977  execsql {
716b92b70bbSdanielk1977    PRAGMA schema_version;
717dae2495bSdanielk1977  }
718dae2495bSdanielk1977} 106
719dae2495bSdanielk1977
720b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really
721b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version).
722dae2495bSdanielk1977do_test pragma-8.1.5 {
723dae2495bSdanielk1977  execsql {
724dae2495bSdanielk1977    CREATE TABLE t4(a, b, c);
725dae2495bSdanielk1977    INSERT INTO t4 VALUES(1, 2, 3);
726dae2495bSdanielk1977    SELECT * FROM t4;
727dae2495bSdanielk1977  }
728dae2495bSdanielk1977} {1 2 3}
729dae2495bSdanielk1977do_test pragma-8.1.6 {
730dae2495bSdanielk1977  execsql {
731b92b70bbSdanielk1977    PRAGMA schema_version;
732dae2495bSdanielk1977  }
733dae2495bSdanielk1977} 107
734dae2495bSdanielk1977
735dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the
736b92b70bbSdanielk1977# schema-version using the first connection forces the second connection
737dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions,
738dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query.
739dae2495bSdanielk1977do_test pragma-8.1.7 {
740dddca286Sdrh  sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
741dae2495bSdanielk1977  execsql {
742dae2495bSdanielk1977    SELECT * FROM t4;
743dae2495bSdanielk1977  } db2
744dae2495bSdanielk1977} {1 2 3}
745dae2495bSdanielk1977do_test pragma-8.1.8 {
746dae2495bSdanielk1977  execsql {
747b92b70bbSdanielk1977    PRAGMA schema_version = 108;
748dae2495bSdanielk1977  }
749dae2495bSdanielk1977} {}
750dae2495bSdanielk1977do_test pragma-8.1.9 {
751dae2495bSdanielk1977  set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
752dae2495bSdanielk1977  sqlite3_step $::STMT
753dae2495bSdanielk1977} SQLITE_ERROR
754dae2495bSdanielk1977do_test pragma-8.1.10 {
755dae2495bSdanielk1977  sqlite3_finalize $::STMT
756dae2495bSdanielk1977} SQLITE_SCHEMA
757dae2495bSdanielk1977
758b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database.
759fda06befSmistachkinforcedelete test2.db
760fda06befSmistachkinforcedelete test2.db-journal
7615a8f9374Sdanielk1977ifcapable attach {
762dae2495bSdanielk1977  do_test pragma-8.1.11 {
763dae2495bSdanielk1977    execsql {
764dae2495bSdanielk1977      ATTACH 'test2.db' AS aux;
765dae2495bSdanielk1977      CREATE TABLE aux.t1(a, b, c);
766b92b70bbSdanielk1977      PRAGMA aux.schema_version = 205;
767dae2495bSdanielk1977    }
768dae2495bSdanielk1977  } {}
769dae2495bSdanielk1977  do_test pragma-8.1.12 {
770dae2495bSdanielk1977    execsql {
771b92b70bbSdanielk1977      PRAGMA aux.schema_version;
772dae2495bSdanielk1977    }
773dae2495bSdanielk1977  } 205
7745a8f9374Sdanielk1977}
775dae2495bSdanielk1977do_test pragma-8.1.13 {
776dae2495bSdanielk1977  execsql {
777b92b70bbSdanielk1977    PRAGMA schema_version;
778dae2495bSdanielk1977  }
779dae2495bSdanielk1977} 108
780dae2495bSdanielk1977
781b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database
782dae2495bSdanielk1977# forces the second connection to reload the schema.
7835a8f9374Sdanielk1977ifcapable attach {
784dae2495bSdanielk1977  do_test pragma-8.1.14 {
785dddca286Sdrh    sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
786dae2495bSdanielk1977    execsql {
787dae2495bSdanielk1977      ATTACH 'test2.db' AS aux;
788dae2495bSdanielk1977      SELECT * FROM aux.t1;
789dae2495bSdanielk1977    } db2
790dae2495bSdanielk1977  } {}
791dae2495bSdanielk1977  do_test pragma-8.1.15 {
792dae2495bSdanielk1977    execsql {
793b92b70bbSdanielk1977      PRAGMA aux.schema_version = 206;
794dae2495bSdanielk1977    }
795dae2495bSdanielk1977  } {}
796dae2495bSdanielk1977  do_test pragma-8.1.16 {
797dae2495bSdanielk1977    set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]
798dae2495bSdanielk1977    sqlite3_step $::STMT
799dae2495bSdanielk1977  } SQLITE_ERROR
800dae2495bSdanielk1977  do_test pragma-8.1.17 {
801dae2495bSdanielk1977    sqlite3_finalize $::STMT
802dae2495bSdanielk1977  } SQLITE_SCHEMA
803dae2495bSdanielk1977  do_test pragma-8.1.18 {
804dae2495bSdanielk1977    db2 close
805dae2495bSdanielk1977  } {}
8065a8f9374Sdanielk1977}
807dae2495bSdanielk1977
808b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't
809b92b70bbSdanielk1977# accidentally manipulating the schema-version instead).
810dae2495bSdanielk1977do_test pragma-8.2.1 {
81125403650Sdrh  execsql2 {
812b92b70bbSdanielk1977    PRAGMA user_version;
813dae2495bSdanielk1977  }
81425403650Sdrh} {user_version 0}
815dae2495bSdanielk1977do_test pragma-8.2.2 {
816dae2495bSdanielk1977  execsql {
817b92b70bbSdanielk1977    PRAGMA user_version = 2;
818dae2495bSdanielk1977  }
819dae2495bSdanielk1977} {}
820802d69a7Sdrhdo_test pragma-8.2.3.1 {
82125403650Sdrh  execsql2 {
822b92b70bbSdanielk1977    PRAGMA user_version;
823dae2495bSdanielk1977  }
82425403650Sdrh} {user_version 2}
825802d69a7Sdrhdo_test pragma-8.2.3.2 {
826802d69a7Sdrh  db close
827802d69a7Sdrh  sqlite3 db test.db
828802d69a7Sdrh  execsql {
829802d69a7Sdrh    PRAGMA user_version;
830802d69a7Sdrh  }
831802d69a7Sdrh} {2}
832802d69a7Sdrhdo_test pragma-8.2.4.1 {
833dae2495bSdanielk1977  execsql {
834b92b70bbSdanielk1977    PRAGMA schema_version;
835dae2495bSdanielk1977  }
836dae2495bSdanielk1977} {108}
837802d69a7Sdrhifcapable vacuum {
838802d69a7Sdrh  do_test pragma-8.2.4.2 {
839802d69a7Sdrh    execsql {
840802d69a7Sdrh      VACUUM;
841802d69a7Sdrh      PRAGMA user_version;
842802d69a7Sdrh    }
843802d69a7Sdrh  } {2}
844802d69a7Sdrh  do_test pragma-8.2.4.3 {
845802d69a7Sdrh    execsql {
846802d69a7Sdrh      PRAGMA schema_version;
847802d69a7Sdrh    }
848802d69a7Sdrh  } {109}
849802d69a7Sdrh}
8505a8f9374Sdanielk1977
8515a8f9374Sdanielk1977ifcapable attach {
852802d69a7Sdrh  db eval {ATTACH 'test2.db' AS aux}
853dae2495bSdanielk1977
854b92b70bbSdanielk1977  # Check that the user-version in the auxilary database can be manipulated (
855dae2495bSdanielk1977  # and that we aren't accidentally manipulating the same in the main db).
856dae2495bSdanielk1977  do_test pragma-8.2.5 {
857dae2495bSdanielk1977    execsql {
858b92b70bbSdanielk1977      PRAGMA aux.user_version;
859dae2495bSdanielk1977    }
860dae2495bSdanielk1977  } {0}
861dae2495bSdanielk1977  do_test pragma-8.2.6 {
862dae2495bSdanielk1977    execsql {
863b92b70bbSdanielk1977      PRAGMA aux.user_version = 3;
864dae2495bSdanielk1977    }
865dae2495bSdanielk1977  } {}
866dae2495bSdanielk1977  do_test pragma-8.2.7 {
867dae2495bSdanielk1977    execsql {
868b92b70bbSdanielk1977      PRAGMA aux.user_version;
869dae2495bSdanielk1977    }
870dae2495bSdanielk1977  } {3}
871dae2495bSdanielk1977  do_test pragma-8.2.8 {
872dae2495bSdanielk1977    execsql {
873b92b70bbSdanielk1977      PRAGMA main.user_version;
874dae2495bSdanielk1977    }
875dae2495bSdanielk1977  } {2}
876dae2495bSdanielk1977
877b92b70bbSdanielk1977  # Now check that a ROLLBACK resets the user-version if it has been modified
878dae2495bSdanielk1977  # within a transaction.
879dae2495bSdanielk1977  do_test pragma-8.2.9 {
880dae2495bSdanielk1977    execsql {
881dae2495bSdanielk1977      BEGIN;
882b92b70bbSdanielk1977      PRAGMA aux.user_version = 10;
883b92b70bbSdanielk1977      PRAGMA user_version = 11;
884dae2495bSdanielk1977    }
885dae2495bSdanielk1977  } {}
886dae2495bSdanielk1977  do_test pragma-8.2.10 {
887dae2495bSdanielk1977    execsql {
888b92b70bbSdanielk1977      PRAGMA aux.user_version;
889dae2495bSdanielk1977    }
890dae2495bSdanielk1977  } {10}
891dae2495bSdanielk1977  do_test pragma-8.2.11 {
892dae2495bSdanielk1977    execsql {
893b92b70bbSdanielk1977      PRAGMA main.user_version;
894dae2495bSdanielk1977    }
895dae2495bSdanielk1977  } {11}
896dae2495bSdanielk1977  do_test pragma-8.2.12 {
897dae2495bSdanielk1977    execsql {
898dae2495bSdanielk1977      ROLLBACK;
899b92b70bbSdanielk1977      PRAGMA aux.user_version;
900dae2495bSdanielk1977    }
901dae2495bSdanielk1977  } {3}
902dae2495bSdanielk1977  do_test pragma-8.2.13 {
903dae2495bSdanielk1977    execsql {
904b92b70bbSdanielk1977      PRAGMA main.user_version;
905dae2495bSdanielk1977    }
906dae2495bSdanielk1977  } {2}
9075a8f9374Sdanielk1977}
908dae2495bSdanielk1977
909b92b70bbSdanielk1977# Try a negative value for the user-version
910dae2495bSdanielk1977do_test pragma-8.2.14 {
911dae2495bSdanielk1977  execsql {
912b92b70bbSdanielk1977    PRAGMA user_version = -450;
913dae2495bSdanielk1977  }
914dae2495bSdanielk1977} {}
915dae2495bSdanielk1977do_test pragma-8.2.15 {
916dae2495bSdanielk1977  execsql {
917b92b70bbSdanielk1977    PRAGMA user_version;
918dae2495bSdanielk1977  }
919dae2495bSdanielk1977} {-450}
920d9c847dcSdanielk1977} ; # ifcapable schema_version
921d9c847dcSdanielk1977
922d19744f3Sdrh# Check to see if TEMP_STORE is memory or disk.  Return strings
923d19744f3Sdrh# "memory" or "disk" as appropriate.
924d19744f3Sdrh#
925d19744f3Sdrhproc check_temp_store {} {
926d19744f3Sdrh  db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)}
927d19744f3Sdrh  db eval {PRAGMA database_list} {
928d19744f3Sdrh    if {$name=="temp"} {
92917b90b53Sdanielk1977      set bt [btree_from_db db 1]
93017b90b53Sdanielk1977      if {[btree_ismemdb $bt]} {
931d19744f3Sdrh        return "memory"
932d19744f3Sdrh      }
93317b90b53Sdanielk1977      return "disk"
934d19744f3Sdrh    }
935d19744f3Sdrh  }
936d19744f3Sdrh  return "unknown"
937d19744f3Sdrh}
938d19744f3Sdrh
939*4ee09b4bSdrh# Application_ID
940*4ee09b4bSdrh#
941*4ee09b4bSdrhdo_test pragma-8.3.1 {
942*4ee09b4bSdrh  execsql {
943*4ee09b4bSdrh    PRAGMA application_id;
944*4ee09b4bSdrh  }
945*4ee09b4bSdrh} {0}
946*4ee09b4bSdrhdo_test pragma-8.3.2 {
947*4ee09b4bSdrh  execsql {PRAGMA Application_ID(12345); PRAGMA application_id;}
948*4ee09b4bSdrh} {12345}
9499a09a3caStpoindex
9509a09a3caStpoindex# Test temp_store and temp_store_directory pragmas
9519a09a3caStpoindex#
952268283bcSdrhifcapable pager_pragmas {
9539a09a3caStpoindexdo_test pragma-9.1 {
9549a09a3caStpoindex  db close
9559a09a3caStpoindex  sqlite3 db test.db
9569a09a3caStpoindex  execsql {
9579a09a3caStpoindex    PRAGMA temp_store;
9589a09a3caStpoindex  }
9599a09a3caStpoindex} {0}
960d19744f3Sdrhif {$TEMP_STORE<=1} {
961d19744f3Sdrh  do_test pragma-9.1.1 {
962d19744f3Sdrh    check_temp_store
963d19744f3Sdrh  } {disk}
964d19744f3Sdrh} else {
965d19744f3Sdrh  do_test pragma-9.1.1 {
966d19744f3Sdrh    check_temp_store
967d19744f3Sdrh  } {memory}
968d19744f3Sdrh}
969d19744f3Sdrh
9709a09a3caStpoindexdo_test pragma-9.2 {
971d19744f3Sdrh  db close
972d19744f3Sdrh  sqlite3 db test.db
9739a09a3caStpoindex  execsql {
9749a09a3caStpoindex    PRAGMA temp_store=file;
9759a09a3caStpoindex    PRAGMA temp_store;
9769a09a3caStpoindex  }
9779a09a3caStpoindex} {1}
978d19744f3Sdrhif {$TEMP_STORE==3} {
979d19744f3Sdrh  # When TEMP_STORE is 3, always use memory regardless of pragma settings.
980d19744f3Sdrh  do_test pragma-9.2.1 {
981d19744f3Sdrh    check_temp_store
982d19744f3Sdrh  } {memory}
983d19744f3Sdrh} else {
984d19744f3Sdrh  do_test pragma-9.2.1 {
985d19744f3Sdrh    check_temp_store
986d19744f3Sdrh  } {disk}
987d19744f3Sdrh}
988d19744f3Sdrh
9899a09a3caStpoindexdo_test pragma-9.3 {
990d19744f3Sdrh  db close
991d19744f3Sdrh  sqlite3 db test.db
9929a09a3caStpoindex  execsql {
9939a09a3caStpoindex    PRAGMA temp_store=memory;
9949a09a3caStpoindex    PRAGMA temp_store;
9959a09a3caStpoindex  }
9969a09a3caStpoindex} {2}
997d19744f3Sdrhif {$TEMP_STORE==0} {
998d19744f3Sdrh  # When TEMP_STORE is 0, always use the disk regardless of pragma settings.
999d19744f3Sdrh  do_test pragma-9.3.1 {
1000d19744f3Sdrh    check_temp_store
1001d19744f3Sdrh  } {disk}
1002d19744f3Sdrh} else {
1003d19744f3Sdrh  do_test pragma-9.3.1 {
1004d19744f3Sdrh    check_temp_store
1005d19744f3Sdrh  } {memory}
1006d19744f3Sdrh}
1007d19744f3Sdrh
10089a09a3caStpoindexdo_test pragma-9.4 {
10099a09a3caStpoindex  execsql {
10109a09a3caStpoindex    PRAGMA temp_store_directory;
10119a09a3caStpoindex  }
10129a09a3caStpoindex} {}
101378f82d1eSdrhifcapable wsd {
10149a09a3caStpoindex  do_test pragma-9.5 {
1015f8a78464Smistachkin    set pwd [string map {' ''} [file nativename [get_pwd]]]
1016268283bcSdrh    execsql "
1017268283bcSdrh      PRAGMA temp_store_directory='$pwd';
10189a09a3caStpoindex    "
10199a09a3caStpoindex  } {}
10209a09a3caStpoindex  do_test pragma-9.6 {
10219a09a3caStpoindex    execsql {
10229a09a3caStpoindex      PRAGMA temp_store_directory;
10239a09a3caStpoindex    }
1024f8a78464Smistachkin  } [list [file nativename [get_pwd]]]
10259a09a3caStpoindex  do_test pragma-9.7 {
1026268283bcSdrh    catchsql {
10279a09a3caStpoindex      PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
10289a09a3caStpoindex    }
1029268283bcSdrh  } {1 {not a writable directory}}
10309a09a3caStpoindex  do_test pragma-9.8 {
10319a09a3caStpoindex    execsql {
10329a09a3caStpoindex      PRAGMA temp_store_directory='';
10339a09a3caStpoindex    }
10349a09a3caStpoindex  } {}
10351e9daa6aSdrh  if {![info exists TEMP_STORE] || $TEMP_STORE<=1} {
103653c0f748Sdanielk1977    ifcapable tempdb {
10379a09a3caStpoindex      do_test pragma-9.9 {
10389a09a3caStpoindex        execsql {
10399a09a3caStpoindex          PRAGMA temp_store_directory;
10409a09a3caStpoindex          PRAGMA temp_store=FILE;
10419a09a3caStpoindex          CREATE TEMP TABLE temp_store_directory_test(a integer);
10429a09a3caStpoindex          INSERT INTO temp_store_directory_test values (2);
10439a09a3caStpoindex          SELECT * FROM temp_store_directory_test;
10449a09a3caStpoindex        }
10459a09a3caStpoindex      } {2}
10469a09a3caStpoindex      do_test pragma-9.10 {
1047268283bcSdrh        catchsql "
1048268283bcSdrh          PRAGMA temp_store_directory='$pwd';
10499a09a3caStpoindex          SELECT * FROM temp_store_directory_test;
10509a09a3caStpoindex        "
1051268283bcSdrh      } {1 {no such table: temp_store_directory_test}}
10521e9daa6aSdrh    }
10531e9daa6aSdrh  }
105478f82d1eSdrh}
105595b289b6Sdanielk1977do_test pragma-9.11 {
105695b289b6Sdanielk1977  execsql {
105795b289b6Sdanielk1977    PRAGMA temp_store = 0;
105895b289b6Sdanielk1977    PRAGMA temp_store;
105995b289b6Sdanielk1977  }
106095b289b6Sdanielk1977} {0}
106195b289b6Sdanielk1977do_test pragma-9.12 {
106295b289b6Sdanielk1977  execsql {
106395b289b6Sdanielk1977    PRAGMA temp_store = 1;
106495b289b6Sdanielk1977    PRAGMA temp_store;
106595b289b6Sdanielk1977  }
106695b289b6Sdanielk1977} {1}
106795b289b6Sdanielk1977do_test pragma-9.13 {
106895b289b6Sdanielk1977  execsql {
106995b289b6Sdanielk1977    PRAGMA temp_store = 2;
107095b289b6Sdanielk1977    PRAGMA temp_store;
107195b289b6Sdanielk1977  }
107295b289b6Sdanielk1977} {2}
107395b289b6Sdanielk1977do_test pragma-9.14 {
107495b289b6Sdanielk1977  execsql {
107595b289b6Sdanielk1977    PRAGMA temp_store = 3;
107695b289b6Sdanielk1977    PRAGMA temp_store;
107795b289b6Sdanielk1977  }
107895b289b6Sdanielk1977} {0}
107995b289b6Sdanielk1977do_test pragma-9.15 {
108095b289b6Sdanielk1977  catchsql {
108195b289b6Sdanielk1977    BEGIN EXCLUSIVE;
108295b289b6Sdanielk1977    CREATE TEMP TABLE temp_table(t);
108395b289b6Sdanielk1977    INSERT INTO temp_table VALUES('valuable data');
108495b289b6Sdanielk1977    PRAGMA temp_store = 1;
108595b289b6Sdanielk1977  }
108695b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}}
108795b289b6Sdanielk1977do_test pragma-9.16 {
108895b289b6Sdanielk1977  execsql {
108995b289b6Sdanielk1977    SELECT * FROM temp_table;
109095b289b6Sdanielk1977    COMMIT;
109195b289b6Sdanielk1977  }
109295b289b6Sdanielk1977} {{valuable data}}
1093983e2309Sdanielk1977
1094983e2309Sdanielk1977do_test pragma-9.17 {
1095983e2309Sdanielk1977  execsql {
1096983e2309Sdanielk1977    INSERT INTO temp_table VALUES('valuable data II');
1097983e2309Sdanielk1977    SELECT * FROM temp_table;
1098983e2309Sdanielk1977  }
1099983e2309Sdanielk1977} {{valuable data} {valuable data II}}
1100983e2309Sdanielk1977
1101983e2309Sdanielk1977do_test pragma-9.18 {
1102983e2309Sdanielk1977  set rc [catch {
1103983e2309Sdanielk1977    db eval {SELECT t FROM temp_table} {
1104983e2309Sdanielk1977      execsql {pragma temp_store = 1}
1105983e2309Sdanielk1977    }
1106983e2309Sdanielk1977  } msg]
1107983e2309Sdanielk1977  list $rc $msg
1108983e2309Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}}
1109983e2309Sdanielk1977
1110268283bcSdrh} ;# ifcapable pager_pragmas
11119a09a3caStpoindex
1112cc6bd383Sdanielk1977ifcapable trigger {
1113cc6bd383Sdanielk1977
1114cc6bd383Sdanielk1977do_test pragma-10.0 {
1115cc6bd383Sdanielk1977  catchsql {
1116cc6bd383Sdanielk1977    DROP TABLE main.t1;
1117cc6bd383Sdanielk1977  }
1118cc6bd383Sdanielk1977  execsql {
1119cc6bd383Sdanielk1977    PRAGMA count_changes = 1;
1120cc6bd383Sdanielk1977
1121cc6bd383Sdanielk1977    CREATE TABLE t1(a PRIMARY KEY);
1122cc6bd383Sdanielk1977    CREATE TABLE t1_mirror(a);
1123cc6bd383Sdanielk1977    CREATE TABLE t1_mirror2(a);
1124cc6bd383Sdanielk1977    CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN
1125cc6bd383Sdanielk1977      INSERT INTO t1_mirror VALUES(new.a);
1126cc6bd383Sdanielk1977    END;
1127cc6bd383Sdanielk1977    CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
1128cc6bd383Sdanielk1977      INSERT INTO t1_mirror2 VALUES(new.a);
1129cc6bd383Sdanielk1977    END;
1130cc6bd383Sdanielk1977    CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
1131cc6bd383Sdanielk1977      UPDATE t1_mirror SET a = new.a WHERE a = old.a;
1132cc6bd383Sdanielk1977    END;
1133cc6bd383Sdanielk1977    CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
1134cc6bd383Sdanielk1977      UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;
1135cc6bd383Sdanielk1977    END;
1136cc6bd383Sdanielk1977    CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN
1137cc6bd383Sdanielk1977      DELETE FROM t1_mirror WHERE a = old.a;
1138cc6bd383Sdanielk1977    END;
1139cc6bd383Sdanielk1977    CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
1140cc6bd383Sdanielk1977      DELETE FROM t1_mirror2 WHERE a = old.a;
1141cc6bd383Sdanielk1977    END;
1142cc6bd383Sdanielk1977  }
1143cc6bd383Sdanielk1977} {}
1144cc6bd383Sdanielk1977
1145cc6bd383Sdanielk1977do_test pragma-10.1 {
1146cc6bd383Sdanielk1977  execsql {
1147cc6bd383Sdanielk1977    INSERT INTO t1 VALUES(randstr(10,10));
1148cc6bd383Sdanielk1977  }
1149cc6bd383Sdanielk1977} {1}
1150cc6bd383Sdanielk1977do_test pragma-10.2 {
1151cc6bd383Sdanielk1977  execsql {
1152cc6bd383Sdanielk1977    UPDATE t1 SET a = randstr(10,10);
1153cc6bd383Sdanielk1977  }
1154cc6bd383Sdanielk1977} {1}
1155cc6bd383Sdanielk1977do_test pragma-10.3 {
1156cc6bd383Sdanielk1977  execsql {
1157cc6bd383Sdanielk1977    DELETE FROM t1;
1158cc6bd383Sdanielk1977  }
1159cc6bd383Sdanielk1977} {1}
1160cc6bd383Sdanielk1977
1161cc6bd383Sdanielk1977} ;# ifcapable trigger
1162cc6bd383Sdanielk1977
116348af65aeSdanielk1977ifcapable schema_pragmas {
116448af65aeSdanielk1977  do_test pragma-11.1 {
116548af65aeSdanielk1977    execsql2 {
116648af65aeSdanielk1977      pragma collation_list;
116748af65aeSdanielk1977    }
11689b5adfa2Sdrh  } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY}
116948af65aeSdanielk1977  do_test pragma-11.2 {
117048af65aeSdanielk1977    db collate New_Collation blah...
117148af65aeSdanielk1977    execsql {
117248af65aeSdanielk1977      pragma collation_list;
117348af65aeSdanielk1977    }
11749b5adfa2Sdrh  } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY}
117548af65aeSdanielk1977}
117648af65aeSdanielk1977
1177ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb {
1178ddfb2f03Sdanielk1977  do_test pragma-12.1 {
1179ddfb2f03Sdanielk1977    sqlite3 db2 test.db
1180ddfb2f03Sdanielk1977    execsql {
1181ddfb2f03Sdanielk1977      PRAGMA temp.table_info('abc');
1182ddfb2f03Sdanielk1977    } db2
1183ddfb2f03Sdanielk1977  } {}
1184ddfb2f03Sdanielk1977  db2 close
1185ddfb2f03Sdanielk1977
1186ddfb2f03Sdanielk1977  do_test pragma-12.2 {
1187ddfb2f03Sdanielk1977    sqlite3 db2 test.db
1188ddfb2f03Sdanielk1977    execsql {
1189ddfb2f03Sdanielk1977      PRAGMA temp.default_cache_size = 200;
1190ddfb2f03Sdanielk1977      PRAGMA temp.default_cache_size;
1191ddfb2f03Sdanielk1977    } db2
1192ddfb2f03Sdanielk1977  } {200}
1193ddfb2f03Sdanielk1977  db2 close
1194ddfb2f03Sdanielk1977
1195ddfb2f03Sdanielk1977  do_test pragma-12.3 {
1196ddfb2f03Sdanielk1977    sqlite3 db2 test.db
1197ddfb2f03Sdanielk1977    execsql {
1198ddfb2f03Sdanielk1977      PRAGMA temp.cache_size = 400;
1199ddfb2f03Sdanielk1977      PRAGMA temp.cache_size;
1200ddfb2f03Sdanielk1977    } db2
1201ddfb2f03Sdanielk1977  } {400}
1202ddfb2f03Sdanielk1977  db2 close
1203ddfb2f03Sdanielk1977}
1204ddfb2f03Sdanielk1977
12054b2688abSdanielk1977ifcapable bloblit {
12064b2688abSdanielk1977
120705a82983Sdrhdo_test pragma-13.1 {
120805a82983Sdrh  execsql {
120905a82983Sdrh    DROP TABLE IF EXISTS t4;
121005a82983Sdrh    PRAGMA vdbe_trace=on;
121105a82983Sdrh    PRAGMA vdbe_listing=on;
121205a82983Sdrh    PRAGMA sql_trace=on;
121305a82983Sdrh    CREATE TABLE t4(a INTEGER PRIMARY KEY,b);
121405a82983Sdrh    INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789');
121505a82983Sdrh    INSERT INTO t4(b) VALUES(randstr(30,30));
121605a82983Sdrh    INSERT INTO t4(b) VALUES(1.23456);
121705a82983Sdrh    INSERT INTO t4(b) VALUES(NULL);
121805a82983Sdrh    INSERT INTO t4(b) VALUES(0);
121905a82983Sdrh    INSERT INTO t4(b) SELECT b||b||b||b FROM t4;
122005a82983Sdrh    SELECT * FROM t4;
122105a82983Sdrh  }
122205a82983Sdrh  execsql {
122305a82983Sdrh    PRAGMA vdbe_trace=off;
122405a82983Sdrh    PRAGMA vdbe_listing=off;
122505a82983Sdrh    PRAGMA sql_trace=off;
122605a82983Sdrh  }
122705a82983Sdrh} {}
122805a82983Sdrh
12294b2688abSdanielk1977} ;# ifcapable bloblit
12304b2688abSdanielk1977
123159a93791Sdanielk1977ifcapable pager_pragmas {
123259a93791Sdanielk1977  db close
1233fda06befSmistachkin  forcedelete test.db
123459a93791Sdanielk1977  sqlite3 db test.db
123559a93791Sdanielk1977
123659a93791Sdanielk1977  do_test pragma-14.1 {
123759a93791Sdanielk1977    execsql { pragma auto_vacuum = 0 }
123859a93791Sdanielk1977    execsql { pragma page_count }
123959a93791Sdanielk1977  } {0}
124059a93791Sdanielk1977
124159a93791Sdanielk1977  do_test pragma-14.2 {
124259a93791Sdanielk1977    execsql {
124359a93791Sdanielk1977      CREATE TABLE abc(a, b, c);
124459a93791Sdanielk1977      PRAGMA page_count;
124559a93791Sdanielk1977    }
124659a93791Sdanielk1977  } {2}
12475d16a9a6Sdrh  do_test pragma-14.2uc {
12485d16a9a6Sdrh    execsql {pragma PAGE_COUNT}
12495d16a9a6Sdrh  } {2}
125059a93791Sdanielk1977
125159a93791Sdanielk1977  do_test pragma-14.3 {
125259a93791Sdanielk1977    execsql {
125359a93791Sdanielk1977      BEGIN;
125459a93791Sdanielk1977      CREATE TABLE def(a, b, c);
125559a93791Sdanielk1977      PRAGMA page_count;
125659a93791Sdanielk1977    }
125759a93791Sdanielk1977  } {3}
12585d16a9a6Sdrh  do_test pragma-14.3uc {
12595d16a9a6Sdrh    execsql {pragma PAGE_COUNT}
12605d16a9a6Sdrh  } {3}
126159a93791Sdanielk1977
126259a93791Sdanielk1977  do_test pragma-14.4 {
126359a93791Sdanielk1977    set page_size [db one {pragma page_size}]
126459a93791Sdanielk1977    expr [file size test.db] / $page_size
126559a93791Sdanielk1977  } {2}
126659a93791Sdanielk1977
126759a93791Sdanielk1977  do_test pragma-14.5 {
126859a93791Sdanielk1977    execsql {
126959a93791Sdanielk1977      ROLLBACK;
127059a93791Sdanielk1977      PRAGMA page_count;
127159a93791Sdanielk1977    }
127259a93791Sdanielk1977  } {2}
127359a93791Sdanielk1977
127459a93791Sdanielk1977  do_test pragma-14.6 {
1275fda06befSmistachkin    forcedelete test2.db
127659a93791Sdanielk1977    sqlite3 db2 test2.db
127759a93791Sdanielk1977    execsql {
127859a93791Sdanielk1977      PRAGMA auto_vacuum = 0;
127959a93791Sdanielk1977      CREATE TABLE t1(a, b, c);
128059a93791Sdanielk1977      CREATE TABLE t2(a, b, c);
128159a93791Sdanielk1977      CREATE TABLE t3(a, b, c);
128259a93791Sdanielk1977      CREATE TABLE t4(a, b, c);
128359a93791Sdanielk1977    } db2
128459a93791Sdanielk1977    db2 close
128559a93791Sdanielk1977    execsql {
128659a93791Sdanielk1977      ATTACH 'test2.db' AS aux;
128759a93791Sdanielk1977      PRAGMA aux.page_count;
128859a93791Sdanielk1977    }
128959a93791Sdanielk1977  } {5}
12905d16a9a6Sdrh  do_test pragma-14.6uc {
12915d16a9a6Sdrh    execsql {pragma AUX.PAGE_COUNT}
12925d16a9a6Sdrh  } {5}
129359a93791Sdanielk1977}
129459a93791Sdanielk1977
12958cf6c554Sdanielk1977# Test that the value set using the cache_size pragma is not reset when the
12968cf6c554Sdanielk1977# schema is reloaded.
12978cf6c554Sdanielk1977#
12988cf6c554Sdanielk1977ifcapable pager_pragmas {
12998cf6c554Sdanielk1977  db close
13008cf6c554Sdanielk1977  sqlite3 db test.db
13018cf6c554Sdanielk1977  do_test pragma-15.1 {
13028cf6c554Sdanielk1977    execsql {
13038cf6c554Sdanielk1977      PRAGMA cache_size=59;
13048cf6c554Sdanielk1977      PRAGMA cache_size;
13058cf6c554Sdanielk1977    }
13068cf6c554Sdanielk1977  } {59}
13078cf6c554Sdanielk1977  do_test pragma-15.2 {
13088cf6c554Sdanielk1977    sqlite3 db2 test.db
13098cf6c554Sdanielk1977    execsql {
13108cf6c554Sdanielk1977      CREATE TABLE newtable(a, b, c);
13118cf6c554Sdanielk1977    } db2
13128cf6c554Sdanielk1977    db2 close
13138cf6c554Sdanielk1977  } {}
13148cf6c554Sdanielk1977  do_test pragma-15.3 {
13158cf6c554Sdanielk1977    # Evaluating this statement will cause the schema to be reloaded (because
13168cf6c554Sdanielk1977    # the schema was changed by another connection in pragma-15.2). At one
13178cf6c554Sdanielk1977    # point there was a bug that reset the cache_size to its default value
13188cf6c554Sdanielk1977    # when this happened.
13198cf6c554Sdanielk1977    execsql { SELECT * FROM sqlite_master }
13208cf6c554Sdanielk1977    execsql { PRAGMA cache_size }
13218cf6c554Sdanielk1977  } {59}
13228cf6c554Sdanielk1977}
13238cf6c554Sdanielk1977
13245558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests:
13255558a8a6Sdanielk1977sqlite3 dbX :memory:
13265558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""}
13275558a8a6Sdanielk1977dbX close
13285558a8a6Sdanielk1977
1329838cce43Sdanielk1977ifcapable lock_proxy_pragmas&&prefer_proxy_locking {
1330aebf413dSaswift  set sqlite_hostid_num 1
1331aebf413dSaswift
1332aebf413dSaswift  set using_proxy 0
1333aebf413dSaswift  foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
1334aebf413dSaswift    set using_proxy $value
1335aebf413dSaswift  }
1336aebf413dSaswift
1337aebf413dSaswift  # Test the lock_proxy_file pragmas.
1338aebf413dSaswift  #
1339aebf413dSaswift  db close
1340aebf413dSaswift  set env(SQLITE_FORCE_PROXY_LOCKING) "0"
1341aebf413dSaswift
1342aebf413dSaswift  sqlite3 db test.db
1343aebf413dSaswift  do_test pragma-16.1 {
1344aebf413dSaswift    execsql {
1345aebf413dSaswift      PRAGMA lock_proxy_file="mylittleproxy";
1346aebf413dSaswift      select * from sqlite_master;
1347aebf413dSaswift    }
1348aebf413dSaswift    execsql {
1349aebf413dSaswift      PRAGMA lock_proxy_file;
1350aebf413dSaswift    }
1351aebf413dSaswift  } {mylittleproxy}
1352aebf413dSaswift
1353aebf413dSaswift  do_test pragma-16.2 {
1354aebf413dSaswift    sqlite3 db2 test.db
1355aebf413dSaswift    execsql {
1356aebf413dSaswift      PRAGMA lock_proxy_file="mylittleproxy";
1357aebf413dSaswift    } db2
1358aebf413dSaswift  } {}
1359aebf413dSaswift
1360aebf413dSaswift  db2 close
1361aebf413dSaswift  do_test pragma-16.2.1 {
1362aebf413dSaswift    sqlite3 db2 test.db
1363aebf413dSaswift    execsql {
1364aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1365aebf413dSaswift      select * from sqlite_master;
1366aebf413dSaswift    } db2
1367aebf413dSaswift    execsql {
1368aebf413dSaswift      PRAGMA lock_proxy_file;
1369aebf413dSaswift    } db2
1370aebf413dSaswift  } {mylittleproxy}
1371aebf413dSaswift
1372aebf413dSaswift  db2 close
1373aebf413dSaswift  do_test pragma-16.3 {
1374aebf413dSaswift    sqlite3 db2 test.db
1375aebf413dSaswift    execsql {
1376aebf413dSaswift      PRAGMA lock_proxy_file="myotherproxy";
1377aebf413dSaswift    } db2
1378aebf413dSaswift    catchsql {
1379aebf413dSaswift      select * from sqlite_master;
1380aebf413dSaswift    } db2
1381aebf413dSaswift  } {1 {database is locked}}
1382aebf413dSaswift
1383aebf413dSaswift  do_test pragma-16.4 {
1384aebf413dSaswift    db2 close
1385aebf413dSaswift    db close
1386aebf413dSaswift    sqlite3 db2 test.db
1387aebf413dSaswift    execsql {
1388aebf413dSaswift      PRAGMA lock_proxy_file="myoriginalproxy";
1389aebf413dSaswift      PRAGMA lock_proxy_file="myotherproxy";
1390aebf413dSaswift      PRAGMA lock_proxy_file;
1391aebf413dSaswift    } db2
1392aebf413dSaswift  } {myotherproxy}
1393aebf413dSaswift
1394aebf413dSaswift  db2 close
1395aebf413dSaswift  set env(SQLITE_FORCE_PROXY_LOCKING) "1"
1396aebf413dSaswift  do_test pragma-16.5 {
1397aebf413dSaswift    sqlite3 db2 test.db
1398aebf413dSaswift    execsql {
1399aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1400aebf413dSaswift      PRAGMA lock_proxy_file;
1401aebf413dSaswift    } db2
1402aebf413dSaswift  } {myotherproxy}
1403aebf413dSaswift
1404aebf413dSaswift  do_test pragma-16.6 {
1405aebf413dSaswift    db2 close
1406aebf413dSaswift    sqlite3 db2 test2.db
1407aebf413dSaswift    set lockpath [execsql {
1408aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1409aebf413dSaswift      PRAGMA lock_proxy_file;
1410aebf413dSaswift    } db2]
1411aebf413dSaswift    string match "*test2.db:auto:" $lockpath
1412aebf413dSaswift  } {1}
1413aebf413dSaswift
1414aebf413dSaswift  set sqlite_hostid_num 2
1415aebf413dSaswift  do_test pragma-16.7 {
141614d14607Sdan    list [catch {
1417aebf413dSaswift      sqlite3 db test2.db
1418aebf413dSaswift      execsql {
1419aebf413dSaswift        PRAGMA lock_proxy_file=":auto:";
1420aebf413dSaswift        select * from sqlite_master;
1421aebf413dSaswift      }
142214d14607Sdan    } msg] $msg
1423aebf413dSaswift  } {1 {database is locked}}
1424aebf413dSaswift  db close
1425aebf413dSaswift
1426aebf413dSaswift  do_test pragma-16.8 {
142714d14607Sdan    list [catch {
1428aebf413dSaswift      sqlite3 db test2.db
142914d14607Sdan      execsql { select * from sqlite_master }
143014d14607Sdan    } msg] $msg
1431aebf413dSaswift  } {1 {database is locked}}
1432aebf413dSaswift
1433aebf413dSaswift  db2 close
1434aebf413dSaswift  do_test pragma-16.8.1 {
1435aebf413dSaswift    execsql {
1436aebf413dSaswift      PRAGMA lock_proxy_file="yetanotherproxy";
1437aebf413dSaswift      PRAGMA lock_proxy_file;
1438aebf413dSaswift    }
1439aebf413dSaswift  } {yetanotherproxy}
1440aebf413dSaswift  do_test pragma-16.8.2 {
1441aebf413dSaswift    execsql {
1442aebf413dSaswift      create table mine(x);
1443aebf413dSaswift    }
1444aebf413dSaswift  } {}
1445aebf413dSaswift
1446aebf413dSaswift  db close
1447aebf413dSaswift  do_test pragma-16.9 {
1448aebf413dSaswift    sqlite3 db proxytest.db
1449aebf413dSaswift    set lockpath2 [execsql {
1450aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1451aebf413dSaswift      PRAGMA lock_proxy_file;
1452aebf413dSaswift    } db]
1453aebf413dSaswift    string match "*proxytest.db:auto:" $lockpath2
1454aebf413dSaswift  } {1}
1455aebf413dSaswift
1456aebf413dSaswift  set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy
1457aebf413dSaswift  set sqlite_hostid_num 0
1458aebf413dSaswift}
1459d2cb50b7Sdrh
1460d2cb50b7Sdrh# Parsing of auto_vacuum settings.
1461d2cb50b7Sdrh#
1462d2cb50b7Sdrhforeach {autovac_setting val} {
1463d2cb50b7Sdrh  0 0
1464d2cb50b7Sdrh  1 1
1465d2cb50b7Sdrh  2 2
1466d2cb50b7Sdrh  3 0
1467d2cb50b7Sdrh  -1 0
1468d2cb50b7Sdrh  none 0
1469d2cb50b7Sdrh  NONE 0
1470d2cb50b7Sdrh  NoNe 0
1471d2cb50b7Sdrh  full 1
1472d2cb50b7Sdrh  FULL 1
1473d2cb50b7Sdrh  incremental 2
1474d2cb50b7Sdrh  INCREMENTAL 2
1475d2cb50b7Sdrh  -1234 0
1476d2cb50b7Sdrh  1234 0
1477d2cb50b7Sdrh} {
1478d2cb50b7Sdrh  do_test pragma-17.1.$autovac_setting {
1479d2cb50b7Sdrh    catch {db close}
1480d2cb50b7Sdrh    sqlite3 db :memory:
1481d2cb50b7Sdrh    execsql "
1482d2cb50b7Sdrh      PRAGMA auto_vacuum=$::autovac_setting;
1483d2cb50b7Sdrh      PRAGMA auto_vacuum;
1484d2cb50b7Sdrh    "
1485d2cb50b7Sdrh  } $val
1486d2cb50b7Sdrh}
1487d2cb50b7Sdrh
1488d2cb50b7Sdrh# Parsing of temp_store settings.
1489d2cb50b7Sdrh#
1490d2cb50b7Sdrhforeach {temp_setting val} {
1491d2cb50b7Sdrh  0 0
1492d2cb50b7Sdrh  1 1
1493d2cb50b7Sdrh  2 2
1494d2cb50b7Sdrh  3 0
1495d2cb50b7Sdrh  -1 0
1496d2cb50b7Sdrh  file 1
1497d2cb50b7Sdrh  FILE 1
1498d2cb50b7Sdrh  fIlE 1
1499d2cb50b7Sdrh  memory 2
1500d2cb50b7Sdrh  MEMORY 2
1501d2cb50b7Sdrh  MeMoRy 2
1502d2cb50b7Sdrh} {
1503d2cb50b7Sdrh  do_test pragma-18.1.$temp_setting {
1504d2cb50b7Sdrh    catch {db close}
1505d2cb50b7Sdrh    sqlite3 db :memory:
1506d2cb50b7Sdrh    execsql "
1507d2cb50b7Sdrh      PRAGMA temp_store=$::temp_setting;
1508d2cb50b7Sdrh      PRAGMA temp_store=$::temp_setting;
1509d2cb50b7Sdrh      PRAGMA temp_store;
1510d2cb50b7Sdrh    "
1511d2cb50b7Sdrh  } $val
1512d2cb50b7Sdrh}
1513d2cb50b7Sdrh
151492c700dbSdrh# The SQLITE_FCNTL_PRAGMA logic, with error handling.
151592c700dbSdrh#
151692c700dbSdrhdb close
151792c700dbSdrhtestvfs tvfs
151892c700dbSdrhsqlite3 db test.db -vfs tvfs
151992c700dbSdrhdo_test pragma-19.1 {
152092c700dbSdrh  catchsql {PRAGMA error}
152192c700dbSdrh} {1 {SQL logic error or missing database}}
152292c700dbSdrhdo_test pragma-19.2 {
152392c700dbSdrh  catchsql {PRAGMA error='This is the error message'}
152492c700dbSdrh} {1 {This is the error message}}
152592c700dbSdrhdo_test pragma-19.3 {
152692c700dbSdrh  catchsql {PRAGMA error='7 This is the error message'}
152792c700dbSdrh} {1 {This is the error message}}
152892c700dbSdrhdo_test pragma-19.4 {
152992c700dbSdrh  catchsql {PRAGMA error=7}
153092c700dbSdrh} {1 {out of memory}}
1531c8517f61Sdrhdo_test pragma-19.5 {
15325b044545Smistachkin  file tail [lindex [execsql {PRAGMA filename}] 0]
1533c8517f61Sdrh} {test.db}
153492c700dbSdrh
1535cc71645bSdrhif {$tcl_platform(platform)=="windows"} {
1536a112d140Smistachkin# Test data_store_directory pragma
1537a112d140Smistachkin#
1538a112d140Smistachkindb close
1539a112d140Smistachkinsqlite3 db test.db
1540a112d140Smistachkinfile mkdir data_dir
1541a112d140Smistachkindo_test pragma-20.1 {
1542a112d140Smistachkin  catchsql {PRAGMA data_store_directory}
1543a112d140Smistachkin} {0 {}}
1544a112d140Smistachkindo_test pragma-20.2 {
1545a112d140Smistachkin  set pwd [string map {' ''} [file nativename [get_pwd]]]
1546a112d140Smistachkin  catchsql "PRAGMA data_store_directory='$pwd';"
1547a112d140Smistachkin} {0 {}}
1548a112d140Smistachkindo_test pragma-20.3 {
1549a112d140Smistachkin  catchsql {PRAGMA data_store_directory}
1550a112d140Smistachkin} [list 0 [list [file nativename [get_pwd]]]]
1551a112d140Smistachkindo_test pragma-20.4 {
1552a112d140Smistachkin  set pwd [string map {' ''} [file nativename \
1553a112d140Smistachkin    [file join [get_pwd] data_dir]]]
1554a112d140Smistachkin  catchsql "PRAGMA data_store_directory='$pwd';"
1555a112d140Smistachkin} {0 {}}
1556a112d140Smistachkindo_test pragma-20.5 {
1557a112d140Smistachkin  sqlite3 db2 test2.db
1558a112d140Smistachkin  catchsql "PRAGMA database_list;" db2
1559a112d140Smistachkin} [list 0 [list 0 main [file nativename \
1560a112d140Smistachkin    [file join [get_pwd] data_dir test2.db]]]]
1561a112d140Smistachkincatch {db2 close}
1562a112d140Smistachkindo_test pragma-20.6 {
1563a112d140Smistachkin  sqlite3 db2 [file join [get_pwd] test2.db]
1564a112d140Smistachkin  catchsql "PRAGMA database_list;" db2
1565a112d140Smistachkin} [list 0 [list 0 main [file nativename \
1566a112d140Smistachkin    [file join [get_pwd] test2.db]]]]
1567a112d140Smistachkincatch {db2 close}
1568a112d140Smistachkindo_test pragma-20.7 {
1569a112d140Smistachkin  catchsql "PRAGMA data_store_directory='';"
1570a112d140Smistachkin} {0 {}}
1571a112d140Smistachkindo_test pragma-20.8 {
1572a112d140Smistachkin  catchsql {PRAGMA data_store_directory}
1573a112d140Smistachkin} {0 {}}
157492c700dbSdrh
1575a112d140Smistachkinforcedelete data_dir
1576cc71645bSdrh} ;# endif windows
1577cd61c281Sdrh
15785885e762Sdando_test 21.1 {
15795885e762Sdan  # Create a corrupt database in testerr.db. And a non-corrupt at test.db.
15805885e762Sdan  #
15815885e762Sdan  db close
15825885e762Sdan  forcedelete test.db
15835885e762Sdan  sqlite3 db test.db
15845885e762Sdan  execsql {
15855885e762Sdan    PRAGMA page_size = 1024;
15865885e762Sdan    PRAGMA auto_vacuum = 0;
15875885e762Sdan    CREATE TABLE t1(a PRIMARY KEY, b);
15885885e762Sdan    INSERT INTO t1 VALUES(1, 1);
15895885e762Sdan  }
15905885e762Sdan  for {set i 0} {$i < 10} {incr i} {
15915885e762Sdan    execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 }
15925885e762Sdan  }
15935885e762Sdan  db close
15945885e762Sdan  forcecopy test.db testerr.db
15955885e762Sdan  hexio_write testerr.db 15000 [string repeat 55 100]
15965885e762Sdan} {100}
15975885e762Sdan
15985885e762Sdanset mainerr {*** in database main ***
15995885e762SdanMultiple uses for byte 672 of page 15}
16005885e762Sdanset auxerr {*** in database aux ***
16015885e762SdanMultiple uses for byte 672 of page 15}
16025885e762Sdan
16035885e762Sdando_test 22.2 {
16045885e762Sdan  catch { db close }
16055885e762Sdan  sqlite3 db testerr.db
16065885e762Sdan  execsql { PRAGMA integrity_check }
16075885e762Sdan} [list $mainerr]
16085885e762Sdan
16095885e762Sdando_test 22.3.1 {
16105885e762Sdan  catch { db close }
16115885e762Sdan  sqlite3 db test.db
16125885e762Sdan  execsql {
16135885e762Sdan    ATTACH 'testerr.db' AS 'aux';
16145885e762Sdan    PRAGMA integrity_check;
16155885e762Sdan  }
16165885e762Sdan} [list $auxerr]
16175885e762Sdando_test 22.3.2 {
16185885e762Sdan  execsql { PRAGMA main.integrity_check; }
16195885e762Sdan} {ok}
16205885e762Sdando_test 22.3.3 {
16215885e762Sdan  execsql { PRAGMA aux.integrity_check; }
16225885e762Sdan} [list $auxerr]
16235885e762Sdan
16245885e762Sdando_test 22.4.1 {
16255885e762Sdan  catch { db close }
16265885e762Sdan  sqlite3 db testerr.db
16275885e762Sdan  execsql {
16285885e762Sdan    ATTACH 'test.db' AS 'aux';
16295885e762Sdan    PRAGMA integrity_check;
16305885e762Sdan  }
16315885e762Sdan} [list $mainerr]
16325885e762Sdando_test 22.4.2 {
16335885e762Sdan  execsql { PRAGMA main.integrity_check; }
16345885e762Sdan} [list $mainerr]
16355885e762Sdando_test 22.4.3 {
16365885e762Sdan  execsql { PRAGMA aux.integrity_check; }
16375885e762Sdan} {ok}
16385885e762Sdan
1639c95e01daSdrhdb close
1640c95e01daSdrhforcedelete test.db test.db-wal test.db-journal
1641c95e01daSdrhsqlite3 db test.db
1642c95e01daSdrhsqlite3 db2 test.db
1643c95e01daSdrhdo_test 23.1 {
1644c95e01daSdrh  db eval {
1645c95e01daSdrh    CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d);
1646c95e01daSdrh    CREATE INDEX i1 ON t1(b,c);
1647c95e01daSdrh    CREATE INDEX i2 ON t1(c,d);
1648c95e01daSdrh    CREATE TABLE t2(x INTEGER REFERENCES t1);
1649c95e01daSdrh  }
1650c95e01daSdrh  db2 eval {SELECT name FROM sqlite_master}
1651c95e01daSdrh} {t1 i1 i2 t2}
1652c95e01daSdrhdo_test 23.2 {
1653c95e01daSdrh  db eval {
1654c95e01daSdrh    DROP INDEX i2;
1655c95e01daSdrh    CREATE INDEX i2 ON t1(c,d,b);
1656c95e01daSdrh  }
1657c95e01daSdrh  db2 eval {PRAGMA index_info(i2)}
1658c95e01daSdrh} {0 2 c 1 3 d 2 1 b}
1659c95e01daSdrhdo_test 23.3 {
1660c95e01daSdrh  db eval {
1661c95e01daSdrh    CREATE INDEX i3 ON t1(d,b,c);
1662c95e01daSdrh  }
1663c95e01daSdrh  db2 eval {PRAGMA index_list(t1)}
1664c95e01daSdrh} {0 i3 0 1 i2 0 2 i1 0}
1665c95e01daSdrhdo_test 23.4 {
1666c95e01daSdrh  db eval {
1667c95e01daSdrh    ALTER TABLE t1 ADD COLUMN e;
1668c95e01daSdrh  }
1669c95e01daSdrh  db2 eval {
1670c95e01daSdrh    PRAGMA table_info(t1);
1671c95e01daSdrh  }
1672c95e01daSdrh} {/4 e {} 0 {} 0/}
1673c95e01daSdrhdo_test 23.5 {
1674c95e01daSdrh  db eval {
1675c95e01daSdrh    DROP TABLE t2;
1676c95e01daSdrh    CREATE TABLE t2(x, y INTEGER REFERENCES t1);
1677c95e01daSdrh  }
1678c95e01daSdrh  db2 eval {
1679c95e01daSdrh    PRAGMA foreign_key_list(t2);
1680c95e01daSdrh  }
1681c95e01daSdrh} {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE}
1682c95e01daSdrh
1683cd61c281Sdrhfinish_test
1684