xref: /sqlite-3.40.0/ext/session/sessionwor.test (revision 9cffb0ff)
1# 2017 Jan 31
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# The focus of this file is testing the session module. Specifically,
13# testing support for WITHOUT ROWID tables.
14#
15
16if {![info exists testdir]} {
17  set testdir [file join [file dirname [info script]] .. .. test]
18}
19source [file join [file dirname [info script]] session_common.tcl]
20source $testdir/tester.tcl
21ifcapable !session {finish_test; return}
22
23set testprefix sessionwor
24
25proc test_reset {} {
26  catch { db close }
27  catch { db2 close }
28  forcedelete test.db test.db2
29  sqlite3 db test.db
30  sqlite3 db2 test.db2
31}
32
33foreach {tn wo} {
34  1 ""
35  2 "WITHOUT ROWID"
36} {
37  reset_db
38
39  do_execsql_test 1.$tn.0 "CREATE TABLE t1(a PRIMARY KEY, b) $wo ;"
40
41  do_iterator_test 1.$tn.1 t1 {
42    INSERT INTO t1 VALUES('one', 'two');
43  } {
44    {INSERT t1 0 X. {} {t one t two}}
45  }
46
47  do_iterator_test 1.$tn.2 t1 {
48    UPDATE t1 SET b='three'
49  } {
50    {UPDATE t1 0 X. {t one t two} {{} {} t three}}
51  }
52
53  do_iterator_test 1.$tn.3 t1 {
54    REPLACE INTO t1 VALUES('one', 'four');
55  } {
56    {UPDATE t1 0 X. {t one t three} {{} {} t four}}
57  }
58
59  do_iterator_test 1.$tn.4 t1 {
60    DELETE FROM t1;
61  } {
62    {DELETE t1 0 X. {t one t four} {}}
63  }
64}
65
66foreach {tn wo} {
67  1 ""
68  2 "WITHOUT ROWID"
69} {
70  reset_db
71
72  do_execsql_test 2.$tn.0.1 "CREATE TABLE t1(a INTEGER PRIMARY KEY, b) $wo ;"
73  do_execsql_test 2.$tn.0.2 "CREATE TABLE t2(a INTEGER PRIMARY KEY, b) $wo ;"
74  do_execsql_test 2.$tn.0.3 "CREATE TABLE t3(a INTEGER PRIMARY KEY, b) $wo ;"
75
76  do_iterator_test 1.1 t1 {
77    INSERT INTO t1 VALUES(1, 'two');
78  } {
79    {INSERT t1 0 X. {} {i 1 t two}}
80  }
81
82  do_iterator_test 2.$tn.2 t1 {
83    UPDATE t1 SET b='three'
84  } {
85    {UPDATE t1 0 X. {i 1 t two} {{} {} t three}}
86  }
87
88  do_iterator_test 2.$tn.3 t1 {
89    REPLACE INTO t1 VALUES(1, 'four');
90  } {
91    {UPDATE t1 0 X. {i 1 t three} {{} {} t four}}
92  }
93
94  do_iterator_test 2.$tn.4 t1 {
95    DELETE FROM t1;
96  } {
97    {DELETE t1 0 X. {i 1 t four} {}}
98  }
99
100  do_execsql_test 2.$tn.5 {
101    INSERT INTO t1 VALUES(1, 'one');
102    INSERT INTO t1 VALUES(2, 'two');
103    INSERT INTO t1 VALUES(3, 'three');
104  }
105
106  do_iterator_test 2.$tn.6 t2 {
107    INSERT INTO t2 SELECT a, b FROM t1
108  } {
109    {INSERT t2 0 X. {} {i 1 t one}}
110    {INSERT t2 0 X. {} {i 2 t two}}
111    {INSERT t2 0 X. {} {i 3 t three}}
112  }
113  do_iterator_test 2.$tn.7 t3 {
114    INSERT INTO t3 SELECT * FROM t1
115  } {
116    {INSERT t3 0 X. {} {i 1 t one}}
117    {INSERT t3 0 X. {} {i 2 t two}}
118    {INSERT t3 0 X. {} {i 3 t three}}
119  }
120}
121
122finish_test
123
124