summaryrefslogtreecommitdiff
path: root/test/tkt-f3e5abed55.test
blob: 3c793d4f4da854962f1a16dd9ff6949862acae18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# 2010 July 29
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl

foreach f [glob -nocomplain test.db*mj*] { forcedelete $f }
forcedelete test.db2

do_test tkt-f3e5abed55-1.1 {
  execsql {
    ATTACH 'test.db2' AS aux;
    CREATE TABLE main.t1(a, b);
    CREATE TABLE aux.t2(c, d);
  }
} {}

do_test tkt-f3e5abed55-1.2 {
  glob -nocomplain test.db*mj*
} {}

do_test tkt-f3e5abed55-1.3 {
  sqlite3 db2 test.db
  execsql { BEGIN; SELECT * FROM t1 } db2
} {}

do_test tkt-f3e5abed55-1.4 {
  execsql {
    BEGIN;
      INSERT INTO t1 VALUES(1, 2);
      INSERT INTO t2 VALUES(1, 2);
  }
  catchsql COMMIT
} {1 {database is locked}}

do_test tkt-f3e5abed55-1.5 {
  execsql COMMIT db2
  execsql COMMIT
} {}

do_test tkt-f3e5abed55-1.6 {
  glob -nocomplain test.db*mj*
} {}
foreach f [glob -nocomplain test.db*mj*] { forcedelete $f }
db close
db2 close



# Set up a testvfs so that the next time SQLite tries to delete the
# file "test.db-journal", a snapshot of the current file-system contents
# is taken.
#
# This test will not work with an in-memory journal.
#
if {[permutation]!="inmemory_journal"} {
  testvfs tvfs -default 1
  tvfs script xDelete
  tvfs filter xDelete
  proc xDelete {method file args} {
    if {[file tail $file] == "test.db-journal"} {
      faultsim_save
      tvfs filter {}
    }
    return "SQLITE_OK"
  }
  
  sqlite3 db  test.db
  sqlite3 db2 test.db
  do_test tkt-f3e5abed55-2.1 {
    execsql {
      ATTACH 'test.db2' AS aux;
      BEGIN;
        INSERT INTO t1 VALUES(3, 4);
        INSERT INTO t2 VALUES(3, 4);
    }
  } {}
  do_test tkt-f3e5abed55-2.2 {
    execsql { BEGIN; SELECT * FROM t1 } db2
  } {1 2}
  do_test tkt-f3e5abed55-2.3 {
    catchsql COMMIT
  } {1 {database is locked}}
  
  do_test tkt-f3e5abed55-2.4 {
    execsql COMMIT db2
    execsql {
      COMMIT;
      SELECT * FROM t1;
      SELECT * FROM t2;
    }
  } {1 2 3 4 1 2 3 4}
  do_test tkt-f3e5abed55-2.5 {
    db close
    db2 close
    faultsim_restore_and_reopen
    execsql {
      ATTACH 'test.db2' AS aux;
      SELECT * FROM t1;
      SELECT * FROM t2;
    }
  } {1 2 3 4 1 2 3 4}
}


finish_test