OLD | NEW |
1 # 2009 January 30 | 1 # 2009 January 30 |
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 file is testing the sqlite3_backup_XXX API. | 12 # focus of this file is testing the sqlite3_backup_XXX API. |
13 # | 13 # |
14 # $Id: backup.test,v 1.11 2009/06/05 17:09:12 drh Exp $ | 14 # $Id: backup.test,v 1.11 2009/06/05 17:09:12 drh Exp $ |
15 | 15 |
16 set testdir [file dirname $argv0] | 16 set testdir [file dirname $argv0] |
17 source $testdir/tester.tcl | 17 source $testdir/tester.tcl |
18 | 18 |
| 19 do_not_use_codec |
| 20 |
19 #--------------------------------------------------------------------- | 21 #--------------------------------------------------------------------- |
20 # Test organization: | 22 # Test organization: |
21 # | 23 # |
22 # backup-1.*: Warm-body tests. | 24 # backup-1.*: Warm-body tests. |
23 # | 25 # |
24 # backup-2.*: Test backup under various conditions. To and from in-memory | 26 # backup-2.*: Test backup under various conditions. To and from in-memory |
25 # databases. To and from empty/populated databases. etc. | 27 # databases. To and from empty/populated databases. etc. |
26 # | 28 # |
27 # backup-3.*: Verify that the locking-page (pending byte page) is handled. | 29 # backup-3.*: Verify that the locking-page (pending byte page) is handled. |
28 # | 30 # |
29 # backup-4.*: Test various error conditions. | 31 # backup-4.*: Test various error conditions. |
30 # | 32 # |
31 # backup-5.*: Test the source database being modified during a backup. | 33 # backup-5.*: Test the source database being modified during a backup. |
32 # | 34 # |
33 # backup-6.*: Test the backup_remaining() and backup_pagecount() APIs. | 35 # backup-6.*: Test the backup_remaining() and backup_pagecount() APIs. |
34 # | 36 # |
35 # backup-7.*: Test SQLITE_BUSY and SQLITE_LOCKED errors. | 37 # backup-7.*: Test SQLITE_BUSY and SQLITE_LOCKED errors. |
36 # | 38 # |
37 # backup-8.*: Test multiple simultaneous backup operations. | 39 # backup-8.*: Test multiple simultaneous backup operations. |
38 # | 40 # |
39 # backup-9.*: Test that passing a negative argument to backup_step() is | 41 # backup-9.*: Test that passing a negative argument to backup_step() is |
40 # interpreted as "copy the whole file". | 42 # interpreted as "copy the whole file". |
| 43 # |
| 44 # backup-10.*: Test writing the source database mid backup. |
41 # | 45 # |
42 | 46 |
43 proc data_checksum {db file} { $db one "SELECT md5sum(a, b) FROM ${file}.t1" } | 47 proc data_checksum {db file} { $db one "SELECT md5sum(a, b) FROM ${file}.t1" } |
44 proc test_contents {name db1 file1 db2 file2} { | 48 proc test_contents {name db1 file1 db2 file2} { |
45 $db2 eval {select * from sqlite_master} | 49 $db2 eval {select * from sqlite_master} |
46 $db1 eval {select * from sqlite_master} | 50 $db1 eval {select * from sqlite_master} |
47 set checksum [data_checksum $db2 $file2] | 51 set checksum [data_checksum $db2 $file2] |
48 uplevel [list do_test $name [list data_checksum $db1 $file1] $checksum] | 52 uplevel [list do_test $name [list data_checksum $db1 $file1] $checksum] |
49 } | 53 } |
50 | 54 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 # Open the databases. | 170 # Open the databases. |
167 catch { file delete test.db } | 171 catch { file delete test.db } |
168 catch { file delete test2.db } | 172 catch { file delete test2.db } |
169 eval $zOpenScript | 173 eval $zOpenScript |
170 | 174 |
171 # Set to true if copying to an in-memory destination. Copying to an | 175 # Set to true if copying to an in-memory destination. Copying to an |
172 # in-memory destination is only possible if the initial destination | 176 # in-memory destination is only possible if the initial destination |
173 # page size is the same as the source page size (in this case 1024 bytes). | 177 # page size is the same as the source page size (in this case 1024 bytes). |
174 # | 178 # |
175 set isMemDest [expr { | 179 set isMemDest [expr { |
176 $zDestFile eq ":memory:" || $file_dest eq "temp" && $TEMP_STORE==3 | 180 $zDestFile eq ":memory:" || $file_dest eq "temp" && $TEMP_STORE>=2 |
177 }] | 181 }] |
178 | 182 |
179 if { $isMemDest==0 || $pgsz_dest == 1024 } { | 183 if { $isMemDest==0 || $pgsz_dest == 1024 } { |
180 if 0 { | 184 if 0 { |
181 puts -nonewline "Test $iTest: src=$zSrcFile dest=$zDestFile" | 185 puts -nonewline "Test $iTest: src=$zSrcFile dest=$zDestFile" |
182 puts -nonewline " (as $db_dest.$file_dest)" | 186 puts -nonewline " (as $db_dest.$file_dest)" |
183 puts -nonewline " rows_dest=$rows_dest pgsz_dest=$pgsz_dest" | 187 puts -nonewline " rows_dest=$rows_dest pgsz_dest=$pgsz_dest" |
184 puts "" | 188 puts "" |
185 } | 189 } |
186 | 190 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 # backup-5.x.5.*: Database is shrunk via incr-vacuum. | 484 # backup-5.x.5.*: Database is shrunk via incr-vacuum. |
481 # | 485 # |
482 # Each test is run three times, in the following configurations: | 486 # Each test is run three times, in the following configurations: |
483 # | 487 # |
484 # 1) Backing up file-to-file. The writer writes via an external pager. | 488 # 1) Backing up file-to-file. The writer writes via an external pager. |
485 # 2) Backing up file-to-file. The writer writes via the same pager as | 489 # 2) Backing up file-to-file. The writer writes via the same pager as |
486 # is used by the backup operation. | 490 # is used by the backup operation. |
487 # 3) Backing up memory-to-file. | 491 # 3) Backing up memory-to-file. |
488 # | 492 # |
489 set iTest 0 | 493 set iTest 0 |
| 494 file delete -force bak.db-wal |
490 foreach {writer file} {db test.db db3 test.db db :memory:} { | 495 foreach {writer file} {db test.db db3 test.db db :memory:} { |
491 incr iTest | 496 incr iTest |
492 catch { file delete bak.db } | 497 catch { file delete bak.db } |
493 sqlite3 db2 bak.db | 498 sqlite3 db2 bak.db |
494 catch { file delete $file } | 499 catch { file delete $file } |
495 sqlite3 db $file | 500 sqlite3 db $file |
496 sqlite3 db3 $file | 501 sqlite3 db3 $file |
497 | 502 |
498 do_test backup-5.$iTest.1.1 { | 503 do_test backup-5.$iTest.1.1 { |
499 execsql { | 504 execsql { |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 B finish | 902 B finish |
898 } {SQLITE_OK} | 903 } {SQLITE_OK} |
899 do_test backup-10.1.5 { | 904 do_test backup-10.1.5 { |
900 execsql { PRAGMA integrity_check } db3 | 905 execsql { PRAGMA integrity_check } db3 |
901 } {ok} | 906 } {ok} |
902 | 907 |
903 db2 close | 908 db2 close |
904 db3 close | 909 db3 close |
905 } | 910 } |
906 | 911 |
| 912 |
| 913 #----------------------------------------------------------------------- |
| 914 # Test that if the database is written to via the same database handle being |
| 915 # used as the source by a backup operation: |
| 916 # |
| 917 # 10.1.*: If the db is in-memory, the backup is restarted. |
| 918 # 10.2.*: If the db is a file, the backup is not restarted. |
| 919 # |
| 920 db close |
| 921 file delete -force test.db test.db-journal |
| 922 foreach {tn file rc} { |
| 923 1 test.db SQLITE_DONE |
| 924 2 :memory: SQLITE_OK |
| 925 } { |
| 926 do_test backup-10.$tn.1 { |
| 927 sqlite3 db $file |
| 928 execsql { |
| 929 CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB); |
| 930 BEGIN; |
| 931 INSERT INTO t1 VALUES(NULL, randomblob(200)); |
| 932 INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; |
| 933 INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; |
| 934 INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; |
| 935 INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; |
| 936 INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; |
| 937 INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; |
| 938 INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; |
| 939 INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; |
| 940 COMMIT; |
| 941 SELECT count(*) FROM t1; |
| 942 } |
| 943 } {256} |
| 944 |
| 945 do_test backup-10.$tn.2 { |
| 946 set pgs [execsql {pragma page_count}] |
| 947 expr {$pgs > 50 && $pgs < 75} |
| 948 } {1} |
| 949 |
| 950 do_test backup-10.$tn.3 { |
| 951 file delete -force bak.db bak.db-journal |
| 952 sqlite3 db2 bak.db |
| 953 sqlite3_backup B db2 main db main |
| 954 B step 50 |
| 955 } {SQLITE_OK} |
| 956 |
| 957 do_test backup-10.$tn.4 { |
| 958 execsql { UPDATE t1 SET b = randomblob(200) WHERE a IN (1, 250) } |
| 959 } {} |
| 960 |
| 961 do_test backup-10.$tn.5 { |
| 962 B step 50 |
| 963 } $rc |
| 964 |
| 965 do_test backup-10.$tn.6 { |
| 966 B finish |
| 967 } {SQLITE_OK} |
| 968 |
| 969 db2 close |
| 970 } |
| 971 |
907 finish_test | 972 finish_test |
OLD | NEW |