OLD | NEW |
1 # 2010 June 15 | 1 # 2010 June 15 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # | 11 # |
12 | 12 |
13 set testdir [file dirname $argv0] | 13 set testdir [file dirname $argv0] |
14 source $testdir/tester.tcl | 14 source $testdir/tester.tcl |
15 source $testdir/lock_common.tcl | 15 source $testdir/lock_common.tcl |
16 source $testdir/malloc_common.tcl | 16 source $testdir/malloc_common.tcl |
17 source $testdir/wal_common.tcl | 17 source $testdir/wal_common.tcl |
| 18 set testprefix pager1 |
18 | 19 |
19 # Do not use a codec for tests in this file, as the database file is | 20 # Do not use a codec for tests in this file, as the database file is |
20 # manipulated directly using tcl scripts (using the [hexio_write] command). | 21 # manipulated directly using tcl scripts (using the [hexio_write] command). |
21 # | 22 # |
22 do_not_use_codec | 23 do_not_use_codec |
23 | 24 |
24 # | 25 # |
25 # pager1-1.*: Test inter-process locking (clients in multiple processes). | 26 # pager1-1.*: Test inter-process locking (clients in multiple processes). |
26 # | 27 # |
27 # pager1-2.*: Test intra-process locking (multiple clients in this process). | 28 # pager1-2.*: Test intra-process locking (multiple clients in this process). |
(...skipping 19 matching lines...) Expand all Loading... |
47 # | 48 # |
48 # pager1-13.*: Cases specific to "PRAGMA journal_mode=PERSIST" | 49 # pager1-13.*: Cases specific to "PRAGMA journal_mode=PERSIST" |
49 # | 50 # |
50 # pager1-14.*: Cases specific to "PRAGMA journal_mode=OFF" | 51 # pager1-14.*: Cases specific to "PRAGMA journal_mode=OFF" |
51 # | 52 # |
52 # pager1-15.*: Varying sqlite3_vfs.szOsFile | 53 # pager1-15.*: Varying sqlite3_vfs.szOsFile |
53 # | 54 # |
54 # pager1-16.*: Varying sqlite3_vfs.mxPathname | 55 # pager1-16.*: Varying sqlite3_vfs.mxPathname |
55 # | 56 # |
56 # pager1-17.*: Tests related to "PRAGMA omit_readlock" | 57 # pager1-17.*: Tests related to "PRAGMA omit_readlock" |
| 58 # (The omit_readlock pragma has been removed and so have |
| 59 # these tests.) |
57 # | 60 # |
58 # pager1-18.*: Test that the pager layer responds correctly if the b-tree | 61 # pager1-18.*: Test that the pager layer responds correctly if the b-tree |
59 # requests an invalid page number (due to db corruption). | 62 # requests an invalid page number (due to db corruption). |
60 # | 63 # |
61 | 64 |
62 proc recursive_select {id table {script {}}} { | 65 proc recursive_select {id table {script {}}} { |
63 set cnt 0 | 66 set cnt 0 |
64 db eval "SELECT rowid, * FROM $table WHERE rowid = ($id-1)" { | 67 db eval "SELECT rowid, * FROM $table WHERE rowid = ($id-1)" { |
65 recursive_select $rowid $table $script | 68 recursive_select $rowid $table $script |
66 incr cnt | 69 incr cnt |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 do_execsql_test pager1-3.1.2 { | 264 do_execsql_test pager1-3.1.2 { |
262 PRAGMA cache_size = 10; | 265 PRAGMA cache_size = 10; |
263 BEGIN; | 266 BEGIN; |
264 INSERT INTO t1 VALUES(1, randomblob(1500)); | 267 INSERT INTO t1 VALUES(1, randomblob(1500)); |
265 INSERT INTO t1 VALUES(2, randomblob(1500)); | 268 INSERT INTO t1 VALUES(2, randomblob(1500)); |
266 INSERT INTO t1 VALUES(3, randomblob(1500)); | 269 INSERT INTO t1 VALUES(3, randomblob(1500)); |
267 SELECT * FROM counter; | 270 SELECT * FROM counter; |
268 } {3 0} | 271 } {3 0} |
269 do_catchsql_test pager1-3.1.3 { | 272 do_catchsql_test pager1-3.1.3 { |
270 INSERT INTO t1 SELECT a+3, randomblob(1500) FROM t1 | 273 INSERT INTO t1 SELECT a+3, randomblob(1500) FROM t1 |
271 } {1 {constraint failed}} | 274 } {1 {CHECK constraint failed: counter}} |
272 do_execsql_test pager1-3.4 { SELECT * FROM counter } {3 0} | 275 do_execsql_test pager1-3.4 { SELECT * FROM counter } {3 0} |
273 do_execsql_test pager1-3.5 { SELECT a FROM t1 } {1 2 3} | 276 do_execsql_test pager1-3.5 { SELECT a FROM t1 } {1 2 3} |
274 do_execsql_test pager1-3.6 { COMMIT } {} | 277 do_execsql_test pager1-3.6 { COMMIT } {} |
275 | 278 |
276 foreach {tn sql tcl} { | 279 foreach {tn sql tcl} { |
277 7 { PRAGMA synchronous = NORMAL ; PRAGMA temp_store = 0 } { | 280 7 { PRAGMA synchronous = NORMAL ; PRAGMA temp_store = 0 } { |
278 testvfs tv -default 1 | 281 testvfs tv -default 1 |
279 tv devchar safe_append | 282 tv devchar safe_append |
280 } | 283 } |
281 8 { PRAGMA synchronous = NORMAL ; PRAGMA temp_store = 2 } { | 284 8 { PRAGMA synchronous = NORMAL ; PRAGMA temp_store = 2 } { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 INSERT INTO t1 SELECT a_string(201), a_string(301) FROM t1; | 437 INSERT INTO t1 SELECT a_string(201), a_string(301) FROM t1; |
435 INSERT INTO t1 SELECT a_string(202), a_string(302) FROM t1; | 438 INSERT INTO t1 SELECT a_string(202), a_string(302) FROM t1; |
436 INSERT INTO t1 SELECT a_string(203), a_string(303) FROM t1; | 439 INSERT INTO t1 SELECT a_string(203), a_string(303) FROM t1; |
437 INSERT INTO t1 SELECT a_string(204), a_string(304) FROM t1; | 440 INSERT INTO t1 SELECT a_string(204), a_string(304) FROM t1; |
438 REPLACE INTO t2 SELECT * FROM t1; | 441 REPLACE INTO t2 SELECT * FROM t1; |
439 COMMIT; | 442 COMMIT; |
440 } | 443 } |
441 db close | 444 db close |
442 tstvfs delete | 445 tstvfs delete |
443 } {} | 446 } {} |
| 447 |
| 448 if {$::tcl_platform(platform)!="windows"} { |
444 do_test pager1.4.2.2 { | 449 do_test pager1.4.2.2 { |
445 faultsim_restore_and_reopen | 450 faultsim_restore_and_reopen |
446 execsql { | 451 execsql { |
447 SELECT count(*) FROM t1; | 452 SELECT count(*) FROM t1; |
448 PRAGMA integrity_check; | 453 PRAGMA integrity_check; |
449 } | 454 } |
450 } {4 ok} | 455 } {4 ok} |
451 do_test pager1.4.2.3 { | 456 do_test pager1.4.2.3 { |
452 faultsim_restore_and_reopen | 457 faultsim_restore_and_reopen |
453 foreach f [glob test.db-mj*] { file delete -force $f } | 458 foreach f [glob test.db-mj*] { forcedelete $f } |
454 execsql { | 459 execsql { |
455 SELECT count(*) FROM t1; | 460 SELECT count(*) FROM t1; |
456 PRAGMA integrity_check; | 461 PRAGMA integrity_check; |
457 } | 462 } |
458 } {64 ok} | 463 } {64 ok} |
459 do_test pager1.4.2.4 { | 464 do_test pager1.4.2.4 { |
460 faultsim_restore_and_reopen | 465 faultsim_restore_and_reopen |
461 hexio_write test.db-journal [expr [file size test.db-journal]-20] 123456 | 466 hexio_write test.db-journal [expr [file size test.db-journal]-30] 123456 |
462 execsql { | 467 execsql { |
463 SELECT count(*) FROM t1; | 468 SELECT count(*) FROM t1; |
464 PRAGMA integrity_check; | 469 PRAGMA integrity_check; |
465 } | 470 } |
466 } {4 ok} | 471 } {4 ok} |
467 do_test pager1.4.2.5 { | 472 do_test pager1.4.2.5 { |
468 faultsim_restore_and_reopen | 473 faultsim_restore_and_reopen |
469 hexio_write test.db-journal [expr [file size test.db-journal]-20] 123456 | 474 hexio_write test.db-journal [expr [file size test.db-journal]-30] 123456 |
470 foreach f [glob test.db-mj*] { file delete -force $f } | 475 foreach f [glob test.db-mj*] { forcedelete $f } |
471 execsql { | 476 execsql { |
472 SELECT count(*) FROM t1; | 477 SELECT count(*) FROM t1; |
473 PRAGMA integrity_check; | 478 PRAGMA integrity_check; |
474 } | 479 } |
475 } {4 ok} | 480 } {4 ok} |
| 481 } |
476 | 482 |
477 do_test pager1.4.3.1 { | 483 do_test pager1.4.3.1 { |
478 testvfs tstvfs -default 1 | 484 testvfs tstvfs -default 1 |
479 tstvfs filter xSync | 485 tstvfs filter xSync |
480 tstvfs script xSyncCallback | 486 tstvfs script xSyncCallback |
481 proc xSyncCallback {method file args} { | 487 proc xSyncCallback {method file args} { |
482 set file [file tail $file] | 488 set file [file tail $file] |
483 if { 0==[string match *journal $file] } { faultsim_save } | 489 if { 0==[string match *journal $file] } { faultsim_save } |
484 } | 490 } |
485 faultsim_delete_and_reopen | 491 faultsim_delete_and_reopen |
(...skipping 26 matching lines...) Expand all Loading... |
512 execsql { SELECT * FROM t1 } | 518 execsql { SELECT * FROM t1 } |
513 } $result | 519 } $result |
514 } | 520 } |
515 db close | 521 db close |
516 | 522 |
517 # Set up a VFS that snapshots the file-system just before a master journal | 523 # Set up a VFS that snapshots the file-system just before a master journal |
518 # file is deleted to commit a multi-file transaction. Specifically, the | 524 # file is deleted to commit a multi-file transaction. Specifically, the |
519 # file-system is saved just before the xDelete() call to remove the | 525 # file-system is saved just before the xDelete() call to remove the |
520 # master journal file from the file-system. | 526 # master journal file from the file-system. |
521 # | 527 # |
| 528 set pwd [get_pwd] |
522 testvfs tv -default 1 | 529 testvfs tv -default 1 |
523 tv script copy_on_mj_delete | 530 tv script copy_on_mj_delete |
524 set ::mj_filename_length 0 | 531 set ::mj_filename_length 0 |
525 proc copy_on_mj_delete {method filename args} { | 532 proc copy_on_mj_delete {method filename args} { |
526 if {[string match *mj* [file tail $filename]]} { | 533 if {[string match *mj* [file tail $filename]]} { |
527 set ::mj_filename_length [string length $filename] | 534 # |
| 535 # NOTE: Is the file name relative? If so, add the length of the current |
| 536 # directory. |
| 537 # |
| 538 if {[is_relative_file $filename]} { |
| 539 set ::mj_filename_length \ |
| 540 [expr {[string length $filename] + [string length $::pwd]}] |
| 541 } else { |
| 542 set ::mj_filename_length [string length $filename] |
| 543 } |
528 faultsim_save | 544 faultsim_save |
529 } | 545 } |
530 return SQLITE_OK | 546 return SQLITE_OK |
531 } | 547 } |
532 | 548 |
533 set pwd [pwd] | |
534 foreach {tn1 tcl} { | 549 foreach {tn1 tcl} { |
535 1 { set prefix "test.db" } | 550 1 { set prefix "test.db" } |
536 2 { | 551 2 { |
537 # This test depends on the underlying VFS being able to open paths | 552 # This test depends on the underlying VFS being able to open paths |
538 # 512 bytes in length. The idea is to create a hot-journal file that | 553 # 512 bytes in length. The idea is to create a hot-journal file that |
539 # contains a master-journal pointer so large that it could contain | 554 # contains a master-journal pointer so large that it could contain |
540 # a valid page record (if the file page-size is 512 bytes). So as to | 555 # a valid page record (if the file page-size is 512 bytes). So as to |
541 # make sure SQLite doesn't get confused by this. | 556 # make sure SQLite doesn't get confused by this. |
542 # | 557 # |
543 set nPadding [expr 511 - $::mj_filename_length] | 558 set nPadding [expr 511 - $::mj_filename_length] |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 } {} | 654 } {} |
640 do_execsql_test pager1-4.4.$tn.5 {SELECT * FROM a} {double-you why zed} | 655 do_execsql_test pager1-4.4.$tn.5 {SELECT * FROM a} {double-you why zed} |
641 do_execsql_test pager1-4.4.$tn.6 {SELECT * FROM b} {won too free} | 656 do_execsql_test pager1-4.4.$tn.6 {SELECT * FROM b} {won too free} |
642 | 657 |
643 # Restore the file-system again. This time, before reopening the databases, | 658 # Restore the file-system again. This time, before reopening the databases, |
644 # delete the master-journal file from the file-system. It now appears that | 659 # delete the master-journal file from the file-system. It now appears that |
645 # the transaction was committed (no master-journal file == no rollback). | 660 # the transaction was committed (no master-journal file == no rollback). |
646 # | 661 # |
647 do_test pager1-4.4.$tn.7 { | 662 do_test pager1-4.4.$tn.7 { |
648 faultsim_restore_and_reopen $prefix | 663 faultsim_restore_and_reopen $prefix |
649 foreach f [glob ${prefix}-mj*] { file delete -force $f } | 664 foreach f [glob ${prefix}-mj*] { forcedelete $f } |
650 execsql "ATTACH '${prefix}2' AS aux" | 665 execsql "ATTACH '${prefix}2' AS aux" |
651 } {} | 666 } {} |
652 do_execsql_test pager1-4.4.$tn.8 { | 667 do_execsql_test pager1-4.4.$tn.8 { |
653 SELECT * FROM a | 668 SELECT * FROM a |
654 } {double-you why zed won too free} | 669 } {double-you why zed won too free} |
655 do_execsql_test pager1-4.4.$tn.9 { | 670 do_execsql_test pager1-4.4.$tn.9 { |
656 SELECT * FROM b | 671 SELECT * FROM b |
657 } {won too free double-you why zed} | 672 } {won too free double-you why zed} |
658 } | 673 } |
659 | 674 |
660 cd $pwd | 675 cd $pwd |
661 } | 676 } |
662 db close | 677 db close |
663 tv delete | 678 tv delete |
664 file delete -force $dirname | 679 forcedelete $dirname |
665 | 680 |
666 | 681 |
667 # Set up a VFS to make a copy of the file-system just before deleting a | 682 # Set up a VFS to make a copy of the file-system just before deleting a |
668 # journal file to commit a transaction. The transaction modifies exactly | 683 # journal file to commit a transaction. The transaction modifies exactly |
669 # two database pages (and page 1 - the change counter). | 684 # two database pages (and page 1 - the change counter). |
670 # | 685 # |
671 testvfs tv -default 1 | 686 testvfs tv -default 1 |
672 tv sectorsize 512 | 687 tv sectorsize 512 |
673 tv script copy_on_journal_delete | 688 tv script copy_on_journal_delete |
674 tv filter xDelete | 689 tv filter xDelete |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 SELECT * FROM t1; | 746 SELECT * FROM t1; |
732 SELECT * FROM t2; | 747 SELECT * FROM t2; |
733 } {I II III IV 3 4} | 748 } {I II III IV 3 4} |
734 | 749 |
735 faultsim_restore_and_reopen | 750 faultsim_restore_and_reopen |
736 db close | 751 db close |
737 sqlite3 db test.db -readonly 1 | 752 sqlite3 db test.db -readonly 1 |
738 do_catchsql_test pager1.4.5.6 { | 753 do_catchsql_test pager1.4.5.6 { |
739 SELECT * FROM t1; | 754 SELECT * FROM t1; |
740 SELECT * FROM t2; | 755 SELECT * FROM t2; |
741 } {1 {disk I/O error}} | 756 } {1 {attempt to write a readonly database}} |
742 db close | 757 db close |
743 | 758 |
744 # Snapshot the file-system just before multi-file commit. Save the name | 759 # Snapshot the file-system just before multi-file commit. Save the name |
745 # of the master journal file in $::mj_filename. | 760 # of the master journal file in $::mj_filename. |
746 # | 761 # |
747 tv script copy_on_mj_delete | 762 tv script copy_on_mj_delete |
748 tv filter xDelete | 763 tv filter xDelete |
749 proc copy_on_mj_delete {method filename args} { | 764 proc copy_on_mj_delete {method filename args} { |
750 if {[string match *mj* [file tail $filename]]} { | 765 if {[string match *mj* [file tail $filename]]} { |
751 set ::mj_filename $filename | 766 set ::mj_filename $filename |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 INSERT INTO t1 VALUES('II', 'four'); | 877 INSERT INTO t1 VALUES('II', 'four'); |
863 INSERT INTO t1 VALUES('III', 'nine'); | 878 INSERT INTO t1 VALUES('III', 'nine'); |
864 BEGIN; | 879 BEGIN; |
865 INSERT INTO t1 VALUES('IV', 'sixteen'); | 880 INSERT INTO t1 VALUES('IV', 'sixteen'); |
866 INSERT INTO t1 VALUES('V' , 'twentyfive'); | 881 INSERT INTO t1 VALUES('V' , 'twentyfive'); |
867 COMMIT; | 882 COMMIT; |
868 } {delete} | 883 } {delete} |
869 tv filter {} | 884 tv filter {} |
870 db close | 885 db close |
871 tv delete | 886 tv delete |
| 887 catch { |
| 888 test_syscall install fchmod |
| 889 test_syscall fault 1 1 |
| 890 } |
872 do_test pager1.4.7.2 { | 891 do_test pager1.4.7.2 { |
873 faultsim_restore_and_reopen | 892 faultsim_restore_and_reopen |
874 catch {file attributes test.db-journal -permissions r--------} | 893 catch {file attributes test.db-journal -permissions r--------} |
875 catch {file attributes test.db-journal -readonly 1} | 894 catch {file attributes test.db-journal -readonly 1} |
876 catchsql { SELECT * FROM t1 } | 895 catchsql { SELECT * FROM t1 } |
877 } {1 {unable to open database file}} | 896 } {1 {unable to open database file}} |
| 897 catch { |
| 898 test_syscall reset |
| 899 test_syscall fault 0 0 |
| 900 } |
878 do_test pager1.4.7.3 { | 901 do_test pager1.4.7.3 { |
879 db close | 902 db close |
880 catch {file attributes test.db-journal -permissions rw-rw-rw-} | 903 catch {file attributes test.db-journal -permissions rw-rw-rw-} |
881 catch {file attributes test.db-journal -readonly 0} | 904 catch {file attributes test.db-journal -readonly 0} |
882 file delete test.db-journal | 905 delete_file test.db-journal |
883 file exists test.db-journal | 906 file exists test.db-journal |
884 } {0} | 907 } {0} |
| 908 do_test pager1.4.8.1 { |
| 909 catch {file attributes test.db -permissions r--------} |
| 910 catch {file attributes test.db -readonly 1} |
| 911 sqlite3 db test.db |
| 912 db eval { SELECT * FROM t1 } |
| 913 sqlite3_db_readonly db main |
| 914 } {1} |
| 915 do_test pager1.4.8.2 { |
| 916 sqlite3_db_readonly db xyz |
| 917 } {-1} |
| 918 do_test pager1.4.8.3 { |
| 919 db close |
| 920 catch {file attributes test.db -readonly 0} |
| 921 catch {file attributes test.db -permissions rw-rw-rw-} msg |
| 922 sqlite3 db test.db |
| 923 db eval { SELECT * FROM t1 } |
| 924 sqlite3_db_readonly db main |
| 925 } {0} |
885 | 926 |
886 #------------------------------------------------------------------------- | 927 #------------------------------------------------------------------------- |
887 # The following tests deal with multi-file commits. | 928 # The following tests deal with multi-file commits. |
888 # | 929 # |
889 # pager1-5.1.*: The case where a multi-file cannot be committed because | 930 # pager1-5.1.*: The case where a multi-file cannot be committed because |
890 # another connection is holding a SHARED lock on one of the | 931 # another connection is holding a SHARED lock on one of the |
891 # files. After the SHARED lock is removed, the COMMIT succeeds. | 932 # files. After the SHARED lock is removed, the COMMIT succeeds. |
892 # | 933 # |
893 # pager1-5.2.*: Multi-file commits with journal_mode=memory. | 934 # pager1-5.2.*: Multi-file commits with journal_mode=memory. |
894 # | 935 # |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 return SQLITE_OK | 1021 return SQLITE_OK |
981 } | 1022 } |
982 execsql { | 1023 execsql { |
983 PRAGMA journal_mode = DELETE; | 1024 PRAGMA journal_mode = DELETE; |
984 PRAGMA synchronous = NORMAL; | 1025 PRAGMA synchronous = NORMAL; |
985 BEGIN; | 1026 BEGIN; |
986 INSERT INTO t1 VALUES(85, 'Gorbachev'); | 1027 INSERT INTO t1 VALUES(85, 'Gorbachev'); |
987 INSERT INTO t2 VALUES(85, 'Gorbachev'); | 1028 INSERT INTO t2 VALUES(85, 'Gorbachev'); |
988 COMMIT; | 1029 COMMIT; |
989 } | 1030 } |
990 set ::max_journal | 1031 |
991 } [expr 2615+[string length [pwd]]] | 1032 # The size of the journal file is now: |
| 1033 # |
| 1034 # 1) 512 byte header + |
| 1035 # 2) 2 * (1024+8) byte records + |
| 1036 # 3) 20+N bytes of master-journal pointer, where N is the size of |
| 1037 # the master-journal name encoded as utf-8 with no nul term. |
| 1038 # |
| 1039 set mj_pointer [expr { |
| 1040 20 + [string length "test.db-mjXXXXXX9XX"] |
| 1041 }] |
| 1042 # |
| 1043 # NOTE: For item 3 above, if the current SQLite VFS lacks the concept of a |
| 1044 # current directory, the length of the current directory name plus 1 |
| 1045 # character for the directory separator character are NOT counted as |
| 1046 # part of the total size; otherwise, they are. |
| 1047 # |
| 1048 ifcapable curdir { |
| 1049 set mj_pointer [expr {$mj_pointer + [string length [get_pwd]] + 1}] |
| 1050 } |
| 1051 expr {$::max_journal==(512+2*(1024+8)+$mj_pointer)} |
| 1052 } 1 |
992 do_test pager1-5.4.2 { | 1053 do_test pager1-5.4.2 { |
993 set ::max_journal 0 | 1054 set ::max_journal 0 |
994 execsql { | 1055 execsql { |
995 PRAGMA synchronous = full; | 1056 PRAGMA synchronous = full; |
996 BEGIN; | 1057 BEGIN; |
997 DELETE FROM t1 WHERE b = 'Lenin'; | 1058 DELETE FROM t1 WHERE b = 'Lenin'; |
998 DELETE FROM t2 WHERE b = 'Lenin'; | 1059 DELETE FROM t2 WHERE b = 'Lenin'; |
999 COMMIT; | 1060 COMMIT; |
1000 } | 1061 } |
1001 set ::max_journal | 1062 |
1002 } [expr 3111+[string length [pwd]]] | 1063 # In synchronous=full mode, the master-journal pointer is not written |
| 1064 # directly after the last record in the journal file. Instead, it is |
| 1065 # written starting at the next (in this case 512 byte) sector boundary. |
| 1066 # |
| 1067 set mj_pointer [expr { |
| 1068 20 + [string length "test.db-mjXXXXXX9XX"] |
| 1069 }] |
| 1070 # |
| 1071 # NOTE: If the current SQLite VFS lacks the concept of a current directory, |
| 1072 # the length of the current directory name plus 1 character for the |
| 1073 # directory separator character are NOT counted as part of the total |
| 1074 # size; otherwise, they are. |
| 1075 # |
| 1076 ifcapable curdir { |
| 1077 set mj_pointer [expr {$mj_pointer + [string length [get_pwd]] + 1}] |
| 1078 } |
| 1079 expr {$::max_journal==(((512+2*(1024+8)+511)/512)*512 + $mj_pointer)} |
| 1080 } 1 |
1003 db close | 1081 db close |
1004 tv delete | 1082 tv delete |
1005 | 1083 |
1006 do_test pager1-5.5.1 { | 1084 do_test pager1-5.5.1 { |
1007 sqlite3 db test.db | 1085 sqlite3 db test.db |
1008 execsql { | 1086 execsql { |
1009 ATTACH 'test.db2' AS aux; | 1087 ATTACH 'test.db2' AS aux; |
1010 PRAGMA journal_mode = PERSIST; | 1088 PRAGMA journal_mode = PERSIST; |
1011 CREATE TABLE t3(a, b); | 1089 CREATE TABLE t3(a, b); |
1012 INSERT INTO t3 SELECT randomblob(1500), randomblob(1500) FROM t1; | 1090 INSERT INTO t3 SELECT randomblob(1500), randomblob(1500) FROM t1; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1289 execsql { | 1367 execsql { |
1290 PRAGMA page_size = 4096; | 1368 PRAGMA page_size = 4096; |
1291 CREATE TABLE t1(a, b); | 1369 CREATE TABLE t1(a, b); |
1292 CREATE TABLE t2(a, b); | 1370 CREATE TABLE t2(a, b); |
1293 } db2 | 1371 } db2 |
1294 sqlite3_backup B db2 main db main | 1372 sqlite3_backup B db2 main db main |
1295 list [B step 10000] [B finish] | 1373 list [B step 10000] [B finish] |
1296 } {SQLITE_DONE SQLITE_OK} | 1374 } {SQLITE_DONE SQLITE_OK} |
1297 do_test pager1-9.4.2 { | 1375 do_test pager1-9.4.2 { |
1298 list [file size test.db2] [file size test.db] | 1376 list [file size test.db2] [file size test.db] |
1299 } {0 0} | 1377 } {1024 0} |
1300 db2 close | 1378 db2 close |
1301 | 1379 |
1302 #------------------------------------------------------------------------- | 1380 #------------------------------------------------------------------------- |
1303 # Test that regardless of the value returned by xSectorSize(), the | 1381 # Test that regardless of the value returned by xSectorSize(), the |
1304 # minimum effective sector-size is 512 and the maximum 65536 bytes. | 1382 # minimum effective sector-size is 512 and the maximum 65536 bytes. |
1305 # | 1383 # |
1306 testvfs tv -default 1 | 1384 testvfs tv -default 1 |
1307 foreach sectorsize { | 1385 foreach sectorsize { |
| 1386 16 |
1308 32 64 128 256 512 1024 2048 | 1387 32 64 128 256 512 1024 2048 |
1309 4096 8192 16384 32768 65536 131072 262144 | 1388 4096 8192 16384 32768 65536 131072 262144 |
1310 } { | 1389 } { |
1311 tv sectorsize $sectorsize | 1390 tv sectorsize $sectorsize |
| 1391 tv devchar {} |
1312 set eff $sectorsize | 1392 set eff $sectorsize |
1313 if {$sectorsize < 512} { set eff 512 } | 1393 if {$sectorsize < 512} { set eff 512 } |
1314 if {$sectorsize > 65536} { set eff 65536 } | 1394 if {$sectorsize > 65536} { set eff 65536 } |
1315 | 1395 |
1316 do_test pager1-10.$sectorsize.1 { | 1396 do_test pager1-10.$sectorsize.1 { |
1317 faultsim_delete_and_reopen | 1397 faultsim_delete_and_reopen |
1318 db func a_string a_string | 1398 db func a_string a_string |
1319 execsql { | 1399 execsql { |
1320 PRAGMA journal_mode = PERSIST; | 1400 PRAGMA journal_mode = PERSIST; |
1321 PRAGMA page_size = 1024; | 1401 PRAGMA page_size = 1024; |
1322 BEGIN; | 1402 BEGIN; |
1323 CREATE TABLE t1(a, b); | 1403 CREATE TABLE t1(a, b); |
1324 CREATE TABLE t2(a, b); | 1404 CREATE TABLE t2(a, b); |
1325 CREATE TABLE t3(a, b); | 1405 CREATE TABLE t3(a, b); |
1326 COMMIT; | 1406 COMMIT; |
1327 } | 1407 } |
1328 file size test.db-journal | 1408 file size test.db-journal |
1329 } [expr $sectorsize > 65536 ? 65536 : $sectorsize] | 1409 } [expr $sectorsize > 65536 ? 65536 : ($sectorsize<32 ? 512 : $sectorsize)] |
1330 | 1410 |
1331 do_test pager1-10.$sectorsize.2 { | 1411 do_test pager1-10.$sectorsize.2 { |
1332 execsql { | 1412 execsql { |
1333 INSERT INTO t3 VALUES(a_string(300), a_string(300)); | 1413 INSERT INTO t3 VALUES(a_string(300), a_string(300)); |
1334 INSERT INTO t3 SELECT * FROM t3; /* 2 */ | 1414 INSERT INTO t3 SELECT * FROM t3; /* 2 */ |
1335 INSERT INTO t3 SELECT * FROM t3; /* 4 */ | 1415 INSERT INTO t3 SELECT * FROM t3; /* 4 */ |
1336 INSERT INTO t3 SELECT * FROM t3; /* 8 */ | 1416 INSERT INTO t3 SELECT * FROM t3; /* 8 */ |
1337 INSERT INTO t3 SELECT * FROM t3; /* 16 */ | 1417 INSERT INTO t3 SELECT * FROM t3; /* 16 */ |
1338 INSERT INTO t3 SELECT * FROM t3; /* 32 */ | 1418 INSERT INTO t3 SELECT * FROM t3; /* 32 */ |
1339 } | 1419 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 4 */ | 1621 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 4 */ |
1542 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 8 */ | 1622 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 8 */ |
1543 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 16 */ | 1623 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 16 */ |
1544 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 32 */ | 1624 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 32 */ |
1545 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 64 */ | 1625 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 64 */ |
1546 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 128 */ | 1626 INSERT INTO t1 SELECT NULL, a_string(400) FROM t1; /* 128 */ |
1547 COMMIT; | 1627 COMMIT; |
1548 UPDATE t1 SET b = a_string(400); | 1628 UPDATE t1 SET b = a_string(400); |
1549 } {persist} | 1629 } {persist} |
1550 | 1630 |
| 1631 if {$::tcl_platform(platform)!="windows"} { |
1551 # Run transactions of increasing sizes. Eventually, one (or more than one) | 1632 # Run transactions of increasing sizes. Eventually, one (or more than one) |
1552 # of these will write just enough content that one of the old headers created | 1633 # of these will write just enough content that one of the old headers created |
1553 # by the transaction in the block above lies immediately after the content | 1634 # by the transaction in the block above lies immediately after the content |
1554 # journalled by the current transaction. | 1635 # journalled by the current transaction. |
1555 # | 1636 # |
1556 for {set nUp 1} {$nUp<64} {incr nUp} { | 1637 for {set nUp 1} {$nUp<64} {incr nUp} { |
1557 do_execsql_test pager1-13.1.2.$nUp.1 { | 1638 do_execsql_test pager1-13.1.2.$nUp.1 { |
1558 UPDATE t1 SET b = a_string(399) WHERE a <= $nUp | 1639 UPDATE t1 SET b = a_string(399) WHERE a <= $nUp |
1559 } {} | 1640 } {} |
1560 do_execsql_test pager1-13.1.2.$nUp.2 { PRAGMA integrity_check } {ok} | 1641 do_execsql_test pager1-13.1.2.$nUp.2 { PRAGMA integrity_check } {ok} |
1561 | 1642 |
1562 # Try to access the snapshot of the file-system. | 1643 # Try to access the snapshot of the file-system. |
1563 # | 1644 # |
1564 sqlite3 db2 sv_test.db | 1645 sqlite3 db2 sv_test.db |
1565 do_test pager1-13.1.2.$nUp.3 { | 1646 do_test pager1-13.1.2.$nUp.3 { |
1566 execsql { SELECT sum(length(b)) FROM t1 } db2 | 1647 execsql { SELECT sum(length(b)) FROM t1 } db2 |
1567 } [expr {128*400 - ($nUp-1)}] | 1648 } [expr {128*400 - ($nUp-1)}] |
1568 do_test pager1-13.1.2.$nUp.4 { | 1649 do_test pager1-13.1.2.$nUp.4 { |
1569 execsql { PRAGMA integrity_check } db2 | 1650 execsql { PRAGMA integrity_check } db2 |
1570 } {ok} | 1651 } {ok} |
1571 db2 close | 1652 db2 close |
1572 } | 1653 } |
| 1654 } |
1573 | 1655 |
| 1656 if {$::tcl_platform(platform)!="windows"} { |
1574 # Same test as above. But this time with an index on the table. | 1657 # Same test as above. But this time with an index on the table. |
1575 # | 1658 # |
1576 do_execsql_test pager1-13.2.1 { | 1659 do_execsql_test pager1-13.2.1 { |
1577 CREATE INDEX i1 ON t1(b); | 1660 CREATE INDEX i1 ON t1(b); |
1578 UPDATE t1 SET b = a_string(400); | 1661 UPDATE t1 SET b = a_string(400); |
1579 } {} | 1662 } {} |
1580 for {set nUp 1} {$nUp<64} {incr nUp} { | 1663 for {set nUp 1} {$nUp<64} {incr nUp} { |
1581 do_execsql_test pager1-13.2.2.$nUp.1 { | 1664 do_execsql_test pager1-13.2.2.$nUp.1 { |
1582 UPDATE t1 SET b = a_string(399) WHERE a <= $nUp | 1665 UPDATE t1 SET b = a_string(399) WHERE a <= $nUp |
1583 } {} | 1666 } {} |
1584 do_execsql_test pager1-13.2.2.$nUp.2 { PRAGMA integrity_check } {ok} | 1667 do_execsql_test pager1-13.2.2.$nUp.2 { PRAGMA integrity_check } {ok} |
1585 sqlite3 db2 sv_test.db | 1668 sqlite3 db2 sv_test.db |
1586 do_test pager1-13.2.2.$nUp.3 { | 1669 do_test pager1-13.2.2.$nUp.3 { |
1587 execsql { SELECT sum(length(b)) FROM t1 } db2 | 1670 execsql { SELECT sum(length(b)) FROM t1 } db2 |
1588 } [expr {128*400 - ($nUp-1)}] | 1671 } [expr {128*400 - ($nUp-1)}] |
1589 do_test pager1-13.2.2.$nUp.4 { | 1672 do_test pager1-13.2.2.$nUp.4 { |
1590 execsql { PRAGMA integrity_check } db2 | 1673 execsql { PRAGMA integrity_check } db2 |
1591 } {ok} | 1674 } {ok} |
1592 db2 close | 1675 db2 close |
1593 } | 1676 } |
| 1677 } |
1594 | 1678 |
1595 db close | 1679 db close |
1596 tv delete | 1680 tv delete |
1597 | 1681 |
1598 #------------------------------------------------------------------------- | 1682 #------------------------------------------------------------------------- |
1599 # Test specal "PRAGMA journal_mode=OFF" test cases. | 1683 # Test specal "PRAGMA journal_mode=OFF" test cases. |
1600 # | 1684 # |
1601 faultsim_delete_and_reopen | 1685 faultsim_delete_and_reopen |
1602 do_execsql_test pager1-14.1.1 { | 1686 do_execsql_test pager1-14.1.1 { |
1603 PRAGMA journal_mode = OFF; | 1687 PRAGMA journal_mode = OFF; |
1604 CREATE TABLE t1(a, b); | 1688 CREATE TABLE t1(a, b); |
1605 BEGIN; | 1689 BEGIN; |
1606 INSERT INTO t1 VALUES(1, 2); | 1690 INSERT INTO t1 VALUES(1, 2); |
1607 COMMIT; | 1691 COMMIT; |
1608 SELECT * FROM t1; | 1692 SELECT * FROM t1; |
1609 } {off 1 2} | 1693 } {off 1 2} |
1610 do_catchsql_test pager1-14.1.2 { | 1694 do_catchsql_test pager1-14.1.2 { |
1611 BEGIN; | 1695 BEGIN; |
1612 INSERT INTO t1 VALUES(3, 4); | 1696 INSERT INTO t1 VALUES(3, 4); |
1613 ROLLBACK; | 1697 ROLLBACK; |
1614 } {0 {}} | 1698 } {0 {}} |
1615 do_execsql_test pager1-14.1.3 { | 1699 do_execsql_test pager1-14.1.3 { |
1616 SELECT * FROM t1; | 1700 SELECT * FROM t1; |
1617 } {1 2} | 1701 } {1 2} |
1618 do_catchsql_test pager1-14.1.4 { | 1702 do_catchsql_test pager1-14.1.4 { |
1619 BEGIN; | 1703 BEGIN; |
1620 INSERT INTO t1(rowid, a, b) SELECT a+3, b, b FROM t1; | 1704 INSERT INTO t1(rowid, a, b) SELECT a+3, b, b FROM t1; |
1621 INSERT INTO t1(rowid, a, b) SELECT a+3, b, b FROM t1; | 1705 INSERT INTO t1(rowid, a, b) SELECT a+3, b, b FROM t1; |
1622 } {1 {PRIMARY KEY must be unique}} | 1706 } {1 {UNIQUE constraint failed: t1.rowid}} |
1623 do_execsql_test pager1-14.1.5 { | 1707 do_execsql_test pager1-14.1.5 { |
1624 COMMIT; | 1708 COMMIT; |
1625 SELECT * FROM t1; | 1709 SELECT * FROM t1; |
1626 } {1 2 2 2} | 1710 } {1 2 2 2} |
1627 | 1711 |
1628 #------------------------------------------------------------------------- | 1712 #------------------------------------------------------------------------- |
1629 # Test opening and closing the pager sub-system with different values | 1713 # Test opening and closing the pager sub-system with different values |
1630 # for the sqlite3_vfs.szOsFile variable. | 1714 # for the sqlite3_vfs.szOsFile variable. |
1631 # | 1715 # |
1632 faultsim_delete_and_reopen | 1716 faultsim_delete_and_reopen |
(...skipping 13 matching lines...) Expand all Loading... |
1646 tv delete | 1730 tv delete |
1647 } | 1731 } |
1648 | 1732 |
1649 #------------------------------------------------------------------------- | 1733 #------------------------------------------------------------------------- |
1650 # Check that it is not possible to open a database file if the full path | 1734 # Check that it is not possible to open a database file if the full path |
1651 # to the associated journal file will be longer than sqlite3_vfs.mxPathname. | 1735 # to the associated journal file will be longer than sqlite3_vfs.mxPathname. |
1652 # | 1736 # |
1653 testvfs tv -default 1 | 1737 testvfs tv -default 1 |
1654 tv script xOpenCb | 1738 tv script xOpenCb |
1655 tv filter xOpen | 1739 tv filter xOpen |
1656 proc xOpenCb {method filename} { | 1740 proc xOpenCb {method filename args} { |
1657 set ::file_len [string length $filename] | 1741 set ::file_len [string length $filename] |
1658 } | 1742 } |
1659 sqlite3 db test.db | 1743 sqlite3 db test.db |
1660 db close | 1744 db close |
1661 tv delete | 1745 tv delete |
1662 | 1746 |
1663 for {set ii [expr $::file_len-5]} {$ii < [expr $::file_len+20]} {incr ii} { | 1747 for {set ii [expr $::file_len-5]} {$ii < [expr $::file_len+20]} {incr ii} { |
1664 testvfs tv -default 1 -mxpathname $ii | 1748 testvfs tv -default 1 -mxpathname $ii |
1665 | 1749 |
1666 # The length of the full path to file "test.db-journal" is ($::file_len+8). | 1750 # The length of the full path to file "test.db-journal" is ($::file_len+8). |
1667 # If the configured sqlite3_vfs.mxPathname value greater than or equal to | 1751 # If the configured sqlite3_vfs.mxPathname value greater than or equal to |
1668 # this, then the file can be opened. Otherwise, it cannot. | 1752 # this, then the file can be opened. Otherwise, it cannot. |
1669 # | 1753 # |
1670 if {$ii >= [expr $::file_len+8]} { | 1754 if {$ii >= [expr $::file_len+8]} { |
1671 set res {0 {}} | 1755 set res {0 {}} |
1672 } else { | 1756 } else { |
1673 set res {1 {unable to open database file}} | 1757 set res {1 {unable to open database file}} |
1674 } | 1758 } |
1675 | 1759 |
1676 do_test pager1-16.1.$ii { | 1760 do_test pager1-16.1.$ii { |
1677 list [catch { sqlite3 db test.db } msg] $msg | 1761 list [catch { sqlite3 db test.db } msg] $msg |
1678 } $res | 1762 } $res |
1679 | 1763 |
1680 catch {db close} | 1764 catch {db close} |
1681 tv delete | 1765 tv delete |
1682 } | 1766 } |
1683 | 1767 |
1684 #------------------------------------------------------------------------- | |
1685 # Test "PRAGMA omit_readlock". | |
1686 # | |
1687 # pager1-17.$tn.1.*: Test that if a second connection has an open | |
1688 # read-transaction, it is not usually possible to write | |
1689 # the database. | |
1690 # | |
1691 # pager1-17.$tn.2.*: Test that if the second connection was opened with | |
1692 # the SQLITE_OPEN_READONLY flag, and | |
1693 # "PRAGMA omit_readlock = 1" is executed before attaching | |
1694 # the database and opening a read-transaction on it, it is | |
1695 # possible to write the db. | |
1696 # | |
1697 # pager1-17.$tn.3.*: Test that if the second connection was *not* opened with | |
1698 # the SQLITE_OPEN_READONLY flag, executing | |
1699 # "PRAGMA omit_readlock = 1" has no effect. | |
1700 # | |
1701 do_multiclient_test tn { | |
1702 do_test pager1-17.$tn.1.1 { | |
1703 sql1 { | |
1704 CREATE TABLE t1(a, b); | |
1705 INSERT INTO t1 VALUES(1, 2); | |
1706 } | |
1707 sql2 { | |
1708 BEGIN; | |
1709 SELECT * FROM t1; | |
1710 } | |
1711 } {1 2} | |
1712 do_test pager1-17.$tn.1.2 { | |
1713 csql1 { INSERT INTO t1 VALUES(3, 4) } | |
1714 } {1 {database is locked}} | |
1715 do_test pager1-17.$tn.1.3 { | |
1716 sql2 { COMMIT } | |
1717 sql1 { INSERT INTO t1 VALUES(3, 4) } | |
1718 } {} | |
1719 | |
1720 do_test pager1-17.$tn.2.1 { | |
1721 code2 { | |
1722 db2 close | |
1723 sqlite3 db2 :memory: -readonly 1 | |
1724 } | |
1725 sql2 { | |
1726 PRAGMA omit_readlock = 1; | |
1727 ATTACH 'test.db' AS two; | |
1728 BEGIN; | |
1729 SELECT * FROM t1; | |
1730 } | |
1731 } {1 2 3 4} | |
1732 do_test pager1-17.$tn.2.2 { sql1 "INSERT INTO t1 VALUES(5, 6)" } {} | |
1733 do_test pager1-17.$tn.2.3 { sql2 "SELECT * FROM t1" } {1 2 3 4} | |
1734 do_test pager1-17.$tn.2.4 { sql2 "COMMIT ; SELECT * FROM t1" } {1 2 3 4 5 6} | |
1735 | |
1736 do_test pager1-17.$tn.3.1 { | |
1737 code2 { | |
1738 db2 close | |
1739 sqlite3 db2 :memory: | |
1740 } | |
1741 sql2 { | |
1742 PRAGMA omit_readlock = 1; | |
1743 ATTACH 'test.db' AS two; | |
1744 BEGIN; | |
1745 SELECT * FROM t1; | |
1746 } | |
1747 } {1 2 3 4 5 6} | |
1748 do_test pager1-17.$tn.3.2 { | |
1749 csql1 { INSERT INTO t1 VALUES(3, 4) } | |
1750 } {1 {database is locked}} | |
1751 do_test pager1-17.$tn.3.3 { sql2 COMMIT } {} | |
1752 } | |
1753 | 1768 |
1754 #------------------------------------------------------------------------- | 1769 #------------------------------------------------------------------------- |
1755 # Test the pagers response to the b-tree layer requesting illegal page | 1770 # Test the pagers response to the b-tree layer requesting illegal page |
1756 # numbers: | 1771 # numbers: |
1757 # | 1772 # |
1758 # + The locking page, | 1773 # + The locking page, |
1759 # + Page 0, | 1774 # + Page 0, |
1760 # + A page with a page number greater than (2^31-1). | 1775 # + A page with a page number greater than (2^31-1). |
1761 # | 1776 # |
| 1777 # These tests will not work if SQLITE_DIRECT_OVERFLOW_READ is defined. In |
| 1778 # that case IO errors are sometimes reported instead of SQLITE_CORRUPT. |
| 1779 # |
| 1780 ifcapable !direct_read { |
1762 do_test pager1-18.1 { | 1781 do_test pager1-18.1 { |
1763 faultsim_delete_and_reopen | 1782 faultsim_delete_and_reopen |
1764 db func a_string a_string | 1783 db func a_string a_string |
1765 execsql { | 1784 execsql { |
1766 PRAGMA page_size = 1024; | 1785 PRAGMA page_size = 1024; |
1767 CREATE TABLE t1(a, b); | 1786 CREATE TABLE t1(a, b); |
1768 INSERT INTO t1 VALUES(a_string(500), a_string(200)); | 1787 INSERT INTO t1 VALUES(a_string(500), a_string(200)); |
1769 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; | 1788 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; |
1770 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; | 1789 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; |
1771 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; | 1790 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; |
1772 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; | 1791 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; |
1773 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; | 1792 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; |
1774 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; | 1793 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; |
1775 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; | 1794 INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1; |
1776 } | 1795 } |
1777 } {} | 1796 } {} |
1778 do_test pager1-18.2 { | 1797 do_test pager1-18.2 { |
1779 set root [db one "SELECT rootpage FROM sqlite_master"] | 1798 set root [db one "SELECT rootpage FROM sqlite_master"] |
1780 set lockingpage [expr (0x10000/1024) + 1] | 1799 set lockingpage [expr (0x10000/1024) + 1] |
1781 execsql { | 1800 execsql { |
1782 PRAGMA writable_schema = 1; | 1801 PRAGMA writable_schema = 1; |
1783 UPDATE sqlite_master SET rootpage = $lockingpage; | 1802 UPDATE sqlite_master SET rootpage = $lockingpage; |
1784 } | 1803 } |
1785 sqlite3 db2 test.db | 1804 sqlite3 db2 test.db |
1786 catchsql { SELECT count(*) FROM t1 } db2 | 1805 catchsql { SELECT count(*) FROM t1 } db2 |
1787 } {1 {database disk image is malformed}} | 1806 } {1 {database disk image is malformed}} |
1788 db2 close | 1807 db2 close |
1789 do_test pager1-18.3 { | 1808 do_test pager1-18.3.1 { |
1790 execsql { | 1809 execsql { |
1791 CREATE TABLE t2(x); | 1810 CREATE TABLE t2(x); |
1792 INSERT INTO t2 VALUES(a_string(5000)); | 1811 INSERT INTO t2 VALUES(a_string(5000)); |
1793 } | 1812 } |
1794 set pgno [expr ([file size test.db] / 1024)-2] | 1813 set pgno [expr ([file size test.db] / 1024)-2] |
1795 hexio_write test.db [expr ($pgno-1)*1024] 00000000 | 1814 hexio_write test.db [expr ($pgno-1)*1024] 00000000 |
1796 sqlite3 db2 test.db | 1815 sqlite3 db2 test.db |
1797 catchsql { SELECT length(x) FROM t2 } db2 | 1816 # even though x is malformed, because typeof() does |
| 1817 # not load the content of x, the error is not noticed. |
| 1818 catchsql { SELECT typeof(x) FROM t2 } db2 |
| 1819 } {0 text} |
| 1820 do_test pager1-18.3.2 { |
| 1821 # in this case, the value of x is loaded and so the error is |
| 1822 # detected |
| 1823 catchsql { SELECT length(x||'') FROM t2 } db2 |
| 1824 } {1 {database disk image is malformed}} |
| 1825 db2 close |
| 1826 do_test pager1-18.3.3 { |
| 1827 execsql { |
| 1828 DELETE FROM t2; |
| 1829 INSERT INTO t2 VALUES(randomblob(5000)); |
| 1830 } |
| 1831 set pgno [expr ([file size test.db] / 1024)-2] |
| 1832 hexio_write test.db [expr ($pgno-1)*1024] 00000000 |
| 1833 sqlite3 db2 test.db |
| 1834 # even though x is malformed, because length() and typeof() do |
| 1835 # not load the content of x, the error is not noticed. |
| 1836 catchsql { SELECT length(x), typeof(x) FROM t2 } db2 |
| 1837 } {0 {5000 blob}} |
| 1838 do_test pager1-18.3.4 { |
| 1839 # in this case, the value of x is loaded and so the error is |
| 1840 # detected |
| 1841 catchsql { SELECT length(x||'') FROM t2 } db2 |
1798 } {1 {database disk image is malformed}} | 1842 } {1 {database disk image is malformed}} |
1799 db2 close | 1843 db2 close |
1800 do_test pager1-18.4 { | 1844 do_test pager1-18.4 { |
1801 hexio_write test.db [expr ($pgno-1)*1024] 90000000 | 1845 hexio_write test.db [expr ($pgno-1)*1024] 90000000 |
1802 sqlite3 db2 test.db | 1846 sqlite3 db2 test.db |
1803 catchsql { SELECT length(x) FROM t2 } db2 | 1847 catchsql { SELECT length(x||'') FROM t2 } db2 |
1804 } {1 {database disk image is malformed}} | 1848 } {1 {database disk image is malformed}} |
1805 db2 close | 1849 db2 close |
1806 do_test pager1-18.5 { | 1850 do_test pager1-18.5 { |
1807 sqlite3 db "" | 1851 sqlite3 db "" |
1808 execsql { | 1852 execsql { |
1809 CREATE TABLE t1(a, b); | 1853 CREATE TABLE t1(a, b); |
1810 CREATE TABLE t2(a, b); | 1854 CREATE TABLE t2(a, b); |
1811 PRAGMA writable_schema = 1; | 1855 PRAGMA writable_schema = 1; |
1812 UPDATE sqlite_master SET rootpage=5 WHERE tbl_name = 't1'; | 1856 UPDATE sqlite_master SET rootpage=5 WHERE tbl_name = 't1'; |
1813 PRAGMA writable_schema = 0; | 1857 PRAGMA writable_schema = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
1827 INSERT INTO t1 VALUES(a_string(800)); | 1871 INSERT INTO t1 VALUES(a_string(800)); |
1828 } | 1872 } |
1829 | 1873 |
1830 set root [db one "SELECT rootpage FROM sqlite_master"] | 1874 set root [db one "SELECT rootpage FROM sqlite_master"] |
1831 db close | 1875 db close |
1832 | 1876 |
1833 hexio_write test.db [expr ($root-1)*1024 + 8] 00000000 | 1877 hexio_write test.db [expr ($root-1)*1024 + 8] 00000000 |
1834 sqlite3 db test.db | 1878 sqlite3 db test.db |
1835 catchsql { SELECT length(x) FROM t1 } | 1879 catchsql { SELECT length(x) FROM t1 } |
1836 } {1 {database disk image is malformed}} | 1880 } {1 {database disk image is malformed}} |
| 1881 } |
1837 | 1882 |
1838 do_test pager1-19.1 { | 1883 do_test pager1-19.1 { |
1839 sqlite3 db "" | 1884 sqlite3 db "" |
1840 db func a_string a_string | 1885 db func a_string a_string |
1841 execsql { | 1886 execsql { |
1842 PRAGMA page_size = 512; | 1887 PRAGMA page_size = 512; |
1843 PRAGMA auto_vacuum = 1; | 1888 PRAGMA auto_vacuum = 1; |
1844 CREATE TABLE t1(aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, | 1889 CREATE TABLE t1(aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, |
1845 ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk, bl, bm, bn, | 1890 ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk, bl, bm, bn, |
1846 ca, cb, cc, cd, ce, cf, cg, ch, ci, cj, ck, cl, cm, cn, | 1891 ca, cb, cc, cd, ce, cf, cg, ch, ci, cj, ck, cl, cm, cn, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1978 db2 close | 2023 db2 close |
1979 tv delete | 2024 tv delete |
1980 } | 2025 } |
1981 | 2026 |
1982 #------------------------------------------------------------------------- | 2027 #------------------------------------------------------------------------- |
1983 # Test that a "PRAGMA wal_checkpoint": | 2028 # Test that a "PRAGMA wal_checkpoint": |
1984 # | 2029 # |
1985 # pager1-22.1.*: is a no-op on a non-WAL db, and | 2030 # pager1-22.1.*: is a no-op on a non-WAL db, and |
1986 # pager1-22.2.*: does not cause xSync calls with a synchronous=off db. | 2031 # pager1-22.2.*: does not cause xSync calls with a synchronous=off db. |
1987 # | 2032 # |
1988 do_test pager1-22.1.1 { | 2033 ifcapable wal { |
1989 faultsim_delete_and_reopen | 2034 do_test pager1-22.1.1 { |
1990 execsql { | 2035 faultsim_delete_and_reopen |
1991 CREATE TABLE ko(c DEFAULT 'abc', b DEFAULT 'def'); | 2036 execsql { |
1992 INSERT INTO ko DEFAULT VALUES; | 2037 CREATE TABLE ko(c DEFAULT 'abc', b DEFAULT 'def'); |
1993 } | 2038 INSERT INTO ko DEFAULT VALUES; |
1994 execsql { PRAGMA wal_checkpoint } | 2039 } |
1995 } {0 -1 -1} | 2040 execsql { PRAGMA wal_checkpoint } |
1996 do_test pager1-22.2.1 { | 2041 } {0 -1 -1} |
1997 testvfs tv -default 1 | 2042 do_test pager1-22.2.1 { |
1998 tv filter xSync | 2043 testvfs tv -default 1 |
1999 tv script xSyncCb | 2044 tv filter xSync |
2000 proc xSyncCb {args} {incr ::synccount} | 2045 tv script xSyncCb |
2001 set ::synccount 0 | 2046 proc xSyncCb {args} {incr ::synccount} |
2002 sqlite3 db test.db | 2047 set ::synccount 0 |
2003 execsql { | 2048 sqlite3 db test.db |
2004 PRAGMA synchronous = off; | 2049 execsql { |
2005 PRAGMA journal_mode = WAL; | 2050 PRAGMA synchronous = off; |
2006 INSERT INTO ko DEFAULT VALUES; | 2051 PRAGMA journal_mode = WAL; |
2007 } | 2052 INSERT INTO ko DEFAULT VALUES; |
2008 execsql { PRAGMA wal_checkpoint } | 2053 } |
2009 set synccount | 2054 execsql { PRAGMA wal_checkpoint } |
2010 } {0} | 2055 set synccount |
2011 db close | 2056 } {0} |
2012 tv delete | 2057 db close |
| 2058 tv delete |
| 2059 } |
2013 | 2060 |
2014 #------------------------------------------------------------------------- | 2061 #------------------------------------------------------------------------- |
2015 # Tests for changing journal mode. | 2062 # Tests for changing journal mode. |
2016 # | 2063 # |
2017 # pager1-23.1.*: Test that when changing from PERSIST to DELETE mode, | 2064 # pager1-23.1.*: Test that when changing from PERSIST to DELETE mode, |
2018 # the journal file is deleted. | 2065 # the journal file is deleted. |
2019 # | 2066 # |
2020 # pager1-23.2.*: Same test as above, but while a shared lock is held | 2067 # pager1-23.2.*: Same test as above, but while a shared lock is held |
2021 # on the database file. | 2068 # on the database file. |
2022 # | 2069 # |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2191 faultsim_delete_and_reopen | 2238 faultsim_delete_and_reopen |
2192 execsql { | 2239 execsql { |
2193 BEGIN; | 2240 BEGIN; |
2194 SAVEPOINT abc; | 2241 SAVEPOINT abc; |
2195 CREATE TABLE t1(a, b); | 2242 CREATE TABLE t1(a, b); |
2196 ROLLBACK TO abc; | 2243 ROLLBACK TO abc; |
2197 COMMIT; | 2244 COMMIT; |
2198 } | 2245 } |
2199 db close | 2246 db close |
2200 } {} | 2247 } {} |
2201 breakpoint | |
2202 do_test pager1-25-2 { | 2248 do_test pager1-25-2 { |
2203 faultsim_delete_and_reopen | 2249 faultsim_delete_and_reopen |
2204 execsql { | 2250 execsql { |
2205 SAVEPOINT abc; | 2251 SAVEPOINT abc; |
2206 CREATE TABLE t1(a, b); | 2252 CREATE TABLE t1(a, b); |
2207 ROLLBACK TO abc; | 2253 ROLLBACK TO abc; |
2208 COMMIT; | 2254 COMMIT; |
2209 } | 2255 } |
2210 db close | 2256 db close |
2211 } {} | 2257 } {} |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2354 } [expr 4096*3] | 2400 } [expr 4096*3] |
2355 | 2401 |
2356 #------------------------------------------------------------------------- | 2402 #------------------------------------------------------------------------- |
2357 # Test that if an empty database file (size 0 bytes) is opened in | 2403 # Test that if an empty database file (size 0 bytes) is opened in |
2358 # exclusive-locking mode, any journal file is deleted from the file-system | 2404 # exclusive-locking mode, any journal file is deleted from the file-system |
2359 # without being rolled back. And that the RESERVED lock obtained while | 2405 # without being rolled back. And that the RESERVED lock obtained while |
2360 # doing this is not released. | 2406 # doing this is not released. |
2361 # | 2407 # |
2362 do_test pager1-30.1 { | 2408 do_test pager1-30.1 { |
2363 db close | 2409 db close |
2364 file delete test.db | 2410 delete_file test.db |
2365 file delete test.db-journal | 2411 delete_file test.db-journal |
2366 set fd [open test.db-journal w] | 2412 set fd [open test.db-journal w] |
2367 seek $fd [expr 512+1032*2] | 2413 seek $fd [expr 512+1032*2] |
2368 puts -nonewline $fd x | 2414 puts -nonewline $fd x |
2369 close $fd | 2415 close $fd |
2370 | 2416 |
2371 sqlite3 db test.db | 2417 sqlite3 db test.db |
2372 execsql { | 2418 execsql { |
2373 PRAGMA locking_mode=EXCLUSIVE; | 2419 PRAGMA locking_mode=EXCLUSIVE; |
2374 SELECT count(*) FROM sqlite_master; | 2420 SELECT count(*) FROM sqlite_master; |
2375 PRAGMA lock_status; | 2421 PRAGMA lock_status; |
2376 } | 2422 } |
2377 } {exclusive 0 main reserved temp closed} | 2423 } {exclusive 0 main reserved temp closed} |
2378 | 2424 |
2379 #------------------------------------------------------------------------- | 2425 #------------------------------------------------------------------------- |
2380 # Test that if the "page-size" field in a journal-header is 0, the journal | 2426 # Test that if the "page-size" field in a journal-header is 0, the journal |
2381 # file can still be rolled back. This is required for backward compatibility - | 2427 # file can still be rolled back. This is required for backward compatibility - |
2382 # versions of SQLite prior to 3.5.8 always set this field to zero. | 2428 # versions of SQLite prior to 3.5.8 always set this field to zero. |
2383 # | 2429 # |
| 2430 if {$tcl_platform(platform)=="unix"} { |
2384 do_test pager1-31.1 { | 2431 do_test pager1-31.1 { |
2385 faultsim_delete_and_reopen | 2432 faultsim_delete_and_reopen |
2386 execsql { | 2433 execsql { |
2387 PRAGMA cache_size = 10; | 2434 PRAGMA cache_size = 10; |
2388 PRAGMA page_size = 1024; | 2435 PRAGMA page_size = 1024; |
2389 CREATE TABLE t1(x, y, UNIQUE(x, y)); | 2436 CREATE TABLE t1(x, y, UNIQUE(x, y)); |
2390 INSERT INTO t1 VALUES(randomblob(1500), randomblob(1500)); | 2437 INSERT INTO t1 VALUES(randomblob(1500), randomblob(1500)); |
2391 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; | 2438 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; |
2392 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; | 2439 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; |
2393 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; | 2440 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; |
2394 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; | 2441 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; |
2395 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; | 2442 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; |
2396 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; | 2443 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; |
2397 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; | 2444 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; |
2398 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; | 2445 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; |
2399 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; | 2446 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; |
2400 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; | 2447 INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1; |
2401 BEGIN; | 2448 BEGIN; |
2402 UPDATE t1 SET y = randomblob(1499); | 2449 UPDATE t1 SET y = randomblob(1499); |
2403 } | 2450 } |
2404 file copy test.db test.db2 | 2451 copy_file test.db test.db2 |
2405 file copy test.db-journal test.db2-journal | 2452 copy_file test.db-journal test.db2-journal |
2406 | 2453 |
2407 hexio_write test.db2-journal 24 00000000 | 2454 hexio_write test.db2-journal 24 00000000 |
2408 sqlite3 db2 test.db2 | 2455 sqlite3 db2 test.db2 |
2409 execsql { PRAGMA integrity_check } db2 | 2456 execsql { PRAGMA integrity_check } db2 |
2410 } {ok} | 2457 } {ok} |
2411 | 2458 } |
2412 | 2459 |
| 2460 #------------------------------------------------------------------------- |
| 2461 # Test that a database file can be "pre-hinted" to a certain size and that |
| 2462 # subsequent spilling of the pager cache does not result in the database |
| 2463 # file being shrunk. |
| 2464 # |
| 2465 catch {db close} |
| 2466 forcedelete test.db |
| 2467 |
| 2468 do_test pager1-32.1 { |
| 2469 sqlite3 db test.db |
| 2470 execsql { |
| 2471 CREATE TABLE t1(x, y); |
| 2472 } |
| 2473 db close |
| 2474 sqlite3 db test.db |
| 2475 execsql { |
| 2476 BEGIN; |
| 2477 INSERT INTO t1 VALUES(1, randomblob(10000)); |
| 2478 } |
| 2479 file_control_chunksize_test db main 1024 |
| 2480 file_control_sizehint_test db main 20971520; # 20MB |
| 2481 execsql { |
| 2482 PRAGMA cache_size = 10; |
| 2483 INSERT INTO t1 VALUES(1, randomblob(10000)); |
| 2484 INSERT INTO t1 VALUES(2, randomblob(10000)); |
| 2485 INSERT INTO t1 SELECT x+2, randomblob(10000) from t1; |
| 2486 INSERT INTO t1 SELECT x+4, randomblob(10000) from t1; |
| 2487 INSERT INTO t1 SELECT x+8, randomblob(10000) from t1; |
| 2488 INSERT INTO t1 SELECT x+16, randomblob(10000) from t1; |
| 2489 SELECT count(*) FROM t1; |
| 2490 COMMIT; |
| 2491 } |
| 2492 db close |
| 2493 file size test.db |
| 2494 } {20971520} |
| 2495 |
| 2496 # Cleanup 20MB file left by the previous test. |
| 2497 forcedelete test.db |
| 2498 |
| 2499 #------------------------------------------------------------------------- |
| 2500 # Test that if a transaction is committed in journal_mode=DELETE mode, |
| 2501 # and the call to unlink() returns an ENOENT error, the COMMIT does not |
| 2502 # succeed. |
| 2503 # |
| 2504 if {$::tcl_platform(platform)=="unix"} { |
| 2505 do_test pager1-33.1 { |
| 2506 sqlite3 db test.db |
| 2507 execsql { |
| 2508 CREATE TABLE t1(x); |
| 2509 INSERT INTO t1 VALUES('one'); |
| 2510 INSERT INTO t1 VALUES('two'); |
| 2511 BEGIN; |
| 2512 INSERT INTO t1 VALUES('three'); |
| 2513 INSERT INTO t1 VALUES('four'); |
| 2514 } |
| 2515 forcedelete bak-journal |
| 2516 file rename test.db-journal bak-journal |
| 2517 |
| 2518 catchsql COMMIT |
| 2519 } {1 {disk I/O error}} |
| 2520 |
| 2521 do_test pager1-33.2 { |
| 2522 file rename bak-journal test.db-journal |
| 2523 execsql { SELECT * FROM t1 } |
| 2524 } {one two} |
| 2525 } |
| 2526 |
| 2527 #------------------------------------------------------------------------- |
| 2528 # Test that appending pages to the database file then moving those pages |
| 2529 # to the free-list before the transaction is committed does not cause |
| 2530 # an error. |
| 2531 # |
| 2532 foreach {tn pragma strsize} { |
| 2533 1 { PRAGMA mmap_size = 0 } 2400 |
| 2534 2 { } 2400 |
| 2535 3 { PRAGMA mmap_size = 0 } 4400 |
| 2536 4 { } 4400 |
| 2537 } { |
| 2538 reset_db |
| 2539 db func a_string a_string |
| 2540 db eval $pragma |
| 2541 do_execsql_test 34.$tn.1 { |
| 2542 CREATE TABLE t1(a, b); |
| 2543 INSERT INTO t1 VALUES(1, 2); |
| 2544 } |
| 2545 do_execsql_test 34.$tn.2 { |
| 2546 BEGIN; |
| 2547 INSERT INTO t1 VALUES(2, a_string($strsize)); |
| 2548 DELETE FROM t1 WHERE oid=2; |
| 2549 COMMIT; |
| 2550 PRAGMA integrity_check; |
| 2551 } {ok} |
| 2552 } |
| 2553 |
| 2554 #------------------------------------------------------------------------- |
| 2555 # |
| 2556 reset_db |
| 2557 do_test 35 { |
| 2558 sqlite3 db test.db |
| 2559 |
| 2560 execsql { |
| 2561 CREATE TABLE t1(x, y); |
| 2562 PRAGMA journal_mode = WAL; |
| 2563 INSERT INTO t1 VALUES(1, 2); |
| 2564 } |
| 2565 |
| 2566 execsql { |
| 2567 BEGIN; |
| 2568 CREATE TABLE t2(a, b); |
| 2569 } |
| 2570 |
| 2571 hexio_write test.db-shm [expr 16*1024] [string repeat 0055 8192] |
| 2572 catchsql ROLLBACK |
| 2573 } {0 {}} |
| 2574 |
| 2575 do_multiclient_test tn { |
| 2576 sql1 { |
| 2577 PRAGMA auto_vacuum = 0; |
| 2578 CREATE TABLE t1(x, y); |
| 2579 INSERT INTO t1 VALUES(1, 2); |
| 2580 } |
| 2581 |
| 2582 do_test 36.$tn.1 { |
| 2583 sql2 { PRAGMA max_page_count = 2 } |
| 2584 list [catch { sql2 { CREATE TABLE t2(x) } } msg] $msg |
| 2585 } {1 {database or disk is full}} |
| 2586 |
| 2587 sql1 { PRAGMA checkpoint_fullfsync = 1 } |
| 2588 sql1 { CREATE TABLE t2(x) } |
| 2589 |
| 2590 do_test 36.$tn.2 { |
| 2591 sql2 { INSERT INTO t2 VALUES('xyz') } |
| 2592 list [catch { sql2 { CREATE TABLE t3(x) } } msg] $msg |
| 2593 } {1 {database or disk is full}} |
| 2594 } |
| 2595 |
| 2596 forcedelete test1 test2 |
| 2597 foreach {tn uri} { |
| 2598 1 {file:?mode=memory&cache=shared} |
| 2599 2 {file:one?mode=memory&cache=shared} |
| 2600 3 {file:test1?cache=shared} |
| 2601 4 {file:test2?another=parameter&yet=anotherone} |
| 2602 } { |
| 2603 do_test 37.$tn { |
| 2604 catch { db close } |
| 2605 sqlite3_shutdown |
| 2606 sqlite3_config_uri 1 |
| 2607 sqlite3 db $uri |
| 2608 |
| 2609 db eval { |
| 2610 CREATE TABLE t1(x); |
| 2611 INSERT INTO t1 VALUES(1); |
| 2612 SELECT * FROM t1; |
| 2613 } |
| 2614 } {1} |
| 2615 |
| 2616 do_execsql_test 37.$tn.2 { |
| 2617 VACUUM; |
| 2618 SELECT * FROM t1; |
| 2619 } {1} |
| 2620 |
| 2621 db close |
| 2622 sqlite3_shutdown |
| 2623 sqlite3_config_uri 0 |
| 2624 } |
| 2625 |
| 2626 do_test 38.1 { |
| 2627 catch { db close } |
| 2628 forcedelete test.db |
| 2629 set fd [open test.db w] |
| 2630 puts $fd "hello world" |
| 2631 close $fd |
| 2632 sqlite3 db test.db |
| 2633 catchsql { CREATE TABLE t1(x) } |
| 2634 } {1 {file is encrypted or is not a database}} |
| 2635 do_test 38.2 { |
| 2636 catch { db close } |
| 2637 forcedelete test.db |
| 2638 } {} |
| 2639 |
| 2640 do_test 39.1 { |
| 2641 sqlite3 db test.db |
| 2642 execsql { |
| 2643 PRAGMA auto_vacuum = 1; |
| 2644 CREATE TABLE t1(x); |
| 2645 INSERT INTO t1 VALUES('xxx'); |
| 2646 INSERT INTO t1 VALUES('two'); |
| 2647 INSERT INTO t1 VALUES(randomblob(400)); |
| 2648 INSERT INTO t1 VALUES(randomblob(400)); |
| 2649 INSERT INTO t1 VALUES(randomblob(400)); |
| 2650 INSERT INTO t1 VALUES(randomblob(400)); |
| 2651 BEGIN; |
| 2652 UPDATE t1 SET x = 'one' WHERE rowid=1; |
| 2653 } |
| 2654 set ::stmt [sqlite3_prepare db "SELECT * FROM t1 ORDER BY rowid" -1 dummy] |
| 2655 sqlite3_step $::stmt |
| 2656 sqlite3_column_text $::stmt 0 |
| 2657 } {one} |
| 2658 do_test 39.2 { |
| 2659 execsql { CREATE TABLE t2(x) } |
| 2660 sqlite3_step $::stmt |
| 2661 sqlite3_column_text $::stmt 0 |
| 2662 } {two} |
| 2663 do_test 39.3 { |
| 2664 sqlite3_finalize $::stmt |
| 2665 execsql COMMIT |
| 2666 } {} |
| 2667 |
| 2668 do_execsql_test 39.4 { |
| 2669 PRAGMA auto_vacuum = 2; |
| 2670 CREATE TABLE t3(x); |
| 2671 CREATE TABLE t4(x); |
| 2672 |
| 2673 DROP TABLE t2; |
| 2674 DROP TABLE t3; |
| 2675 DROP TABLE t4; |
| 2676 } |
| 2677 do_test 39.5 { |
| 2678 db close |
| 2679 sqlite3 db test.db |
| 2680 execsql { |
| 2681 PRAGMA cache_size = 1; |
| 2682 PRAGMA incremental_vacuum; |
| 2683 PRAGMA integrity_check; |
| 2684 } |
| 2685 } {ok} |
| 2686 |
| 2687 do_test 40.1 { |
| 2688 reset_db |
| 2689 execsql { |
| 2690 PRAGMA auto_vacuum = 1; |
| 2691 CREATE TABLE t1(x PRIMARY KEY); |
| 2692 INSERT INTO t1 VALUES(randomblob(1200)); |
| 2693 PRAGMA page_count; |
| 2694 } |
| 2695 } {6} |
| 2696 do_test 40.2 { |
| 2697 execsql { |
| 2698 INSERT INTO t1 VALUES(randomblob(1200)); |
| 2699 INSERT INTO t1 VALUES(randomblob(1200)); |
| 2700 INSERT INTO t1 VALUES(randomblob(1200)); |
| 2701 } |
| 2702 } {} |
| 2703 do_test 40.3 { |
| 2704 db close |
| 2705 sqlite3 db test.db |
| 2706 execsql { |
| 2707 PRAGMA cache_size = 1; |
| 2708 CREATE TABLE t2(x); |
| 2709 PRAGMA integrity_check; |
| 2710 } |
| 2711 } {ok} |
| 2712 |
| 2713 do_test 41.1 { |
| 2714 reset_db |
| 2715 execsql { |
| 2716 CREATE TABLE t1(x PRIMARY KEY); |
| 2717 INSERT INTO t1 VALUES(randomblob(200)); |
| 2718 INSERT INTO t1 SELECT randomblob(200) FROM t1; |
| 2719 INSERT INTO t1 SELECT randomblob(200) FROM t1; |
| 2720 INSERT INTO t1 SELECT randomblob(200) FROM t1; |
| 2721 INSERT INTO t1 SELECT randomblob(200) FROM t1; |
| 2722 INSERT INTO t1 SELECT randomblob(200) FROM t1; |
| 2723 INSERT INTO t1 SELECT randomblob(200) FROM t1; |
| 2724 } |
| 2725 } {} |
| 2726 do_test 41.2 { |
| 2727 testvfs tv -default 1 |
| 2728 tv sectorsize 16384; |
| 2729 tv devchar [list] |
| 2730 db close |
| 2731 sqlite3 db test.db |
| 2732 execsql { |
| 2733 PRAGMA cache_size = 1; |
| 2734 DELETE FROM t1 WHERE rowid%4; |
| 2735 PRAGMA integrity_check; |
| 2736 } |
| 2737 } {ok} |
| 2738 db close |
| 2739 tv delete |
| 2740 |
| 2741 set pending_prev [sqlite3_test_control_pending_byte 0x1000000] |
| 2742 do_test 42.1 { |
| 2743 reset_db |
| 2744 execsql { |
| 2745 CREATE TABLE t1(x, y); |
| 2746 INSERT INTO t1 VALUES(randomblob(200), randomblob(200)); |
| 2747 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2748 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2749 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2750 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2751 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2752 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2753 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2754 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2755 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2756 } |
| 2757 db close |
| 2758 sqlite3_test_control_pending_byte 0x0010000 |
| 2759 sqlite3 db test.db |
| 2760 db eval { PRAGMA mmap_size = 0 } |
| 2761 catchsql { SELECT sum(length(y)) FROM t1 } |
| 2762 } {1 {database disk image is malformed}} |
| 2763 do_test 42.2 { |
| 2764 reset_db |
| 2765 execsql { |
| 2766 CREATE TABLE t1(x, y); |
| 2767 INSERT INTO t1 VALUES(randomblob(200), randomblob(200)); |
| 2768 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2769 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2770 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2771 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2772 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2773 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2774 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2775 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1; |
| 2776 } |
| 2777 db close |
| 2778 |
| 2779 testvfs tv -default 1 |
| 2780 tv sectorsize 16384; |
| 2781 tv devchar [list] |
| 2782 sqlite3 db test.db -vfs tv |
| 2783 execsql { UPDATE t1 SET x = randomblob(200) } |
| 2784 } {} |
| 2785 db close |
| 2786 tv delete |
| 2787 sqlite3_test_control_pending_byte $pending_prev |
| 2788 |
| 2789 do_test 43.1 { |
| 2790 reset_db |
| 2791 execsql { |
| 2792 CREATE TABLE t1(x, y); |
| 2793 INSERT INTO t1 VALUES(1, 2); |
| 2794 CREATE TABLE t2(x, y); |
| 2795 INSERT INTO t2 VALUES(1, 2); |
| 2796 CREATE TABLE t3(x, y); |
| 2797 INSERT INTO t3 VALUES(1, 2); |
| 2798 } |
| 2799 db close |
| 2800 sqlite3 db test.db |
| 2801 |
| 2802 db eval { PRAGMA mmap_size = 0 } |
| 2803 db eval { SELECT * FROM t1 } |
| 2804 sqlite3_db_status db CACHE_MISS 0 |
| 2805 } {0 2 0} |
| 2806 |
| 2807 do_test 43.2 { |
| 2808 db eval { SELECT * FROM t2 } |
| 2809 sqlite3_db_status db CACHE_MISS 1 |
| 2810 } {0 3 0} |
| 2811 |
| 2812 do_test 43.3 { |
| 2813 db eval { SELECT * FROM t3 } |
| 2814 sqlite3_db_status db CACHE_MISS 0 |
| 2815 } {0 1 0} |
2413 | 2816 |
2414 finish_test | 2817 finish_test |
OLD | NEW |