3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # Tests for the [sqldiff --changeset] command.
15 if {![info exists testdir]} {
16 set testdir [file join [file dirname [info script]] .. .. test]
18 source $testdir/tester.tcl
19 ifcapable !session {finish_test; return}
20 set testprefix sessiondiff
22 set PROG [test_find_sqldiff]
26 set ret "'[string map {' ''} $id]'"
30 proc database_cksum {db1} {
34 foreach tbl [dbtmp eval {SELECT name FROM sqlite_master WHERE type='table'}] {
36 dbtmp eval "PRAGMA table_info = [sqlesc $tbl]" {
37 lappend cols "quote( $name )"
39 append txt [dbtmp eval \
40 "SELECT [join $cols {||'.'||}] FROM [sqlesc $tbl] ORDER BY 1"
48 proc readfile {filename} {
49 set fd [open $filename]
50 fconfigure $fd -translation binary -encoding binary
56 proc get_changeset {db1 db2} {
57 exec $::PROG --changeset changeset.bin $db1 $db2
58 set bin [readfile changeset.bin]
62 proc xConflict {args} {
66 proc do_changeset_test {tn sql1 sql2} {
67 forcedelete test.db123 test.db124
76 set cs [get_changeset test.db124 test.db123]
77 sqlite3changeset_apply db $cs xConflict
80 set database_cksum1 [database_cksum test.db123]
81 set database_cksum2 [database_cksum test.db124]
84 do_test $tn [list string compare $database_cksum1 $database_cksum2] 0
88 do_changeset_test 1.0 {
89 CREATE TABLE t1(x PRIMARY KEY);
91 CREATE TABLE t1(x PRIMARY KEY);
94 do_changeset_test 1.1 {
95 CREATE TABLE t1(x PRIMARY KEY);
96 CREATE TABLE t2(x PRIMARY KEY, y);
97 INSERT INTO t2 VALUES(1, 2);
99 CREATE TABLE t1(x PRIMARY KEY);
100 CREATE TABLE t2(x PRIMARY KEY, y);
101 INSERT INTO t2 VALUES(3, 4);
104 do_changeset_test 1.2 {
105 CREATE TABLE t2(a, b, c, PRIMARY KEY(b, c));
106 INSERT INTO t2 VALUES(1, 2, 3);
107 INSERT INTO t2 VALUES(4, 5, 6);
109 CREATE TABLE t2(a, b, c, PRIMARY KEY(b, c));
110 INSERT INTO t2 VALUES(1, 2, 11);
111 INSERT INTO t2 VALUES(7, 8, 9);