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 the session module. More
12 # specifically, it focuses on testing the session modules response to
13 # database schema modifications and mismatches.
16 if {![info exists testdir]} {
17 set testdir [file join [file dirname [info script]] .. .. test]
19 source [file join [file dirname [info script]] session_common.tcl]
20 source $testdir/tester.tcl
21 ifcapable !session {finish_test; return}
23 set testprefix session3
25 #-------------------------------------------------------------------------
26 # These tests - session3-1.* - verify that the session module behaves
27 # correctly when confronted with a schema mismatch when applying a
28 # changeset (in function sqlite3changeset_apply()).
30 # session3-1.1.*: Table does not exist in target db.
31 # session3-1.2.*: Table has wrong number of columns in target db.
32 # session3-1.3.*: Table has wrong PK columns in target db.
39 proc log {code msg} { lappend ::log $code $msg }
45 CREATE TABLE t1(a PRIMARY KEY, b);
50 INSERT INTO t1 VALUES(1, 2);
51 INSERT INTO t1 VALUES(3, 4);
54 } {SQLITE_SCHEMA {sqlite3changeset_apply(): no such table: t1}}
57 execsql { CREATE TABLE t1(a PRIMARY KEY, b, c) } db2
62 INSERT INTO t1 VALUES(5, 6);
63 INSERT INTO t1 VALUES(7, 8);
68 db2 eval { SELECT * FROM t1 }
74 CREATE TABLE t1(a, b PRIMARY KEY);
80 INSERT INTO t1 VALUES(9, 10);
81 INSERT INTO t1 VALUES(11, 12);
84 } {SQLITE_SCHEMA {sqlite3changeset_apply(): primary key mismatch for table t1}}
86 #-------------------------------------------------------------------------
87 # These tests - session3-2.* - verify that the session module behaves
88 # correctly when the schema of an attached table is modified during the
91 # session3-2.1.*: Table is dropped midway through the session.
92 # session3-2.2.*: Table is dropped and recreated with a different # cols.
93 # session3-2.3.*: Table is dropped and recreated with a different PK.
95 # In all of these scenarios, the call to sqlite3session_changeset() will
96 # return SQLITE_SCHEMA. Also:
98 # session3-2.4.*: Table is dropped and recreated with an identical schema.
99 # In this case sqlite3session_changeset() returns SQLITE_OK.
103 execsql { CREATE TABLE t2(a, b PRIMARY KEY) }
104 sqlite3session S db main
107 INSERT INTO t2 VALUES(1, 2);
110 list [catch { S changeset } msg] $msg
115 sqlite3session S db main
116 execsql { CREATE TABLE t2(a, b PRIMARY KEY, c) }
119 INSERT INTO t2 VALUES(1, 2, 3);
121 CREATE TABLE t2(a, b PRIMARY KEY);
123 list [catch { S changeset } msg] $msg
127 sqlite3session S db main
130 CREATE TABLE t2(a, b PRIMARY KEY, c);
134 INSERT INTO t2 VALUES(1, 2, 3);
136 CREATE TABLE t2(a, b PRIMARY KEY, c, d);
138 list [catch { S changeset } msg] $msg
142 sqlite3session S db main
145 CREATE TABLE t2(a, b PRIMARY KEY, c);
149 INSERT INTO t2 VALUES(1, 2, 3);
151 CREATE TABLE t2(a, b PRIMARY KEY);
152 INSERT INTO t2 VALUES(4, 5);
154 list [catch { S changeset } msg] $msg
158 sqlite3session S db main
161 CREATE TABLE t2(a, b PRIMARY KEY, c);
165 INSERT INTO t2 VALUES(1, 2, 3);
167 CREATE TABLE t2(a, b PRIMARY KEY, c, d);
168 INSERT INTO t2 VALUES(4, 5, 6, 7);
170 list [catch { S changeset } msg] $msg
175 sqlite3session S db main
178 CREATE TABLE t2(a, b PRIMARY KEY);
182 INSERT INTO t2 VALUES(1, 2);
184 CREATE TABLE t2(a PRIMARY KEY, b);
186 list [catch { S changeset } msg] $msg
191 sqlite3session S db main
194 CREATE TABLE t2(a, b PRIMARY KEY);
198 INSERT INTO t2 VALUES(1, 2);
200 CREATE TABLE t2(a, b PRIMARY KEY);
202 list [catch { S changeset } msg] $msg