drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 1 | # 2002 March 6 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
| 9 | # |
| 10 | #*********************************************************************** |
| 11 | # This file implements regression tests for SQLite library. |
| 12 | # |
| 13 | # This file implements tests for the PRAGMA command. |
| 14 | # |
danielk1977 | 838cce4 | 2009-01-12 14:01:45 +0000 | [diff] [blame] | 15 | # $Id: pragma.test,v 1.73 2009/01/12 14:01:45 danielk1977 Exp $ |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 19 | set testprefix pragma |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 20 | |
dan | 68928b6 | 2010-06-22 13:46:43 +0000 | [diff] [blame] | 21 | # Do not use a codec for tests in this file, as the database file is |
| 22 | # manipulated directly using tcl scripts (using the [hexio_write] command). |
| 23 | # |
| 24 | do_not_use_codec |
| 25 | |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 26 | # Test organization: |
| 27 | # |
| 28 | # pragma-1.*: Test cache_size, default_cache_size and synchronous on main db. |
| 29 | # pragma-2.*: Test synchronous on attached db. |
| 30 | # pragma-3.*: Test detection of table/index inconsistency by integrity_check. |
| 31 | # pragma-4.*: Test cache_size and default_cache_size on attached db. |
| 32 | # pragma-5.*: Test that pragma synchronous may not be used inside of a |
| 33 | # transaction. |
danielk1977 | cc6bd38 | 2005-01-10 02:48:49 +0000 | [diff] [blame] | 34 | # pragma-6.*: Test schema-query pragmas. |
| 35 | # pragma-7.*: Miscellaneous tests. |
| 36 | # pragma-8.*: Test user_version and schema_version pragmas. |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 37 | # pragma-9.*: Test temp_store and temp_store_directory. |
danielk1977 | cc6bd38 | 2005-01-10 02:48:49 +0000 | [diff] [blame] | 38 | # pragma-10.*: Test the count_changes pragma in the presence of triggers. |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 39 | # pragma-11.*: Test the collation_list pragma. |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 40 | # pragma-14.*: Test the page_count pragma. |
danielk1977 | 8cf6c55 | 2008-06-23 16:53:46 +0000 | [diff] [blame] | 41 | # pragma-15.*: Test that the value set using the cache_size pragma is not |
| 42 | # reset when the schema is reloaded. |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 43 | # pragma-16.*: Test proxy locking |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 44 | # pragma-20.*: Test data_store_directory. |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 45 | # pragma-22.*: Test that "PRAGMA [db].integrity_check" respects the "db" |
| 46 | # directive - if it is present. |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 47 | # |
| 48 | |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 49 | ifcapable !pragma { |
| 50 | finish_test |
| 51 | return |
| 52 | } |
| 53 | |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 54 | # Delete the preexisting database to avoid the special setup |
| 55 | # that the "all.test" script does. |
| 56 | # |
| 57 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 58 | delete_file test.db test.db-journal |
| 59 | delete_file test3.db test3.db-journal |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 60 | sqlite3 db test.db; set DB [sqlite3_connection_pointer db] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 61 | |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 62 | |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 63 | ifcapable pager_pragmas { |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 64 | set DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}] |
| 65 | set TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 66 | do_test pragma-1.1 { |
| 67 | execsql { |
| 68 | PRAGMA cache_size; |
| 69 | PRAGMA default_cache_size; |
| 70 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 71 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 72 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 73 | do_test pragma-1.2 { |
| 74 | execsql { |
drh | eb43e5c | 2005-05-22 20:30:39 +0000 | [diff] [blame] | 75 | PRAGMA synchronous=OFF; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 76 | PRAGMA cache_size=1234; |
| 77 | PRAGMA cache_size; |
| 78 | PRAGMA default_cache_size; |
| 79 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 80 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 81 | } [list 1234 $DFLT_CACHE_SZ 0] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 82 | do_test pragma-1.3 { |
| 83 | db close |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 84 | sqlite3 db test.db |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 85 | execsql { |
| 86 | PRAGMA cache_size; |
| 87 | PRAGMA default_cache_size; |
| 88 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 89 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 90 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 91 | do_test pragma-1.4 { |
| 92 | execsql { |
| 93 | PRAGMA synchronous=OFF; |
| 94 | PRAGMA cache_size; |
| 95 | PRAGMA default_cache_size; |
| 96 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 97 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 98 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 99 | do_test pragma-1.5 { |
| 100 | execsql { |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 101 | PRAGMA cache_size=-4321; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 102 | PRAGMA cache_size; |
| 103 | PRAGMA default_cache_size; |
| 104 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 105 | } |
drh | 3b42abb | 2011-11-09 14:23:04 +0000 | [diff] [blame] | 106 | } [list -4321 $DFLT_CACHE_SZ 0] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 107 | do_test pragma-1.6 { |
| 108 | execsql { |
| 109 | PRAGMA synchronous=ON; |
| 110 | PRAGMA cache_size; |
| 111 | PRAGMA default_cache_size; |
| 112 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 113 | } |
drh | 3b42abb | 2011-11-09 14:23:04 +0000 | [diff] [blame] | 114 | } [list -4321 $DFLT_CACHE_SZ 1] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 115 | do_test pragma-1.7 { |
| 116 | db close |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 117 | sqlite3 db test.db |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 118 | execsql { |
| 119 | PRAGMA cache_size; |
| 120 | PRAGMA default_cache_size; |
| 121 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 122 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 123 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 124 | do_test pragma-1.8 { |
| 125 | execsql { |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 126 | PRAGMA default_cache_size=-123; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 127 | PRAGMA cache_size; |
| 128 | PRAGMA default_cache_size; |
| 129 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 130 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 131 | } {123 123 2} |
drh | 802d69a | 2005-02-13 23:34:24 +0000 | [diff] [blame] | 132 | do_test pragma-1.9.1 { |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 133 | db close |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 134 | sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 135 | execsql { |
| 136 | PRAGMA cache_size; |
| 137 | PRAGMA default_cache_size; |
| 138 | PRAGMA synchronous; |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 139 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 140 | } {123 123 2} |
drh | 802d69a | 2005-02-13 23:34:24 +0000 | [diff] [blame] | 141 | ifcapable vacuum { |
| 142 | do_test pragma-1.9.2 { |
| 143 | execsql { |
| 144 | VACUUM; |
| 145 | PRAGMA cache_size; |
| 146 | PRAGMA default_cache_size; |
| 147 | PRAGMA synchronous; |
| 148 | } |
| 149 | } {123 123 2} |
| 150 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 151 | do_test pragma-1.10 { |
drh | 5a38705 | 2003-01-11 14:19:51 +0000 | [diff] [blame] | 152 | execsql { |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 153 | PRAGMA synchronous=NORMAL; |
| 154 | PRAGMA cache_size; |
| 155 | PRAGMA default_cache_size; |
| 156 | PRAGMA synchronous; |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 157 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 158 | } {123 123 1} |
| 159 | do_test pragma-1.11 { |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 160 | execsql { |
| 161 | PRAGMA synchronous=FULL; |
| 162 | PRAGMA cache_size; |
| 163 | PRAGMA default_cache_size; |
| 164 | PRAGMA synchronous; |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 165 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 166 | } {123 123 2} |
| 167 | do_test pragma-1.12 { |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 168 | db close |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 169 | sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 170 | execsql { |
| 171 | PRAGMA cache_size; |
| 172 | PRAGMA default_cache_size; |
| 173 | PRAGMA synchronous; |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 174 | } |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 175 | } {123 123 2} |
| 176 | |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 177 | # Make sure the pragma handler understands numeric values in addition |
| 178 | # to keywords like "off" and "full". |
| 179 | # |
| 180 | do_test pragma-1.13 { |
| 181 | execsql { |
| 182 | PRAGMA synchronous=0; |
| 183 | PRAGMA synchronous; |
| 184 | } |
| 185 | } {0} |
| 186 | do_test pragma-1.14 { |
| 187 | execsql { |
| 188 | PRAGMA synchronous=2; |
| 189 | PRAGMA synchronous; |
| 190 | } |
| 191 | } {2} |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 192 | } ;# ifcapable pager_pragmas |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 193 | |
| 194 | # Test turning "flag" pragmas on and off. |
| 195 | # |
danielk1977 | 6338c76 | 2007-05-17 16:38:30 +0000 | [diff] [blame] | 196 | ifcapable debug { |
| 197 | # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG |
| 198 | # |
| 199 | do_test pragma-1.15 { |
| 200 | execsql { |
| 201 | PRAGMA vdbe_listing=YES; |
| 202 | PRAGMA vdbe_listing; |
| 203 | } |
| 204 | } {1} |
| 205 | do_test pragma-1.16 { |
| 206 | execsql { |
| 207 | PRAGMA vdbe_listing=NO; |
| 208 | PRAGMA vdbe_listing; |
| 209 | } |
| 210 | } {0} |
| 211 | } |
| 212 | |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 213 | do_test pragma-1.17 { |
| 214 | execsql { |
| 215 | PRAGMA parser_trace=ON; |
| 216 | PRAGMA parser_trace=OFF; |
| 217 | } |
| 218 | } {} |
| 219 | do_test pragma-1.18 { |
| 220 | execsql { |
| 221 | PRAGMA bogus = -1234; -- Parsing of negative values |
| 222 | } |
| 223 | } {} |
| 224 | |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 225 | # Test modifying the safety_level of an attached database. |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 226 | ifcapable pager_pragmas&&attach { |
| 227 | do_test pragma-2.1 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 228 | forcedelete test2.db |
| 229 | forcedelete test2.db-journal |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 230 | execsql { |
| 231 | ATTACH 'test2.db' AS aux; |
| 232 | } |
| 233 | } {} |
| 234 | do_test pragma-2.2 { |
| 235 | execsql { |
| 236 | pragma aux.synchronous; |
| 237 | } |
| 238 | } {2} |
| 239 | do_test pragma-2.3 { |
| 240 | execsql { |
| 241 | pragma aux.synchronous = OFF; |
| 242 | pragma aux.synchronous; |
| 243 | pragma synchronous; |
| 244 | } |
| 245 | } {0 2} |
| 246 | do_test pragma-2.4 { |
| 247 | execsql { |
| 248 | pragma aux.synchronous = ON; |
| 249 | pragma synchronous; |
| 250 | pragma aux.synchronous; |
| 251 | } |
| 252 | } {2 1} |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 253 | } ;# ifcapable pager_pragmas |
drh | 4303fee | 2003-02-15 23:09:17 +0000 | [diff] [blame] | 254 | |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 255 | # Construct a corrupted index and make sure the integrity_check |
| 256 | # pragma finds it. |
| 257 | # |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 258 | # These tests won't work if the database is encrypted |
| 259 | # |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 260 | do_test pragma-3.1 { |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 261 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 262 | forcedelete test.db test.db-journal |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 263 | sqlite3 db test.db |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 264 | execsql { |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 265 | PRAGMA auto_vacuum=OFF; |
drh | ed717fe | 2003-06-15 23:42:24 +0000 | [diff] [blame] | 266 | BEGIN; |
| 267 | CREATE TABLE t2(a,b,c); |
| 268 | CREATE INDEX i2 ON t2(a); |
| 269 | INSERT INTO t2 VALUES(11,2,3); |
| 270 | INSERT INTO t2 VALUES(22,3,4); |
| 271 | COMMIT; |
| 272 | SELECT rowid, * from t2; |
| 273 | } |
| 274 | } {1 11 2 3 2 22 3 4} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 275 | ifcapable attach { |
| 276 | if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { |
| 277 | do_test pragma-3.2 { |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 278 | db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break |
| 279 | set pgsz [db eval {PRAGMA page_size}] |
| 280 | # overwrite the header on the rootpage of the index in order to |
| 281 | # make the index appear to be empty. |
| 282 | # |
| 283 | set offset [expr {$pgsz*($rootpage-1)}] |
| 284 | hexio_write test.db $offset 0a00000000040000000000 |
| 285 | db close |
| 286 | sqlite3 db test.db |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 287 | execsql {PRAGMA integrity_check} |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 288 | } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 289 | do_test pragma-3.3 { |
| 290 | execsql {PRAGMA integrity_check=1} |
| 291 | } {{rowid 1 missing from index i2}} |
| 292 | do_test pragma-3.4 { |
| 293 | execsql { |
| 294 | ATTACH DATABASE 'test.db' AS t2; |
| 295 | PRAGMA integrity_check |
| 296 | } |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 297 | } {{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}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 298 | do_test pragma-3.5 { |
| 299 | execsql { |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 300 | PRAGMA integrity_check=4 |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 301 | } |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 302 | } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 303 | do_test pragma-3.6 { |
| 304 | execsql { |
| 305 | PRAGMA integrity_check=xyz |
| 306 | } |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 307 | } {{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}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 308 | do_test pragma-3.7 { |
| 309 | execsql { |
| 310 | PRAGMA integrity_check=0 |
| 311 | } |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 312 | } {{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}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 313 | |
| 314 | # Add additional corruption by appending unused pages to the end of |
| 315 | # the database file testerr.db |
| 316 | # |
| 317 | do_test pragma-3.8 { |
| 318 | execsql {DETACH t2} |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 319 | forcedelete testerr.db testerr.db-journal |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 320 | set out [open testerr.db w] |
| 321 | fconfigure $out -translation binary |
| 322 | set in [open test.db r] |
| 323 | fconfigure $in -translation binary |
| 324 | puts -nonewline $out [read $in] |
| 325 | seek $in 0 |
| 326 | puts -nonewline $out [read $in] |
| 327 | close $in |
| 328 | close $out |
drh | dd3cd97 | 2010-03-27 17:12:36 +0000 | [diff] [blame] | 329 | hexio_write testerr.db 28 00000000 |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 330 | execsql {REINDEX t2} |
| 331 | execsql {PRAGMA integrity_check} |
| 332 | } {ok} |
danielk1977 | 41c58b7 | 2007-12-29 13:39:19 +0000 | [diff] [blame] | 333 | do_test pragma-3.8.1 { |
| 334 | execsql {PRAGMA quick_check} |
| 335 | } {ok} |
drh | 5d16a9a | 2011-10-13 14:41:22 +0000 | [diff] [blame] | 336 | do_test pragma-3.8.2 { |
| 337 | execsql {PRAGMA QUICK_CHECK} |
| 338 | } {ok} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 339 | do_test pragma-3.9 { |
| 340 | execsql { |
| 341 | ATTACH 'testerr.db' AS t2; |
| 342 | PRAGMA integrity_check |
| 343 | } |
| 344 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 345 | Page 4 is never used |
| 346 | Page 5 is never used |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 347 | Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 348 | do_test pragma-3.10 { |
| 349 | execsql { |
| 350 | PRAGMA integrity_check=1 |
| 351 | } |
| 352 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 353 | Page 4 is never used}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 354 | do_test pragma-3.11 { |
| 355 | execsql { |
| 356 | PRAGMA integrity_check=5 |
| 357 | } |
| 358 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 359 | Page 4 is never used |
| 360 | Page 5 is never used |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 361 | Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 362 | do_test pragma-3.12 { |
| 363 | execsql { |
| 364 | PRAGMA integrity_check=4 |
| 365 | } |
| 366 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 367 | Page 4 is never used |
| 368 | Page 5 is never used |
| 369 | Page 6 is never used} {rowid 1 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 370 | do_test pragma-3.13 { |
| 371 | execsql { |
| 372 | PRAGMA integrity_check=3 |
| 373 | } |
| 374 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 375 | Page 4 is never used |
| 376 | Page 5 is never used |
| 377 | Page 6 is never used}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 378 | do_test pragma-3.14 { |
| 379 | execsql { |
| 380 | PRAGMA integrity_check(2) |
| 381 | } |
| 382 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 383 | Page 4 is never used |
| 384 | Page 5 is never used}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 385 | do_test pragma-3.15 { |
| 386 | execsql { |
| 387 | ATTACH 'testerr.db' AS t3; |
| 388 | PRAGMA integrity_check |
| 389 | } |
| 390 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 391 | Page 4 is never used |
| 392 | Page 5 is never used |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 393 | Page 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 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 394 | Page 4 is never used |
| 395 | Page 5 is never used |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 396 | Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 397 | do_test pragma-3.16 { |
| 398 | execsql { |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 399 | PRAGMA integrity_check(10) |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 400 | } |
| 401 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 402 | Page 4 is never used |
| 403 | Page 5 is never used |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 404 | Page 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 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 405 | Page 4 is never used |
| 406 | Page 5 is never used |
| 407 | Page 6 is never used} {rowid 1 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 408 | do_test pragma-3.17 { |
| 409 | execsql { |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 410 | PRAGMA integrity_check=8 |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 411 | } |
| 412 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 413 | Page 4 is never used |
| 414 | Page 5 is never used |
drh | bb8a279 | 2008-03-19 00:21:30 +0000 | [diff] [blame] | 415 | Page 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 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 416 | Page 4 is never used |
| 417 | Page 5 is never used}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 418 | do_test pragma-3.18 { |
| 419 | execsql { |
| 420 | PRAGMA integrity_check=4 |
| 421 | } |
| 422 | } {{*** in database t2 *** |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 423 | Page 4 is never used |
| 424 | Page 5 is never used |
| 425 | Page 6 is never used} {rowid 1 missing from index i2}} |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 426 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 427 | do_test pragma-3.19 { |
| 428 | catch {db close} |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 429 | forcedelete test.db test.db-journal |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 430 | sqlite3 db test.db |
| 431 | db eval {PRAGMA integrity_check} |
| 432 | } {ok} |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 433 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 434 | #exit |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 435 | |
| 436 | # Test modifying the cache_size of an attached database. |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 437 | ifcapable pager_pragmas&&attach { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 438 | do_test pragma-4.1 { |
| 439 | execsql { |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 440 | ATTACH 'test2.db' AS aux; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 441 | pragma aux.cache_size; |
| 442 | pragma aux.default_cache_size; |
| 443 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 444 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 445 | do_test pragma-4.2 { |
| 446 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 447 | pragma aux.cache_size = 50; |
| 448 | pragma aux.cache_size; |
| 449 | pragma aux.default_cache_size; |
| 450 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 451 | } [list 50 $DFLT_CACHE_SZ] |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 452 | do_test pragma-4.3 { |
| 453 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 454 | pragma aux.default_cache_size = 456; |
| 455 | pragma aux.cache_size; |
| 456 | pragma aux.default_cache_size; |
| 457 | } |
| 458 | } {456 456} |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 459 | do_test pragma-4.4 { |
| 460 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 461 | pragma cache_size; |
| 462 | pragma default_cache_size; |
| 463 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 464 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 465 | do_test pragma-4.5 { |
| 466 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 467 | DETACH aux; |
| 468 | ATTACH 'test3.db' AS aux; |
| 469 | pragma aux.cache_size; |
| 470 | pragma aux.default_cache_size; |
| 471 | } |
drh | 1e9daa6 | 2007-04-06 21:42:22 +0000 | [diff] [blame] | 472 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 473 | do_test pragma-4.6 { |
| 474 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 475 | DETACH aux; |
| 476 | ATTACH 'test2.db' AS aux; |
| 477 | pragma aux.cache_size; |
| 478 | pragma aux.default_cache_size; |
| 479 | } |
| 480 | } {456 456} |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 481 | } ;# ifcapable pager_pragmas |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 482 | |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 483 | # Test that modifying the sync-level in the middle of a transaction is |
| 484 | # disallowed. |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 485 | ifcapable pager_pragmas { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 486 | do_test pragma-5.0 { |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 487 | execsql { |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 488 | pragma synchronous; |
| 489 | } |
| 490 | } {2} |
| 491 | do_test pragma-5.1 { |
drh | 1bdd9b5 | 2004-04-23 17:04:44 +0000 | [diff] [blame] | 492 | catchsql { |
| 493 | BEGIN; |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 494 | pragma synchronous = OFF; |
| 495 | } |
| 496 | } {1 {Safety level may not be changed inside a transaction}} |
| 497 | do_test pragma-5.2 { |
| 498 | execsql { |
| 499 | pragma synchronous; |
| 500 | } |
| 501 | } {2} |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 502 | catchsql {COMMIT;} |
danielk1977 | c7b4a44 | 2004-11-23 10:52:51 +0000 | [diff] [blame] | 503 | } ;# ifcapable pager_pragmas |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 504 | |
| 505 | # Test schema-query pragmas |
| 506 | # |
danielk1977 | 27188fb | 2004-11-23 10:13:03 +0000 | [diff] [blame] | 507 | ifcapable schema_pragmas { |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 508 | ifcapable tempdb&&attach { |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 509 | do_test pragma-6.1 { |
| 510 | set res {} |
| 511 | execsql {SELECT * FROM sqlite_temp_master} |
| 512 | foreach {idx name file} [execsql {pragma database_list}] { |
| 513 | lappend res $idx $name |
| 514 | } |
| 515 | set res |
| 516 | } {0 main 1 temp 2 aux} |
| 517 | } |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 518 | do_test pragma-6.2 { |
| 519 | execsql { |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 520 | CREATE TABLE t2(a,b,c); |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 521 | pragma table_info(t2) |
| 522 | } |
drh | bfa8b10 | 2006-03-03 21:20:16 +0000 | [diff] [blame] | 523 | } {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0} |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 524 | do_test pragma-6.2.1 { |
| 525 | execsql { |
| 526 | pragma table_info; |
| 527 | } |
| 528 | } {} |
drh | 736c7d4 | 2006-11-30 13:06:37 +0000 | [diff] [blame] | 529 | db nullvalue <<NULL>> |
drh | 417ec63 | 2006-08-14 14:23:41 +0000 | [diff] [blame] | 530 | do_test pragma-6.2.2 { |
| 531 | execsql { |
drh | 736c7d4 | 2006-11-30 13:06:37 +0000 | [diff] [blame] | 532 | CREATE TABLE t5( |
| 533 | a TEXT DEFAULT CURRENT_TIMESTAMP, |
| 534 | b DEFAULT (5+3), |
| 535 | c TEXT, |
| 536 | d INTEGER DEFAULT NULL, |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 537 | e TEXT DEFAULT '', |
| 538 | UNIQUE(b,c,d), |
| 539 | PRIMARY KEY(e,b,c) |
drh | 736c7d4 | 2006-11-30 13:06:37 +0000 | [diff] [blame] | 540 | ); |
drh | 417ec63 | 2006-08-14 14:23:41 +0000 | [diff] [blame] | 541 | PRAGMA table_info(t5); |
| 542 | } |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 543 | } {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} |
drh | 736c7d4 | 2006-11-30 13:06:37 +0000 | [diff] [blame] | 544 | db nullvalue {} |
drh | 384b7fe | 2013-01-01 13:55:31 +0000 | [diff] [blame] | 545 | do_test pragma-6.2.3 { |
| 546 | execsql { |
| 547 | CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c); |
| 548 | pragma table_info(t2_3) |
| 549 | } |
| 550 | } {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0} |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 551 | ifcapable {foreignkey} { |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 552 | do_test pragma-6.3.1 { |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 553 | execsql { |
| 554 | CREATE TABLE t3(a int references t2(b), b UNIQUE); |
| 555 | pragma foreign_key_list(t3); |
| 556 | } |
dan | 1da40a3 | 2009-09-19 17:00:31 +0000 | [diff] [blame] | 557 | } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE} |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 558 | do_test pragma-6.3.2 { |
| 559 | execsql { |
| 560 | pragma foreign_key_list; |
| 561 | } |
| 562 | } {} |
| 563 | do_test pragma-6.3.3 { |
| 564 | execsql { |
| 565 | pragma foreign_key_list(t3_bogus); |
| 566 | } |
| 567 | } {} |
| 568 | do_test pragma-6.3.4 { |
| 569 | execsql { |
| 570 | pragma foreign_key_list(t5); |
| 571 | } |
| 572 | } {} |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 573 | do_test pragma-6.4 { |
| 574 | execsql { |
| 575 | pragma index_list(t3); |
| 576 | } |
| 577 | } {0 sqlite_autoindex_t3_1 1} |
| 578 | } |
| 579 | ifcapable {!foreignkey} { |
| 580 | execsql {CREATE TABLE t3(a,b UNIQUE)} |
| 581 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 582 | do_test pragma-6.5.1 { |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 583 | execsql { |
| 584 | CREATE INDEX t3i1 ON t3(a,b); |
| 585 | pragma index_info(t3i1); |
| 586 | } |
| 587 | } {0 0 a 1 1 b} |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 588 | do_test pragma-6.5.2 { |
| 589 | execsql { |
| 590 | pragma index_info(t3i1_bogus); |
| 591 | } |
| 592 | } {} |
danielk1977 | 260d8a6 | 2008-08-20 16:34:24 +0000 | [diff] [blame] | 593 | |
| 594 | ifcapable tempdb { |
| 595 | # Test for ticket #3320. When a temp table of the same name exists, make |
| 596 | # sure the schema of the main table can still be queried using |
| 597 | # "pragma table_info": |
| 598 | do_test pragma-6.6.1 { |
| 599 | execsql { |
| 600 | CREATE TABLE trial(col_main); |
| 601 | CREATE TEMP TABLE trial(col_temp); |
| 602 | } |
| 603 | } {} |
| 604 | do_test pragma-6.6.2 { |
| 605 | execsql { |
| 606 | PRAGMA table_info(trial); |
| 607 | } |
| 608 | } {0 col_temp {} 0 {} 0} |
| 609 | do_test pragma-6.6.3 { |
| 610 | execsql { |
| 611 | PRAGMA temp.table_info(trial); |
| 612 | } |
| 613 | } {0 col_temp {} 0 {} 0} |
| 614 | do_test pragma-6.6.4 { |
| 615 | execsql { |
| 616 | PRAGMA main.table_info(trial); |
| 617 | } |
| 618 | } {0 col_main {} 0 {} 0} |
| 619 | } |
danielk1977 | f96a377 | 2008-10-23 05:45:07 +0000 | [diff] [blame] | 620 | |
danielk1977 | f96a377 | 2008-10-23 05:45:07 +0000 | [diff] [blame] | 621 | do_test pragma-6.7 { |
| 622 | execsql { |
| 623 | CREATE TABLE test_table( |
| 624 | one INT NOT NULL DEFAULT -1, |
| 625 | two text, |
| 626 | three VARCHAR(45, 65) DEFAULT 'abcde', |
| 627 | four REAL DEFAULT X'abcdef', |
| 628 | five DEFAULT CURRENT_TIME |
| 629 | ); |
| 630 | PRAGMA table_info(test_table); |
| 631 | } |
| 632 | } [concat \ |
| 633 | {0 one INT 1 -1 0} \ |
| 634 | {1 two text 0 {} 0} \ |
| 635 | {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \ |
| 636 | {3 four REAL 0 X'abcdef' 0} \ |
| 637 | {4 five {} 0 CURRENT_TIME 0} \ |
| 638 | ] |
danielk1977 | 27188fb | 2004-11-23 10:13:03 +0000 | [diff] [blame] | 639 | } ;# ifcapable schema_pragmas |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 640 | # Miscellaneous tests |
| 641 | # |
danielk1977 | 27188fb | 2004-11-23 10:13:03 +0000 | [diff] [blame] | 642 | ifcapable schema_pragmas { |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 643 | do_test pragma-7.1.1 { |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 644 | # Make sure a pragma knows to read the schema if it needs to |
| 645 | db close |
| 646 | sqlite3 db test.db |
| 647 | execsql { |
| 648 | pragma index_list(t3); |
| 649 | } |
| 650 | } {0 t3i1 0 1 sqlite_autoindex_t3_1 1} |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 651 | do_test pragma-7.1.2 { |
| 652 | execsql { |
| 653 | pragma index_list(t3_bogus); |
| 654 | } |
| 655 | } {} |
danielk1977 | 27188fb | 2004-11-23 10:13:03 +0000 | [diff] [blame] | 656 | } ;# ifcapable schema_pragmas |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 657 | ifcapable {utf16} { |
dan | cb35460 | 2010-07-08 09:44:42 +0000 | [diff] [blame] | 658 | if {[permutation] == ""} { |
| 659 | do_test pragma-7.2 { |
| 660 | db close |
| 661 | sqlite3 db test.db |
| 662 | catchsql { |
| 663 | pragma encoding=bogus; |
| 664 | } |
| 665 | } {1 {unsupported encoding: bogus}} |
| 666 | } |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 667 | } |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 668 | ifcapable tempdb { |
| 669 | do_test pragma-7.3 { |
| 670 | db close |
| 671 | sqlite3 db test.db |
| 672 | execsql { |
| 673 | pragma lock_status; |
| 674 | } |
| 675 | } {main unlocked temp closed} |
| 676 | } else { |
| 677 | do_test pragma-7.3 { |
| 678 | db close |
| 679 | sqlite3 db test.db |
| 680 | execsql { |
| 681 | pragma lock_status; |
| 682 | } |
| 683 | } {main unlocked} |
| 684 | } |
drh | 5260f7e | 2004-06-26 19:35:29 +0000 | [diff] [blame] | 685 | |
| 686 | |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 687 | #---------------------------------------------------------------------- |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 688 | # Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA |
| 689 | # user_version" statements. |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 690 | # |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 691 | # pragma-8.1: PRAGMA schema_version |
| 692 | # pragma-8.2: PRAGMA user_version |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 693 | # |
| 694 | |
danielk1977 | 11cf9fb | 2004-11-23 11:16:42 +0000 | [diff] [blame] | 695 | ifcapable schema_version { |
| 696 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 697 | # First check that we can set the schema version and then retrieve the |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 698 | # same value. |
| 699 | do_test pragma-8.1.1 { |
| 700 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 701 | PRAGMA schema_version = 105; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 702 | } |
| 703 | } {} |
| 704 | do_test pragma-8.1.2 { |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 705 | execsql2 { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 706 | PRAGMA schema_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 707 | } |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 708 | } {schema_version 105} |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 709 | do_test pragma-8.1.3 { |
| 710 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 711 | PRAGMA schema_version = 106; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 712 | } |
| 713 | } {} |
| 714 | do_test pragma-8.1.4 { |
| 715 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 716 | PRAGMA schema_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 717 | } |
| 718 | } 106 |
| 719 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 720 | # Check that creating a table modifies the schema-version (this is really |
| 721 | # to verify that the value being read is in fact the schema version). |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 722 | do_test pragma-8.1.5 { |
| 723 | execsql { |
| 724 | CREATE TABLE t4(a, b, c); |
| 725 | INSERT INTO t4 VALUES(1, 2, 3); |
| 726 | SELECT * FROM t4; |
| 727 | } |
| 728 | } {1 2 3} |
| 729 | do_test pragma-8.1.6 { |
| 730 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 731 | PRAGMA schema_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 732 | } |
| 733 | } 107 |
| 734 | |
| 735 | # Now open a second connection to the database. Ensure that changing the |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 736 | # schema-version using the first connection forces the second connection |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 737 | # to reload the schema. This has to be done using the C-API test functions, |
| 738 | # because the TCL API accounts for SCHEMA_ERROR and retries the query. |
| 739 | do_test pragma-8.1.7 { |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 740 | sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 741 | execsql { |
| 742 | SELECT * FROM t4; |
| 743 | } db2 |
| 744 | } {1 2 3} |
| 745 | do_test pragma-8.1.8 { |
| 746 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 747 | PRAGMA schema_version = 108; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 748 | } |
| 749 | } {} |
| 750 | do_test pragma-8.1.9 { |
| 751 | set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] |
| 752 | sqlite3_step $::STMT |
| 753 | } SQLITE_ERROR |
| 754 | do_test pragma-8.1.10 { |
| 755 | sqlite3_finalize $::STMT |
| 756 | } SQLITE_SCHEMA |
| 757 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 758 | # Make sure the schema-version can be manipulated in an attached database. |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 759 | forcedelete test2.db |
| 760 | forcedelete test2.db-journal |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 761 | ifcapable attach { |
| 762 | do_test pragma-8.1.11 { |
| 763 | execsql { |
| 764 | ATTACH 'test2.db' AS aux; |
| 765 | CREATE TABLE aux.t1(a, b, c); |
| 766 | PRAGMA aux.schema_version = 205; |
| 767 | } |
| 768 | } {} |
| 769 | do_test pragma-8.1.12 { |
| 770 | execsql { |
| 771 | PRAGMA aux.schema_version; |
| 772 | } |
| 773 | } 205 |
| 774 | } |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 775 | do_test pragma-8.1.13 { |
| 776 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 777 | PRAGMA schema_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 778 | } |
| 779 | } 108 |
| 780 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 781 | # And check that modifying the schema-version in an attached database |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 782 | # forces the second connection to reload the schema. |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 783 | ifcapable attach { |
| 784 | do_test pragma-8.1.14 { |
| 785 | sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] |
| 786 | execsql { |
| 787 | ATTACH 'test2.db' AS aux; |
| 788 | SELECT * FROM aux.t1; |
| 789 | } db2 |
| 790 | } {} |
| 791 | do_test pragma-8.1.15 { |
| 792 | execsql { |
| 793 | PRAGMA aux.schema_version = 206; |
| 794 | } |
| 795 | } {} |
| 796 | do_test pragma-8.1.16 { |
| 797 | set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] |
| 798 | sqlite3_step $::STMT |
| 799 | } SQLITE_ERROR |
| 800 | do_test pragma-8.1.17 { |
| 801 | sqlite3_finalize $::STMT |
| 802 | } SQLITE_SCHEMA |
| 803 | do_test pragma-8.1.18 { |
| 804 | db2 close |
| 805 | } {} |
| 806 | } |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 807 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 808 | # Now test that the user-version can be read and written (and that we aren't |
| 809 | # accidentally manipulating the schema-version instead). |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 810 | do_test pragma-8.2.1 { |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 811 | execsql2 { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 812 | PRAGMA user_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 813 | } |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 814 | } {user_version 0} |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 815 | do_test pragma-8.2.2 { |
| 816 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 817 | PRAGMA user_version = 2; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 818 | } |
| 819 | } {} |
drh | 802d69a | 2005-02-13 23:34:24 +0000 | [diff] [blame] | 820 | do_test pragma-8.2.3.1 { |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 821 | execsql2 { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 822 | PRAGMA user_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 823 | } |
drh | 2540365 | 2007-01-04 22:13:41 +0000 | [diff] [blame] | 824 | } {user_version 2} |
drh | 802d69a | 2005-02-13 23:34:24 +0000 | [diff] [blame] | 825 | do_test pragma-8.2.3.2 { |
| 826 | db close |
| 827 | sqlite3 db test.db |
| 828 | execsql { |
| 829 | PRAGMA user_version; |
| 830 | } |
| 831 | } {2} |
| 832 | do_test pragma-8.2.4.1 { |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 833 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 834 | PRAGMA schema_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 835 | } |
| 836 | } {108} |
drh | 802d69a | 2005-02-13 23:34:24 +0000 | [diff] [blame] | 837 | ifcapable vacuum { |
| 838 | do_test pragma-8.2.4.2 { |
| 839 | execsql { |
| 840 | VACUUM; |
| 841 | PRAGMA user_version; |
| 842 | } |
| 843 | } {2} |
| 844 | do_test pragma-8.2.4.3 { |
| 845 | execsql { |
| 846 | PRAGMA schema_version; |
| 847 | } |
| 848 | } {109} |
| 849 | } |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 850 | |
danielk1977 | 5a8f937 | 2007-10-09 08:29:32 +0000 | [diff] [blame] | 851 | ifcapable attach { |
| 852 | db eval {ATTACH 'test2.db' AS aux} |
| 853 | |
| 854 | # Check that the user-version in the auxilary database can be manipulated ( |
| 855 | # and that we aren't accidentally manipulating the same in the main db). |
| 856 | do_test pragma-8.2.5 { |
| 857 | execsql { |
| 858 | PRAGMA aux.user_version; |
| 859 | } |
| 860 | } {0} |
| 861 | do_test pragma-8.2.6 { |
| 862 | execsql { |
| 863 | PRAGMA aux.user_version = 3; |
| 864 | } |
| 865 | } {} |
| 866 | do_test pragma-8.2.7 { |
| 867 | execsql { |
| 868 | PRAGMA aux.user_version; |
| 869 | } |
| 870 | } {3} |
| 871 | do_test pragma-8.2.8 { |
| 872 | execsql { |
| 873 | PRAGMA main.user_version; |
| 874 | } |
| 875 | } {2} |
| 876 | |
| 877 | # Now check that a ROLLBACK resets the user-version if it has been modified |
| 878 | # within a transaction. |
| 879 | do_test pragma-8.2.9 { |
| 880 | execsql { |
| 881 | BEGIN; |
| 882 | PRAGMA aux.user_version = 10; |
| 883 | PRAGMA user_version = 11; |
| 884 | } |
| 885 | } {} |
| 886 | do_test pragma-8.2.10 { |
| 887 | execsql { |
| 888 | PRAGMA aux.user_version; |
| 889 | } |
| 890 | } {10} |
| 891 | do_test pragma-8.2.11 { |
| 892 | execsql { |
| 893 | PRAGMA main.user_version; |
| 894 | } |
| 895 | } {11} |
| 896 | do_test pragma-8.2.12 { |
| 897 | execsql { |
| 898 | ROLLBACK; |
| 899 | PRAGMA aux.user_version; |
| 900 | } |
| 901 | } {3} |
| 902 | do_test pragma-8.2.13 { |
| 903 | execsql { |
| 904 | PRAGMA main.user_version; |
| 905 | } |
| 906 | } {2} |
| 907 | } |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 908 | |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 909 | # Try a negative value for the user-version |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 910 | do_test pragma-8.2.14 { |
| 911 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 912 | PRAGMA user_version = -450; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 913 | } |
| 914 | } {} |
| 915 | do_test pragma-8.2.15 { |
| 916 | execsql { |
danielk1977 | b92b70b | 2004-11-12 16:11:59 +0000 | [diff] [blame] | 917 | PRAGMA user_version; |
danielk1977 | dae2495 | 2004-11-11 05:10:43 +0000 | [diff] [blame] | 918 | } |
| 919 | } {-450} |
danielk1977 | d9c847d | 2005-01-07 10:42:48 +0000 | [diff] [blame] | 920 | } ; # ifcapable schema_version |
| 921 | |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 922 | # Check to see if TEMP_STORE is memory or disk. Return strings |
| 923 | # "memory" or "disk" as appropriate. |
| 924 | # |
| 925 | proc check_temp_store {} { |
| 926 | db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)} |
| 927 | db eval {PRAGMA database_list} { |
| 928 | if {$name=="temp"} { |
danielk1977 | 17b90b5 | 2008-06-06 11:11:25 +0000 | [diff] [blame] | 929 | set bt [btree_from_db db 1] |
| 930 | if {[btree_ismemdb $bt]} { |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 931 | return "memory" |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 932 | } |
danielk1977 | 17b90b5 | 2008-06-06 11:11:25 +0000 | [diff] [blame] | 933 | return "disk" |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | return "unknown" |
| 937 | } |
| 938 | |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 939 | |
| 940 | # Test temp_store and temp_store_directory pragmas |
| 941 | # |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 942 | ifcapable pager_pragmas { |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 943 | do_test pragma-9.1 { |
| 944 | db close |
| 945 | sqlite3 db test.db |
| 946 | execsql { |
| 947 | PRAGMA temp_store; |
| 948 | } |
| 949 | } {0} |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 950 | if {$TEMP_STORE<=1} { |
| 951 | do_test pragma-9.1.1 { |
| 952 | check_temp_store |
| 953 | } {disk} |
| 954 | } else { |
| 955 | do_test pragma-9.1.1 { |
| 956 | check_temp_store |
| 957 | } {memory} |
| 958 | } |
| 959 | |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 960 | do_test pragma-9.2 { |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 961 | db close |
| 962 | sqlite3 db test.db |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 963 | execsql { |
| 964 | PRAGMA temp_store=file; |
| 965 | PRAGMA temp_store; |
| 966 | } |
| 967 | } {1} |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 968 | if {$TEMP_STORE==3} { |
| 969 | # When TEMP_STORE is 3, always use memory regardless of pragma settings. |
| 970 | do_test pragma-9.2.1 { |
| 971 | check_temp_store |
| 972 | } {memory} |
| 973 | } else { |
| 974 | do_test pragma-9.2.1 { |
| 975 | check_temp_store |
| 976 | } {disk} |
| 977 | } |
| 978 | |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 979 | do_test pragma-9.3 { |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 980 | db close |
| 981 | sqlite3 db test.db |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 982 | execsql { |
| 983 | PRAGMA temp_store=memory; |
| 984 | PRAGMA temp_store; |
| 985 | } |
| 986 | } {2} |
drh | d19744f | 2008-03-18 13:46:53 +0000 | [diff] [blame] | 987 | if {$TEMP_STORE==0} { |
| 988 | # When TEMP_STORE is 0, always use the disk regardless of pragma settings. |
| 989 | do_test pragma-9.3.1 { |
| 990 | check_temp_store |
| 991 | } {disk} |
| 992 | } else { |
| 993 | do_test pragma-9.3.1 { |
| 994 | check_temp_store |
| 995 | } {memory} |
| 996 | } |
| 997 | |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 998 | do_test pragma-9.4 { |
| 999 | execsql { |
| 1000 | PRAGMA temp_store_directory; |
| 1001 | } |
| 1002 | } {} |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 1003 | ifcapable wsd { |
| 1004 | do_test pragma-9.5 { |
mistachkin | f8a7846 | 2012-03-08 20:00:36 +0000 | [diff] [blame] | 1005 | set pwd [string map {' ''} [file nativename [get_pwd]]] |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 1006 | execsql " |
| 1007 | PRAGMA temp_store_directory='$pwd'; |
| 1008 | " |
| 1009 | } {} |
| 1010 | do_test pragma-9.6 { |
| 1011 | execsql { |
| 1012 | PRAGMA temp_store_directory; |
| 1013 | } |
mistachkin | f8a7846 | 2012-03-08 20:00:36 +0000 | [diff] [blame] | 1014 | } [list [file nativename [get_pwd]]] |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 1015 | do_test pragma-9.7 { |
| 1016 | catchsql { |
| 1017 | PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; |
| 1018 | } |
| 1019 | } {1 {not a writable directory}} |
| 1020 | do_test pragma-9.8 { |
| 1021 | execsql { |
| 1022 | PRAGMA temp_store_directory=''; |
| 1023 | } |
| 1024 | } {} |
| 1025 | if {![info exists TEMP_STORE] || $TEMP_STORE<=1} { |
| 1026 | ifcapable tempdb { |
| 1027 | do_test pragma-9.9 { |
| 1028 | execsql { |
| 1029 | PRAGMA temp_store_directory; |
| 1030 | PRAGMA temp_store=FILE; |
| 1031 | CREATE TEMP TABLE temp_store_directory_test(a integer); |
| 1032 | INSERT INTO temp_store_directory_test values (2); |
| 1033 | SELECT * FROM temp_store_directory_test; |
| 1034 | } |
| 1035 | } {2} |
| 1036 | do_test pragma-9.10 { |
| 1037 | catchsql " |
| 1038 | PRAGMA temp_store_directory='$pwd'; |
| 1039 | SELECT * FROM temp_store_directory_test; |
| 1040 | " |
| 1041 | } {1 {no such table: temp_store_directory_test}} |
| 1042 | } |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1043 | } |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 1044 | } |
danielk1977 | 95b289b | 2007-03-30 17:11:12 +0000 | [diff] [blame] | 1045 | do_test pragma-9.11 { |
| 1046 | execsql { |
| 1047 | PRAGMA temp_store = 0; |
| 1048 | PRAGMA temp_store; |
| 1049 | } |
| 1050 | } {0} |
| 1051 | do_test pragma-9.12 { |
| 1052 | execsql { |
| 1053 | PRAGMA temp_store = 1; |
| 1054 | PRAGMA temp_store; |
| 1055 | } |
| 1056 | } {1} |
| 1057 | do_test pragma-9.13 { |
| 1058 | execsql { |
| 1059 | PRAGMA temp_store = 2; |
| 1060 | PRAGMA temp_store; |
| 1061 | } |
| 1062 | } {2} |
| 1063 | do_test pragma-9.14 { |
| 1064 | execsql { |
| 1065 | PRAGMA temp_store = 3; |
| 1066 | PRAGMA temp_store; |
| 1067 | } |
| 1068 | } {0} |
danielk1977 | 95b289b | 2007-03-30 17:11:12 +0000 | [diff] [blame] | 1069 | do_test pragma-9.15 { |
| 1070 | catchsql { |
| 1071 | BEGIN EXCLUSIVE; |
| 1072 | CREATE TEMP TABLE temp_table(t); |
| 1073 | INSERT INTO temp_table VALUES('valuable data'); |
| 1074 | PRAGMA temp_store = 1; |
| 1075 | } |
| 1076 | } {1 {temporary storage cannot be changed from within a transaction}} |
| 1077 | do_test pragma-9.16 { |
| 1078 | execsql { |
| 1079 | SELECT * FROM temp_table; |
| 1080 | COMMIT; |
| 1081 | } |
| 1082 | } {{valuable data}} |
danielk1977 | 983e230 | 2008-07-08 07:35:51 +0000 | [diff] [blame] | 1083 | |
| 1084 | do_test pragma-9.17 { |
| 1085 | execsql { |
| 1086 | INSERT INTO temp_table VALUES('valuable data II'); |
| 1087 | SELECT * FROM temp_table; |
| 1088 | } |
| 1089 | } {{valuable data} {valuable data II}} |
| 1090 | |
| 1091 | do_test pragma-9.18 { |
| 1092 | set rc [catch { |
| 1093 | db eval {SELECT t FROM temp_table} { |
| 1094 | execsql {pragma temp_store = 1} |
| 1095 | } |
| 1096 | } msg] |
| 1097 | list $rc $msg |
| 1098 | } {1 {temporary storage cannot be changed from within a transaction}} |
| 1099 | |
drh | 268283b | 2005-01-08 15:44:25 +0000 | [diff] [blame] | 1100 | } ;# ifcapable pager_pragmas |
tpoindex | 9a09a3c | 2004-12-20 19:01:32 +0000 | [diff] [blame] | 1101 | |
danielk1977 | cc6bd38 | 2005-01-10 02:48:49 +0000 | [diff] [blame] | 1102 | ifcapable trigger { |
| 1103 | |
| 1104 | do_test pragma-10.0 { |
| 1105 | catchsql { |
| 1106 | DROP TABLE main.t1; |
| 1107 | } |
| 1108 | execsql { |
| 1109 | PRAGMA count_changes = 1; |
| 1110 | |
| 1111 | CREATE TABLE t1(a PRIMARY KEY); |
| 1112 | CREATE TABLE t1_mirror(a); |
| 1113 | CREATE TABLE t1_mirror2(a); |
| 1114 | CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN |
| 1115 | INSERT INTO t1_mirror VALUES(new.a); |
| 1116 | END; |
| 1117 | CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN |
| 1118 | INSERT INTO t1_mirror2 VALUES(new.a); |
| 1119 | END; |
| 1120 | CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN |
| 1121 | UPDATE t1_mirror SET a = new.a WHERE a = old.a; |
| 1122 | END; |
| 1123 | CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN |
| 1124 | UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; |
| 1125 | END; |
| 1126 | CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN |
| 1127 | DELETE FROM t1_mirror WHERE a = old.a; |
| 1128 | END; |
| 1129 | CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN |
| 1130 | DELETE FROM t1_mirror2 WHERE a = old.a; |
| 1131 | END; |
| 1132 | } |
| 1133 | } {} |
| 1134 | |
| 1135 | do_test pragma-10.1 { |
| 1136 | execsql { |
| 1137 | INSERT INTO t1 VALUES(randstr(10,10)); |
| 1138 | } |
| 1139 | } {1} |
| 1140 | do_test pragma-10.2 { |
| 1141 | execsql { |
| 1142 | UPDATE t1 SET a = randstr(10,10); |
| 1143 | } |
| 1144 | } {1} |
| 1145 | do_test pragma-10.3 { |
| 1146 | execsql { |
| 1147 | DELETE FROM t1; |
| 1148 | } |
| 1149 | } {1} |
| 1150 | |
| 1151 | } ;# ifcapable trigger |
| 1152 | |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1153 | ifcapable schema_pragmas { |
| 1154 | do_test pragma-11.1 { |
| 1155 | execsql2 { |
| 1156 | pragma collation_list; |
| 1157 | } |
drh | 9b5adfa | 2008-01-20 23:19:56 +0000 | [diff] [blame] | 1158 | } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY} |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1159 | do_test pragma-11.2 { |
| 1160 | db collate New_Collation blah... |
| 1161 | execsql { |
| 1162 | pragma collation_list; |
| 1163 | } |
drh | 9b5adfa | 2008-01-20 23:19:56 +0000 | [diff] [blame] | 1164 | } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY} |
danielk1977 | 48af65a | 2005-02-09 03:20:37 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
danielk1977 | ddfb2f0 | 2006-02-17 12:25:14 +0000 | [diff] [blame] | 1167 | ifcapable schema_pragmas&&tempdb { |
| 1168 | do_test pragma-12.1 { |
| 1169 | sqlite3 db2 test.db |
| 1170 | execsql { |
| 1171 | PRAGMA temp.table_info('abc'); |
| 1172 | } db2 |
| 1173 | } {} |
| 1174 | db2 close |
| 1175 | |
| 1176 | do_test pragma-12.2 { |
| 1177 | sqlite3 db2 test.db |
| 1178 | execsql { |
| 1179 | PRAGMA temp.default_cache_size = 200; |
| 1180 | PRAGMA temp.default_cache_size; |
| 1181 | } db2 |
| 1182 | } {200} |
| 1183 | db2 close |
| 1184 | |
| 1185 | do_test pragma-12.3 { |
| 1186 | sqlite3 db2 test.db |
| 1187 | execsql { |
| 1188 | PRAGMA temp.cache_size = 400; |
| 1189 | PRAGMA temp.cache_size; |
| 1190 | } db2 |
| 1191 | } {400} |
| 1192 | db2 close |
| 1193 | } |
| 1194 | |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 1195 | ifcapable bloblit { |
| 1196 | |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 1197 | do_test pragma-13.1 { |
| 1198 | execsql { |
| 1199 | DROP TABLE IF EXISTS t4; |
| 1200 | PRAGMA vdbe_trace=on; |
| 1201 | PRAGMA vdbe_listing=on; |
| 1202 | PRAGMA sql_trace=on; |
| 1203 | CREATE TABLE t4(a INTEGER PRIMARY KEY,b); |
| 1204 | INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); |
| 1205 | INSERT INTO t4(b) VALUES(randstr(30,30)); |
| 1206 | INSERT INTO t4(b) VALUES(1.23456); |
| 1207 | INSERT INTO t4(b) VALUES(NULL); |
| 1208 | INSERT INTO t4(b) VALUES(0); |
| 1209 | INSERT INTO t4(b) SELECT b||b||b||b FROM t4; |
| 1210 | SELECT * FROM t4; |
| 1211 | } |
| 1212 | execsql { |
| 1213 | PRAGMA vdbe_trace=off; |
| 1214 | PRAGMA vdbe_listing=off; |
| 1215 | PRAGMA sql_trace=off; |
| 1216 | } |
| 1217 | } {} |
| 1218 | |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 1219 | } ;# ifcapable bloblit |
| 1220 | |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1221 | ifcapable pager_pragmas { |
| 1222 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 1223 | forcedelete test.db |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1224 | sqlite3 db test.db |
| 1225 | |
| 1226 | do_test pragma-14.1 { |
| 1227 | execsql { pragma auto_vacuum = 0 } |
| 1228 | execsql { pragma page_count } |
| 1229 | } {0} |
| 1230 | |
| 1231 | do_test pragma-14.2 { |
| 1232 | execsql { |
| 1233 | CREATE TABLE abc(a, b, c); |
| 1234 | PRAGMA page_count; |
| 1235 | } |
| 1236 | } {2} |
drh | 5d16a9a | 2011-10-13 14:41:22 +0000 | [diff] [blame] | 1237 | do_test pragma-14.2uc { |
| 1238 | execsql {pragma PAGE_COUNT} |
| 1239 | } {2} |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1240 | |
| 1241 | do_test pragma-14.3 { |
| 1242 | execsql { |
| 1243 | BEGIN; |
| 1244 | CREATE TABLE def(a, b, c); |
| 1245 | PRAGMA page_count; |
| 1246 | } |
| 1247 | } {3} |
drh | 5d16a9a | 2011-10-13 14:41:22 +0000 | [diff] [blame] | 1248 | do_test pragma-14.3uc { |
| 1249 | execsql {pragma PAGE_COUNT} |
| 1250 | } {3} |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1251 | |
| 1252 | do_test pragma-14.4 { |
| 1253 | set page_size [db one {pragma page_size}] |
| 1254 | expr [file size test.db] / $page_size |
| 1255 | } {2} |
| 1256 | |
| 1257 | do_test pragma-14.5 { |
| 1258 | execsql { |
| 1259 | ROLLBACK; |
| 1260 | PRAGMA page_count; |
| 1261 | } |
| 1262 | } {2} |
| 1263 | |
| 1264 | do_test pragma-14.6 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 1265 | forcedelete test2.db |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1266 | sqlite3 db2 test2.db |
| 1267 | execsql { |
| 1268 | PRAGMA auto_vacuum = 0; |
| 1269 | CREATE TABLE t1(a, b, c); |
| 1270 | CREATE TABLE t2(a, b, c); |
| 1271 | CREATE TABLE t3(a, b, c); |
| 1272 | CREATE TABLE t4(a, b, c); |
| 1273 | } db2 |
| 1274 | db2 close |
| 1275 | execsql { |
| 1276 | ATTACH 'test2.db' AS aux; |
| 1277 | PRAGMA aux.page_count; |
| 1278 | } |
| 1279 | } {5} |
drh | 5d16a9a | 2011-10-13 14:41:22 +0000 | [diff] [blame] | 1280 | do_test pragma-14.6uc { |
| 1281 | execsql {pragma AUX.PAGE_COUNT} |
| 1282 | } {5} |
danielk1977 | 59a9379 | 2008-05-15 17:48:20 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
danielk1977 | 8cf6c55 | 2008-06-23 16:53:46 +0000 | [diff] [blame] | 1285 | # Test that the value set using the cache_size pragma is not reset when the |
| 1286 | # schema is reloaded. |
| 1287 | # |
| 1288 | ifcapable pager_pragmas { |
| 1289 | db close |
| 1290 | sqlite3 db test.db |
| 1291 | do_test pragma-15.1 { |
| 1292 | execsql { |
| 1293 | PRAGMA cache_size=59; |
| 1294 | PRAGMA cache_size; |
| 1295 | } |
| 1296 | } {59} |
| 1297 | do_test pragma-15.2 { |
| 1298 | sqlite3 db2 test.db |
| 1299 | execsql { |
| 1300 | CREATE TABLE newtable(a, b, c); |
| 1301 | } db2 |
| 1302 | db2 close |
| 1303 | } {} |
| 1304 | do_test pragma-15.3 { |
| 1305 | # Evaluating this statement will cause the schema to be reloaded (because |
| 1306 | # the schema was changed by another connection in pragma-15.2). At one |
| 1307 | # point there was a bug that reset the cache_size to its default value |
| 1308 | # when this happened. |
| 1309 | execsql { SELECT * FROM sqlite_master } |
| 1310 | execsql { PRAGMA cache_size } |
| 1311 | } {59} |
| 1312 | } |
| 1313 | |
danielk1977 | 5558a8a | 2005-01-17 07:53:44 +0000 | [diff] [blame] | 1314 | # Reset the sqlite3_temp_directory variable for the next run of tests: |
| 1315 | sqlite3 dbX :memory: |
| 1316 | dbX eval {PRAGMA temp_store_directory = ""} |
| 1317 | dbX close |
| 1318 | |
danielk1977 | 838cce4 | 2009-01-12 14:01:45 +0000 | [diff] [blame] | 1319 | ifcapable lock_proxy_pragmas&&prefer_proxy_locking { |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1320 | set sqlite_hostid_num 1 |
| 1321 | |
| 1322 | set using_proxy 0 |
| 1323 | foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { |
| 1324 | set using_proxy $value |
| 1325 | } |
| 1326 | |
| 1327 | # Test the lock_proxy_file pragmas. |
| 1328 | # |
| 1329 | db close |
| 1330 | set env(SQLITE_FORCE_PROXY_LOCKING) "0" |
| 1331 | |
| 1332 | sqlite3 db test.db |
| 1333 | do_test pragma-16.1 { |
| 1334 | execsql { |
| 1335 | PRAGMA lock_proxy_file="mylittleproxy"; |
| 1336 | select * from sqlite_master; |
| 1337 | } |
| 1338 | execsql { |
| 1339 | PRAGMA lock_proxy_file; |
| 1340 | } |
| 1341 | } {mylittleproxy} |
| 1342 | |
| 1343 | do_test pragma-16.2 { |
| 1344 | sqlite3 db2 test.db |
| 1345 | execsql { |
| 1346 | PRAGMA lock_proxy_file="mylittleproxy"; |
| 1347 | } db2 |
| 1348 | } {} |
| 1349 | |
| 1350 | db2 close |
| 1351 | do_test pragma-16.2.1 { |
| 1352 | sqlite3 db2 test.db |
| 1353 | execsql { |
| 1354 | PRAGMA lock_proxy_file=":auto:"; |
| 1355 | select * from sqlite_master; |
| 1356 | } db2 |
| 1357 | execsql { |
| 1358 | PRAGMA lock_proxy_file; |
| 1359 | } db2 |
| 1360 | } {mylittleproxy} |
| 1361 | |
| 1362 | db2 close |
| 1363 | do_test pragma-16.3 { |
| 1364 | sqlite3 db2 test.db |
| 1365 | execsql { |
| 1366 | PRAGMA lock_proxy_file="myotherproxy"; |
| 1367 | } db2 |
| 1368 | catchsql { |
| 1369 | select * from sqlite_master; |
| 1370 | } db2 |
| 1371 | } {1 {database is locked}} |
| 1372 | |
| 1373 | do_test pragma-16.4 { |
| 1374 | db2 close |
| 1375 | db close |
| 1376 | sqlite3 db2 test.db |
| 1377 | execsql { |
| 1378 | PRAGMA lock_proxy_file="myoriginalproxy"; |
| 1379 | PRAGMA lock_proxy_file="myotherproxy"; |
| 1380 | PRAGMA lock_proxy_file; |
| 1381 | } db2 |
| 1382 | } {myotherproxy} |
| 1383 | |
| 1384 | db2 close |
| 1385 | set env(SQLITE_FORCE_PROXY_LOCKING) "1" |
| 1386 | do_test pragma-16.5 { |
| 1387 | sqlite3 db2 test.db |
| 1388 | execsql { |
| 1389 | PRAGMA lock_proxy_file=":auto:"; |
| 1390 | PRAGMA lock_proxy_file; |
| 1391 | } db2 |
| 1392 | } {myotherproxy} |
| 1393 | |
| 1394 | do_test pragma-16.6 { |
| 1395 | db2 close |
| 1396 | sqlite3 db2 test2.db |
| 1397 | set lockpath [execsql { |
| 1398 | PRAGMA lock_proxy_file=":auto:"; |
| 1399 | PRAGMA lock_proxy_file; |
| 1400 | } db2] |
| 1401 | string match "*test2.db:auto:" $lockpath |
| 1402 | } {1} |
| 1403 | |
| 1404 | set sqlite_hostid_num 2 |
| 1405 | do_test pragma-16.7 { |
dan | 14d1460 | 2010-10-06 16:42:52 +0000 | [diff] [blame] | 1406 | list [catch { |
| 1407 | sqlite3 db test2.db |
| 1408 | execsql { |
| 1409 | PRAGMA lock_proxy_file=":auto:"; |
| 1410 | select * from sqlite_master; |
| 1411 | } |
| 1412 | } msg] $msg |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1413 | } {1 {database is locked}} |
| 1414 | db close |
| 1415 | |
| 1416 | do_test pragma-16.8 { |
dan | 14d1460 | 2010-10-06 16:42:52 +0000 | [diff] [blame] | 1417 | list [catch { |
| 1418 | sqlite3 db test2.db |
| 1419 | execsql { select * from sqlite_master } |
| 1420 | } msg] $msg |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 1421 | } {1 {database is locked}} |
| 1422 | |
| 1423 | db2 close |
| 1424 | do_test pragma-16.8.1 { |
| 1425 | execsql { |
| 1426 | PRAGMA lock_proxy_file="yetanotherproxy"; |
| 1427 | PRAGMA lock_proxy_file; |
| 1428 | } |
| 1429 | } {yetanotherproxy} |
| 1430 | do_test pragma-16.8.2 { |
| 1431 | execsql { |
| 1432 | create table mine(x); |
| 1433 | } |
| 1434 | } {} |
| 1435 | |
| 1436 | db close |
| 1437 | do_test pragma-16.9 { |
| 1438 | sqlite3 db proxytest.db |
| 1439 | set lockpath2 [execsql { |
| 1440 | PRAGMA lock_proxy_file=":auto:"; |
| 1441 | PRAGMA lock_proxy_file; |
| 1442 | } db] |
| 1443 | string match "*proxytest.db:auto:" $lockpath2 |
| 1444 | } {1} |
| 1445 | |
| 1446 | set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy |
| 1447 | set sqlite_hostid_num 0 |
| 1448 | } |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 1449 | |
| 1450 | # Parsing of auto_vacuum settings. |
| 1451 | # |
| 1452 | foreach {autovac_setting val} { |
| 1453 | 0 0 |
| 1454 | 1 1 |
| 1455 | 2 2 |
| 1456 | 3 0 |
| 1457 | -1 0 |
| 1458 | none 0 |
| 1459 | NONE 0 |
| 1460 | NoNe 0 |
| 1461 | full 1 |
| 1462 | FULL 1 |
| 1463 | incremental 2 |
| 1464 | INCREMENTAL 2 |
| 1465 | -1234 0 |
| 1466 | 1234 0 |
| 1467 | } { |
| 1468 | do_test pragma-17.1.$autovac_setting { |
| 1469 | catch {db close} |
| 1470 | sqlite3 db :memory: |
| 1471 | execsql " |
| 1472 | PRAGMA auto_vacuum=$::autovac_setting; |
| 1473 | PRAGMA auto_vacuum; |
| 1474 | " |
| 1475 | } $val |
| 1476 | } |
| 1477 | |
| 1478 | # Parsing of temp_store settings. |
| 1479 | # |
| 1480 | foreach {temp_setting val} { |
| 1481 | 0 0 |
| 1482 | 1 1 |
| 1483 | 2 2 |
| 1484 | 3 0 |
| 1485 | -1 0 |
| 1486 | file 1 |
| 1487 | FILE 1 |
| 1488 | fIlE 1 |
| 1489 | memory 2 |
| 1490 | MEMORY 2 |
| 1491 | MeMoRy 2 |
| 1492 | } { |
| 1493 | do_test pragma-18.1.$temp_setting { |
| 1494 | catch {db close} |
| 1495 | sqlite3 db :memory: |
| 1496 | execsql " |
| 1497 | PRAGMA temp_store=$::temp_setting; |
| 1498 | PRAGMA temp_store=$::temp_setting; |
| 1499 | PRAGMA temp_store; |
| 1500 | " |
| 1501 | } $val |
| 1502 | } |
| 1503 | |
drh | 92c700d | 2012-02-22 19:56:17 +0000 | [diff] [blame] | 1504 | # The SQLITE_FCNTL_PRAGMA logic, with error handling. |
| 1505 | # |
| 1506 | db close |
| 1507 | testvfs tvfs |
| 1508 | sqlite3 db test.db -vfs tvfs |
| 1509 | do_test pragma-19.1 { |
| 1510 | catchsql {PRAGMA error} |
| 1511 | } {1 {SQL logic error or missing database}} |
| 1512 | do_test pragma-19.2 { |
| 1513 | catchsql {PRAGMA error='This is the error message'} |
| 1514 | } {1 {This is the error message}} |
| 1515 | do_test pragma-19.3 { |
| 1516 | catchsql {PRAGMA error='7 This is the error message'} |
| 1517 | } {1 {This is the error message}} |
| 1518 | do_test pragma-19.4 { |
| 1519 | catchsql {PRAGMA error=7} |
| 1520 | } {1 {out of memory}} |
drh | c8517f6 | 2012-02-22 20:08:49 +0000 | [diff] [blame] | 1521 | do_test pragma-19.5 { |
mistachkin | 5b04454 | 2012-03-02 22:41:06 +0000 | [diff] [blame] | 1522 | file tail [lindex [execsql {PRAGMA filename}] 0] |
drh | c8517f6 | 2012-02-22 20:08:49 +0000 | [diff] [blame] | 1523 | } {test.db} |
drh | 92c700d | 2012-02-22 19:56:17 +0000 | [diff] [blame] | 1524 | |
drh | cc71645 | 2012-06-06 23:23:23 +0000 | [diff] [blame] | 1525 | if {$tcl_platform(platform)=="windows"} { |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1526 | # Test data_store_directory pragma |
| 1527 | # |
| 1528 | db close |
| 1529 | sqlite3 db test.db |
| 1530 | file mkdir data_dir |
| 1531 | do_test pragma-20.1 { |
| 1532 | catchsql {PRAGMA data_store_directory} |
| 1533 | } {0 {}} |
| 1534 | do_test pragma-20.2 { |
| 1535 | set pwd [string map {' ''} [file nativename [get_pwd]]] |
| 1536 | catchsql "PRAGMA data_store_directory='$pwd';" |
| 1537 | } {0 {}} |
| 1538 | do_test pragma-20.3 { |
| 1539 | catchsql {PRAGMA data_store_directory} |
| 1540 | } [list 0 [list [file nativename [get_pwd]]]] |
| 1541 | do_test pragma-20.4 { |
| 1542 | set pwd [string map {' ''} [file nativename \ |
| 1543 | [file join [get_pwd] data_dir]]] |
| 1544 | catchsql "PRAGMA data_store_directory='$pwd';" |
| 1545 | } {0 {}} |
| 1546 | do_test pragma-20.5 { |
| 1547 | sqlite3 db2 test2.db |
| 1548 | catchsql "PRAGMA database_list;" db2 |
| 1549 | } [list 0 [list 0 main [file nativename \ |
| 1550 | [file join [get_pwd] data_dir test2.db]]]] |
| 1551 | catch {db2 close} |
| 1552 | do_test pragma-20.6 { |
| 1553 | sqlite3 db2 [file join [get_pwd] test2.db] |
| 1554 | catchsql "PRAGMA database_list;" db2 |
| 1555 | } [list 0 [list 0 main [file nativename \ |
| 1556 | [file join [get_pwd] test2.db]]]] |
| 1557 | catch {db2 close} |
| 1558 | do_test pragma-20.7 { |
| 1559 | catchsql "PRAGMA data_store_directory='';" |
| 1560 | } {0 {}} |
| 1561 | do_test pragma-20.8 { |
| 1562 | catchsql {PRAGMA data_store_directory} |
| 1563 | } {0 {}} |
drh | 92c700d | 2012-02-22 19:56:17 +0000 | [diff] [blame] | 1564 | |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 1565 | forcedelete data_dir |
drh | cc71645 | 2012-06-06 23:23:23 +0000 | [diff] [blame] | 1566 | } ;# endif windows |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 1567 | |
dan | 5885e76 | 2012-07-16 10:06:12 +0000 | [diff] [blame] | 1568 | do_test 21.1 { |
| 1569 | # Create a corrupt database in testerr.db. And a non-corrupt at test.db. |
| 1570 | # |
| 1571 | db close |
| 1572 | forcedelete test.db |
| 1573 | sqlite3 db test.db |
| 1574 | execsql { |
| 1575 | PRAGMA page_size = 1024; |
| 1576 | PRAGMA auto_vacuum = 0; |
| 1577 | CREATE TABLE t1(a PRIMARY KEY, b); |
| 1578 | INSERT INTO t1 VALUES(1, 1); |
| 1579 | } |
| 1580 | for {set i 0} {$i < 10} {incr i} { |
| 1581 | execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 } |
| 1582 | } |
| 1583 | db close |
| 1584 | forcecopy test.db testerr.db |
| 1585 | hexio_write testerr.db 15000 [string repeat 55 100] |
| 1586 | } {100} |
| 1587 | |
| 1588 | set mainerr {*** in database main *** |
| 1589 | Multiple uses for byte 672 of page 15} |
| 1590 | set auxerr {*** in database aux *** |
| 1591 | Multiple uses for byte 672 of page 15} |
| 1592 | |
| 1593 | do_test 22.2 { |
| 1594 | catch { db close } |
| 1595 | sqlite3 db testerr.db |
| 1596 | execsql { PRAGMA integrity_check } |
| 1597 | } [list $mainerr] |
| 1598 | |
| 1599 | do_test 22.3.1 { |
| 1600 | catch { db close } |
| 1601 | sqlite3 db test.db |
| 1602 | execsql { |
| 1603 | ATTACH 'testerr.db' AS 'aux'; |
| 1604 | PRAGMA integrity_check; |
| 1605 | } |
| 1606 | } [list $auxerr] |
| 1607 | do_test 22.3.2 { |
| 1608 | execsql { PRAGMA main.integrity_check; } |
| 1609 | } {ok} |
| 1610 | do_test 22.3.3 { |
| 1611 | execsql { PRAGMA aux.integrity_check; } |
| 1612 | } [list $auxerr] |
| 1613 | |
| 1614 | do_test 22.4.1 { |
| 1615 | catch { db close } |
| 1616 | sqlite3 db testerr.db |
| 1617 | execsql { |
| 1618 | ATTACH 'test.db' AS 'aux'; |
| 1619 | PRAGMA integrity_check; |
| 1620 | } |
| 1621 | } [list $mainerr] |
| 1622 | do_test 22.4.2 { |
| 1623 | execsql { PRAGMA main.integrity_check; } |
| 1624 | } [list $mainerr] |
| 1625 | do_test 22.4.3 { |
| 1626 | execsql { PRAGMA aux.integrity_check; } |
| 1627 | } {ok} |
| 1628 | |
drh | c95e01d | 2013-02-14 16:16:05 +0000 | [diff] [blame] | 1629 | db close |
| 1630 | forcedelete test.db test.db-wal test.db-journal |
| 1631 | sqlite3 db test.db |
| 1632 | sqlite3 db2 test.db |
| 1633 | do_test 23.1 { |
| 1634 | db eval { |
| 1635 | CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d); |
| 1636 | CREATE INDEX i1 ON t1(b,c); |
| 1637 | CREATE INDEX i2 ON t1(c,d); |
| 1638 | CREATE TABLE t2(x INTEGER REFERENCES t1); |
| 1639 | } |
| 1640 | db2 eval {SELECT name FROM sqlite_master} |
| 1641 | } {t1 i1 i2 t2} |
| 1642 | do_test 23.2 { |
| 1643 | db eval { |
| 1644 | DROP INDEX i2; |
| 1645 | CREATE INDEX i2 ON t1(c,d,b); |
| 1646 | } |
| 1647 | db2 eval {PRAGMA index_info(i2)} |
| 1648 | } {0 2 c 1 3 d 2 1 b} |
| 1649 | do_test 23.3 { |
| 1650 | db eval { |
| 1651 | CREATE INDEX i3 ON t1(d,b,c); |
| 1652 | } |
| 1653 | db2 eval {PRAGMA index_list(t1)} |
| 1654 | } {0 i3 0 1 i2 0 2 i1 0} |
| 1655 | do_test 23.4 { |
| 1656 | db eval { |
| 1657 | ALTER TABLE t1 ADD COLUMN e; |
| 1658 | } |
| 1659 | db2 eval { |
| 1660 | PRAGMA table_info(t1); |
| 1661 | } |
| 1662 | } {/4 e {} 0 {} 0/} |
| 1663 | do_test 23.5 { |
| 1664 | db eval { |
| 1665 | DROP TABLE t2; |
| 1666 | CREATE TABLE t2(x, y INTEGER REFERENCES t1); |
| 1667 | } |
| 1668 | db2 eval { |
| 1669 | PRAGMA foreign_key_list(t2); |
| 1670 | } |
| 1671 | } {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE} |
| 1672 | |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 1673 | finish_test |