xref: /sqlite-3.40.0/test/pragma.test (revision cefc87fc)
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}
2886fbe41acSdrh    } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
28991cf71b0Sdanielk1977    do_test pragma-3.3 {
2901dcdbc06Sdrh      execsql {PRAGMA integrity_check=1}
2916fbe41acSdrh    } {{row 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      }
2976fbe41acSdrh    } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 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      }
3026fbe41acSdrh    } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2}}
3031dcdbc06Sdrh    do_test pragma-3.6 {
3041dcdbc06Sdrh      execsql {
3051dcdbc06Sdrh        PRAGMA integrity_check=xyz
3061dcdbc06Sdrh      }
3076fbe41acSdrh    } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 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      }
3126fbe41acSdrh    } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 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
3476fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 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
3616fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 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
3696fbe41acSdrhPage 6 is never used} {row 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
3936fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
3941dcdbc06SdrhPage 4 is never used
3951dcdbc06SdrhPage 5 is never used
3966fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 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
4046fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
4051dcdbc06SdrhPage 4 is never used
4061dcdbc06SdrhPage 5 is never used
4076fbe41acSdrhPage 6 is never used} {row 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
4156fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 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
4256fbe41acSdrhPage 6 is never used} {row 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}
434*cefc87fcSdrh
435*cefc87fcSdrh# Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL
436*cefc87fcSdrh# constraint violations.
437*cefc87fcSdrh#
438*cefc87fcSdrhdo_execsql_test pragma-3.20 {
439*cefc87fcSdrh  CREATE TABLE t1(a,b);
440*cefc87fcSdrh  CREATE INDEX t1a ON t1(a);
441*cefc87fcSdrh  INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6);
442*cefc87fcSdrh  PRAGMA writable_schema=ON;
443*cefc87fcSdrh  UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)'
444*cefc87fcSdrh   WHERE name='t1a';
445*cefc87fcSdrh  UPDATE sqlite_master SET sql='CREATE TABLE t1(a NOT NULL,b)'
446*cefc87fcSdrh   WHERE name='t1';
447*cefc87fcSdrh  PRAGMA writable_schema=OFF;
448*cefc87fcSdrh  ALTER TABLE t1 RENAME TO t1x;
449*cefc87fcSdrh  PRAGMA integrity_check;
450*cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a} {NULL value in t1x.a}}
451*cefc87fcSdrhdo_execsql_test pragma-3.21 {
452*cefc87fcSdrh  PRAGMA integrity_check(3);
453*cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a}}
454*cefc87fcSdrhdo_execsql_test pragma-3.22 {
455*cefc87fcSdrh  PRAGMA integrity_check(2);
456*cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a}}
457*cefc87fcSdrhdo_execsql_test pragma-3.21 {
458*cefc87fcSdrh  PRAGMA integrity_check(1);
459*cefc87fcSdrh} {{non-unique entry in index t1a}}
46091cf71b0Sdanielk1977
46191cf71b0Sdanielk1977# Test modifying the cache_size of an attached database.
4625a8f9374Sdanielk1977ifcapable pager_pragmas&&attach {
46391cf71b0Sdanielk1977do_test pragma-4.1 {
46491cf71b0Sdanielk1977  execsql {
4651e9daa6aSdrh    ATTACH 'test2.db' AS aux;
46691cf71b0Sdanielk1977    pragma aux.cache_size;
46791cf71b0Sdanielk1977    pragma aux.default_cache_size;
46891cf71b0Sdanielk1977  }
4691e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4701bdd9b57Sdrhdo_test pragma-4.2 {
4711bdd9b57Sdrh  execsql {
47291cf71b0Sdanielk1977    pragma aux.cache_size = 50;
47391cf71b0Sdanielk1977    pragma aux.cache_size;
47491cf71b0Sdanielk1977    pragma aux.default_cache_size;
4751bdd9b57Sdrh  }
4761e9daa6aSdrh} [list 50 $DFLT_CACHE_SZ]
4771bdd9b57Sdrhdo_test pragma-4.3 {
4781bdd9b57Sdrh  execsql {
47991cf71b0Sdanielk1977    pragma aux.default_cache_size = 456;
48091cf71b0Sdanielk1977    pragma aux.cache_size;
48191cf71b0Sdanielk1977    pragma aux.default_cache_size;
4821bdd9b57Sdrh  }
48391cf71b0Sdanielk1977} {456 456}
4841bdd9b57Sdrhdo_test pragma-4.4 {
4851bdd9b57Sdrh  execsql {
48691cf71b0Sdanielk1977    pragma cache_size;
48791cf71b0Sdanielk1977    pragma default_cache_size;
4881bdd9b57Sdrh  }
4891e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4901bdd9b57Sdrhdo_test pragma-4.5 {
4911bdd9b57Sdrh  execsql {
49291cf71b0Sdanielk1977    DETACH aux;
49391cf71b0Sdanielk1977    ATTACH 'test3.db' AS aux;
49491cf71b0Sdanielk1977    pragma aux.cache_size;
49591cf71b0Sdanielk1977    pragma aux.default_cache_size;
4961bdd9b57Sdrh  }
4971e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
4981bdd9b57Sdrhdo_test pragma-4.6 {
4991bdd9b57Sdrh  execsql {
50091cf71b0Sdanielk1977    DETACH aux;
50191cf71b0Sdanielk1977    ATTACH 'test2.db' AS aux;
50291cf71b0Sdanielk1977    pragma aux.cache_size;
50391cf71b0Sdanielk1977    pragma aux.default_cache_size;
5041bdd9b57Sdrh  }
50591cf71b0Sdanielk1977} {456 456}
506c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
5071bdd9b57Sdrh
50891cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is
50991cf71b0Sdanielk1977# disallowed.
510c7b4a44cSdanielk1977ifcapable pager_pragmas {
51191cf71b0Sdanielk1977do_test pragma-5.0 {
5121bdd9b57Sdrh  execsql {
51391cf71b0Sdanielk1977    pragma synchronous;
5141bdd9b57Sdrh  }
51591cf71b0Sdanielk1977} {2}
51691cf71b0Sdanielk1977do_test pragma-5.1 {
5171bdd9b57Sdrh  catchsql {
5181bdd9b57Sdrh    BEGIN;
51991cf71b0Sdanielk1977    pragma synchronous = OFF;
5201bdd9b57Sdrh  }
52191cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}}
52291cf71b0Sdanielk1977do_test pragma-5.2 {
52391cf71b0Sdanielk1977  execsql {
52491cf71b0Sdanielk1977    pragma synchronous;
52591cf71b0Sdanielk1977  }
52691cf71b0Sdanielk1977} {2}
5275260f7e9Sdrhcatchsql {COMMIT;}
528c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas
5295260f7e9Sdrh
5305260f7e9Sdrh# Test schema-query pragmas
5315260f7e9Sdrh#
53227188fb5Sdanielk1977ifcapable schema_pragmas {
5335a8f9374Sdanielk1977ifcapable tempdb&&attach {
5345260f7e9Sdrh  do_test pragma-6.1 {
535956bc92cSdrh    set res {}
53640e016e4Sdrh    execsql {SELECT * FROM sqlite_temp_master}
5375260f7e9Sdrh    foreach {idx name file} [execsql {pragma database_list}] {
5385260f7e9Sdrh      lappend res $idx $name
5395260f7e9Sdrh    }
5405260f7e9Sdrh    set res
541a71aa001Sdrh  } {0 main 1 temp 2 aux}
54253c0f748Sdanielk1977}
5435260f7e9Sdrhdo_test pragma-6.2 {
5445260f7e9Sdrh  execsql {
545d2cb50b7Sdrh    CREATE TABLE t2(a,b,c);
5465260f7e9Sdrh    pragma table_info(t2)
5475260f7e9Sdrh  }
548bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0}
549d2cb50b7Sdrhdo_test pragma-6.2.1 {
550d2cb50b7Sdrh  execsql {
551d2cb50b7Sdrh    pragma table_info;
552d2cb50b7Sdrh  }
553d2cb50b7Sdrh} {}
554736c7d4bSdrhdb nullvalue <<NULL>>
555417ec638Sdrhdo_test pragma-6.2.2 {
556417ec638Sdrh  execsql {
557736c7d4bSdrh    CREATE TABLE t5(
558736c7d4bSdrh      a TEXT DEFAULT CURRENT_TIMESTAMP,
559736c7d4bSdrh      b DEFAULT (5+3),
560736c7d4bSdrh      c TEXT,
561736c7d4bSdrh      d INTEGER DEFAULT NULL,
562384b7fe2Sdrh      e TEXT DEFAULT '',
563384b7fe2Sdrh      UNIQUE(b,c,d),
564384b7fe2Sdrh      PRIMARY KEY(e,b,c)
565736c7d4bSdrh    );
566417ec638Sdrh    PRAGMA table_info(t5);
567417ec638Sdrh  }
568384b7fe2Sdrh} {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}
569736c7d4bSdrhdb nullvalue {}
570384b7fe2Sdrhdo_test pragma-6.2.3 {
571384b7fe2Sdrh  execsql {
572384b7fe2Sdrh    CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c);
573384b7fe2Sdrh    pragma table_info(t2_3)
574384b7fe2Sdrh  }
575384b7fe2Sdrh} {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0}
5766bf89570Sdrhifcapable {foreignkey} {
577d2cb50b7Sdrh  do_test pragma-6.3.1 {
5785260f7e9Sdrh    execsql {
5795260f7e9Sdrh      CREATE TABLE t3(a int references t2(b), b UNIQUE);
5805260f7e9Sdrh      pragma foreign_key_list(t3);
5815260f7e9Sdrh    }
5821da40a38Sdan  } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE}
583d2cb50b7Sdrh  do_test pragma-6.3.2 {
584d2cb50b7Sdrh    execsql {
585d2cb50b7Sdrh      pragma foreign_key_list;
586d2cb50b7Sdrh    }
587d2cb50b7Sdrh  } {}
588d2cb50b7Sdrh  do_test pragma-6.3.3 {
589d2cb50b7Sdrh    execsql {
590d2cb50b7Sdrh      pragma foreign_key_list(t3_bogus);
591d2cb50b7Sdrh    }
592d2cb50b7Sdrh  } {}
593d2cb50b7Sdrh  do_test pragma-6.3.4 {
594d2cb50b7Sdrh    execsql {
595d2cb50b7Sdrh      pragma foreign_key_list(t5);
596d2cb50b7Sdrh    }
597d2cb50b7Sdrh  } {}
5985260f7e9Sdrh  do_test pragma-6.4 {
5995260f7e9Sdrh    execsql {
6005260f7e9Sdrh      pragma index_list(t3);
6015260f7e9Sdrh    }
6023ef26156Sdrh  } {0 sqlite_autoindex_t3_1 1}
6036bf89570Sdrh}
6046bf89570Sdrhifcapable {!foreignkey} {
6056bf89570Sdrh  execsql {CREATE TABLE t3(a,b UNIQUE)}
6066bf89570Sdrh}
607d2cb50b7Sdrhdo_test pragma-6.5.1 {
6085260f7e9Sdrh  execsql {
6095260f7e9Sdrh    CREATE INDEX t3i1 ON t3(a,b);
6105260f7e9Sdrh    pragma index_info(t3i1);
6115260f7e9Sdrh  }
6125260f7e9Sdrh} {0 0 a 1 1 b}
613d2cb50b7Sdrhdo_test pragma-6.5.2 {
614d2cb50b7Sdrh  execsql {
615d2cb50b7Sdrh    pragma index_info(t3i1_bogus);
616d2cb50b7Sdrh  }
617d2cb50b7Sdrh} {}
618260d8a6aSdanielk1977
619260d8a6aSdanielk1977ifcapable tempdb {
620260d8a6aSdanielk1977  # Test for ticket #3320. When a temp table of the same name exists, make
621260d8a6aSdanielk1977  # sure the schema of the main table can still be queried using
622260d8a6aSdanielk1977  # "pragma table_info":
623260d8a6aSdanielk1977  do_test pragma-6.6.1 {
624260d8a6aSdanielk1977    execsql {
625260d8a6aSdanielk1977      CREATE TABLE trial(col_main);
626260d8a6aSdanielk1977      CREATE TEMP TABLE trial(col_temp);
627260d8a6aSdanielk1977    }
628260d8a6aSdanielk1977  } {}
629260d8a6aSdanielk1977  do_test pragma-6.6.2 {
630260d8a6aSdanielk1977    execsql {
631260d8a6aSdanielk1977      PRAGMA table_info(trial);
632260d8a6aSdanielk1977    }
633260d8a6aSdanielk1977  } {0 col_temp {} 0 {} 0}
634260d8a6aSdanielk1977  do_test pragma-6.6.3 {
635260d8a6aSdanielk1977    execsql {
636260d8a6aSdanielk1977      PRAGMA temp.table_info(trial);
637260d8a6aSdanielk1977    }
638260d8a6aSdanielk1977  } {0 col_temp {} 0 {} 0}
639260d8a6aSdanielk1977  do_test pragma-6.6.4 {
640260d8a6aSdanielk1977    execsql {
641260d8a6aSdanielk1977      PRAGMA main.table_info(trial);
642260d8a6aSdanielk1977    }
643260d8a6aSdanielk1977  } {0 col_main {} 0 {} 0}
644260d8a6aSdanielk1977}
645f96a3778Sdanielk1977
646f96a3778Sdanielk1977do_test pragma-6.7 {
647f96a3778Sdanielk1977  execsql {
648f96a3778Sdanielk1977    CREATE TABLE test_table(
649f96a3778Sdanielk1977      one INT NOT NULL DEFAULT -1,
650f96a3778Sdanielk1977      two text,
651f96a3778Sdanielk1977      three VARCHAR(45, 65) DEFAULT 'abcde',
652f96a3778Sdanielk1977      four REAL DEFAULT X'abcdef',
653f96a3778Sdanielk1977      five DEFAULT CURRENT_TIME
654f96a3778Sdanielk1977    );
655f96a3778Sdanielk1977    PRAGMA table_info(test_table);
656f96a3778Sdanielk1977  }
657f96a3778Sdanielk1977} [concat \
658f96a3778Sdanielk1977  {0 one INT 1 -1 0} \
659f96a3778Sdanielk1977  {1 two text 0 {} 0} \
660f96a3778Sdanielk1977  {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \
661f96a3778Sdanielk1977  {3 four REAL 0 X'abcdef' 0} \
662f96a3778Sdanielk1977  {4 five {} 0 CURRENT_TIME 0} \
663f96a3778Sdanielk1977]
66427188fb5Sdanielk1977} ;# ifcapable schema_pragmas
6655260f7e9Sdrh# Miscellaneous tests
6665260f7e9Sdrh#
66727188fb5Sdanielk1977ifcapable schema_pragmas {
668d2cb50b7Sdrhdo_test pragma-7.1.1 {
6695260f7e9Sdrh  # Make sure a pragma knows to read the schema if it needs to
6705260f7e9Sdrh  db close
6715260f7e9Sdrh  sqlite3 db test.db
6725260f7e9Sdrh  execsql {
6735260f7e9Sdrh    pragma index_list(t3);
6745260f7e9Sdrh  }
6753ef26156Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1}
676d2cb50b7Sdrhdo_test pragma-7.1.2 {
677d2cb50b7Sdrh  execsql {
678d2cb50b7Sdrh    pragma index_list(t3_bogus);
679d2cb50b7Sdrh  }
680d2cb50b7Sdrh} {}
68127188fb5Sdanielk1977} ;# ifcapable schema_pragmas
6826c62608fSdrhifcapable {utf16} {
683cb354603Sdan  if {[permutation] == ""} {
6845260f7e9Sdrh    do_test pragma-7.2 {
6855260f7e9Sdrh      db close
6865260f7e9Sdrh      sqlite3 db test.db
6875260f7e9Sdrh      catchsql {
6885260f7e9Sdrh        pragma encoding=bogus;
6895260f7e9Sdrh      }
6905260f7e9Sdrh    } {1 {unsupported encoding: bogus}}
6916c62608fSdrh  }
692cb354603Sdan}
69353c0f748Sdanielk1977ifcapable tempdb {
6945260f7e9Sdrh  do_test pragma-7.3 {
6955260f7e9Sdrh    db close
6965260f7e9Sdrh    sqlite3 db test.db
6975260f7e9Sdrh    execsql {
6985260f7e9Sdrh      pragma lock_status;
6995260f7e9Sdrh    }
7005260f7e9Sdrh  } {main unlocked temp closed}
70153c0f748Sdanielk1977} else {
70253c0f748Sdanielk1977  do_test pragma-7.3 {
70353c0f748Sdanielk1977    db close
70453c0f748Sdanielk1977    sqlite3 db test.db
70553c0f748Sdanielk1977    execsql {
70653c0f748Sdanielk1977      pragma lock_status;
70753c0f748Sdanielk1977    }
70853c0f748Sdanielk1977  } {main unlocked}
70953c0f748Sdanielk1977}
7105260f7e9Sdrh
7115260f7e9Sdrh
712dae2495bSdanielk1977#----------------------------------------------------------------------
713b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
714b92b70bbSdanielk1977# user_version" statements.
715dae2495bSdanielk1977#
716b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version
717b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version
718dae2495bSdanielk1977#
719dae2495bSdanielk1977
72011cf9fbcSdanielk1977ifcapable schema_version {
72111cf9fbcSdanielk1977
722b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the
723dae2495bSdanielk1977# same value.
724dae2495bSdanielk1977do_test pragma-8.1.1 {
725dae2495bSdanielk1977  execsql {
726b92b70bbSdanielk1977    PRAGMA schema_version = 105;
727dae2495bSdanielk1977  }
728dae2495bSdanielk1977} {}
729dae2495bSdanielk1977do_test pragma-8.1.2 {
73025403650Sdrh  execsql2 {
731b92b70bbSdanielk1977    PRAGMA schema_version;
732dae2495bSdanielk1977  }
73325403650Sdrh} {schema_version 105}
734dae2495bSdanielk1977do_test pragma-8.1.3 {
735dae2495bSdanielk1977  execsql {
736b92b70bbSdanielk1977    PRAGMA schema_version = 106;
737dae2495bSdanielk1977  }
738dae2495bSdanielk1977} {}
739dae2495bSdanielk1977do_test pragma-8.1.4 {
740dae2495bSdanielk1977  execsql {
741b92b70bbSdanielk1977    PRAGMA schema_version;
742dae2495bSdanielk1977  }
743dae2495bSdanielk1977} 106
744dae2495bSdanielk1977
745b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really
746b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version).
747dae2495bSdanielk1977do_test pragma-8.1.5 {
748dae2495bSdanielk1977  execsql {
749dae2495bSdanielk1977    CREATE TABLE t4(a, b, c);
750dae2495bSdanielk1977    INSERT INTO t4 VALUES(1, 2, 3);
751dae2495bSdanielk1977    SELECT * FROM t4;
752dae2495bSdanielk1977  }
753dae2495bSdanielk1977} {1 2 3}
754dae2495bSdanielk1977do_test pragma-8.1.6 {
755dae2495bSdanielk1977  execsql {
756b92b70bbSdanielk1977    PRAGMA schema_version;
757dae2495bSdanielk1977  }
758dae2495bSdanielk1977} 107
759dae2495bSdanielk1977
760dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the
761b92b70bbSdanielk1977# schema-version using the first connection forces the second connection
762dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions,
763dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query.
764dae2495bSdanielk1977do_test pragma-8.1.7 {
765dddca286Sdrh  sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
766dae2495bSdanielk1977  execsql {
767dae2495bSdanielk1977    SELECT * FROM t4;
768dae2495bSdanielk1977  } db2
769dae2495bSdanielk1977} {1 2 3}
770dae2495bSdanielk1977do_test pragma-8.1.8 {
771dae2495bSdanielk1977  execsql {
772b92b70bbSdanielk1977    PRAGMA schema_version = 108;
773dae2495bSdanielk1977  }
774dae2495bSdanielk1977} {}
775dae2495bSdanielk1977do_test pragma-8.1.9 {
776dae2495bSdanielk1977  set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
777dae2495bSdanielk1977  sqlite3_step $::STMT
778dae2495bSdanielk1977} SQLITE_ERROR
779dae2495bSdanielk1977do_test pragma-8.1.10 {
780dae2495bSdanielk1977  sqlite3_finalize $::STMT
781dae2495bSdanielk1977} SQLITE_SCHEMA
782dae2495bSdanielk1977
783b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database.
784fda06befSmistachkinforcedelete test2.db
785fda06befSmistachkinforcedelete test2.db-journal
7865a8f9374Sdanielk1977ifcapable attach {
787dae2495bSdanielk1977  do_test pragma-8.1.11 {
788dae2495bSdanielk1977    execsql {
789dae2495bSdanielk1977      ATTACH 'test2.db' AS aux;
790dae2495bSdanielk1977      CREATE TABLE aux.t1(a, b, c);
791b92b70bbSdanielk1977      PRAGMA aux.schema_version = 205;
792dae2495bSdanielk1977    }
793dae2495bSdanielk1977  } {}
794dae2495bSdanielk1977  do_test pragma-8.1.12 {
795dae2495bSdanielk1977    execsql {
796b92b70bbSdanielk1977      PRAGMA aux.schema_version;
797dae2495bSdanielk1977    }
798dae2495bSdanielk1977  } 205
7995a8f9374Sdanielk1977}
800dae2495bSdanielk1977do_test pragma-8.1.13 {
801dae2495bSdanielk1977  execsql {
802b92b70bbSdanielk1977    PRAGMA schema_version;
803dae2495bSdanielk1977  }
804dae2495bSdanielk1977} 108
805dae2495bSdanielk1977
806b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database
807dae2495bSdanielk1977# forces the second connection to reload the schema.
8085a8f9374Sdanielk1977ifcapable attach {
809dae2495bSdanielk1977  do_test pragma-8.1.14 {
810dddca286Sdrh    sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
811dae2495bSdanielk1977    execsql {
812dae2495bSdanielk1977      ATTACH 'test2.db' AS aux;
813dae2495bSdanielk1977      SELECT * FROM aux.t1;
814dae2495bSdanielk1977    } db2
815dae2495bSdanielk1977  } {}
816dae2495bSdanielk1977  do_test pragma-8.1.15 {
817dae2495bSdanielk1977    execsql {
818b92b70bbSdanielk1977      PRAGMA aux.schema_version = 206;
819dae2495bSdanielk1977    }
820dae2495bSdanielk1977  } {}
821dae2495bSdanielk1977  do_test pragma-8.1.16 {
822dae2495bSdanielk1977    set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]
823dae2495bSdanielk1977    sqlite3_step $::STMT
824dae2495bSdanielk1977  } SQLITE_ERROR
825dae2495bSdanielk1977  do_test pragma-8.1.17 {
826dae2495bSdanielk1977    sqlite3_finalize $::STMT
827dae2495bSdanielk1977  } SQLITE_SCHEMA
828dae2495bSdanielk1977  do_test pragma-8.1.18 {
829dae2495bSdanielk1977    db2 close
830dae2495bSdanielk1977  } {}
8315a8f9374Sdanielk1977}
832dae2495bSdanielk1977
833b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't
834b92b70bbSdanielk1977# accidentally manipulating the schema-version instead).
835dae2495bSdanielk1977do_test pragma-8.2.1 {
83625403650Sdrh  execsql2 {
837b92b70bbSdanielk1977    PRAGMA user_version;
838dae2495bSdanielk1977  }
83925403650Sdrh} {user_version 0}
840dae2495bSdanielk1977do_test pragma-8.2.2 {
841dae2495bSdanielk1977  execsql {
842b92b70bbSdanielk1977    PRAGMA user_version = 2;
843dae2495bSdanielk1977  }
844dae2495bSdanielk1977} {}
845802d69a7Sdrhdo_test pragma-8.2.3.1 {
84625403650Sdrh  execsql2 {
847b92b70bbSdanielk1977    PRAGMA user_version;
848dae2495bSdanielk1977  }
84925403650Sdrh} {user_version 2}
850802d69a7Sdrhdo_test pragma-8.2.3.2 {
851802d69a7Sdrh  db close
852802d69a7Sdrh  sqlite3 db test.db
853802d69a7Sdrh  execsql {
854802d69a7Sdrh    PRAGMA user_version;
855802d69a7Sdrh  }
856802d69a7Sdrh} {2}
857802d69a7Sdrhdo_test pragma-8.2.4.1 {
858dae2495bSdanielk1977  execsql {
859b92b70bbSdanielk1977    PRAGMA schema_version;
860dae2495bSdanielk1977  }
861dae2495bSdanielk1977} {108}
862802d69a7Sdrhifcapable vacuum {
863802d69a7Sdrh  do_test pragma-8.2.4.2 {
864802d69a7Sdrh    execsql {
865802d69a7Sdrh      VACUUM;
866802d69a7Sdrh      PRAGMA user_version;
867802d69a7Sdrh    }
868802d69a7Sdrh  } {2}
869802d69a7Sdrh  do_test pragma-8.2.4.3 {
870802d69a7Sdrh    execsql {
871802d69a7Sdrh      PRAGMA schema_version;
872802d69a7Sdrh    }
873802d69a7Sdrh  } {109}
874802d69a7Sdrh}
8755a8f9374Sdanielk1977
8765a8f9374Sdanielk1977ifcapable attach {
877802d69a7Sdrh  db eval {ATTACH 'test2.db' AS aux}
878dae2495bSdanielk1977
879b92b70bbSdanielk1977  # Check that the user-version in the auxilary database can be manipulated (
880dae2495bSdanielk1977  # and that we aren't accidentally manipulating the same in the main db).
881dae2495bSdanielk1977  do_test pragma-8.2.5 {
882dae2495bSdanielk1977    execsql {
883b92b70bbSdanielk1977      PRAGMA aux.user_version;
884dae2495bSdanielk1977    }
885dae2495bSdanielk1977  } {0}
886dae2495bSdanielk1977  do_test pragma-8.2.6 {
887dae2495bSdanielk1977    execsql {
888b92b70bbSdanielk1977      PRAGMA aux.user_version = 3;
889dae2495bSdanielk1977    }
890dae2495bSdanielk1977  } {}
891dae2495bSdanielk1977  do_test pragma-8.2.7 {
892dae2495bSdanielk1977    execsql {
893b92b70bbSdanielk1977      PRAGMA aux.user_version;
894dae2495bSdanielk1977    }
895dae2495bSdanielk1977  } {3}
896dae2495bSdanielk1977  do_test pragma-8.2.8 {
897dae2495bSdanielk1977    execsql {
898b92b70bbSdanielk1977      PRAGMA main.user_version;
899dae2495bSdanielk1977    }
900dae2495bSdanielk1977  } {2}
901dae2495bSdanielk1977
902b92b70bbSdanielk1977  # Now check that a ROLLBACK resets the user-version if it has been modified
903dae2495bSdanielk1977  # within a transaction.
904dae2495bSdanielk1977  do_test pragma-8.2.9 {
905dae2495bSdanielk1977    execsql {
906dae2495bSdanielk1977      BEGIN;
907b92b70bbSdanielk1977      PRAGMA aux.user_version = 10;
908b92b70bbSdanielk1977      PRAGMA user_version = 11;
909dae2495bSdanielk1977    }
910dae2495bSdanielk1977  } {}
911dae2495bSdanielk1977  do_test pragma-8.2.10 {
912dae2495bSdanielk1977    execsql {
913b92b70bbSdanielk1977      PRAGMA aux.user_version;
914dae2495bSdanielk1977    }
915dae2495bSdanielk1977  } {10}
916dae2495bSdanielk1977  do_test pragma-8.2.11 {
917dae2495bSdanielk1977    execsql {
918b92b70bbSdanielk1977      PRAGMA main.user_version;
919dae2495bSdanielk1977    }
920dae2495bSdanielk1977  } {11}
921dae2495bSdanielk1977  do_test pragma-8.2.12 {
922dae2495bSdanielk1977    execsql {
923dae2495bSdanielk1977      ROLLBACK;
924b92b70bbSdanielk1977      PRAGMA aux.user_version;
925dae2495bSdanielk1977    }
926dae2495bSdanielk1977  } {3}
927dae2495bSdanielk1977  do_test pragma-8.2.13 {
928dae2495bSdanielk1977    execsql {
929b92b70bbSdanielk1977      PRAGMA main.user_version;
930dae2495bSdanielk1977    }
931dae2495bSdanielk1977  } {2}
9325a8f9374Sdanielk1977}
933dae2495bSdanielk1977
934b92b70bbSdanielk1977# Try a negative value for the user-version
935dae2495bSdanielk1977do_test pragma-8.2.14 {
936dae2495bSdanielk1977  execsql {
937b92b70bbSdanielk1977    PRAGMA user_version = -450;
938dae2495bSdanielk1977  }
939dae2495bSdanielk1977} {}
940dae2495bSdanielk1977do_test pragma-8.2.15 {
941dae2495bSdanielk1977  execsql {
942b92b70bbSdanielk1977    PRAGMA user_version;
943dae2495bSdanielk1977  }
944dae2495bSdanielk1977} {-450}
945d9c847dcSdanielk1977} ; # ifcapable schema_version
946d9c847dcSdanielk1977
947d19744f3Sdrh# Check to see if TEMP_STORE is memory or disk.  Return strings
948d19744f3Sdrh# "memory" or "disk" as appropriate.
949d19744f3Sdrh#
950d19744f3Sdrhproc check_temp_store {} {
951d19744f3Sdrh  db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)}
952d19744f3Sdrh  db eval {PRAGMA database_list} {
953d19744f3Sdrh    if {$name=="temp"} {
95417b90b53Sdanielk1977      set bt [btree_from_db db 1]
95517b90b53Sdanielk1977      if {[btree_ismemdb $bt]} {
956d19744f3Sdrh        return "memory"
957d19744f3Sdrh      }
95817b90b53Sdanielk1977      return "disk"
959d19744f3Sdrh    }
960d19744f3Sdrh  }
961d19744f3Sdrh  return "unknown"
962d19744f3Sdrh}
963d19744f3Sdrh
9644ee09b4bSdrh# Application_ID
9654ee09b4bSdrh#
9664ee09b4bSdrhdo_test pragma-8.3.1 {
9674ee09b4bSdrh  execsql {
9684ee09b4bSdrh    PRAGMA application_id;
9694ee09b4bSdrh  }
9704ee09b4bSdrh} {0}
9714ee09b4bSdrhdo_test pragma-8.3.2 {
9724ee09b4bSdrh  execsql {PRAGMA Application_ID(12345); PRAGMA application_id;}
9734ee09b4bSdrh} {12345}
9749a09a3caStpoindex
9759a09a3caStpoindex# Test temp_store and temp_store_directory pragmas
9769a09a3caStpoindex#
977268283bcSdrhifcapable pager_pragmas {
9789a09a3caStpoindexdo_test pragma-9.1 {
9799a09a3caStpoindex  db close
9809a09a3caStpoindex  sqlite3 db test.db
9819a09a3caStpoindex  execsql {
9829a09a3caStpoindex    PRAGMA temp_store;
9839a09a3caStpoindex  }
9849a09a3caStpoindex} {0}
985d19744f3Sdrhif {$TEMP_STORE<=1} {
986d19744f3Sdrh  do_test pragma-9.1.1 {
987d19744f3Sdrh    check_temp_store
988d19744f3Sdrh  } {disk}
989d19744f3Sdrh} else {
990d19744f3Sdrh  do_test pragma-9.1.1 {
991d19744f3Sdrh    check_temp_store
992d19744f3Sdrh  } {memory}
993d19744f3Sdrh}
994d19744f3Sdrh
9959a09a3caStpoindexdo_test pragma-9.2 {
996d19744f3Sdrh  db close
997d19744f3Sdrh  sqlite3 db test.db
9989a09a3caStpoindex  execsql {
9999a09a3caStpoindex    PRAGMA temp_store=file;
10009a09a3caStpoindex    PRAGMA temp_store;
10019a09a3caStpoindex  }
10029a09a3caStpoindex} {1}
1003d19744f3Sdrhif {$TEMP_STORE==3} {
1004d19744f3Sdrh  # When TEMP_STORE is 3, always use memory regardless of pragma settings.
1005d19744f3Sdrh  do_test pragma-9.2.1 {
1006d19744f3Sdrh    check_temp_store
1007d19744f3Sdrh  } {memory}
1008d19744f3Sdrh} else {
1009d19744f3Sdrh  do_test pragma-9.2.1 {
1010d19744f3Sdrh    check_temp_store
1011d19744f3Sdrh  } {disk}
1012d19744f3Sdrh}
1013d19744f3Sdrh
10149a09a3caStpoindexdo_test pragma-9.3 {
1015d19744f3Sdrh  db close
1016d19744f3Sdrh  sqlite3 db test.db
10179a09a3caStpoindex  execsql {
10189a09a3caStpoindex    PRAGMA temp_store=memory;
10199a09a3caStpoindex    PRAGMA temp_store;
10209a09a3caStpoindex  }
10219a09a3caStpoindex} {2}
1022d19744f3Sdrhif {$TEMP_STORE==0} {
1023d19744f3Sdrh  # When TEMP_STORE is 0, always use the disk regardless of pragma settings.
1024d19744f3Sdrh  do_test pragma-9.3.1 {
1025d19744f3Sdrh    check_temp_store
1026d19744f3Sdrh  } {disk}
1027d19744f3Sdrh} else {
1028d19744f3Sdrh  do_test pragma-9.3.1 {
1029d19744f3Sdrh    check_temp_store
1030d19744f3Sdrh  } {memory}
1031d19744f3Sdrh}
1032d19744f3Sdrh
10339a09a3caStpoindexdo_test pragma-9.4 {
10349a09a3caStpoindex  execsql {
10359a09a3caStpoindex    PRAGMA temp_store_directory;
10369a09a3caStpoindex  }
10379a09a3caStpoindex} {}
103878f82d1eSdrhifcapable wsd {
10399a09a3caStpoindex  do_test pragma-9.5 {
1040f8a78464Smistachkin    set pwd [string map {' ''} [file nativename [get_pwd]]]
1041268283bcSdrh    execsql "
1042268283bcSdrh      PRAGMA temp_store_directory='$pwd';
10439a09a3caStpoindex    "
10449a09a3caStpoindex  } {}
10459a09a3caStpoindex  do_test pragma-9.6 {
10469a09a3caStpoindex    execsql {
10479a09a3caStpoindex      PRAGMA temp_store_directory;
10489a09a3caStpoindex    }
1049f8a78464Smistachkin  } [list [file nativename [get_pwd]]]
10509a09a3caStpoindex  do_test pragma-9.7 {
1051268283bcSdrh    catchsql {
10529a09a3caStpoindex      PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
10539a09a3caStpoindex    }
1054268283bcSdrh  } {1 {not a writable directory}}
10559a09a3caStpoindex  do_test pragma-9.8 {
10569a09a3caStpoindex    execsql {
10579a09a3caStpoindex      PRAGMA temp_store_directory='';
10589a09a3caStpoindex    }
10599a09a3caStpoindex  } {}
10601e9daa6aSdrh  if {![info exists TEMP_STORE] || $TEMP_STORE<=1} {
106153c0f748Sdanielk1977    ifcapable tempdb {
10629a09a3caStpoindex      do_test pragma-9.9 {
10639a09a3caStpoindex        execsql {
10649a09a3caStpoindex          PRAGMA temp_store_directory;
10659a09a3caStpoindex          PRAGMA temp_store=FILE;
10669a09a3caStpoindex          CREATE TEMP TABLE temp_store_directory_test(a integer);
10679a09a3caStpoindex          INSERT INTO temp_store_directory_test values (2);
10689a09a3caStpoindex          SELECT * FROM temp_store_directory_test;
10699a09a3caStpoindex        }
10709a09a3caStpoindex      } {2}
10719a09a3caStpoindex      do_test pragma-9.10 {
1072268283bcSdrh        catchsql "
1073268283bcSdrh          PRAGMA temp_store_directory='$pwd';
10749a09a3caStpoindex          SELECT * FROM temp_store_directory_test;
10759a09a3caStpoindex        "
1076268283bcSdrh      } {1 {no such table: temp_store_directory_test}}
10771e9daa6aSdrh    }
10781e9daa6aSdrh  }
107978f82d1eSdrh}
108095b289b6Sdanielk1977do_test pragma-9.11 {
108195b289b6Sdanielk1977  execsql {
108295b289b6Sdanielk1977    PRAGMA temp_store = 0;
108395b289b6Sdanielk1977    PRAGMA temp_store;
108495b289b6Sdanielk1977  }
108595b289b6Sdanielk1977} {0}
108695b289b6Sdanielk1977do_test pragma-9.12 {
108795b289b6Sdanielk1977  execsql {
108895b289b6Sdanielk1977    PRAGMA temp_store = 1;
108995b289b6Sdanielk1977    PRAGMA temp_store;
109095b289b6Sdanielk1977  }
109195b289b6Sdanielk1977} {1}
109295b289b6Sdanielk1977do_test pragma-9.13 {
109395b289b6Sdanielk1977  execsql {
109495b289b6Sdanielk1977    PRAGMA temp_store = 2;
109595b289b6Sdanielk1977    PRAGMA temp_store;
109695b289b6Sdanielk1977  }
109795b289b6Sdanielk1977} {2}
109895b289b6Sdanielk1977do_test pragma-9.14 {
109995b289b6Sdanielk1977  execsql {
110095b289b6Sdanielk1977    PRAGMA temp_store = 3;
110195b289b6Sdanielk1977    PRAGMA temp_store;
110295b289b6Sdanielk1977  }
110395b289b6Sdanielk1977} {0}
110495b289b6Sdanielk1977do_test pragma-9.15 {
110595b289b6Sdanielk1977  catchsql {
110695b289b6Sdanielk1977    BEGIN EXCLUSIVE;
110795b289b6Sdanielk1977    CREATE TEMP TABLE temp_table(t);
110895b289b6Sdanielk1977    INSERT INTO temp_table VALUES('valuable data');
110995b289b6Sdanielk1977    PRAGMA temp_store = 1;
111095b289b6Sdanielk1977  }
111195b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}}
111295b289b6Sdanielk1977do_test pragma-9.16 {
111395b289b6Sdanielk1977  execsql {
111495b289b6Sdanielk1977    SELECT * FROM temp_table;
111595b289b6Sdanielk1977    COMMIT;
111695b289b6Sdanielk1977  }
111795b289b6Sdanielk1977} {{valuable data}}
1118983e2309Sdanielk1977
1119983e2309Sdanielk1977do_test pragma-9.17 {
1120983e2309Sdanielk1977  execsql {
1121983e2309Sdanielk1977    INSERT INTO temp_table VALUES('valuable data II');
1122983e2309Sdanielk1977    SELECT * FROM temp_table;
1123983e2309Sdanielk1977  }
1124983e2309Sdanielk1977} {{valuable data} {valuable data II}}
1125983e2309Sdanielk1977
1126983e2309Sdanielk1977do_test pragma-9.18 {
1127983e2309Sdanielk1977  set rc [catch {
1128983e2309Sdanielk1977    db eval {SELECT t FROM temp_table} {
1129983e2309Sdanielk1977      execsql {pragma temp_store = 1}
1130983e2309Sdanielk1977    }
1131983e2309Sdanielk1977  } msg]
1132983e2309Sdanielk1977  list $rc $msg
1133983e2309Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}}
1134983e2309Sdanielk1977
1135268283bcSdrh} ;# ifcapable pager_pragmas
11369a09a3caStpoindex
1137cc6bd383Sdanielk1977ifcapable trigger {
1138cc6bd383Sdanielk1977
1139cc6bd383Sdanielk1977do_test pragma-10.0 {
1140cc6bd383Sdanielk1977  catchsql {
1141cc6bd383Sdanielk1977    DROP TABLE main.t1;
1142cc6bd383Sdanielk1977  }
1143cc6bd383Sdanielk1977  execsql {
1144cc6bd383Sdanielk1977    PRAGMA count_changes = 1;
1145cc6bd383Sdanielk1977
1146cc6bd383Sdanielk1977    CREATE TABLE t1(a PRIMARY KEY);
1147cc6bd383Sdanielk1977    CREATE TABLE t1_mirror(a);
1148cc6bd383Sdanielk1977    CREATE TABLE t1_mirror2(a);
1149cc6bd383Sdanielk1977    CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN
1150cc6bd383Sdanielk1977      INSERT INTO t1_mirror VALUES(new.a);
1151cc6bd383Sdanielk1977    END;
1152cc6bd383Sdanielk1977    CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
1153cc6bd383Sdanielk1977      INSERT INTO t1_mirror2 VALUES(new.a);
1154cc6bd383Sdanielk1977    END;
1155cc6bd383Sdanielk1977    CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
1156cc6bd383Sdanielk1977      UPDATE t1_mirror SET a = new.a WHERE a = old.a;
1157cc6bd383Sdanielk1977    END;
1158cc6bd383Sdanielk1977    CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
1159cc6bd383Sdanielk1977      UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;
1160cc6bd383Sdanielk1977    END;
1161cc6bd383Sdanielk1977    CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN
1162cc6bd383Sdanielk1977      DELETE FROM t1_mirror WHERE a = old.a;
1163cc6bd383Sdanielk1977    END;
1164cc6bd383Sdanielk1977    CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
1165cc6bd383Sdanielk1977      DELETE FROM t1_mirror2 WHERE a = old.a;
1166cc6bd383Sdanielk1977    END;
1167cc6bd383Sdanielk1977  }
1168cc6bd383Sdanielk1977} {}
1169cc6bd383Sdanielk1977
1170cc6bd383Sdanielk1977do_test pragma-10.1 {
1171cc6bd383Sdanielk1977  execsql {
1172cc6bd383Sdanielk1977    INSERT INTO t1 VALUES(randstr(10,10));
1173cc6bd383Sdanielk1977  }
1174cc6bd383Sdanielk1977} {1}
1175cc6bd383Sdanielk1977do_test pragma-10.2 {
1176cc6bd383Sdanielk1977  execsql {
1177cc6bd383Sdanielk1977    UPDATE t1 SET a = randstr(10,10);
1178cc6bd383Sdanielk1977  }
1179cc6bd383Sdanielk1977} {1}
1180cc6bd383Sdanielk1977do_test pragma-10.3 {
1181cc6bd383Sdanielk1977  execsql {
1182cc6bd383Sdanielk1977    DELETE FROM t1;
1183cc6bd383Sdanielk1977  }
1184cc6bd383Sdanielk1977} {1}
1185cc6bd383Sdanielk1977
1186cc6bd383Sdanielk1977} ;# ifcapable trigger
1187cc6bd383Sdanielk1977
118848af65aeSdanielk1977ifcapable schema_pragmas {
118948af65aeSdanielk1977  do_test pragma-11.1 {
119048af65aeSdanielk1977    execsql2 {
119148af65aeSdanielk1977      pragma collation_list;
119248af65aeSdanielk1977    }
11939b5adfa2Sdrh  } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY}
119448af65aeSdanielk1977  do_test pragma-11.2 {
119548af65aeSdanielk1977    db collate New_Collation blah...
119648af65aeSdanielk1977    execsql {
119748af65aeSdanielk1977      pragma collation_list;
119848af65aeSdanielk1977    }
11999b5adfa2Sdrh  } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY}
120048af65aeSdanielk1977}
120148af65aeSdanielk1977
1202ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb {
1203ddfb2f03Sdanielk1977  do_test pragma-12.1 {
1204ddfb2f03Sdanielk1977    sqlite3 db2 test.db
1205ddfb2f03Sdanielk1977    execsql {
1206ddfb2f03Sdanielk1977      PRAGMA temp.table_info('abc');
1207ddfb2f03Sdanielk1977    } db2
1208ddfb2f03Sdanielk1977  } {}
1209ddfb2f03Sdanielk1977  db2 close
1210ddfb2f03Sdanielk1977
1211ddfb2f03Sdanielk1977  do_test pragma-12.2 {
1212ddfb2f03Sdanielk1977    sqlite3 db2 test.db
1213ddfb2f03Sdanielk1977    execsql {
1214ddfb2f03Sdanielk1977      PRAGMA temp.default_cache_size = 200;
1215ddfb2f03Sdanielk1977      PRAGMA temp.default_cache_size;
1216ddfb2f03Sdanielk1977    } db2
1217ddfb2f03Sdanielk1977  } {200}
1218ddfb2f03Sdanielk1977  db2 close
1219ddfb2f03Sdanielk1977
1220ddfb2f03Sdanielk1977  do_test pragma-12.3 {
1221ddfb2f03Sdanielk1977    sqlite3 db2 test.db
1222ddfb2f03Sdanielk1977    execsql {
1223ddfb2f03Sdanielk1977      PRAGMA temp.cache_size = 400;
1224ddfb2f03Sdanielk1977      PRAGMA temp.cache_size;
1225ddfb2f03Sdanielk1977    } db2
1226ddfb2f03Sdanielk1977  } {400}
1227ddfb2f03Sdanielk1977  db2 close
1228ddfb2f03Sdanielk1977}
1229ddfb2f03Sdanielk1977
12304b2688abSdanielk1977ifcapable bloblit {
12314b2688abSdanielk1977
123205a82983Sdrhdo_test pragma-13.1 {
123305a82983Sdrh  execsql {
123405a82983Sdrh    DROP TABLE IF EXISTS t4;
123505a82983Sdrh    PRAGMA vdbe_trace=on;
123605a82983Sdrh    PRAGMA vdbe_listing=on;
123705a82983Sdrh    PRAGMA sql_trace=on;
123805a82983Sdrh    CREATE TABLE t4(a INTEGER PRIMARY KEY,b);
123905a82983Sdrh    INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789');
124005a82983Sdrh    INSERT INTO t4(b) VALUES(randstr(30,30));
124105a82983Sdrh    INSERT INTO t4(b) VALUES(1.23456);
124205a82983Sdrh    INSERT INTO t4(b) VALUES(NULL);
124305a82983Sdrh    INSERT INTO t4(b) VALUES(0);
124405a82983Sdrh    INSERT INTO t4(b) SELECT b||b||b||b FROM t4;
124505a82983Sdrh    SELECT * FROM t4;
124605a82983Sdrh  }
124705a82983Sdrh  execsql {
124805a82983Sdrh    PRAGMA vdbe_trace=off;
124905a82983Sdrh    PRAGMA vdbe_listing=off;
125005a82983Sdrh    PRAGMA sql_trace=off;
125105a82983Sdrh  }
125205a82983Sdrh} {}
125305a82983Sdrh
12544b2688abSdanielk1977} ;# ifcapable bloblit
12554b2688abSdanielk1977
125659a93791Sdanielk1977ifcapable pager_pragmas {
125759a93791Sdanielk1977  db close
1258fda06befSmistachkin  forcedelete test.db
125959a93791Sdanielk1977  sqlite3 db test.db
126059a93791Sdanielk1977
126159a93791Sdanielk1977  do_test pragma-14.1 {
126259a93791Sdanielk1977    execsql { pragma auto_vacuum = 0 }
126359a93791Sdanielk1977    execsql { pragma page_count }
126459a93791Sdanielk1977  } {0}
126559a93791Sdanielk1977
126659a93791Sdanielk1977  do_test pragma-14.2 {
126759a93791Sdanielk1977    execsql {
126859a93791Sdanielk1977      CREATE TABLE abc(a, b, c);
126959a93791Sdanielk1977      PRAGMA page_count;
127059a93791Sdanielk1977    }
127159a93791Sdanielk1977  } {2}
12725d16a9a6Sdrh  do_test pragma-14.2uc {
12735d16a9a6Sdrh    execsql {pragma PAGE_COUNT}
12745d16a9a6Sdrh  } {2}
127559a93791Sdanielk1977
127659a93791Sdanielk1977  do_test pragma-14.3 {
127759a93791Sdanielk1977    execsql {
127859a93791Sdanielk1977      BEGIN;
127959a93791Sdanielk1977      CREATE TABLE def(a, b, c);
128059a93791Sdanielk1977      PRAGMA page_count;
128159a93791Sdanielk1977    }
128259a93791Sdanielk1977  } {3}
12835d16a9a6Sdrh  do_test pragma-14.3uc {
12845d16a9a6Sdrh    execsql {pragma PAGE_COUNT}
12855d16a9a6Sdrh  } {3}
128659a93791Sdanielk1977
128759a93791Sdanielk1977  do_test pragma-14.4 {
128859a93791Sdanielk1977    set page_size [db one {pragma page_size}]
128959a93791Sdanielk1977    expr [file size test.db] / $page_size
129059a93791Sdanielk1977  } {2}
129159a93791Sdanielk1977
129259a93791Sdanielk1977  do_test pragma-14.5 {
129359a93791Sdanielk1977    execsql {
129459a93791Sdanielk1977      ROLLBACK;
129559a93791Sdanielk1977      PRAGMA page_count;
129659a93791Sdanielk1977    }
129759a93791Sdanielk1977  } {2}
129859a93791Sdanielk1977
129959a93791Sdanielk1977  do_test pragma-14.6 {
1300fda06befSmistachkin    forcedelete test2.db
130159a93791Sdanielk1977    sqlite3 db2 test2.db
130259a93791Sdanielk1977    execsql {
130359a93791Sdanielk1977      PRAGMA auto_vacuum = 0;
130459a93791Sdanielk1977      CREATE TABLE t1(a, b, c);
130559a93791Sdanielk1977      CREATE TABLE t2(a, b, c);
130659a93791Sdanielk1977      CREATE TABLE t3(a, b, c);
130759a93791Sdanielk1977      CREATE TABLE t4(a, b, c);
130859a93791Sdanielk1977    } db2
130959a93791Sdanielk1977    db2 close
131059a93791Sdanielk1977    execsql {
131159a93791Sdanielk1977      ATTACH 'test2.db' AS aux;
131259a93791Sdanielk1977      PRAGMA aux.page_count;
131359a93791Sdanielk1977    }
131459a93791Sdanielk1977  } {5}
13155d16a9a6Sdrh  do_test pragma-14.6uc {
13165d16a9a6Sdrh    execsql {pragma AUX.PAGE_COUNT}
13175d16a9a6Sdrh  } {5}
131859a93791Sdanielk1977}
131959a93791Sdanielk1977
13208cf6c554Sdanielk1977# Test that the value set using the cache_size pragma is not reset when the
13218cf6c554Sdanielk1977# schema is reloaded.
13228cf6c554Sdanielk1977#
13238cf6c554Sdanielk1977ifcapable pager_pragmas {
13248cf6c554Sdanielk1977  db close
13258cf6c554Sdanielk1977  sqlite3 db test.db
13268cf6c554Sdanielk1977  do_test pragma-15.1 {
13278cf6c554Sdanielk1977    execsql {
13288cf6c554Sdanielk1977      PRAGMA cache_size=59;
13298cf6c554Sdanielk1977      PRAGMA cache_size;
13308cf6c554Sdanielk1977    }
13318cf6c554Sdanielk1977  } {59}
13328cf6c554Sdanielk1977  do_test pragma-15.2 {
13338cf6c554Sdanielk1977    sqlite3 db2 test.db
13348cf6c554Sdanielk1977    execsql {
13358cf6c554Sdanielk1977      CREATE TABLE newtable(a, b, c);
13368cf6c554Sdanielk1977    } db2
13378cf6c554Sdanielk1977    db2 close
13388cf6c554Sdanielk1977  } {}
13398cf6c554Sdanielk1977  do_test pragma-15.3 {
13408cf6c554Sdanielk1977    # Evaluating this statement will cause the schema to be reloaded (because
13418cf6c554Sdanielk1977    # the schema was changed by another connection in pragma-15.2). At one
13428cf6c554Sdanielk1977    # point there was a bug that reset the cache_size to its default value
13438cf6c554Sdanielk1977    # when this happened.
13448cf6c554Sdanielk1977    execsql { SELECT * FROM sqlite_master }
13458cf6c554Sdanielk1977    execsql { PRAGMA cache_size }
13468cf6c554Sdanielk1977  } {59}
13478cf6c554Sdanielk1977}
13488cf6c554Sdanielk1977
13495558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests:
13505558a8a6Sdanielk1977sqlite3 dbX :memory:
13515558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""}
13525558a8a6Sdanielk1977dbX close
13535558a8a6Sdanielk1977
1354838cce43Sdanielk1977ifcapable lock_proxy_pragmas&&prefer_proxy_locking {
1355aebf413dSaswift  set sqlite_hostid_num 1
1356aebf413dSaswift
1357aebf413dSaswift  set using_proxy 0
1358aebf413dSaswift  foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
1359aebf413dSaswift    set using_proxy $value
1360aebf413dSaswift  }
1361aebf413dSaswift
1362aebf413dSaswift  # Test the lock_proxy_file pragmas.
1363aebf413dSaswift  #
1364aebf413dSaswift  db close
1365aebf413dSaswift  set env(SQLITE_FORCE_PROXY_LOCKING) "0"
1366aebf413dSaswift
1367aebf413dSaswift  sqlite3 db test.db
1368aebf413dSaswift  do_test pragma-16.1 {
1369aebf413dSaswift    execsql {
1370aebf413dSaswift      PRAGMA lock_proxy_file="mylittleproxy";
1371aebf413dSaswift      select * from sqlite_master;
1372aebf413dSaswift    }
1373aebf413dSaswift    execsql {
1374aebf413dSaswift      PRAGMA lock_proxy_file;
1375aebf413dSaswift    }
1376aebf413dSaswift  } {mylittleproxy}
1377aebf413dSaswift
1378aebf413dSaswift  do_test pragma-16.2 {
1379aebf413dSaswift    sqlite3 db2 test.db
1380aebf413dSaswift    execsql {
1381aebf413dSaswift      PRAGMA lock_proxy_file="mylittleproxy";
1382aebf413dSaswift    } db2
1383aebf413dSaswift  } {}
1384aebf413dSaswift
1385aebf413dSaswift  db2 close
1386aebf413dSaswift  do_test pragma-16.2.1 {
1387aebf413dSaswift    sqlite3 db2 test.db
1388aebf413dSaswift    execsql {
1389aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1390aebf413dSaswift      select * from sqlite_master;
1391aebf413dSaswift    } db2
1392aebf413dSaswift    execsql {
1393aebf413dSaswift      PRAGMA lock_proxy_file;
1394aebf413dSaswift    } db2
1395aebf413dSaswift  } {mylittleproxy}
1396aebf413dSaswift
1397aebf413dSaswift  db2 close
1398aebf413dSaswift  do_test pragma-16.3 {
1399aebf413dSaswift    sqlite3 db2 test.db
1400aebf413dSaswift    execsql {
1401aebf413dSaswift      PRAGMA lock_proxy_file="myotherproxy";
1402aebf413dSaswift    } db2
1403aebf413dSaswift    catchsql {
1404aebf413dSaswift      select * from sqlite_master;
1405aebf413dSaswift    } db2
1406aebf413dSaswift  } {1 {database is locked}}
1407aebf413dSaswift
1408aebf413dSaswift  do_test pragma-16.4 {
1409aebf413dSaswift    db2 close
1410aebf413dSaswift    db close
1411aebf413dSaswift    sqlite3 db2 test.db
1412aebf413dSaswift    execsql {
1413aebf413dSaswift      PRAGMA lock_proxy_file="myoriginalproxy";
1414aebf413dSaswift      PRAGMA lock_proxy_file="myotherproxy";
1415aebf413dSaswift      PRAGMA lock_proxy_file;
1416aebf413dSaswift    } db2
1417aebf413dSaswift  } {myotherproxy}
1418aebf413dSaswift
1419aebf413dSaswift  db2 close
1420aebf413dSaswift  set env(SQLITE_FORCE_PROXY_LOCKING) "1"
1421aebf413dSaswift  do_test pragma-16.5 {
1422aebf413dSaswift    sqlite3 db2 test.db
1423aebf413dSaswift    execsql {
1424aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1425aebf413dSaswift      PRAGMA lock_proxy_file;
1426aebf413dSaswift    } db2
1427aebf413dSaswift  } {myotherproxy}
1428aebf413dSaswift
1429aebf413dSaswift  do_test pragma-16.6 {
1430aebf413dSaswift    db2 close
1431aebf413dSaswift    sqlite3 db2 test2.db
1432aebf413dSaswift    set lockpath [execsql {
1433aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1434aebf413dSaswift      PRAGMA lock_proxy_file;
1435aebf413dSaswift    } db2]
1436aebf413dSaswift    string match "*test2.db:auto:" $lockpath
1437aebf413dSaswift  } {1}
1438aebf413dSaswift
1439aebf413dSaswift  set sqlite_hostid_num 2
1440aebf413dSaswift  do_test pragma-16.7 {
144114d14607Sdan    list [catch {
1442aebf413dSaswift      sqlite3 db test2.db
1443aebf413dSaswift      execsql {
1444aebf413dSaswift        PRAGMA lock_proxy_file=":auto:";
1445aebf413dSaswift        select * from sqlite_master;
1446aebf413dSaswift      }
144714d14607Sdan    } msg] $msg
1448aebf413dSaswift  } {1 {database is locked}}
1449aebf413dSaswift  db close
1450aebf413dSaswift
1451aebf413dSaswift  do_test pragma-16.8 {
145214d14607Sdan    list [catch {
1453aebf413dSaswift      sqlite3 db test2.db
145414d14607Sdan      execsql { select * from sqlite_master }
145514d14607Sdan    } msg] $msg
1456aebf413dSaswift  } {1 {database is locked}}
1457aebf413dSaswift
1458aebf413dSaswift  db2 close
1459aebf413dSaswift  do_test pragma-16.8.1 {
1460aebf413dSaswift    execsql {
1461aebf413dSaswift      PRAGMA lock_proxy_file="yetanotherproxy";
1462aebf413dSaswift      PRAGMA lock_proxy_file;
1463aebf413dSaswift    }
1464aebf413dSaswift  } {yetanotherproxy}
1465aebf413dSaswift  do_test pragma-16.8.2 {
1466aebf413dSaswift    execsql {
1467aebf413dSaswift      create table mine(x);
1468aebf413dSaswift    }
1469aebf413dSaswift  } {}
1470aebf413dSaswift
1471aebf413dSaswift  db close
1472aebf413dSaswift  do_test pragma-16.9 {
1473aebf413dSaswift    sqlite3 db proxytest.db
1474aebf413dSaswift    set lockpath2 [execsql {
1475aebf413dSaswift      PRAGMA lock_proxy_file=":auto:";
1476aebf413dSaswift      PRAGMA lock_proxy_file;
1477aebf413dSaswift    } db]
1478aebf413dSaswift    string match "*proxytest.db:auto:" $lockpath2
1479aebf413dSaswift  } {1}
1480aebf413dSaswift
1481aebf413dSaswift  set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy
1482aebf413dSaswift  set sqlite_hostid_num 0
1483aebf413dSaswift}
1484d2cb50b7Sdrh
1485d2cb50b7Sdrh# Parsing of auto_vacuum settings.
1486d2cb50b7Sdrh#
1487d2cb50b7Sdrhforeach {autovac_setting val} {
1488d2cb50b7Sdrh  0 0
1489d2cb50b7Sdrh  1 1
1490d2cb50b7Sdrh  2 2
1491d2cb50b7Sdrh  3 0
1492d2cb50b7Sdrh  -1 0
1493d2cb50b7Sdrh  none 0
1494d2cb50b7Sdrh  NONE 0
1495d2cb50b7Sdrh  NoNe 0
1496d2cb50b7Sdrh  full 1
1497d2cb50b7Sdrh  FULL 1
1498d2cb50b7Sdrh  incremental 2
1499d2cb50b7Sdrh  INCREMENTAL 2
1500d2cb50b7Sdrh  -1234 0
1501d2cb50b7Sdrh  1234 0
1502d2cb50b7Sdrh} {
1503d2cb50b7Sdrh  do_test pragma-17.1.$autovac_setting {
1504d2cb50b7Sdrh    catch {db close}
1505d2cb50b7Sdrh    sqlite3 db :memory:
1506d2cb50b7Sdrh    execsql "
1507d2cb50b7Sdrh      PRAGMA auto_vacuum=$::autovac_setting;
1508d2cb50b7Sdrh      PRAGMA auto_vacuum;
1509d2cb50b7Sdrh    "
1510d2cb50b7Sdrh  } $val
1511d2cb50b7Sdrh}
1512d2cb50b7Sdrh
1513d2cb50b7Sdrh# Parsing of temp_store settings.
1514d2cb50b7Sdrh#
1515d2cb50b7Sdrhforeach {temp_setting val} {
1516d2cb50b7Sdrh  0 0
1517d2cb50b7Sdrh  1 1
1518d2cb50b7Sdrh  2 2
1519d2cb50b7Sdrh  3 0
1520d2cb50b7Sdrh  -1 0
1521d2cb50b7Sdrh  file 1
1522d2cb50b7Sdrh  FILE 1
1523d2cb50b7Sdrh  fIlE 1
1524d2cb50b7Sdrh  memory 2
1525d2cb50b7Sdrh  MEMORY 2
1526d2cb50b7Sdrh  MeMoRy 2
1527d2cb50b7Sdrh} {
1528d2cb50b7Sdrh  do_test pragma-18.1.$temp_setting {
1529d2cb50b7Sdrh    catch {db close}
1530d2cb50b7Sdrh    sqlite3 db :memory:
1531d2cb50b7Sdrh    execsql "
1532d2cb50b7Sdrh      PRAGMA temp_store=$::temp_setting;
1533d2cb50b7Sdrh      PRAGMA temp_store=$::temp_setting;
1534d2cb50b7Sdrh      PRAGMA temp_store;
1535d2cb50b7Sdrh    "
1536d2cb50b7Sdrh  } $val
1537d2cb50b7Sdrh}
1538d2cb50b7Sdrh
153992c700dbSdrh# The SQLITE_FCNTL_PRAGMA logic, with error handling.
154092c700dbSdrh#
154192c700dbSdrhdb close
154292c700dbSdrhtestvfs tvfs
154392c700dbSdrhsqlite3 db test.db -vfs tvfs
154492c700dbSdrhdo_test pragma-19.1 {
154592c700dbSdrh  catchsql {PRAGMA error}
154692c700dbSdrh} {1 {SQL logic error or missing database}}
154792c700dbSdrhdo_test pragma-19.2 {
154892c700dbSdrh  catchsql {PRAGMA error='This is the error message'}
154992c700dbSdrh} {1 {This is the error message}}
155092c700dbSdrhdo_test pragma-19.3 {
155192c700dbSdrh  catchsql {PRAGMA error='7 This is the error message'}
155292c700dbSdrh} {1 {This is the error message}}
155392c700dbSdrhdo_test pragma-19.4 {
155492c700dbSdrh  catchsql {PRAGMA error=7}
155592c700dbSdrh} {1 {out of memory}}
1556c8517f61Sdrhdo_test pragma-19.5 {
15575b044545Smistachkin  file tail [lindex [execsql {PRAGMA filename}] 0]
1558c8517f61Sdrh} {test.db}
155992c700dbSdrh
1560cc71645bSdrhif {$tcl_platform(platform)=="windows"} {
1561a112d140Smistachkin# Test data_store_directory pragma
1562a112d140Smistachkin#
1563a112d140Smistachkindb close
1564a112d140Smistachkinsqlite3 db test.db
1565a112d140Smistachkinfile mkdir data_dir
1566a112d140Smistachkindo_test pragma-20.1 {
1567a112d140Smistachkin  catchsql {PRAGMA data_store_directory}
1568a112d140Smistachkin} {0 {}}
1569a112d140Smistachkindo_test pragma-20.2 {
1570a112d140Smistachkin  set pwd [string map {' ''} [file nativename [get_pwd]]]
1571a112d140Smistachkin  catchsql "PRAGMA data_store_directory='$pwd';"
1572a112d140Smistachkin} {0 {}}
1573a112d140Smistachkindo_test pragma-20.3 {
1574a112d140Smistachkin  catchsql {PRAGMA data_store_directory}
1575a112d140Smistachkin} [list 0 [list [file nativename [get_pwd]]]]
1576a112d140Smistachkindo_test pragma-20.4 {
1577a112d140Smistachkin  set pwd [string map {' ''} [file nativename \
1578a112d140Smistachkin    [file join [get_pwd] data_dir]]]
1579a112d140Smistachkin  catchsql "PRAGMA data_store_directory='$pwd';"
1580a112d140Smistachkin} {0 {}}
1581a112d140Smistachkindo_test pragma-20.5 {
1582a112d140Smistachkin  sqlite3 db2 test2.db
1583a112d140Smistachkin  catchsql "PRAGMA database_list;" db2
1584a112d140Smistachkin} [list 0 [list 0 main [file nativename \
1585a112d140Smistachkin    [file join [get_pwd] data_dir test2.db]]]]
1586a112d140Smistachkincatch {db2 close}
1587a112d140Smistachkindo_test pragma-20.6 {
1588a112d140Smistachkin  sqlite3 db2 [file join [get_pwd] test2.db]
1589a112d140Smistachkin  catchsql "PRAGMA database_list;" db2
1590a112d140Smistachkin} [list 0 [list 0 main [file nativename \
1591a112d140Smistachkin    [file join [get_pwd] test2.db]]]]
1592a112d140Smistachkincatch {db2 close}
1593a112d140Smistachkindo_test pragma-20.7 {
1594a112d140Smistachkin  catchsql "PRAGMA data_store_directory='';"
1595a112d140Smistachkin} {0 {}}
1596a112d140Smistachkindo_test pragma-20.8 {
1597a112d140Smistachkin  catchsql {PRAGMA data_store_directory}
1598a112d140Smistachkin} {0 {}}
159992c700dbSdrh
1600a112d140Smistachkinforcedelete data_dir
1601cc71645bSdrh} ;# endif windows
1602cd61c281Sdrh
16031fed5dabSdandatabase_may_be_corrupt
16041fed5dabSdan
16055885e762Sdando_test 21.1 {
16065885e762Sdan  # Create a corrupt database in testerr.db. And a non-corrupt at test.db.
16075885e762Sdan  #
16085885e762Sdan  db close
16095885e762Sdan  forcedelete test.db
16105885e762Sdan  sqlite3 db test.db
16115885e762Sdan  execsql {
16125885e762Sdan    PRAGMA page_size = 1024;
16135885e762Sdan    PRAGMA auto_vacuum = 0;
16145885e762Sdan    CREATE TABLE t1(a PRIMARY KEY, b);
16155885e762Sdan    INSERT INTO t1 VALUES(1, 1);
16165885e762Sdan  }
16175885e762Sdan  for {set i 0} {$i < 10} {incr i} {
16185885e762Sdan    execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 }
16195885e762Sdan  }
16205885e762Sdan  db close
16215885e762Sdan  forcecopy test.db testerr.db
16225885e762Sdan  hexio_write testerr.db 15000 [string repeat 55 100]
16235885e762Sdan} {100}
16245885e762Sdan
16255885e762Sdanset mainerr {*** in database main ***
16265885e762SdanMultiple uses for byte 672 of page 15}
16275885e762Sdanset auxerr {*** in database aux ***
16285885e762SdanMultiple uses for byte 672 of page 15}
16295885e762Sdan
1630597515d7Sdanset mainerr {/{\*\*\* in database main \*\*\*
1631597515d7SdanMultiple uses for byte 672 of page 15}.*/}
1632597515d7Sdanset auxerr {/{\*\*\* in database aux \*\*\*
1633597515d7SdanMultiple uses for byte 672 of page 15}.*/}
1634597515d7Sdan
16355885e762Sdando_test 22.2 {
16365885e762Sdan  catch { db close }
16375885e762Sdan  sqlite3 db testerr.db
16385885e762Sdan  execsql { PRAGMA integrity_check }
1639597515d7Sdan} $mainerr
16405885e762Sdan
16415885e762Sdando_test 22.3.1 {
16425885e762Sdan  catch { db close }
16435885e762Sdan  sqlite3 db test.db
16445885e762Sdan  execsql {
16455885e762Sdan    ATTACH 'testerr.db' AS 'aux';
16465885e762Sdan    PRAGMA integrity_check;
16475885e762Sdan  }
1648597515d7Sdan} $auxerr
16495885e762Sdando_test 22.3.2 {
16505885e762Sdan  execsql { PRAGMA main.integrity_check; }
16515885e762Sdan} {ok}
16525885e762Sdando_test 22.3.3 {
16535885e762Sdan  execsql { PRAGMA aux.integrity_check; }
1654597515d7Sdan} $auxerr
16555885e762Sdan
16565885e762Sdando_test 22.4.1 {
16575885e762Sdan  catch { db close }
16585885e762Sdan  sqlite3 db testerr.db
16595885e762Sdan  execsql {
16605885e762Sdan    ATTACH 'test.db' AS 'aux';
16615885e762Sdan    PRAGMA integrity_check;
16625885e762Sdan  }
1663597515d7Sdan} $mainerr
16645885e762Sdando_test 22.4.2 {
16655885e762Sdan  execsql { PRAGMA main.integrity_check; }
1666597515d7Sdan} $mainerr
16675885e762Sdando_test 22.4.3 {
16685885e762Sdan  execsql { PRAGMA aux.integrity_check; }
16695885e762Sdan} {ok}
16705885e762Sdan
1671c95e01daSdrhdb close
1672c95e01daSdrhforcedelete test.db test.db-wal test.db-journal
1673c95e01daSdrhsqlite3 db test.db
1674c95e01daSdrhsqlite3 db2 test.db
1675c95e01daSdrhdo_test 23.1 {
1676c95e01daSdrh  db eval {
1677c95e01daSdrh    CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d);
1678c95e01daSdrh    CREATE INDEX i1 ON t1(b,c);
1679c95e01daSdrh    CREATE INDEX i2 ON t1(c,d);
1680c95e01daSdrh    CREATE TABLE t2(x INTEGER REFERENCES t1);
1681c95e01daSdrh  }
1682c95e01daSdrh  db2 eval {SELECT name FROM sqlite_master}
1683c95e01daSdrh} {t1 i1 i2 t2}
1684c95e01daSdrhdo_test 23.2 {
1685c95e01daSdrh  db eval {
1686c95e01daSdrh    DROP INDEX i2;
1687c95e01daSdrh    CREATE INDEX i2 ON t1(c,d,b);
1688c95e01daSdrh  }
1689c95e01daSdrh  db2 eval {PRAGMA index_info(i2)}
1690c95e01daSdrh} {0 2 c 1 3 d 2 1 b}
1691c95e01daSdrhdo_test 23.3 {
1692c95e01daSdrh  db eval {
1693c95e01daSdrh    CREATE INDEX i3 ON t1(d,b,c);
1694c95e01daSdrh  }
1695c95e01daSdrh  db2 eval {PRAGMA index_list(t1)}
16963ef26156Sdrh} {0 i3 0 1 i2 0 2 i1 0}
1697c95e01daSdrhdo_test 23.4 {
1698c95e01daSdrh  db eval {
1699c95e01daSdrh    ALTER TABLE t1 ADD COLUMN e;
1700c95e01daSdrh  }
1701c95e01daSdrh  db2 eval {
1702c95e01daSdrh    PRAGMA table_info(t1);
1703c95e01daSdrh  }
1704c95e01daSdrh} {/4 e {} 0 {} 0/}
1705c95e01daSdrhdo_test 23.5 {
1706c95e01daSdrh  db eval {
1707c95e01daSdrh    DROP TABLE t2;
1708c95e01daSdrh    CREATE TABLE t2(x, y INTEGER REFERENCES t1);
1709c95e01daSdrh  }
1710c95e01daSdrh  db2 eval {
1711c95e01daSdrh    PRAGMA foreign_key_list(t2);
1712c95e01daSdrh  }
1713c95e01daSdrh} {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE}
1714c95e01daSdrh
17151fed5dabSdandatabase_never_corrupt
1716cd61c281Sdrhfinish_test
1717