OLD | NEW |
1 # 2014 August 30 | 1 # 2014 August 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 # | 11 # |
12 | 12 |
13 if {![info exists testdir]} { | 13 source [file join [file dirname [info script]] rbu_common.tcl] |
14 set testdir [file join [file dirname [info script]] .. .. test] | |
15 } | |
16 source $testdir/tester.tcl | |
17 set ::testprefix rbu1 | 14 set ::testprefix rbu1 |
18 | 15 |
19 db close | 16 db close |
20 sqlite3_shutdown | 17 sqlite3_shutdown |
21 sqlite3_config_uri 1 | 18 sqlite3_config_uri 1 |
22 | 19 |
23 # Create a simple RBU database. That expects to write to a table: | 20 # Create a simple RBU database. That expects to write to a table: |
24 # | 21 # |
25 # CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); | 22 # CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); |
26 # | 23 # |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 rbu5 eval { | 86 rbu5 eval { |
90 CREATE TABLE data_t1(a, b, c, d, rbu_control); | 87 CREATE TABLE data_t1(a, b, c, d, rbu_control); |
91 INSERT INTO data_t1 VALUES(1, NULL, NULL, 5, '...x'); -- SET d = 5 | 88 INSERT INTO data_t1 VALUES(1, NULL, NULL, 5, '...x'); -- SET d = 5 |
92 INSERT INTO data_t1 VALUES(2, NULL, 10, 5, '..xx'); -- SET c=10, d = 5 | 89 INSERT INTO data_t1 VALUES(2, NULL, 10, 5, '..xx'); -- SET c=10, d = 5 |
93 INSERT INTO data_t1 VALUES(3, 11, NULL, NULL, '.x..'); -- SET b=11 | 90 INSERT INTO data_t1 VALUES(3, 11, NULL, NULL, '.x..'); -- SET b=11 |
94 } | 91 } |
95 rbu5 close | 92 rbu5 close |
96 return $filename | 93 return $filename |
97 } | 94 } |
98 | 95 |
99 # Run the RBU in file $rbu on target database $target until completion. | |
100 # | |
101 proc run_rbu {target rbu} { | |
102 sqlite3rbu rbu $target $rbu | |
103 while 1 { | |
104 set rc [rbu step] | |
105 if {$rc!="SQLITE_OK"} break | |
106 } | |
107 rbu close | |
108 } | |
109 | |
110 proc step_rbu {target rbu} { | |
111 while 1 { | |
112 sqlite3rbu rbu $target $rbu | |
113 set rc [rbu step] | |
114 rbu close | |
115 if {$rc != "SQLITE_OK"} break | |
116 } | |
117 set rc | |
118 } | |
119 | 96 |
120 # Same as [step_rbu], except using a URI to open the target db. | 97 # Same as [step_rbu], except using a URI to open the target db. |
121 # | 98 # |
122 proc step_rbu_uri {target rbu} { | 99 proc step_rbu_uri {target rbu} { |
123 while 1 { | 100 while 1 { |
124 sqlite3rbu rbu file:$target?xyz=&abc=123 $rbu | 101 sqlite3rbu rbu file:$target?xyz=&abc=123 $rbu |
125 set rc [rbu step] | 102 set rc [rbu step] |
126 rbu close | 103 rbu close |
127 if {$rc != "SQLITE_OK"} break | 104 if {$rc != "SQLITE_OK"} break |
128 } | 105 } |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 | 581 |
605 8 { | 582 8 { |
606 CREATE TABLE t1(a, b PRIMARY KEY) WITHOUT ROWID; | 583 CREATE TABLE t1(a, b PRIMARY KEY) WITHOUT ROWID; |
607 CREATE TABLE rbu.data_t1(a, b, rbu_control); | 584 CREATE TABLE rbu.data_t1(a, b, rbu_control); |
608 INSERT INTO rbu.data_t1 VALUES(1, 2, 4); | 585 INSERT INTO rbu.data_t1 VALUES(1, 2, 4); |
609 } {SQLITE_ERROR - invalid rbu_control value} | 586 } {SQLITE_ERROR - invalid rbu_control value} |
610 | 587 |
611 9 { | 588 9 { |
612 CREATE TABLE t1(a, b PRIMARY KEY) WITHOUT ROWID; | 589 CREATE TABLE t1(a, b PRIMARY KEY) WITHOUT ROWID; |
613 CREATE TABLE rbu.data_t1(a, b, rbu_control); | 590 CREATE TABLE rbu.data_t1(a, b, rbu_control); |
614 INSERT INTO rbu.data_t1 VALUES(1, 2, 2); | 591 INSERT INTO rbu.data_t1 VALUES(1, 2, 3); |
615 } {SQLITE_ERROR - invalid rbu_control value} | 592 } {SQLITE_ERROR - invalid rbu_control value} |
616 | 593 |
617 10 { | 594 10 { |
618 CREATE TABLE t2(a, b); | 595 CREATE TABLE t2(a, b); |
619 CREATE TABLE rbu.data_t1(a, b, rbu_control); | 596 CREATE TABLE rbu.data_t1(a, b, rbu_control); |
620 INSERT INTO rbu.data_t1 VALUES(1, 2, 2); | 597 INSERT INTO rbu.data_t1 VALUES(1, 2, 2); |
621 } {SQLITE_ERROR - no such table: t1} | 598 } {SQLITE_ERROR - no such table: t1} |
622 | 599 |
623 11 { | 600 11 { |
624 CREATE TABLE rbu.data_t2(a, b, rbu_control); | 601 CREATE TABLE rbu.data_t2(a, b, rbu_control); |
625 INSERT INTO rbu.data_t2 VALUES(1, 2, 2); | 602 INSERT INTO rbu.data_t2 VALUES(1, 2, 2); |
626 } {SQLITE_ERROR - no such table: t2} | 603 } {SQLITE_ERROR - no such table: t2} |
627 | 604 |
628 } { | 605 } { |
629 reset_db | 606 reset_db |
630 forcedelete rbu.db | 607 forcedelete rbu.db |
631 execsql { ATTACH 'rbu.db' AS rbu } | 608 execsql { ATTACH 'rbu.db' AS rbu } |
632 execsql $schema | 609 execsql $schema |
633 | 610 |
634 do_test $tn3.7.$tn { | 611 do_test $tn3.7.$tn { |
635 list [catch { run_rbu test.db rbu.db } msg] $msg | 612 list [catch { run_rbu test.db rbu.db } msg] $msg |
636 } [list 1 $error] | 613 } [list 1 $error] |
637 } | 614 } |
638 } | 615 } |
639 | 616 |
640 # Test that an RBU database containing no input tables is handled | 617 # Test that an RBU database containing no input tables is handled |
641 # correctly. | 618 # correctly. |
642 reset_db | 619 reset_db |
643 forcedelete rbu.db | 620 forcedelete rbu.db |
644 do_test $tn3.8 { | 621 do_test $tn3.8.1 { |
645 list [catch { run_rbu test.db rbu.db } msg] $msg | 622 list [catch { run_rbu test.db rbu.db } msg] $msg |
646 } {0 SQLITE_DONE} | 623 } {0 SQLITE_DONE} |
647 | 624 |
| 625 # Test that an RBU database containing only empty data_xxx tables is |
| 626 # also handled correctly. |
| 627 reset_db |
| 628 forcedelete rbu.db |
| 629 do_execsql_test $tn3.8.2.1 { |
| 630 CREATE TABLE t1(a PRIMARY KEY, b); |
| 631 INSERT INTO t1 VALUES(1, 2); |
| 632 ATTACH 'rbu.db' AS rbu; |
| 633 CREATE TABLE data_t1(a, b, rbu_control); |
| 634 DETACH rbu; |
| 635 } |
| 636 do_test $tn3.8.2.1 { |
| 637 list [catch { run_rbu test.db rbu.db } msg] $msg |
| 638 } {0 SQLITE_DONE} |
| 639 |
648 # Test that RBU can update indexes containing NULL values. | 640 # Test that RBU can update indexes containing NULL values. |
649 # | 641 # |
650 reset_db | 642 reset_db |
651 forcedelete rbu.db | 643 forcedelete rbu.db |
652 do_execsql_test $tn3.9.1 { | 644 do_execsql_test $tn3.9.1 { |
653 CREATE TABLE t1(a PRIMARY KEY, b, c); | 645 CREATE TABLE t1(a PRIMARY KEY, b, c); |
654 CREATE INDEX i1 ON t1(b, c); | 646 CREATE INDEX i1 ON t1(b, c); |
655 INSERT INTO t1 VALUES(1, 1, NULL); | 647 INSERT INTO t1 VALUES(1, 1, NULL); |
656 INSERT INTO t1 VALUES(2, NULL, 2); | 648 INSERT INTO t1 VALUES(2, NULL, 2); |
657 INSERT INTO t1 VALUES(3, NULL, NULL); | 649 INSERT INTO t1 VALUES(3, NULL, NULL); |
(...skipping 13 matching lines...) Expand all Loading... |
671 } {2 {} 2} | 663 } {2 {} 2} |
672 do_execsql_test $tn3.9.4 { PRAGMA integrity_check } {ok} | 664 do_execsql_test $tn3.9.4 { PRAGMA integrity_check } {ok} |
673 | 665 |
674 catch { db close } | 666 catch { db close } |
675 eval $destroy_vfs | 667 eval $destroy_vfs |
676 } | 668 } |
677 | 669 |
678 | 670 |
679 finish_test | 671 finish_test |
680 | 672 |
OLD | NEW |