xref: /sqlite-3.40.0/ext/session/sessionH.test (revision 9e5ecdc1)
1# 2018 January 18
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
13if {![info exists testdir]} {
14  set testdir [file join [file dirname [info script]] .. .. test]
15}
16source [file join [file dirname [info script]] session_common.tcl]
17source $testdir/tester.tcl
18ifcapable !session {finish_test; return}
19set testprefix sessionH
20
21forcedelete test.db2
22sqlite3 db2 test.db2
23
24do_test 1.0 {
25  do_common_sql {
26    CREATE TABLE t1(a, b, c, PRIMARY KEY(a, b));
27  }
28  do_then_apply_sql {
29    WITH s(i) AS (
30      VALUES(1) UNION ALL SELECT i+1 FROM s WHERe i<10000
31    )
32    INSERT INTO t1 SELECT 'abcde', randomblob(16), i FROM s;
33  }
34  compare_db db db2
35} {}
36
37#------------------------------------------------------------------------
38db2 close
39reset_db
40
41do_execsql_test 2.0 {
42  CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
43  INSERT INTO main.t1 VALUES(1, 2, 3), (4, 5, 6), (7, 8, 9);
44}
45
46do_test 2.1 {
47  sqlite3session S db main
48  S attach *
49  db eval {
50    BEGIN;
51      INSERT INTO t1 VALUES(10, 11, 12);
52      DELETE FROM t1 WHERE a=1;
53      UPDATE t1 SET b='five', c='six' WHERE a=4;
54  }
55
56  set C [S changeset]
57  db eval ROLLBACK
58  S delete
59  set {} {}
60} {}
61
62do_execsql_test 2.2 {
63  CREATE TEMP TABLE t1(a INTEGER PRIMARY KEY, b, c);
64  INSERT INTO temp.t1 VALUES(1, 2, 3), (4, 5, 6), (7, 8, 9);
65}
66
67set ::conflict [list]
68proc xConflict {args} { lappend ::conflict $args ; return "" }
69do_test 2.3 {
70  sqlite3changeset_apply db $C xConflict
71  set ::conflict
72} {}
73do_execsql_test 2.4 {
74  SELECT * FROM main.t1;
75  SELECT '****';
76  SELECT * FROM temp.t1;
77} {
78  4 five six 7 8 9 10 11 12
79  ****
80  1 2 3 4 5 6 7 8 9
81}
82
83
84finish_test
85