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 session8
25 # Like [dbcksum] in tester.tcl. Except this version is not sensitive
26 # to changes in the value of implicit IPK columns.
28 proc udbcksum {db dbname} {
29 if {$dbname=="temp"} {
30 set master sqlite_temp_master
32 set master $dbname.sqlite_master
34 set alltab [$db eval "SELECT name FROM $master WHERE type='table'"]
35 set txt [$db eval "SELECT * FROM $master"]\n
37 append txt [lsort [$db eval "SELECT * FROM $dbname.$tab"]]\n
42 proc do_then_undo {tn sql} {
43 set ck1 [udbcksum db main]
45 sqlite3session S db main
49 set ck2 [udbcksum db main]
51 set invert [sqlite3changeset_invert [S changeset]]
53 sqlite3changeset_apply db $invert noop
55 set ck3 [udbcksum db main]
57 set a [expr {$ck1==$ck2}]
58 set b [expr {$ck1==$ck3}]
59 uplevel [list do_test $tn.1 "set {} $a" 0]
60 uplevel [list do_test $tn.2 "set {} $b" 1]
64 CREATE TABLE t1(a PRIMARY KEY, b);
65 INSERT INTO t1 VALUES(1, 2);
66 INSERT INTO t1 VALUES('abc', 'xyz');
68 do_then_undo 1.2 { INSERT INTO t1 VALUES(3, 4); }
69 do_then_undo 1.3 { DELETE FROM t1 WHERE b=2; }
70 do_then_undo 1.4 { UPDATE t1 SET b = 3 WHERE a = 1; }
73 CREATE TABLE t2(a, b PRIMARY KEY);
74 INSERT INTO t2 VALUES(1, 2);
75 INSERT INTO t2 VALUES('abc', 'xyz');
77 do_then_undo 1.2 { INSERT INTO t2 VALUES(3, 4); }
78 do_then_undo 1.3 { DELETE FROM t2 WHERE b=2; }
79 do_then_undo 1.4 { UPDATE t1 SET a = '123' WHERE b = 'xyz'; }
82 CREATE TABLE t3(a, b, c, d, e, PRIMARY KEY(c, e));
83 INSERT INTO t3 VALUES('x', 45, 0.0, 'abcdef', 12);
84 INSERT INTO t3 VALUES(45, 0.0, 'abcdef', 12, 'x');
85 INSERT INTO t3 VALUES(0.0, 'abcdef', 12, 'x', 45);
88 do_then_undo 3.2 { UPDATE t3 SET b=b||b WHERE e!='x' }
89 do_then_undo 3.3 { UPDATE t3 SET a = 46 }