forked from sqlcipher/sqlcipher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaltertab2.test
More file actions
89 lines (78 loc) · 2.37 KB
/
altertab2.test
File metadata and controls
89 lines (78 loc) · 2.37 KB
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
# 2018 September 30
#
# 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
set testprefix altertab
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
ifcapable !altertable {
finish_test
return
}
ifcapable fts5 {
do_execsql_test 1.0 {
CREATE TABLE rr(a, b);
CREATE VIRTUAL TABLE ff USING fts5(a, b);
CREATE TRIGGER tr1 AFTER INSERT ON rr BEGIN
INSERT INTO ff VALUES(new.a, new.b);
END;
INSERT INTO rr VALUES('hello', 'world');
SELECT * FROM ff;
} {hello world}
do_execsql_test 1.1 {
ALTER TABLE ff RENAME TO ffff;
}
do_execsql_test 1.2 {
INSERT INTO rr VALUES('in', 'tcl');
SELECT * FROM ffff;
} {hello world in tcl}
}
#-------------------------------------------------------------------------
# Check that table names that appear in REFERENCES clauses are updated
# when a table is renamed unless:
#
# a) "PRAGMA legacy_alter_table" is true, and
# b) "PRAGMA foreign_keys" is false.
#
do_execsql_test 2.0 {
CREATE TABLE p1(a PRIMARY KEY, b);
CREATE TABLE c1(x REFERENCES p1);
CREATE TABLE c2(x, FOREIGN KEY (x) REFERENCES p1);
CREATE TABLE c3(x, FOREIGN KEY (x) REFERENCES p1(a));
}
do_execsql_test 2.1 {
ALTER TABLE p1 RENAME TO p2;
SELECT sql FROM sqlite_master WHERE name LIKE 'c%';
} {
{CREATE TABLE c1(x REFERENCES "p2")}
{CREATE TABLE c2(x, FOREIGN KEY (x) REFERENCES "p2")}
{CREATE TABLE c3(x, FOREIGN KEY (x) REFERENCES "p2"(a))}
}
do_execsql_test 2.2 {
PRAGMA legacy_alter_table = 1;
ALTER TABLE p2 RENAME TO p3;
SELECT sql FROM sqlite_master WHERE name LIKE 'c%';
} {
{CREATE TABLE c1(x REFERENCES "p2")}
{CREATE TABLE c2(x, FOREIGN KEY (x) REFERENCES "p2")}
{CREATE TABLE c3(x, FOREIGN KEY (x) REFERENCES "p2"(a))}
}
do_execsql_test 2.3 {
ALTER TABLE p3 RENAME TO p2;
PRAGMA foreign_keys = 1;
ALTER TABLE p2 RENAME TO p3;
SELECT sql FROM sqlite_master WHERE name LIKE 'c%';
} {
{CREATE TABLE c1(x REFERENCES "p3")}
{CREATE TABLE c2(x, FOREIGN KEY (x) REFERENCES "p3")}
{CREATE TABLE c3(x, FOREIGN KEY (x) REFERENCES "p3"(a))}
}
finish_test