xref: /sqlite-3.40.0/ext/session/sessionE.test (revision dfe4e6bb)
1# 2015 June 02
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#
12# This file implements regression tests for the sessions module.
13# Specifically, it tests that operations on tables without primary keys
14# are ignored.
15#
16
17
18
19if {![info exists testdir]} {
20  set testdir [file join [file dirname [info script]] .. .. test]
21}
22source [file join [file dirname [info script]] session_common.tcl]
23source $testdir/tester.tcl
24ifcapable !session {finish_test; return}
25set testprefix sessionE
26
27#
28# Test plan:
29#
30#    1.*: Test that non-PK tables are not auto-attached.
31#    2.*: Test that explicitly attaching a non-PK table is a no-op.
32#    3.*: Test that sqlite3session_diff() on a non-PK table is a no-op.
33#
34
35
36#--------------------------------------------------------------------------
37reset_db
38do_execsql_test 1.0 {
39  CREATE TABLE t1(a, b);
40  CREATE TABLE t2(a PRIMARY KEY, b);
41}
42do_test 1.1 {
43  sqlite3session S db main
44  S attach *
45  breakpoint
46  execsql {
47    INSERT INTO t1 VALUES(1, 2);
48    INSERT INTO t2 VALUES(1, 2);
49  }
50} {}
51do_changeset_test 1.2 S {
52  {INSERT t2 0 X. {} {i 1 i 2}}
53}
54S delete
55
56reset_db
57do_execsql_test 2.0 {
58  CREATE TABLE t1(a, b);
59  CREATE TABLE t2(a PRIMARY KEY, b);
60}
61do_test 2.1 {
62  sqlite3session S db main
63  S attach t1
64  S attach t2
65  breakpoint
66  execsql {
67    INSERT INTO t1 VALUES(3, 4);
68    INSERT INTO t2 VALUES(3, 4);
69    INSERT INTO t1 VALUES(5, 6);
70    INSERT INTO t2 VALUES(5, 6);
71  }
72} {}
73do_changeset_test 2.2 S {
74  {INSERT t2 0 X. {} {i 3 i 4}}
75  {INSERT t2 0 X. {} {i 5 i 6}}
76}
77S delete
78
79reset_db
80forcedelete test.db2
81do_execsql_test 3.0 {
82  ATTACH 'test.db2' AS aux;
83  CREATE TABLE aux.t1(a, b);
84  CREATE TABLE aux.t2(a PRIMARY KEY, b);
85
86  CREATE TABLE t1(a, b);
87  CREATE TABLE t2(a PRIMARY KEY, b);
88
89  INSERT INTO t1 VALUES(1, 2);
90  INSERT INTO t2 VALUES(3, 4);
91}
92do_test 3.1 {
93  sqlite3session S db main
94  S attach t1
95  S diff aux t1
96
97  S attach t2
98  S diff aux t2
99} {}
100do_changeset_test 3.2 S {
101  {INSERT t2 0 X. {} {i 3 i 4}}
102}
103do_execsql_test 3.3 {
104  INSERT INTO t1 VALUES(5, 6);
105  INSERT INTO t2 VALUES(7, 8);
106}
107do_changeset_test 3.4 S {
108  {INSERT t2 0 X. {} {i 3 i 4}}
109  {INSERT t2 0 X. {} {i 7 i 8}}
110}
111
112
113S delete
114
115finish_test
116
117
118