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