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