1# 2011 April 13 2# 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 the session module. 12# Specifically, for the sqlite3changeset_concat() command. 13# 14 15if {![info exists testdir]} { 16 set testdir [file join [file dirname [info script]] .. .. test] 17} 18source [file join [file dirname [info script]] session_common.tcl] 19source $testdir/tester.tcl 20ifcapable !session {finish_test; return} 21 22set testprefix session5 23 24proc do_concat_test {tn sql1 sql2} { 25 sqlite3session S1 db main ; S1 attach * 26 sqlite3session S2 db main ; S2 attach * 27 28 execsql $sql1 29 set C1 [S1 changeset] 30 S1 delete 31 32 sqlite3session S1 db main ; S1 attach * 33 34 execsql $sql2 35 set C2 [S1 changeset] 36 S1 delete 37 38 set C3 [S2 changeset] 39 S2 delete 40 41 set C4 [sqlite3changeset_concat $C1 $C2] 42 43 set c3 [list] 44 set c4 [list] 45 sqlite3session_foreach c $C3 { lappend c3 $c } 46 sqlite3session_foreach c $C4 { lappend c4 $c } 47 set c3 [lsort $c3] 48 set c4 [lsort $c4] 49 50 do_test $tn [list set {} $c4] $c3 51} 52 53do_execsql_test 1.0 { 54 CREATE TABLE t1(a PRIMARY KEY, b); 55} 56 57do_concat_test 1.1.1 { 58 INSERT INTO t1 VALUES(1, 'one'); 59} { 60 INSERT INTO t1 VALUES(2, 'two'); 61} 62 63do_concat_test 1.1.2 { 64 UPDATE t1 SET b = 'five' WHERE a = 1; 65} { 66 UPDATE t1 SET b = 'six' WHERE a = 2; 67} 68 69do_concat_test 1.1.3 { 70 DELETE FROM t1 WHERE a = 1; 71} { 72 DELETE FROM t1 WHERE a = 2; 73} 74 75 76# 1.2.1: INSERT + DELETE -> (none) 77# 1.2.2: INSERT + UPDATE -> INSERT 78# 79# 1.2.3: DELETE + INSERT (matching data) -> (none) 80# 1.2.4: DELETE + INSERT (non-matching data) -> UPDATE 81# 82# 1.2.5: UPDATE + UPDATE (matching data) -> (none) 83# 1.2.6: UPDATE + UPDATE (non-matching data) -> UPDATE 84# 1.2.7: UPDATE + DELETE -> DELETE 85# 86do_concat_test 1.2.1 { 87 INSERT INTO t1 VALUES('x', 'y'); 88} { 89 DELETE FROM t1 WHERE a = 'x'; 90} 91do_concat_test 1.2.2 { 92 INSERT INTO t1 VALUES(5.0, 'five'); 93} { 94 UPDATE t1 SET b = 'six' WHERE a = 5.0; 95} 96 97do_execsql_test 1.2.3.1 "INSERT INTO t1 VALUES('I', 'one')" 98do_concat_test 1.2.3.2 { 99 DELETE FROM t1 WHERE a = 'I'; 100} { 101 INSERT INTO t1 VALUES('I', 'one'); 102} 103do_concat_test 1.2.4 { 104 DELETE FROM t1 WHERE a = 'I'; 105} { 106 INSERT INTO t1 VALUES('I', 'two'); 107} 108do_concat_test 1.2.5 { 109 UPDATE t1 SET b = 'five' WHERE a = 'I'; 110} { 111 UPDATE t1 SET b = 'two' WHERE a = 'I'; 112} 113do_concat_test 1.2.6 { 114 UPDATE t1 SET b = 'six' WHERE a = 'I'; 115} { 116 UPDATE t1 SET b = 'seven' WHERE a = 'I'; 117} 118do_concat_test 1.2.7 { 119 UPDATE t1 SET b = 'eight' WHERE a = 'I'; 120} { 121 DELETE FROM t1 WHERE a = 'I'; 122} 123 124finish_test 125