1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# 2015-07-31
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Tests for the [sqldiff --changeset] command.
#
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source $testdir/tester.tcl
ifcapable !session {finish_test; return}
set testprefix sessiondiff
set PROG [test_find_sqldiff]
db close
proc sqlesc {id} {
set ret "'[string map {' ''} $id]'"
set ret
}
proc database_cksum {db1} {
set txt ""
sqlite3 dbtmp $db1
foreach tbl [dbtmp eval {SELECT name FROM sqlite_master WHERE type='table'}] {
set cols [list]
dbtmp eval "PRAGMA table_info = [sqlesc $tbl]" {
lappend cols "quote( $name )"
}
append txt [dbtmp eval \
"SELECT [join $cols {||'.'||}] FROM [sqlesc $tbl] ORDER BY 1"
]
}
dbtmp close
md5 $txt
}
proc readfile {filename} {
set fd [open $filename]
fconfigure $fd -translation binary -encoding binary
set data [read $fd]
close $fd
set data
}
proc get_changeset {db1 db2} {
exec $::PROG --changeset changeset.bin $db1 $db2
set bin [readfile changeset.bin]
return $bin
}
proc xConflict {args} {
return ""
}
proc do_changeset_test {tn sql1 sql2} {
forcedelete test.db123 test.db124
sqlite3 db test.db123
db eval $sql1
db close
sqlite3 db test.db124
db eval $sql2
set cs [get_changeset test.db124 test.db123]
sqlite3changeset_apply db $cs xConflict
db close
set database_cksum1 [database_cksum test.db123]
set database_cksum2 [database_cksum test.db124]
uplevel [list \
do_test $tn [list string compare $database_cksum1 $database_cksum2] 0
]
}
do_changeset_test 1.0 {
CREATE TABLE t1(x PRIMARY KEY);
} {
CREATE TABLE t1(x PRIMARY KEY);
}
do_changeset_test 1.1 {
CREATE TABLE t1(x PRIMARY KEY);
CREATE TABLE t2(x PRIMARY KEY, y);
INSERT INTO t2 VALUES(1, 2);
} {
CREATE TABLE t1(x PRIMARY KEY);
CREATE TABLE t2(x PRIMARY KEY, y);
INSERT INTO t2 VALUES(3, 4);
}
do_changeset_test 1.2 {
CREATE TABLE t2(a, b, c, PRIMARY KEY(b, c));
INSERT INTO t2 VALUES(1, 2, 3);
INSERT INTO t2 VALUES(4, 5, 6);
} {
CREATE TABLE t2(a, b, c, PRIMARY KEY(b, c));
INSERT INTO t2 VALUES(1, 2, 11);
INSERT INTO t2 VALUES(7, 8, 9);
}
finish_test
|