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 sessionnoop2
28 eval [string map [list %WO% $wo] {
29 do_execsql_test $tn.1.0 {
30 CREATE TABLE t1(a PRIMARY KEY, b, c) %WO%;
31 INSERT INTO t1 VALUES('a', 'A', 'AAA');
32 INSERT INTO t1 VALUES('b', 'B', 'BBB');
33 INSERT INTO t1 VALUES('c', 'C', 'CCC');
34 INSERT INTO t1 VALUES('d', 'D', 'DDD');
35 INSERT INTO t1 VALUES('e', 'E', 'EEE');
41 do_execsql_test -db db2 $tn.1.1 {
42 CREATE TABLE t1(a PRIMARY KEY, b, c) %WO%;
43 INSERT INTO t1 VALUES('a', 'A', 'AAA');
44 INSERT INTO t1 VALUES('b', 'B', '123');
45 INSERT INTO t1 VALUES('c', 'C', 'CCC');
46 INSERT INTO t1 VALUES('e', 'E', 'EEE');
47 INSERT INTO t1 VALUES('f', 'F', 'FFF');
50 set C [changeset_from_sql {
51 UPDATE t1 SET c='123' WHERE a='b';
52 DELETE FROM t1 WHERE a='d';
53 INSERT INTO t1 VALUES('f', 'F', 'FFF');
57 set ::conflict_list [list]
58 proc xConflict {args} {
59 lappend ::conflict_list $args
63 sqlite3changeset_apply_v2 db2 $C xConflict
66 {UPDATE t1 DATA {t b {} {} t BBB} {{} {} {} {} t 123} {t b t B t 123}}
67 {INSERT t1 CONFLICT {t f t F t FFF} {t f t F t FFF}}
68 {DELETE t1 NOTFOUND {t d t D t DDD}}
71 set ::conflict_list [list]
72 sqlite3changeset_apply_v2 db2 $C xConflict
75 {UPDATE t1 DATA {t b {} {} t BBB} {{} {} {} {} t 123} {t b t B t 123}}
76 {INSERT t1 CONFLICT {t f t F t FFF} {t f t F t FFF}}
77 {DELETE t1 NOTFOUND {t d t D t DDD}}
81 set ::conflict_list [list]
82 sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
86 do_execsql_test -db db2 1.5 {
87 UPDATE t1 SET b='G' WHERE a='f';
88 UPDATE t1 SET c='456' WHERE a='b';
92 set ::conflict_list [list]
93 sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
96 {UPDATE t1 DATA {t b {} {} t BBB} {{} {} {} {} t 123} {t b t B t 456}}
97 {INSERT t1 CONFLICT {t f t F t FFF} {t f t G t FFF}}
102 #--------------------------------------------------------------------------
107 do_execsql_test $tn.2.0 {
108 CREATE TABLE t1(a PRIMARY KEY, b) %WO%;
110 do_execsql_test -db db2 $tn.2.1 {
111 CREATE TABLE t1(a PRIMARY KEY, b, c DEFAULT 'val') %WO%;
115 do_then_apply_sql -ignorenoop {
116 INSERT INTO t1 VALUES(1, 2);
118 do_then_apply_sql -ignorenoop {
119 UPDATE t1 SET b=2 WHERE a=1
129 #-------------------------------------------------------------------------
132 do_execsql_test 3.0 {
133 CREATE TABLE xyz(a, b, c, PRIMARY KEY(a, b), UNIQUE(c));
136 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100
138 INSERT INTO xyz SELECT i, i, i FROM s;
139 VACUUM INTO 'test.db2';
142 set C [changeset_from_sql { ANALYZE }]
145 set ::conflict_list [list]
146 proc xConflict {args} { lappend ::conflict_list $args ; return "OMIT" }
148 sqlite3changeset_apply_v2 db2 $C xConflict
153 sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
158 sqlite3changeset_apply_v2 db2 $C xConflict
161 {INSERT sqlite_stat1 CONFLICT {t xyz t sqlite_autoindex_xyz_1 t {100 1 1}} {t xyz t sqlite_autoindex_xyz_1 t {100 1 1}}}
162 {INSERT sqlite_stat1 CONFLICT {t xyz t sqlite_autoindex_xyz_2 t {100 1}} {t xyz t sqlite_autoindex_xyz_2 t {100 1}}}
165 do_execsql_test -db db2 3.4 {
166 UPDATE sqlite_stat1 SET stat='200 1 1' WHERE idx='sqlite_autoindex_xyz_1';
170 set ::conflict_list [list]
171 sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
174 {INSERT sqlite_stat1 CONFLICT {t xyz t sqlite_autoindex_xyz_1 t {100 1 1}} {t xyz t sqlite_autoindex_xyz_1 t {200 1 1}}}