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 #***********************************************************************
11 # This file implements regression tests for SQLite library.
14 if {![info exists testdir]} {
15 set testdir [file join [file dirname [info script]] .. .. test]
17 source [file join [file dirname [info script]] session_common.tcl]
18 source $testdir/tester.tcl
19 ifcapable !session {finish_test; return}
21 set testprefix sessionnoop
23 #-------------------------------------------------------------------------
26 # 1.*: Test that concatenating changesets cannot produce a noop UPDATE.
27 # 2.*: Test that rebasing changesets cannot produce a noop UPDATE.
28 # 3.*: Test that sqlite3changeset_apply() ignores noop UPDATE changes.
32 CREATE TABLE t1(a PRIMARY KEY, b, c, d);
33 INSERT INTO t1 VALUES(1, 1, 1, 1);
34 INSERT INTO t1 VALUES(2, 2, 2, 2);
35 INSERT INTO t1 VALUES(3, 3, 3, 3);
38 proc do_concat_test {tn sql1 sql2 res} {
39 uplevel [list do_test $tn [subst -nocommands {
40 set C1 [changeset_from_sql {$sql1}]
41 set C2 [changeset_from_sql {$sql2}]
42 set C3 [sqlite3changeset_concat [set C1] [set C2]]
44 sqlite3session_foreach elem [set C3] { lappend got [set elem] }
56 #-------------------------------------------------------------------------
59 CREATE TABLE t1(a PRIMARY KEY, b, c);
60 INSERT INTO t1 VALUES(1, 1, 1);
61 INSERT INTO t1 VALUES(2, 2, 2);
62 INSERT INTO t1 VALUES(3, 3, 3);
65 proc do_rebase_test {tn sql_local sql_remote conflict_res expected} {
66 proc xConflict {args} [list return $conflict_res]
69 do_test $tn [subst -nocommands {
71 set c_remote [changeset_from_sql {$sql_remote}]
75 set c_local [changeset_from_sql {$sql_local}]
76 set base [sqlite3changeset_apply_v2 db [set c_remote] xConflict]
79 sqlite3rebaser_create R
82 sqlite3session_foreach elem [R rebase [set c_local]] {
83 lappend res [set elem]
87 }] [list {*}$expected]
92 UPDATE t1 SET c=2 WHERE a=1; -- local
94 UPDATE t1 SET c=3 WHERE a=1; -- remote
96 {UPDATE t1 0 X.. {i 1 {} {} i 3} {{} {} {} {} i 2}}
100 UPDATE t1 SET c=2 WHERE a=1; -- local
102 UPDATE t1 SET c=3 WHERE a=1; -- remote
106 do_rebase_test 2.3.1 {
107 UPDATE t1 SET c=4 WHERE a=1; -- local
109 UPDATE t1 SET c=4 WHERE a=1 -- remote
111 {UPDATE t1 0 X.. {i 1 {} {} i 4} {{} {} {} {} i 4}}
114 do_rebase_test 2.3.2 {
115 UPDATE t1 SET c=5 WHERE a=1; -- local
117 UPDATE t1 SET c=5 WHERE a=1 -- remote
121 #-------------------------------------------------------------------------
124 do_execsql_test 3.0 {
125 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
126 INSERT INTO t1 VALUES(1, 1, 1);
127 INSERT INTO t1 VALUES(2, 2, 2);
128 INSERT INTO t1 VALUES(3, 3, 3);
129 INSERT INTO t1 VALUES(4, 4, 4);
132 # Arg $pkstr contains one character for each column in the table. An
133 # "X" for PK column, or a "." for a non-PK.
135 proc mk_tbl_header {name pkstr} {
136 set ret [binary format H2c 54 [string length $pkstr]]
137 foreach i [split $pkstr {}] {
139 append ret [binary format H2 01]
141 if {$i!="."} {error "bad pkstr: $pkstr ($i)"}
142 append ret [binary format H2 00]
146 append ret [binary format H2 00]
150 proc mk_update_change {args} {
151 set ret [binary format H2H2 17 00]
154 append ret [binary format H2 00]
156 append ret [binary format H2W 01 $a]
162 proc xConflict {args} { return "ABORT" }
164 set C [mk_tbl_header t1 X..]
165 append C [mk_update_change 1 {} 1 {} {} 500]
166 append C [mk_update_change 2 {} {} {} {} {}]
167 append C [mk_update_change 3 3 {} {} 600 {}]
168 append C [mk_update_change 4 {} {} {} {} {}]
170 sqlite3changeset_apply_v2 db $C xConflict
172 do_execsql_test 3.2 {