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