Enhance the command-line completion extension to return the names of
[sqlite.git] / ext / session / session8.test
blob9f70fe2829bf34f00f5b0d02aba52b4999f8fc6e
1 # 2011 July 13
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]
16
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
23 proc noop {args} {}
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
31   } else {
32     set master $dbname.sqlite_master
33   }
34   set alltab [$db eval "SELECT name FROM $master WHERE type='table'"]
35   set txt [$db eval "SELECT * FROM $master"]\n
36   foreach tab $alltab {
37     append txt [lsort [$db eval "SELECT * FROM $dbname.$tab"]]\n
38   }
39   return [md5 $txt]
42 proc do_then_undo {tn sql} {
43   set ck1 [udbcksum db main]
45   sqlite3session S db main
46   S attach *
47   db eval $sql
49   set ck2 [udbcksum db main]
50   
51   set invert [sqlite3changeset_invert [S changeset]]
52   S delete
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]
63 do_execsql_test 1.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; }
72 do_execsql_test 2.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'; }
81 do_execsql_test 3.1 {
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 }
91 finish_test