xref: /sqlite-3.40.0/ext/session/sessionwor.test (revision dac7e69d)
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 "CREATE TABLE t1(a INTEGER PRIMARY KEY, b) $wo ;"
73
74  do_iterator_test 1.1 t1 {
75    INSERT INTO t1 VALUES(1, 'two');
76  } {
77    {INSERT t1 0 X. {} {i 1 t two}}
78  }
79
80  do_iterator_test 2.$tn.2 t1 {
81    UPDATE t1 SET b='three'
82  } {
83    {UPDATE t1 0 X. {i 1 t two} {{} {} t three}}
84  }
85
86  do_iterator_test 2.$tn.3 t1 {
87    REPLACE INTO t1 VALUES(1, 'four');
88  } {
89    {UPDATE t1 0 X. {i 1 t three} {{} {} t four}}
90  }
91
92  do_iterator_test 2.$tn.4 t1 {
93    DELETE FROM t1;
94  } {
95    {DELETE t1 0 X. {i 1 t four} {}}
96  }
97}
98
99finish_test
100
101