blob: 3db2a499d5c64cc389c77400b288e61811b09193 [file] [log] [blame]
drhdc2c4912009-02-04 22:46:47 +00001# 2009 January 30
danielk197704103022009-02-03 16:51:24 +00002#
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. The
12# focus of this file is testing the sqlite3_backup_XXX API.
13#
danielk197703ab0352009-02-06 05:59:44 +000014# $Id: backup.test,v 1.4 2009/02/06 05:59:45 danielk1977 Exp $
danielk197704103022009-02-03 16:51:24 +000015
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19#---------------------------------------------------------------------
20# Test organization:
21#
22# backup-1.*: Warm-body tests.
23#
24# backup-2.*: Test backup under various conditions. To and from in-memory
25# databases. To and from empty/populated databases. etc.
26#
27# backup-3.*: Verify that the locking-page (pending byte page) is handled.
28#
29# backup-4.*: Test various error conditions.
30#
31# backup-5.*: Test the source database being modified during a backup.
32#
33# backup-6.*: Test the backup_remaining() and backup_pagecount() APIs.
34#
35# backup-7.*: Test SQLITE_BUSY and SQLITE_LOCKED errors.
36#
37# backup-8.*: Test multiple simultaneous backup operations.
38#
danielk197703ab0352009-02-06 05:59:44 +000039# backup-9.*: Test that passing a negative argument to backup_step() is
40# interpreted as "copy the whole file".
41#
danielk197704103022009-02-03 16:51:24 +000042
43proc data_checksum {db file} { $db one "SELECT md5sum(a, b) FROM ${file}.t1" }
44proc test_contents {name db1 file1 db2 file2} {
45 $db2 eval {select * from sqlite_master}
46 $db1 eval {select * from sqlite_master}
47 set checksum [data_checksum $db2 $file2]
48 uplevel [list do_test $name [list data_checksum $db1 $file1] $checksum]
49}
50
51do_test backup-1.1 {
52 execsql {
53 BEGIN;
54 CREATE TABLE t1(a, b);
55 CREATE INDEX i1 ON t1(a, b);
56 INSERT INTO t1 VALUES(1, randstr(1000,1000));
57 INSERT INTO t1 VALUES(2, randstr(1000,1000));
58 INSERT INTO t1 VALUES(3, randstr(1000,1000));
59 INSERT INTO t1 VALUES(4, randstr(1000,1000));
60 INSERT INTO t1 VALUES(5, randstr(1000,1000));
61 COMMIT;
62 }
63} {}
64
65# Sanity check to verify that the [test_contents] proc works.
66#
67test_contents backup-1.2 db main db main
68
69# Check that it is possible to create and finish backup operations.
70#
71do_test backup-1.3.1 {
72 file delete test2.db
73 sqlite3 db2 test2.db
74 sqlite3_backup B db2 main db main
75} {B}
76do_test backup-1.3.2 {
77 B finish
78} {SQLITE_OK}
79do_test backup-1.3.3 {
80 info commands B
81} {}
82
83# Simplest backup operation. Backup test.db to test2.db. test2.db is
84# initially empty. test.db uses the default page size.
85#
86do_test backup-1.4.1 {
87 sqlite3_backup B db2 main db main
88} {B}
89do_test backup-1.4.2 {
90 B step 200
91} {SQLITE_DONE}
92do_test backup-1.4.3 {
93 B finish
94} {SQLITE_OK}
95do_test backup-1.4.4 {
96 info commands B
97} {}
98test_contents backup-1.4.5 db2 main db main
99db close
100db2 close
101#
102# End of backup-1.* tests.
103#---------------------------------------------------------------------
104
105
106#---------------------------------------------------------------------
107# The following tests, backup-2.*, are based on the following procedure:
108#
109# 1) Populate the source database.
110# 2) Populate the destination database.
111# 3) Run the backup to completion. (backup-2.*.1)
112# 4) Integrity check the destination db. (backup-2.*.2)
113# 5) Check that the contents of the destination db is the same as that
114# of the source db. (backup-2.*.3)
115#
116# The test is run with all possible combinations of the following
117# input parameters, except that if the destination is an in-memory
118# database, the only page size tested is 1024 bytes (the same as the
119# source page-size).
120#
121# * Source database is an in-memory database, OR
122# * Source database is a file-backed database.
123#
124# * Target database is an in-memory database, OR
125# * Target database is a file-backed database.
126#
127# * Destination database is a main file, OR
128# * Destination database is an attached file, OR
129# * Destination database is a temp database.
130#
131# * Target database is empty (zero bytes), OR
132# * Target database is larger than the source, OR
133# * Target database is smaller than the source.
134#
135# * Target database page-size is the same as the source, OR
136# * Target database page-size is larger than the source, OR
137# * Target database page-size is smaller than the source.
138#
139# * Each call to step copies a single page, OR
140# * A single call to step copies the entire source database.
141#
142set iTest 1
143foreach zSrcFile {test.db :memory:} {
144foreach zDestFile {test2.db :memory:} {
145foreach zOpenScript [list {
146 sqlite3 db $zSrcFile
147 sqlite3 db2 $zSrcFile
148 db2 eval "ATTACH '$zDestFile' AS bak"
149 set db_dest db2
150 set file_dest bak
151} {
152 sqlite3 db $zSrcFile
153 sqlite3 db2 $zDestFile
154 set db_dest db2
155 set file_dest main
156} {
157 sqlite3 db $zSrcFile
158 sqlite3 db2 $zDestFile
159 set db_dest db2
160 set file_dest temp
161}] {
162foreach rows_dest {0 3 10} {
163foreach pgsz_dest {512 1024 2048} {
164foreach nPagePerStep {1 200} {
165
166 # Open the databases.
167 catch { file delete test.db }
168 catch { file delete test2.db }
169 eval $zOpenScript
170
171 if {$zDestFile ne ":memory:" || $pgsz_dest == 1024 } {
172
173 if 0 {
174 puts -nonewline "Test $iTest: src=$zSrcFile dest=$zDestFile"
175 puts -nonewline " (as $db_dest.$file_dest)"
176 puts -nonewline " rows_dest=$rows_dest pgsz_dest=$pgsz_dest"
177 puts ""
178 }
179
180 # Set up the content of the source database.
181 execsql {
182 BEGIN;
183 CREATE TABLE t1(a, b);
184 CREATE INDEX i1 ON t1(a, b);
185 INSERT INTO t1 VALUES(1, randstr(1000,1000));
186 INSERT INTO t1 VALUES(2, randstr(1000,1000));
187 INSERT INTO t1 VALUES(3, randstr(1000,1000));
188 INSERT INTO t1 VALUES(4, randstr(1000,1000));
189 INSERT INTO t1 VALUES(5, randstr(1000,1000));
190 COMMIT;
191 }
192
193
194
195 # Set up the content of the target database.
196 execsql "PRAGMA ${file_dest}.page_size = ${pgsz_dest}" $db_dest
197 if {$rows_dest != 0} {
198 execsql "
199 BEGIN;
200 CREATE TABLE ${file_dest}.t1(a, b);
201 CREATE INDEX ${file_dest}.i1 ON t1(a, b);
202 " $db_dest
203 for {set ii 0} {$ii < $rows_dest} {incr ii} {
204 execsql "
205 INSERT INTO ${file_dest}.t1 VALUES(1, randstr(1000,1000))
206 " $db_dest
207 }
208 }
209
210 # Backup the source database.
211 do_test backup-2.$iTest.1 {
212 sqlite3_backup B $db_dest $file_dest db main
213 while {[B step $nPagePerStep]=="SQLITE_OK"} {}
214 B finish
215 } {SQLITE_OK}
216
217 # Run integrity check on the backup.
218 do_test backup-2.$iTest.2 {
219 execsql "PRAGMA ${file_dest}.integrity_check" $db_dest
220 } {ok}
221
222 test_contents backup-2.$iTest.3 db main $db_dest $file_dest
223
224 }
225
226 db close
227 catch {db2 close}
228 incr iTest
229
230} } } } } }
231#
232# End of backup-2.* tests.
233#---------------------------------------------------------------------
234
235#---------------------------------------------------------------------
236# These tests, backup-3.*, ensure that nothing goes wrong if either
237# the source or destination database are large enough to include the
238# the locking-page (the page that contains the range of bytes that
239# the locks are applied to). These tests assume that the pending
240# byte is at offset 0x00010000 (64KB offset), as set by tester.tcl,
241# not at the 1GB offset as it usually is.
242#
243# The test procedure is as follows (same procedure as used for
244# the backup-2.* tests):
245#
246# 1) Populate the source database.
247# 2) Populate the destination database.
248# 3) Run the backup to completion. (backup-3.*.1)
249# 4) Integrity check the destination db. (backup-3.*.2)
250# 5) Check that the contents of the destination db is the same as that
251# of the source db. (backup-3.*.3)
252#
253# The test procedure is run with the following parameters varied:
254#
255# * Source database includes pending-byte page.
256# * Source database does not include pending-byte page.
257#
258# * Target database includes pending-byte page.
259# * Target database does not include pending-byte page.
260#
261# * Target database page-size is the same as the source, OR
262# * Target database page-size is larger than the source, OR
263# * Target database page-size is smaller than the source.
264#
265set iTest 1
266foreach nSrcRow {10 100} {
267foreach nDestRow {10 100} {
268foreach nDestPgsz {512 1024 2048 4096} {
269
270 catch { file delete test.db }
271 catch { file delete test2.db }
272 sqlite3 db test.db
273 sqlite3 db2 test2.db
274
275 # Set up the content of the two databases.
276 #
277 foreach {db nRow} [list db $nSrcRow db2 $nDestRow] {
278 execsql {
279 BEGIN;
280 CREATE TABLE t1(a, b);
281 CREATE INDEX i1 ON t1(a, b);
282 } $db
283 for {set ii 0} {$ii < $nSrcRow} {incr ii} {
284 execsql { INSERT INTO t1 VALUES($ii, randstr(1000,1000)) } $db
285 }
286 execsql COMMIT $db
287 }
288
289 # Backup the source database.
290 do_test backup-3.$iTest.1 {
291 sqlite3_backup B db main db2 main
292 while {[B step 10]=="SQLITE_OK"} {}
293 B finish
294 } {SQLITE_OK}
295
296 # Run integrity check on the backup.
297 do_test backup-3.$iTest.2 {
298 execsql "PRAGMA integrity_check" db2
299 } {ok}
300
301 test_contents backup-3.$iTest.3 db main db2 main
302
303 db close
304 db2 close
305 incr iTest
306}
307}
308}
309#
310# End of backup-3.* tests.
311#---------------------------------------------------------------------
312
313
314#---------------------------------------------------------------------
315# The following tests, backup-4.*, test various error conditions:
316#
317# backup-4.1.*: Test invalid database names.
318#
319# backup-4.2.*: Test that the source database cannot be detached while
320# a backup is in progress.
321#
322# backup-4.3.*: Test that the source database handle cannot be closed
323# while a backup is in progress.
324#
325# backup-4.4.*: Test an attempt to specify the same handle for the
326# source and destination databases.
327#
328# backup-4.5.*: Test that an in-memory destination with a different
329# page-size to the source database is an error.
330#
331sqlite3 db test.db
332sqlite3 db2 test2.db
333
334do_test backup-4.1.1 {
335 catch { sqlite3_backup B db aux db2 main }
336} {1}
337do_test backup-4.1.2 {
338 sqlite3_errmsg db
339} {unknown database aux}
340do_test backup-4.1.3 {
341 catch { sqlite3_backup B db main db2 aux }
342} {1}
343do_test backup-4.1.4 {
344 sqlite3_errmsg db
345} {unknown database aux}
346
347do_test backup-4.2.1 {
348 execsql { ATTACH 'test3.db' AS aux1 }
349 execsql { ATTACH 'test4.db' AS aux2 } db2
350 sqlite3_backup B db aux1 db2 aux2
351} {B}
352do_test backup-4.2.2 {
353 catchsql { DETACH aux2 } db2
354} {1 {database aux2 is locked}}
355do_test backup-4.2.3 {
356 B step 50
357} {SQLITE_DONE}
358do_test backup-4.2.4 {
359 B finish
360} {SQLITE_OK}
361
362do_test backup-4.3.1 {
363 sqlite3_backup B db aux1 db2 aux2
364} {B}
365do_test backup-4.3.2 {
366 db2 cache flush
367 sqlite3_close db2
368} {SQLITE_BUSY}
369do_test backup-4.3.3 {
370 sqlite3_errmsg db2
drhb309bec2009-02-04 17:40:57 +0000371} {unable to close due to unfinished backup operation}
danielk197704103022009-02-03 16:51:24 +0000372do_test backup-4.3.4 {
373 B step 50
374} {SQLITE_DONE}
375do_test backup-4.3.5 {
376 B finish
377} {SQLITE_OK}
378
379do_test backup-4.4.1 {
380 set rc [catch {sqlite3_backup B db main db aux1}]
381 list $rc [sqlite3_errcode db] [sqlite3_errmsg db]
drhb309bec2009-02-04 17:40:57 +0000382} {1 SQLITE_ERROR {source and destination must be distinct}}
danielk197704103022009-02-03 16:51:24 +0000383db close
384db2 close
385
386do_test backup-4.5.1 {
387 catch { file delete -force test.db }
388 sqlite3 db test.db
389 sqlite3 db2 :memory:
390 execsql {
391 CREATE TABLE t1(a, b);
392 INSERT INTO t1 VALUES(1, 2);
393 }
394 execsql {
395 PRAGMA page_size = 4096;
396 CREATE TABLE t2(a, b);
397 INSERT INTO t2 VALUES(3, 4);
398 } db2
399 sqlite3_backup B db2 main db main
400} {B}
401do_test backup-4.5.2 {
402 B step 5000
403} {SQLITE_READONLY}
404do_test backup-4.5.3 {
405 B finish
406} {SQLITE_READONLY}
407
408db close
409db2 close
410#
411# End of backup-5.* tests.
412#---------------------------------------------------------------------
413
414#---------------------------------------------------------------------
415# The following tests, backup-5.*, test that the backup works properly
416# when the source database is modified during the backup. Test cases
417# are organized as follows:
418#
419# backup-5.x.1.*: Nothing special. Modify the database mid-backup.
420#
421# backup-5.x.2.*: Modify the database mid-backup so that one or more
422# pages are written out due to cache stress. Then
423# rollback the transaction.
424#
425# backup-5.x.3.*: Database is vacuumed.
426#
427# backup-5.x.4.*: Database is vacuumed and the page-size modified.
428#
429# backup-5.x.5.*: Database is shrunk via incr-vacuum.
430#
431# Each test is run three times, in the following configurations:
432#
433# 1) Backing up file-to-file. The writer writes via an external pager.
434# 2) Backing up file-to-file. The writer writes via the same pager as
435# is used by the backup operation.
436# 3) Backing up memory-to-file.
437#
438set iTest 0
439foreach {writer file} {db test.db db3 test.db db :memory:} {
440 incr iTest
441 catch { file delete bak.db }
442 sqlite3 db2 bak.db
443 catch { file delete $file }
444 sqlite3 db $file
445 sqlite3 db3 $file
446
447 do_test backup-5.$iTest.1.1 {
448 execsql {
449 BEGIN;
450 CREATE TABLE t1(a, b);
451 CREATE INDEX i1 ON t1(a, b);
452 INSERT INTO t1 VALUES(1, randstr(1000,1000));
453 INSERT INTO t1 VALUES(2, randstr(1000,1000));
454 INSERT INTO t1 VALUES(3, randstr(1000,1000));
455 INSERT INTO t1 VALUES(4, randstr(1000,1000));
456 INSERT INTO t1 VALUES(5, randstr(1000,1000));
457 COMMIT;
458 }
459 expr {[execsql {PRAGMA page_count}] > 10}
460 } {1}
461 do_test backup-5.$iTest.1.2 {
462 sqlite3_backup B db2 main db main
463 B step 5
464 } {SQLITE_OK}
465 do_test backup-5.$iTest.1.3 {
466 execsql { UPDATE t1 SET a = a + 1 } $writer
467 B step 50
468 } {SQLITE_DONE}
469 do_test backup-5.$iTest.1.4 {
470 B finish
471 } {SQLITE_OK}
472 integrity_check backup-5.$iTest.1.5 db2
473 test_contents backup-5.$iTest.1.6 db main db2 main
474
475 do_test backup-5.$iTest.2.1 {
476 execsql {
477 PRAGMA cache_size = 10;
478 BEGIN;
479 INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1;
480 INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1;
481 INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1;
482 INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1;
483 COMMIT;
484 }
485 } {}
486 do_test backup-5.$iTest.2.2 {
487 sqlite3_backup B db2 main db main
488 B step 50
489 } {SQLITE_OK}
490 do_test backup-5.$iTest.2.3 {
491 execsql {
492 BEGIN;
493 UPDATE t1 SET a = a + 1;
494 ROLLBACK;
495 } $writer
496 B step 5000
497 } {SQLITE_DONE}
498 do_test backup-5.$iTest.2.4 {
499 B finish
500 } {SQLITE_OK}
501 integrity_check backup-5.$iTest.2.5 db2
502 test_contents backup-5.$iTest.2.6 db main db2 main
503
504 do_test backup-5.$iTest.3.1 {
505 execsql { UPDATE t1 SET b = randstr(1000,1000) }
506 } {}
507 do_test backup-5.$iTest.3.2 {
508 sqlite3_backup B db2 main db main
509 B step 50
510 } {SQLITE_OK}
511 do_test backup-5.$iTest.3.3 {
512 execsql { VACUUM } $writer
513 B step 5000
514 } {SQLITE_DONE}
515 do_test backup-5.$iTest.3.4 {
516 B finish
517 } {SQLITE_OK}
518 integrity_check backup-5.$iTest.3.5 db2
519 test_contents backup-5.$iTest.3.6 db main db2 main
520
521 do_test backup-5.$iTest.4.1 {
522 execsql { UPDATE t1 SET b = randstr(1000,1000) }
523 } {}
524 do_test backup-5.$iTest.4.2 {
525 sqlite3_backup B db2 main db main
526 B step 50
527 } {SQLITE_OK}
528 do_test backup-5.$iTest.4.3 {
529 execsql {
530 PRAGMA page_size = 2048;
531 VACUUM;
532 } $writer
533 B step 5000
534 } {SQLITE_DONE}
535 do_test backup-5.$iTest.4.4 {
536 B finish
537 } {SQLITE_OK}
538 integrity_check backup-5.$iTest.4.5 db2
539 test_contents backup-5.$iTest.4.6 db main db2 main
540
541 catch { file delete bak.db }
542 sqlite3 db2 bak.db
543 catch { file delete $file }
544 sqlite3 db $file
545 sqlite3 db3 $file
546 do_test backup-5.$iTest.5.1 {
547 execsql {
548 PRAGMA auto_vacuum = incremental;
549 BEGIN;
550 CREATE TABLE t1(a, b);
551 CREATE INDEX i1 ON t1(a, b);
552 INSERT INTO t1 VALUES(1, randstr(1000,1000));
553 INSERT INTO t1 VALUES(2, randstr(1000,1000));
554 INSERT INTO t1 VALUES(3, randstr(1000,1000));
555 INSERT INTO t1 VALUES(4, randstr(1000,1000));
556 INSERT INTO t1 VALUES(5, randstr(1000,1000));
557 COMMIT;
558 }
559 } {}
560 do_test backup-5.$iTest.5.2 {
561 sqlite3_backup B db2 main db main
562 B step 8
563 } {SQLITE_OK}
564 do_test backup-5.$iTest.5.3 {
565 execsql {
566 DELETE FROM t1;
567 PRAGMA incremental_vacuum;
568 } $writer
569 B step 50
570 } {SQLITE_DONE}
571 do_test backup-5.$iTest.5.4 {
572 B finish
573 } {SQLITE_OK}
574 integrity_check backup-5.$iTest.5.5 db2
575 test_contents backup-5.$iTest.5.6 db main db2 main
576}
577catch {db close}
578catch {db2 close}
579catch {db3 close}
580#
581# End of backup-5.* tests.
582#---------------------------------------------------------------------
583
584#---------------------------------------------------------------------
585# Test the sqlite3_backup_remaining() and backup_pagecount() APIs.
586#
587do_test backup-6.1 {
588 catch { file delete -force test.db }
589 catch { file delete -force test2.db }
590 sqlite3 db test.db
591 sqlite3 db2 test2.db
592 execsql {
593 BEGIN;
594 CREATE TABLE t1(a, b);
595 CREATE INDEX i1 ON t1(a, b);
596 INSERT INTO t1 VALUES(1, randstr(1000,1000));
597 INSERT INTO t1 VALUES(2, randstr(1000,1000));
598 INSERT INTO t1 VALUES(3, randstr(1000,1000));
599 INSERT INTO t1 VALUES(4, randstr(1000,1000));
600 INSERT INTO t1 VALUES(5, randstr(1000,1000));
601 COMMIT;
602 }
603} {}
604do_test backup-6.2 {
605 set nTotal [expr {[file size test.db]/1024}]
606 sqlite3_backup B db2 main db main
607 B step 1
608} {SQLITE_OK}
609do_test backup-6.3 {
610 B pagecount
611} $nTotal
612do_test backup-6.4 {
613 B remaining
614} [expr $nTotal-1]
615do_test backup-6.5 {
616 B step 5
617 list [B remaining] [B pagecount]
618} [list [expr $nTotal-6] $nTotal]
619do_test backup-6.6 {
620 execsql { CREATE TABLE t2(a PRIMARY KEY, b) }
621 B step 1
622 list [B remaining] [B pagecount]
623} [list [expr $nTotal-5] [expr $nTotal+2]]
624
625do_test backup-6.X {
626 B finish
627} {SQLITE_OK}
628
629
630
631#---------------------------------------------------------------------
632# Test cases backup-7.* test that SQLITE_BUSY and SQLITE_LOCKED errors
633# are returned correctly:
634#
635# backup-7.1.*: Source database is externally locked (return SQLITE_BUSY).
636#
637# backup-7.2.*: Attempt to step the backup process while a
638# write-transaction is underway on the source pager (return
639# SQLITE_LOCKED).
640#
641# backup-7.3.*: Destination database is externally locked (return SQLITE_BUSY).
642#
643do_test backup-7.0 {
644 catch { file delete -force test.db }
645 catch { file delete -force test2.db }
646 sqlite3 db2 test2.db
647 sqlite3 db test.db
648 execsql {
649 CREATE TABLE t1(a, b);
650 CREATE INDEX i1 ON t1(a, b);
651 INSERT INTO t1 VALUES(1, randstr(1000,1000));
652 INSERT INTO t1 SELECT a+ 1, randstr(1000,1000) FROM t1;
653 INSERT INTO t1 SELECT a+ 2, randstr(1000,1000) FROM t1;
654 INSERT INTO t1 SELECT a+ 4, randstr(1000,1000) FROM t1;
655 INSERT INTO t1 SELECT a+ 8, randstr(1000,1000) FROM t1;
656 INSERT INTO t1 SELECT a+16, randstr(1000,1000) FROM t1;
657 INSERT INTO t1 SELECT a+32, randstr(1000,1000) FROM t1;
658 INSERT INTO t1 SELECT a+64, randstr(1000,1000) FROM t1;
659 }
660} {}
661
662do_test backup-7.1.1 {
663 sqlite3_backup B db2 main db main
664 B step 5
665} {SQLITE_OK}
666do_test backup-7.1.2 {
667 sqlite3 db3 test.db
668 execsql { BEGIN EXCLUSIVE } db3
669 B step 5
670} {SQLITE_BUSY}
671do_test backup-7.1.3 {
672 execsql { ROLLBACK } db3
673 B step 5
674} {SQLITE_OK}
675do_test backup-7.2.1 {
676 execsql {
677 BEGIN;
678 INSERT INTO t1 VALUES(1, 4);
679 }
680} {}
681do_test backup-7.2.2 {
682 B step 5000
683} {SQLITE_LOCKED}
684do_test backup-7.2.3 {
685 execsql { ROLLBACK }
686 B step 5000
687} {SQLITE_DONE}
688do_test backup-7.2.4 {
689 B finish
690} {SQLITE_OK}
691test_contents backup-7.2.5 db main db2 main
692integrity_check backup-7.3.6 db2
693
694do_test backup-7.3.1 {
695 db2 close
696 db3 close
697 file delete -force test2.db
698 sqlite3 db2 test2.db
699 sqlite3 db3 test2.db
700
701 sqlite3_backup B db2 main db main
702 execsql { BEGIN ; CREATE TABLE t2(a, b); } db3
703
704 B step 5
705} {SQLITE_BUSY}
706do_test backup-7.3.2 {
707 execsql { COMMIT } db3
708 B step 5000
709} {SQLITE_DONE}
710do_test backup-7.3.3 {
711 B finish
712} {SQLITE_OK}
713test_contents backup-7.3.4 db main db2 main
714integrity_check backup-7.3.5 db2
715catch { db2 close }
716catch { db3 close }
717
718#-----------------------------------------------------------------------
719# The following tests, backup-8.*, test attaching multiple backup
720# processes to the same source database. Also, reading from the source
721# database while a read transaction is active.
722#
723# These tests reuse the database "test.db" left over from backup-7.*.
724#
725do_test backup-8.1 {
726 catch { file delete -force test2.db }
727 catch { file delete -force test3.db }
728 sqlite3 db2 test2.db
729 sqlite3 db3 test3.db
730
731 sqlite3_backup B2 db2 main db main
732 sqlite3_backup B3 db3 main db main
733 list [B2 finish] [B3 finish]
734} {SQLITE_OK SQLITE_OK}
735do_test backup-8.2 {
736 sqlite3_backup B3 db3 main db main
737 sqlite3_backup B2 db2 main db main
738 list [B2 finish] [B3 finish]
739} {SQLITE_OK SQLITE_OK}
740do_test backup-8.3 {
741 sqlite3_backup B2 db2 main db main
742 sqlite3_backup B3 db3 main db main
743 B2 step 5
744} {SQLITE_OK}
745do_test backup-8.4 {
746 execsql {
747 BEGIN;
748 SELECT * FROM sqlite_master;
749 }
750 B3 step 5
751} {SQLITE_OK}
752do_test backup-8.5 {
753 list [B3 step 5000] [B3 finish]
754} {SQLITE_DONE SQLITE_OK}
755do_test backup-8.6 {
756 list [B2 step 5000] [B2 finish]
757} {SQLITE_DONE SQLITE_OK}
758test_contents backup-8.7 db main db2 main
759test_contents backup-8.8 db main db3 main
760do_test backup-8.9 {
761 execsql { PRAGMA lock_status }
762} {main shared temp closed}
763do_test backup-8.10 {
764 execsql COMMIT
765} {}
766catch { db2 close }
767catch { db3 close }
768
danielk197703ab0352009-02-06 05:59:44 +0000769#-----------------------------------------------------------------------
770# The following tests, backup-9.*, test that:
771#
772# * Passing 0 as an argument to sqlite3_backup_step() means no pages
773# are backed up (backup-9.1.*), and
774# * Passing a negative value as an argument to sqlite3_backup_step() means
775# all pages are backed up (backup-9.2.*).
776#
777# These tests reuse the database "test.db" left over from backup-7.*.
778#
779do_test backup-9.1.1 {
780 sqlite3 db2 test2.db
781 sqlite3_backup B db2 main db main
782 B step 1
783} {SQLITE_OK}
784do_test backup-9.1.2 {
785 set nRemaining [B remaining]
786 expr {$nRemaining>100}
787} {1}
788do_test backup-9.1.3 {
789 B step 0
790} {SQLITE_OK}
791do_test backup-9.1.4 {
792 B remaining
793} $nRemaining
794
795do_test backup-9.2.1 {
796 B step -1
797} {SQLITE_DONE}
798do_test backup-9.2.2 {
799 B remaining
800} {0}
801do_test backup-9.2.3 {
802 B finish
803} {SQLITE_OK}
804catch {db2 close}
danielk197704103022009-02-03 16:51:24 +0000805
806finish_test
danielk197703ab0352009-02-06 05:59:44 +0000807