OLD | NEW |
1 # 2001 September 15 | 1 # 2001 September 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 # This file implements regression tests for SQLite library. The | 11 # This file implements regression tests for SQLite library. The |
12 # focus of this script is database locks. | 12 # focus of this script is database locks. |
13 # | 13 # |
14 # $Id: trans.test,v 1.41 2009/04/28 16:37:59 danielk1977 Exp $ | 14 # $Id: trans.test,v 1.41 2009/04/28 16:37:59 danielk1977 Exp $ |
15 | 15 |
16 | 16 |
17 set testdir [file dirname $argv0] | 17 set testdir [file dirname $argv0] |
18 source $testdir/tester.tcl | 18 source $testdir/tester.tcl |
19 | 19 |
20 # Create several tables to work with. | 20 # Create several tables to work with. |
21 # | 21 # |
| 22 wal_set_journal_mode |
22 do_test trans-1.0 { | 23 do_test trans-1.0 { |
23 execsql { | 24 execsql { |
24 CREATE TABLE one(a int PRIMARY KEY, b text); | 25 CREATE TABLE one(a int PRIMARY KEY, b text); |
25 INSERT INTO one VALUES(1,'one'); | 26 INSERT INTO one VALUES(1,'one'); |
26 INSERT INTO one VALUES(2,'two'); | 27 INSERT INTO one VALUES(2,'two'); |
27 INSERT INTO one VALUES(3,'three'); | 28 INSERT INTO one VALUES(3,'three'); |
28 SELECT b FROM one ORDER BY a; | 29 SELECT b FROM one ORDER BY a; |
29 } | 30 } |
30 } {one two three} | 31 } {one two three} |
31 integrity_check trans-1.0.1 | 32 integrity_check trans-1.0.1 |
32 do_test trans-1.1 { | 33 do_test trans-1.1 { |
33 execsql { | 34 execsql { |
34 CREATE TABLE two(a int PRIMARY KEY, b text); | 35 CREATE TABLE two(a int PRIMARY KEY, b text); |
35 INSERT INTO two VALUES(1,'I'); | 36 INSERT INTO two VALUES(1,'I'); |
36 INSERT INTO two VALUES(5,'V'); | 37 INSERT INTO two VALUES(5,'V'); |
37 INSERT INTO two VALUES(10,'X'); | 38 INSERT INTO two VALUES(10,'X'); |
38 SELECT b FROM two ORDER BY a; | 39 SELECT b FROM two ORDER BY a; |
39 } | 40 } |
40 } {I V X} | 41 } {I V X} |
41 do_test trans-1.9 { | 42 do_test trans-1.9 { |
42 sqlite3 altdb test.db | 43 sqlite3 altdb test.db |
43 execsql {SELECT b FROM one ORDER BY a} altdb | 44 execsql {SELECT b FROM one ORDER BY a} altdb |
44 } {one two three} | 45 } {one two three} |
45 do_test trans-1.10 { | 46 do_test trans-1.10 { |
46 execsql {SELECT b FROM two ORDER BY a} altdb | 47 execsql {SELECT b FROM two ORDER BY a} altdb |
47 } {I V X} | 48 } {I V X} |
48 integrity_check trans-1.11 | 49 integrity_check trans-1.11 |
| 50 wal_check_journal_mode trans-1.12 |
49 | 51 |
50 # Basic transactions | 52 # Basic transactions |
51 # | 53 # |
52 do_test trans-2.1 { | 54 do_test trans-2.1 { |
53 set v [catch {execsql {BEGIN}} msg] | 55 set v [catch {execsql {BEGIN}} msg] |
54 lappend v $msg | 56 lappend v $msg |
55 } {0 {}} | 57 } {0 {}} |
56 do_test trans-2.2 { | 58 do_test trans-2.2 { |
57 set v [catch {execsql {END}} msg] | 59 set v [catch {execsql {END}} msg] |
58 lappend v $msg | 60 lappend v $msg |
(...skipping 16 matching lines...) Expand all Loading... |
75 } {0 {}} | 77 } {0 {}} |
76 do_test trans-2.10 { | 78 do_test trans-2.10 { |
77 execsql { | 79 execsql { |
78 BEGIN; | 80 BEGIN; |
79 SELECT a FROM one ORDER BY a; | 81 SELECT a FROM one ORDER BY a; |
80 SELECT a FROM two ORDER BY a; | 82 SELECT a FROM two ORDER BY a; |
81 END; | 83 END; |
82 } | 84 } |
83 } {1 2 3 1 5 10} | 85 } {1 2 3 1 5 10} |
84 integrity_check trans-2.11 | 86 integrity_check trans-2.11 |
| 87 wal_check_journal_mode trans-2.12 |
85 | 88 |
86 # Check the locking behavior | 89 # Check the locking behavior |
87 # | 90 # |
88 do_test trans-3.1 { | 91 do_test trans-3.1 { |
89 execsql { | 92 execsql { |
90 BEGIN; | 93 BEGIN; |
91 UPDATE one SET a = 0 WHERE 0; | 94 UPDATE one SET a = 0 WHERE 0; |
92 SELECT a FROM one ORDER BY a; | 95 SELECT a FROM one ORDER BY a; |
93 } | 96 } |
94 } {1 2 3} | 97 } {1 2 3} |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } db} msg] | 158 } db} msg] |
156 lappend v $msg | 159 lappend v $msg |
157 } {0 {1 4 5 10}} | 160 } {0 {1 4 5 10}} |
158 do_test trans-3.14 { | 161 do_test trans-3.14 { |
159 set v [catch {execsql { | 162 set v [catch {execsql { |
160 SELECT a FROM one ORDER BY a; | 163 SELECT a FROM one ORDER BY a; |
161 } db} msg] | 164 } db} msg] |
162 lappend v $msg | 165 lappend v $msg |
163 } {0 {1 2 3 4}} | 166 } {0 {1 2 3 4}} |
164 integrity_check trans-3.15 | 167 integrity_check trans-3.15 |
| 168 wal_check_journal_mode trans-3.16 |
165 | 169 |
166 do_test trans-4.1 { | 170 do_test trans-4.1 { |
167 set v [catch {execsql { | 171 set v [catch {execsql { |
168 COMMIT; | 172 COMMIT; |
169 } db} msg] | 173 } db} msg] |
170 lappend v $msg | 174 lappend v $msg |
171 } {1 {cannot commit - no transaction is active}} | 175 } {1 {cannot commit - no transaction is active}} |
172 do_test trans-4.2 { | 176 do_test trans-4.2 { |
173 set v [catch {execsql { | 177 set v [catch {execsql { |
174 ROLLBACK; | 178 ROLLBACK; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } altdb} msg] | 225 } altdb} msg] |
222 lappend v $msg | 226 lappend v $msg |
223 } {0 {1 4 5 10}} | 227 } {0 {1 4 5 10}} |
224 do_test trans-4.11 { | 228 do_test trans-4.11 { |
225 set v [catch {execsql { | 229 set v [catch {execsql { |
226 SELECT a FROM one ORDER BY a; | 230 SELECT a FROM one ORDER BY a; |
227 } altdb} msg] | 231 } altdb} msg] |
228 lappend v $msg | 232 lappend v $msg |
229 } {0 {1 2 3 4}} | 233 } {0 {1 2 3 4}} |
230 integrity_check trans-4.12 | 234 integrity_check trans-4.12 |
| 235 wal_check_journal_mode trans-4.13 |
| 236 wal_check_journal_mode trans-4.14 altdb |
231 do_test trans-4.98 { | 237 do_test trans-4.98 { |
232 altdb close | 238 altdb close |
233 execsql { | 239 execsql { |
234 DROP TABLE one; | 240 DROP TABLE one; |
235 DROP TABLE two; | 241 DROP TABLE two; |
236 } | 242 } |
237 } {} | 243 } {} |
238 integrity_check trans-4.99 | 244 integrity_check trans-4.99 |
239 | 245 |
240 # Check out the commit/rollback behavior of the database | 246 # Check out the commit/rollback behavior of the database |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 DROP TABLE t2; | 774 DROP TABLE t2; |
769 ROLLBACK; | 775 ROLLBACK; |
770 SELECT md5sum(x,y,z) FROM t2; | 776 SELECT md5sum(x,y,z) FROM t2; |
771 } | 777 } |
772 } $checksum | 778 } $checksum |
773 } | 779 } |
774 do_test trans-7.14 { | 780 do_test trans-7.14 { |
775 execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} | 781 execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} |
776 } $checksum2 | 782 } $checksum2 |
777 integrity_check trans-7.15 | 783 integrity_check trans-7.15 |
| 784 wal_check_journal_mode trans-7.16 |
778 | 785 |
779 # Arrange for another process to begin modifying the database but abort | 786 # Arrange for another process to begin modifying the database but abort |
780 # and die in the middle of the modification. Then have this process read | 787 # and die in the middle of the modification. Then have this process read |
781 # the database. This process should detect the journal file and roll it | 788 # the database. This process should detect the journal file and roll it |
782 # back. Verify that this happens correctly. | 789 # back. Verify that this happens correctly. |
783 # | 790 # |
784 set fd [open test.tcl w] | 791 set fd [open test.tcl w] |
785 puts $fd { | 792 puts $fd { |
786 sqlite3_test_control_pending_byte 0x0010000 | 793 sqlite3_test_control_pending_byte 0x0010000 |
787 sqlite3 db test.db | 794 sqlite3 db test.db |
(...skipping 29 matching lines...) Expand all Loading... |
817 } | 824 } |
818 close $fd | 825 close $fd |
819 do_test trans-8.4 { | 826 do_test trans-8.4 { |
820 catch {exec [info nameofexec] test.tcl} | 827 catch {exec [info nameofexec] test.tcl} |
821 execsql {SELECT md5sum(x,y,z) FROM t2} | 828 execsql {SELECT md5sum(x,y,z) FROM t2} |
822 } $checksum | 829 } $checksum |
823 do_test trans-8.5 { | 830 do_test trans-8.5 { |
824 execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} | 831 execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} |
825 } $checksum2 | 832 } $checksum2 |
826 integrity_check trans-8.6 | 833 integrity_check trans-8.6 |
827 | 834 wal_check_journal_mode trans-8.7 |
828 | 835 |
829 # In the following sequence of tests, compute the MD5 sum of the content | 836 # In the following sequence of tests, compute the MD5 sum of the content |
830 # of a table, make lots of modifications to that table, then do a rollback. | 837 # of a table, make lots of modifications to that table, then do a rollback. |
831 # Verify that after the rollback, the MD5 checksum is unchanged. | 838 # Verify that after the rollback, the MD5 checksum is unchanged. |
832 # | 839 # |
833 do_test trans-9.1 { | 840 do_test trans-9.1 { |
834 execsql { | 841 execsql { |
835 PRAGMA default_cache_size=10; | 842 PRAGMA default_cache_size=10; |
836 } | 843 } |
837 db close | 844 db close |
838 sqlite3 db test.db | 845 sqlite3 db test.db |
839 execsql { | 846 execsql { |
840 BEGIN; | 847 BEGIN; |
841 CREATE TABLE t3(x TEXT); | 848 CREATE TABLE t3(x TEXT); |
842 INSERT INTO t3 VALUES(randstr(10,400)); | 849 INSERT INTO t3 VALUES(randstr(10,400)); |
843 INSERT INTO t3 VALUES(randstr(10,400)); | 850 INSERT INTO t3 VALUES(randstr(10,400)); |
844 INSERT INTO t3 SELECT randstr(10,400) FROM t3; | 851 INSERT INTO t3 SELECT randstr(10,400) FROM t3; |
845 INSERT INTO t3 SELECT randstr(10,400) FROM t3; | 852 INSERT INTO t3 SELECT randstr(10,400) FROM t3; |
846 INSERT INTO t3 SELECT randstr(10,400) FROM t3; | 853 INSERT INTO t3 SELECT randstr(10,400) FROM t3; |
847 INSERT INTO t3 SELECT randstr(10,400) FROM t3; | 854 INSERT INTO t3 SELECT randstr(10,400) FROM t3; |
848 INSERT INTO t3 SELECT randstr(10,400) FROM t3; | 855 INSERT INTO t3 SELECT randstr(10,400) FROM t3; |
849 INSERT INTO t3 SELECT randstr(10,400) FROM t3; | 856 INSERT INTO t3 SELECT randstr(10,400) FROM t3; |
850 INSERT INTO t3 SELECT randstr(10,400) FROM t3; | 857 INSERT INTO t3 SELECT randstr(10,400) FROM t3; |
851 INSERT INTO t3 SELECT randstr(10,400) FROM t3; | 858 INSERT INTO t3 SELECT randstr(10,400) FROM t3; |
852 INSERT INTO t3 SELECT randstr(10,400) FROM t3; | 859 INSERT INTO t3 SELECT randstr(10,400) FROM t3; |
853 COMMIT; | 860 COMMIT; |
854 SELECT count(*) FROM t3; | 861 SELECT count(*) FROM t3; |
855 } | 862 } |
856 } {1024} | 863 } {1024} |
| 864 wal_check_journal_mode trans-9.1.1 |
857 | 865 |
858 # The following procedure computes a "signature" for table "t3". If | 866 # The following procedure computes a "signature" for table "t3". If |
859 # T3 changes in any way, the signature should change. | 867 # T3 changes in any way, the signature should change. |
860 # | 868 # |
861 # This is used to test ROLLBACK. We gather a signature for t3, then | 869 # This is used to test ROLLBACK. We gather a signature for t3, then |
862 # make lots of changes to t3, then rollback and take another signature. | 870 # make lots of changes to t3, then rollback and take another signature. |
863 # The two signatures should be the same. | 871 # The two signatures should be the same. |
864 # | 872 # |
865 proc signature {} { | 873 proc signature {} { |
866 return [db eval {SELECT count(*), md5sum(x) FROM t3}] | 874 return [db eval {SELECT count(*), md5sum(x) FROM t3}] |
867 } | 875 } |
868 | 876 |
869 # Repeat the following group of tests 20 times for quick testing and | 877 # Repeat the following group of tests 20 times for quick testing and |
870 # 40 times for full testing. Each iteration of the test makes table | 878 # 40 times for full testing. Each iteration of the test makes table |
871 # t3 a little larger, and thus takes a little longer, so doing 40 tests | 879 # t3 a little larger, and thus takes a little longer, so doing 40 tests |
872 # is more than 2.0 times slower than doing 20 tests. Considerably more. | 880 # is more than 2.0 times slower than doing 20 tests. Considerably more. |
873 # | 881 # |
874 # Also, if temporary tables are stored in memory and the test pcache | 882 # Also, if temporary tables are stored in memory and the test pcache |
875 # is in use, only 20 iterations. Otherwise the test pcache runs out | 883 # is in use, only 20 iterations. Otherwise the test pcache runs out |
876 # of page slots and SQLite reports "out of memory". | 884 # of page slots and SQLite reports "out of memory". |
877 # | 885 # |
878 if {[info exists ISQUICK] || ( | 886 if {[info exists G(isquick)] || ( |
879 $TEMP_STORE==3 && [catch {set ::permutations_test_prefix} val]==0 && | 887 $TEMP_STORE==3 && [regexp {^pcache[[:digit:]]*$} [permutation]] |
880 [regexp {^pcache[[:digit:]]*$} $val] | |
881 ) } { | 888 ) } { |
882 set limit 20 | 889 set limit 20 |
883 } elseif {[info exists SOAKTEST]} { | 890 } elseif {[info exists G(issoak)]} { |
884 set limit 100 | 891 set limit 100 |
885 } else { | 892 } else { |
886 set limit 40 | 893 set limit 40 |
887 } | 894 } |
888 | 895 |
889 # Do rollbacks. Make sure the signature does not change. | 896 # Do rollbacks. Make sure the signature does not change. |
890 # | 897 # |
891 for {set i 2} {$i<=$limit} {incr i} { | 898 for {set i 2} {$i<=$limit} {incr i} { |
892 set ::sig [signature] | 899 set ::sig [signature] |
893 set cnt [lindex $::sig 0] | 900 set cnt [lindex $::sig 0] |
(...skipping 24 matching lines...) Expand all Loading... |
918 ROLLBACK; | 925 ROLLBACK; |
919 } | 926 } |
920 signature | 927 signature |
921 } $sig | 928 } $sig |
922 if {$i<$limit} { | 929 if {$i<$limit} { |
923 do_test trans-9.$i.3-$cnt { | 930 do_test trans-9.$i.3-$cnt { |
924 execsql { | 931 execsql { |
925 INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0; | 932 INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0; |
926 } | 933 } |
927 } {} | 934 } {} |
| 935 catch flush_async_queue |
928 if {$tcl_platform(platform)=="unix"} { | 936 if {$tcl_platform(platform)=="unix"} { |
929 do_test trans-9.$i.4-$cnt { | 937 do_test trans-9.$i.4-$cnt { |
930 expr {$sqlite_sync_count>0} | 938 expr {$sqlite_sync_count>0} |
931 } 1 | 939 } 1 |
932 ifcapable pager_pragmas { | 940 ifcapable pager_pragmas { |
933 do_test trans-9.$i.5-$cnt { | 941 do_test trans-9.$i.5-$cnt { |
934 expr {$sqlite_fullsync_count>0} | 942 expr {$sqlite_fullsync_count>0} |
935 } [expr {$i%2==0}] | 943 } [expr {$i%2==0}] |
936 } else { | 944 } else { |
937 do_test trans-9.$i.5-$cnt { | 945 do_test trans-9.$i.5-$cnt { |
938 expr {$sqlite_fullsync_count==0} | 946 expr {$sqlite_fullsync_count==0} |
939 } {1} | 947 } {1} |
940 } | 948 } |
941 } | 949 } |
942 } | 950 } |
| 951 |
| 952 wal_check_journal_mode trans-9.$i.6-$cnt |
943 set ::pager_old_format 0 | 953 set ::pager_old_format 0 |
944 } | 954 } |
945 | 955 |
946 finish_test | 956 finish_test |
OLD | NEW |