blob: 9d54e7df5723ae4622127f14c5ad8e9f5f676e8b (
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# 200 July 1
#
# 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.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is attaching many database files to a single
# connection.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix attach4
ifcapable !attach {
finish_test
return
}
puts "Testing with SQLITE_MAX_ATTACHED=$SQLITE_MAX_ATTACHED"
set files {main test.db}
for {set ii 0} {$ii < $SQLITE_MAX_ATTACHED} {incr ii} {
lappend files aux$ii "test.db$ii"
}
do_test 1.1 {
sqlite3_limit db SQLITE_LIMIT_ATTACHED -1
} $SQLITE_MAX_ATTACHED
do_test 1.2.1 {
db close
foreach {name f} $files { forcedelete $f }
sqlite3 db test.db
foreach {name f} $files {
if {$name == "main"} continue
execsql "ATTACH '$f' AS $name"
}
db eval {PRAGMA database_list} {
lappend L $name [file tail $file]
}
set L
} $files
do_catchsql_test 1.2.2 {
ATTACH 'x.db' AS next;
} [list 1 "too many attached databases - max $SQLITE_MAX_ATTACHED"]
do_test 1.3 {
execsql BEGIN;
foreach {name f} $files {
execsql "CREATE TABLE $name.tbl(x)"
execsql "INSERT INTO $name.tbl VALUES('$f')"
}
execsql COMMIT;
} {}
do_test 1.4 {
set L [list]
foreach {name f} $files {
lappend L $name [execsql "SELECT x FROM $name.tbl"]
}
set L
} $files
set L [list]
set S ""
foreach {name f} $files {
if {[permutation] == "journaltest"} {
set mode delete
} else {
set mode wal
}
ifcapable !wal { set mode delete }
lappend L $mode
append S "
PRAGMA $name.journal_mode = WAL;
UPDATE $name.tbl SET x = '$name';
"
}
do_execsql_test 1.5 $S $L
do_test 1.6 {
set L [list]
foreach {name f} $files {
lappend L [execsql "SELECT x FROM $name.tbl"] $f
}
set L
} $files
do_test 1.7 {
execsql BEGIN;
foreach {name f} $files {
execsql "UPDATE $name.tbl SET x = '$f'"
}
execsql COMMIT;
} {}
do_test 1.8 {
set L [list]
foreach {name f} $files {
lappend L $name [execsql "SELECT x FROM $name.tbl"]
}
set L
} $files
db close
foreach {name f} $files { forcedelete $f }
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
ATTACH DATABASE '' AS aux;
CREATE TABLE IF NOT EXISTS aux.t1(a, b);
CREATE TEMPORARY TRIGGER tr1 DELETE ON t1 BEGIN
DELETE FROM t1;
END;
CREATE TABLE temp.t1(a, b);
}
do_execsql_test 2.1 {
DETACH DATABASE aux;
}
do_execsql_test 2.2 {
DROP TRIGGER tr1;
}
finish_test
|