#
reset_db
ifcapable !trigger&&foreignkey {
- do_test e__fkey-2.1 {
+ do_test e_fkey-2.1 {
execsql {
PRAGMA foreign_keys = ON;
CREATE TABLE p(i PRIMARY KEY);
SELECT * FROM c;
}
} {hello}
- do_test e__fkey-2.2 {
+ do_test e_fkey-2.2 {
execsql { PRAGMA foreign_key_list(c) }
} {0 0 p j {} CASCADE {NO ACTION} NONE}
- do_test e__fkey-2.3 {
+ do_test e_fkey-2.3 {
execsql { PRAGMA foreign_keys }
} {}
}
#
reset_db
ifcapable !foreignkey {
- do_test e__fkey-3.1 {
+ do_test e_fkey-3.1 {
execsql { CREATE TABLE p(i PRIMARY KEY) }
catchsql { CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE) }
} {1 {near "ON": syntax error}}
- do_test e__fkey-3.2 {
+ do_test e_fkey-3.2 {
# This is allowed, as in this build, "REFERENCES" is not a keyword.
# The declared datatype of column j is "REFERENCES p".
execsql { CREATE TABLE c(j REFERENCES p) }
} {}
- do_test e__fkey-3.3 {
+ do_test e_fkey-3.3 {
execsql { PRAGMA table_info(c) }
} {0 j {REFERENCES p} 0 {} 0}
- do_test e__fkey-3.4 {
+ do_test e_fkey-3.4 {
execsql { PRAGMA foreign_key_list(c) }
} {}
- do_test e__fkey-3.5 {
+ do_test e_fkey-3.5 {
execsql { PRAGMA foreign_keys }
} {}
}
# This also tests that foreign key constraints are disabled by default.
#
drop_all_tables
-do_test e__fkey-4.1 {
+do_test e_fkey-4.1 {
execsql {
CREATE TABLE p(i PRIMARY KEY);
CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE);
SELECT * FROM c;
}
} {hello}
-do_test e__fkey-4.2 {
+do_test e_fkey-4.2 {
execsql {
DELETE FROM c;
DELETE FROM p;
# the example code in section 2 of foreignkeys.in.
#
reset_db
-do_test e__fkey-5.1 {
+do_test e_fkey-5.1 {
execsql { PRAGMA foreign_keys }
} {0}
-do_test e__fkey-5.2 {
+do_test e_fkey-5.2 {
execsql {
PRAGMA foreign_keys = ON;
PRAGMA foreign_keys;
}
} {1}
-do_test e__fkey-5.3 {
+do_test e_fkey-5.3 {
execsql {
PRAGMA foreign_keys = OFF;
PRAGMA foreign_keys;
# while not in auto-commit mode.
#
reset_db
-do_test e__fkey-6.1 {
+do_test e_fkey-6.1 {
execsql {
PRAGMA foreign_keys = ON;
CREATE TABLE t1(a UNIQUE, b);
DELETE FROM t1
}
} {1 {foreign key constraint failed}}
-do_test e__fkey-6.2 {
+do_test e_fkey-6.2 {
execsql { PRAGMA foreign_keys }
} {1}
-do_test e__fkey-6.3 {
+do_test e_fkey-6.3 {
execsql {
COMMIT;
PRAGMA foreign_keys = OFF;
PRAGMA foreign_keys;
}
} {0}
-do_test e__fkey-6.4 {
+do_test e_fkey-6.4 {
execsql COMMIT
} {}
#
# Verify that the syntax in the first example in section 1 is valid.
#
-do_test e__fkey-7.1 {
+do_test e_fkey-7.1 {
execsql {
CREATE TABLE artist(
artistid INTEGER PRIMARY KEY,
# Attempting to insert a row into the 'track' table that corresponds
# to no row in the 'artist' table fails.
#
-do_test e__fkey-8.1 {
+do_test e_fkey-8.1 {
catchsql { INSERT INTO track VALUES(1, 'track 1', 1) }
} {1 {foreign key constraint failed}}
-do_test e__fkey-8.2 {
+do_test e_fkey-8.2 {
execsql { INSERT INTO artist VALUES(2, 'artist 1') }
catchsql { INSERT INTO track VALUES(1, 'track 1', 1) }
} {1 {foreign key constraint failed}}
-do_test e__fkey-8.2 {
+do_test e_fkey-8.2 {
execsql { INSERT INTO track VALUES(1, 'track 1', 2) }
} {}
# Attempting to delete a row from the 'artist' table while there are
# dependent rows in the track table also fails.
#
-do_test e__fkey-9.1 {
+do_test e_fkey-9.1 {
catchsql { DELETE FROM artist WHERE artistid = 2 }
} {1 {foreign key constraint failed}}
-do_test e__fkey-9.2 {
+do_test e_fkey-9.2 {
execsql {
DELETE FROM track WHERE trackartist = 2;
DELETE FROM artist WHERE artistid = 2;
# If the foreign key column (trackartist) in table 'track' is set to NULL,
# there is no requirement for a matching row in the 'artist' table.
#
-do_test e__fkey-10.1 {
+do_test e_fkey-10.1 {
execsql {
INSERT INTO track VALUES(1, 'track 1', NULL);
INSERT INTO track VALUES(2, 'track 2', NULL);
}
} {}
-do_test e__fkey-10.2 {
+do_test e_fkey-10.2 {
execsql { SELECT * FROM artist }
} {}
-do_test e__fkey-10.3 {
+do_test e_fkey-10.3 {
# Setting the trackid to a non-NULL value fails, of course.
catchsql { UPDATE track SET trackartist = 5 WHERE trackid = 1 }
} {1 {foreign key constraint failed}}
-do_test e__fkey-10.4 {
+do_test e_fkey-10.4 {
execsql {
INSERT INTO artist VALUES(5, 'artist 5');
UPDATE track SET trackartist = 5 WHERE trackid = 1;
}
catchsql { DELETE FROM artist WHERE artistid = 5}
} {1 {foreign key constraint failed}}
-do_test e__fkey-10.5 {
+do_test e_fkey-10.5 {
execsql {
UPDATE track SET trackartist = NULL WHERE trackid = 1;
DELETE FROM artist WHERE artistid = 5;
error $res
}
- do_test e__fkey-11.$tn {
+ do_test e_fkey-11.$tn {
execsql {
SELECT count(*) FROM track WHERE NOT (
trackartist IS NULL OR
# to prohibit NULL child keys from being inserted.
#
drop_all_tables
-do_test e__fkey-12.1 {
+do_test e_fkey-12.1 {
execsql {
CREATE TABLE artist(
artistid INTEGER PRIMARY KEY,
);
}
} {}
-do_test e__fkey-12.2 {
+do_test e_fkey-12.2 {
catchsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', NULL) }
} {1 {track.trackartist may not be NULL}}
# Test an example from foreignkeys.html.
#
drop_all_tables
-do_test e__fkey-13.1 {
+do_test e_fkey-13.1 {
execsql {
CREATE TABLE artist(
artistid INTEGER PRIMARY KEY,
INSERT INTO track VALUES(13, 'My Way', 2);
}
} {}
-do_test e__fkey-13.2 {
+do_test e_fkey-13.2 {
catchsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', 3) }
} {1 {foreign key constraint failed}}
-do_test e__fkey-13.3 {
+do_test e_fkey-13.3 {
execsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', NULL) }
} {}
-do_test e__fkey-13.4 {
+do_test e_fkey-13.4 {
catchsql {
UPDATE track SET trackartist = 3 WHERE trackname = 'Mr. Bojangles';
}
} {1 {foreign key constraint failed}}
-do_test e__fkey-13.5 {
+do_test e_fkey-13.5 {
execsql {
INSERT INTO artist VALUES(3, 'Sammy Davis Jr.');
UPDATE track SET trackartist = 3 WHERE trackname = 'Mr. Bojangles';
#
# Test the second example from the first section of foreignkeys.html.
#
-do_test e__fkey-14.1 {
+do_test e_fkey-14.1 {
catchsql {
DELETE FROM artist WHERE artistname = 'Frank Sinatra';
}
} {1 {foreign key constraint failed}}
-do_test e__fkey-14.2 {
+do_test e_fkey-14.2 {
execsql {
DELETE FROM track WHERE trackname = 'My Way';
DELETE FROM artist WHERE artistname = 'Frank Sinatra';
}
} {}
-do_test e__fkey-14.3 {
+do_test e_fkey-14.3 {
catchsql {
UPDATE artist SET artistid=4 WHERE artistname = 'Dean Martin';
}
} {1 {foreign key constraint failed}}
-do_test e__fkey-14.4 {
+do_test e_fkey-14.4 {
execsql {
DELETE FROM track WHERE trackname IN('That''s Amore', 'Christmas Blues');
UPDATE artist SET artistid=4 WHERE artistname = 'Dean Martin';
# is a matching row in the parent table of a foreign key constraint.
#
drop_all_tables
-do_test e__fkey-15.1 {
+do_test e_fkey-15.1 {
execsql {
CREATE TABLE par(p PRIMARY KEY);
CREATE TABLE chi(c REFERENCES par);
} {integer text blob}
proc test_efkey_45 {tn isError sql} {
- do_test e__fkey-15.$tn.1 "
+ do_test e_fkey-15.$tn.1 "
catchsql {$sql}
" [lindex {{0 {}} {1 {foreign key constraint failed}}} $isError]
- do_test e__fkey-15.$tn.2 {
+ do_test e_fkey-15.$tn.2 {
execsql {
SELECT * FROM chi WHERE c IS NOT NULL AND c NOT IN (SELECT p FROM par)
}
# default collation sequence of the parent key column is used.
#
drop_all_tables
-do_test e__fkey-16.1 {
+do_test e_fkey-16.1 {
execsql {
CREATE TABLE t1(a COLLATE nocase PRIMARY KEY);
CREATE TABLE t2(b REFERENCES t1);
}
} {}
-do_test e__fkey-16.2 {
+do_test e_fkey-16.2 {
execsql {
INSERT INTO t1 VALUES('oNe');
INSERT INTO t2 VALUES('one');
UPDATE t1 SET a = 'ONE';
}
} {}
-do_test e__fkey-16.3 {
+do_test e_fkey-16.3 {
catchsql { UPDATE t2 SET b = 'two' WHERE rowid = 1 }
} {1 {foreign key constraint failed}}
-do_test e__fkey-16.4 {
+do_test e_fkey-16.4 {
catchsql { DELETE FROM t1 WHERE rowid = 1 }
} {1 {foreign key constraint failed}}
# before the comparison takes place.
#
drop_all_tables
-do_test e__fkey-17.1 {
+do_test e_fkey-17.1 {
execsql {
CREATE TABLE t1(a NUMERIC PRIMARY KEY);
CREATE TABLE t2(b TEXT REFERENCES t1);
}
} {}
-do_test e__fkey-17.2 {
+do_test e_fkey-17.2 {
execsql {
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES(2);
SELECT b, typeof(b) FROM t2;
}
} {2.0 text}
-do_test e__fkey-17.3 {
+do_test e_fkey-17.3 {
execsql { SELECT typeof(a) FROM t1 }
} {integer integer text}
-do_test e__fkey-17.4 {
+do_test e_fkey-17.4 {
catchsql { DELETE FROM t1 WHERE rowid = 2 }
} {1 {foreign key constraint failed}}
# columns.
#
drop_all_tables
-do_test e__fkey-18.1 {
+do_test e_fkey-18.1 {
execsql {
CREATE TABLE t2(a REFERENCES t1(x));
}
proc test_efkey_57 {tn isError sql} {
catchsql { DROP TABLE t1 }
execsql $sql
- do_test e__fkey-18.$tn {
+ do_test e_fkey-18.$tn {
catchsql { INSERT INTO t2 VALUES(NULL) }
} [lindex {{0 {}} {1 {foreign key mismatch}}} $isError]
}
# Problem with FK on child6 and child7.
#
drop_all_tables
-do_test e__fkey-19.1 {
+do_test e_fkey-19.1 {
execsql {
CREATE TABLE parent(a PRIMARY KEY, b UNIQUE, c, d, e, f);
CREATE UNIQUE INDEX i1 ON parent(c, d);
CREATE TABLE child7(r REFERENCES parent(c)); -- Err
}
} {}
-do_test e__fkey-19.2 {
+do_test e_fkey-19.2 {
execsql {
INSERT INTO parent VALUES(1, 2, 3, 4, 5, 6);
INSERT INTO child1 VALUES('xxx', 1);
INSERT INTO child3 VALUES(3, 4);
}
} {}
-do_test e__fkey-19.2 {
+do_test e_fkey-19.2 {
catchsql { INSERT INTO child4 VALUES('xxx', 5) }
} {1 {foreign key mismatch}}
-do_test e__fkey-19.3 {
+do_test e_fkey-19.3 {
catchsql { INSERT INTO child5 VALUES('xxx', 6) }
} {1 {foreign key mismatch}}
-do_test e__fkey-19.4 {
+do_test e_fkey-19.4 {
catchsql { INSERT INTO child6 VALUES(2, 3) }
} {1 {foreign key mismatch}}
-do_test e__fkey-19.5 {
+do_test e_fkey-19.5 {
catchsql { INSERT INTO child7 VALUES(3) }
} {1 {foreign key mismatch}}
# DML statements. The error text for these messages always matches
# either "foreign key mismatch" or "no such table*" (using [string match]).
#
-do_test e__fkey-20.1 {
+do_test e_fkey-20.1 {
execsql {
CREATE TABLE c1(c REFERENCES nosuchtable, d);
7 c6 p6 "foreign key mismatch"
8 c7 p7 "foreign key mismatch"
} {
- do_test e__fkey-20.$tn.1 {
+ do_test e_fkey-20.$tn.1 {
catchsql "INSERT INTO $tbl VALUES('a', 'b')"
} [list 1 $err]
- do_test e__fkey-20.$tn.2 {
+ do_test e_fkey-20.$tn.2 {
catchsql "UPDATE $tbl SET c = ?, d = ?"
} [list 1 $err]
- do_test e__fkey-20.$tn.3 {
+ do_test e_fkey-20.$tn.3 {
catchsql "INSERT INTO $tbl SELECT ?, ?"
} [list 1 $err]
if {$ptbl ne ""} {
- do_test e__fkey-20.$tn.4 {
+ do_test e_fkey-20.$tn.4 {
catchsql "DELETE FROM $ptbl"
} [list 1 $err]
- do_test e__fkey-20.$tn.5 {
+ do_test e_fkey-20.$tn.5 {
catchsql "UPDATE $ptbl SET a = ?, b = ?"
} [list 1 $err]
- do_test e__fkey-20.$tn.6 {
+ do_test e_fkey-20.$tn.6 {
catchsql "INSERT INTO $ptbl SELECT ?, ?"
} [list 1 $err]
}
# child key consists of a different number of columns to that primary key.
#
drop_all_tables
-do_test e__fkey-21.1 {
+do_test e_fkey-21.1 {
execsql {
CREATE TABLE parent2(a, b, PRIMARY KEY(a,b));
CREATE TABLE child10(x,y,z, FOREIGN KEY(x,y,z) REFERENCES parent2); -- Err
}
} {}
-do_test e__fkey-21.2 {
+do_test e_fkey-21.2 {
execsql {
INSERT INTO parent2 VALUES('I', 'II');
INSERT INTO child8 VALUES('I', 'II');
}
} {}
-do_test e__fkey-21.3 {
+do_test e_fkey-21.3 {
catchsql { INSERT INTO child9 VALUES('I') }
} {1 {foreign key mismatch}}
-do_test e__fkey-21.4 {
+do_test e_fkey-21.4 {
catchsql { INSERT INTO child9 VALUES('II') }
} {1 {foreign key mismatch}}
-do_test e__fkey-21.5 {
+do_test e_fkey-21.5 {
catchsql { INSERT INTO child9 VALUES(NULL) }
} {1 {foreign key mismatch}}
-do_test e__fkey-21.6 {
+do_test e_fkey-21.6 {
catchsql { INSERT INTO child10 VALUES('I', 'II', 'III') }
} {1 {foreign key mismatch}}
-do_test e__fkey-21.7 {
+do_test e_fkey-21.7 {
catchsql { INSERT INTO child10 VALUES(1, 2, 3) }
} {1 {foreign key mismatch}}
-do_test e__fkey-21.8 {
+do_test e_fkey-21.8 {
catchsql { INSERT INTO child10 VALUES(NULL, NULL, NULL) }
} {1 {foreign key mismatch}}
"CREATE TABLE child2(a, b, FOREIGN KEY(c, b) REFERENCES p(c, d))"
{unknown column "c" in foreign key definition}
} {
- do_test e__fkey-22.$fk.[incr i] {
+ do_test e_fkey-22.$fk.[incr i] {
catchsql $sql
} [list 1 $error]
}
# Test that a REFERENCING clause that does not specify parent key columns
# implicitly maps to the primary key of the parent table.
#
-do_test e__fkey-23.1 {
+do_test e_fkey-23.1 {
execsql {
CREATE TABLE p1(a, b, PRIMARY KEY(a, b));
CREATE TABLE p2(a, b PRIMARY KEY);
}
} {}
proc test_efkey_60 {tn isError sql} {
- do_test e__fkey-23.$tn "
+ do_test e_fkey-23.$tn "
catchsql {$sql}
" [lindex {{0 {}} {1 {foreign key constraint failed}}} $isError]
}
# not make a difference whether or not it is a UNIQUE index.
#
drop_all_tables
-do_test e__fkey-24.1 {
+do_test e_fkey-24.1 {
execsql {
CREATE TABLE parent(x, y, UNIQUE(y, x));
CREATE TABLE c1(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y));
}
} {}
proc test_efkey_61 {tn isError sql} {
- do_test e__fkey-24.$tn "
+ do_test e_fkey-24.$tn "
catchsql {$sql}
" [lindex {{0 {}} {1 {foreign key constraint failed}}} $isError]
}
# Also test that if the SELECT above would return any rows, a foreign
# key constraint is violated.
#
-do_test e__fkey-25.1 {
+do_test e_fkey-25.1 {
execsql {
CREATE TABLE artist(
artistid INTEGER PRIMARY KEY,
);
}
} {}
-do_test e__fkey-25.2 {
+do_test e_fkey-25.2 {
execsql {
PRAGMA foreign_keys = OFF;
EXPLAIN QUERY PLAN DELETE FROM artist WHERE 1;
EXPLAIN QUERY PLAN SELECT rowid FROM track WHERE trackartist = ?;
}
} {0 0 {TABLE artist} 0 0 {TABLE track}}
-do_test e__fkey-25.3 {
+do_test e_fkey-25.3 {
execsql {
PRAGMA foreign_keys = ON;
EXPLAIN QUERY PLAN DELETE FROM artist WHERE 1;
}
} {0 0 {TABLE artist} 0 0 {TABLE track}}
-do_test e__fkey-25.4 {
+do_test e_fkey-25.4 {
execsql {
INSERT INTO artist VALUES(5, 'artist 5');
INSERT INTO artist VALUES(6, 'artist 6');
}
} {}
-do_test e__fkey-25.5 {
+do_test e_fkey-25.5 {
concat \
[execsql { SELECT rowid FROM track WHERE trackartist = 5 }] \
[catchsql { DELETE FROM artist WHERE artistid = 5 }]
} {1 1 {foreign key constraint failed}}
-do_test e__fkey-25.6 {
+do_test e_fkey-25.6 {
concat \
[execsql { SELECT rowid FROM track WHERE trackartist = 7 }] \
[catchsql { DELETE FROM artist WHERE artistid = 7 }]
} {0 {}}
-do_test e__fkey-25.7 {
+do_test e_fkey-25.7 {
concat \
[execsql { SELECT rowid FROM track WHERE trackartist = 6 }] \
[catchsql { DELETE FROM artist WHERE artistid = 6 }]
#
#
drop_all_tables
-do_test e__fkey-26.1 {
+do_test e_fkey-26.1 {
execsql { CREATE TABLE parent(x, y, UNIQUE(y, x)) }
} {}
foreach {tn sql} {
]
execsql {PRAGMA foreign_keys = ON}
- do_test e__fkey-26.$tn.1 { eqp "DELETE FROM parent WHERE 1" } $delete
- do_test e__fkey-26.$tn.2 { eqp "UPDATE parent set x=?, y=?" } $update
+ do_test e_fkey-26.$tn.1 { eqp "DELETE FROM parent WHERE 1" } $delete
+ do_test e_fkey-26.$tn.2 { eqp "UPDATE parent set x=?, y=?" } $update
execsql {DROP TABLE child}
}
# related operations on the parent table do not provoke linear scans.
#
drop_all_tables
-do_test e__fkey-27.1 {
+do_test e_fkey-27.1 {
execsql {
CREATE TABLE artist(
artistid INTEGER PRIMARY KEY,
CREATE INDEX trackindex ON track(trackartist);
}
} {}
-do_test e__fkey-27.2 {
+do_test e_fkey-27.2 {
eqp { INSERT INTO artist VALUES(?, ?) }
} {}
-do_test e__fkey-27.3 {
+do_test e_fkey-27.3 {
eqp { UPDATE artist SET artistid = ?, artistname = ? }
} [list \
0 0 {TABLE artist} \
0 0 {TABLE track WITH INDEX trackindex} \
0 0 {TABLE track WITH INDEX trackindex}
]
-do_test e__fkey-27.4 {
+do_test e_fkey-27.4 {
eqp { DELETE FROM artist }
} [list \
0 0 {TABLE artist} \
{number of columns in foreign key does not match the number of columns in the referenced table}
} {
drop_all_tables
- do_test e__fkey-28.$tn [list catchsql $sql] [list 1 $err]
+ do_test e_fkey-28.$tn [list catchsql $sql] [list 1 $err]
}
-do_test e__fkey-28.8 {
+do_test e_fkey-28.8 {
drop_all_tables
execsql {
CREATE TABLE p(x PRIMARY KEY);
}
catchsql {DELETE FROM p}
} {1 {foreign key mismatch}}
-do_test e__fkey-28.9 {
+do_test e_fkey-28.9 {
drop_all_tables
execsql {
CREATE TABLE p(x, y, PRIMARY KEY(x,y));
# Test the example schema in the "Composite Foreign Key Constraints"
# section.
#
-do_test e__fkey-29.1 {
+do_test e_fkey-29.1 {
execsql {
CREATE TABLE album(
albumartist TEXT,
}
} {}
-do_test e__fkey-29.2 {
+do_test e_fkey-29.2 {
execsql {
INSERT INTO album VALUES('Elvis Presley', 'Elvis'' Christmas Album', NULL);
INSERT INTO song VALUES(
);
}
} {}
-do_test e__fkey-29.3 {
+do_test e_fkey-29.3 {
catchsql {
INSERT INTO song VALUES(2, 'Elvis Presley', 'Elvis Is Back!', 'Fever');
}
# Check that if any of the child key columns in the above schema are NULL,
# there is no requirement for a corresponding parent key.
#
-do_test e__fkey-30.1 {
+do_test e_fkey-30.1 {
execsql {
INSERT INTO song VALUES(2, 'Elvis Presley', NULL, 'Fever');
INSERT INTO song VALUES(3, NULL, 'Elvis Is Back', 'Soldier Boy');
# the statement rolled back.
#
drop_all_tables
-do_test e__fkey-31.1 {
+do_test e_fkey-31.1 {
execsql {
CREATE TABLE king(a, b, PRIMARY KEY(a));
CREATE TABLE prince(c REFERENCES king, d);
}
} {}
-do_test e__fkey-31.2 {
+do_test e_fkey-31.2 {
# Execute a statement that violates the immediate FK constraint.
catchsql { INSERT INTO prince VALUES(1, 2) }
} {1 {foreign key constraint failed}}
-do_test e__fkey-31.3 {
+do_test e_fkey-31.3 {
# This time, use a trigger to fix the constraint violation before the
# statement has finished executing. Then execute the same statement as
# in the previous test case. This time, no error.
# Test that operating inside a transaction makes no difference to
# immediate constraint violation handling.
-do_test e__fkey-31.4 {
+do_test e_fkey-31.4 {
execsql {
BEGIN;
INSERT INTO prince VALUES(2, 3);
}
catchsql { INSERT INTO prince VALUES(3, 4) }
} {1 {foreign key constraint failed}}
-do_test e__fkey-31.5 {
+do_test e_fkey-31.5 {
execsql {
COMMIT;
SELECT * FROM king;
# to COMMIT the transaction fail until the FK constraint is satisfied.
#
proc test_efkey_34 {tn isError sql} {
- do_test e__fkey-32.$tn "
+ do_test e_fkey-32.$tn "
catchsql {$sql}
" [lindex {{0 {}} {1 {foreign key constraint failed}}} $isError]
}
#
drop_all_tables
proc test_efkey_35 {tn isError sql} {
- do_test e__fkey-33.$tn "
+ do_test e_fkey-33.$tn "
catchsql {$sql}
" [lindex {{0 {}} {1 {foreign key constraint failed}}} $isError]
}
-do_test e__fkey-33.1 {
+do_test e_fkey-33.1 {
execsql {
CREATE TABLE parent(x, y);
CREATE UNIQUE INDEX pi ON parent(x, y);
# /* EV: R-30323-21917 */ FKs are either IMMEDIATE or DEFERRED.
#
drop_all_tables
-do_test e__fkey-34.1 {
+do_test e_fkey-34.1 {
execsql {
CREATE TABLE parent(x, y, z, PRIMARY KEY(x,y,z));
CREATE TABLE c1(a, b, c,
} {}
proc test_efkey_29 {tn sql isError} {
- do_test e__fkey-34.$tn "catchsql {$sql}" [
+ do_test e_fkey-34.$tn "catchsql {$sql}" [
lindex {{0 {}} {1 {foreign key constraint failed}}} $isError
]
}
# Test an example from foreignkeys.html dealing with a deferred foreign
# key constraint.
#
-do_test e__fkey-35.1 {
+do_test e_fkey-35.1 {
drop_all_tables
execsql {
CREATE TABLE artist(
);
}
} {}
-do_test e__fkey-35.2 {
+do_test e_fkey-35.2 {
execsql {
BEGIN;
INSERT INTO track VALUES(1, 'White Christmas', 5);
}
catchsql COMMIT
} {1 {foreign key constraint failed}}
-do_test e__fkey-35.3 {
+do_test e_fkey-35.3 {
execsql {
INSERT INTO artist VALUES(5, 'Bing Crosby');
COMMIT;
# deferred foreign key constraints.
#
drop_all_tables
-do_test e__fkey-36.1 {
+do_test e_fkey-36.1 {
execsql {
CREATE TABLE t1(a PRIMARY KEY,
b REFERENCES t1 DEFERRABLE INITIALLY DEFERRED
INSERT INTO t1 VALUES(3, 3);
}
} {}
-do_test e__fkey-36.2 {
+do_test e_fkey-36.2 {
execsql {
BEGIN;
SAVEPOINT one;
RELEASE one;
}
} {}
-do_test e__fkey-36.3 {
+do_test e_fkey-36.3 {
catchsql COMMIT
} {1 {foreign key constraint failed}}
-do_test e__fkey-36.4 {
+do_test e_fkey-36.4 {
execsql {
UPDATE t1 SET a = 5 WHERE a = 4;
COMMIT;
# the database was in auto-commit mode) cannot be released without
# satisfying deferred foreign key constraints. It may be rolled back.
#
-do_test e__fkey-37.1 {
+do_test e_fkey-37.1 {
execsql {
SAVEPOINT one;
SAVEPOINT two;
RELEASE two;
}
} {}
-do_test e__fkey-37.2 {
+do_test e_fkey-37.2 {
catchsql {RELEASE one}
} {1 {foreign key constraint failed}}
-do_test e__fkey-37.3 {
+do_test e_fkey-37.3 {
execsql {
UPDATE t1 SET a = 7 WHERE a = 6;
RELEASE one;
}
} {}
-do_test e__fkey-37.4 {
+do_test e_fkey-37.4 {
execsql {
SAVEPOINT one;
SAVEPOINT two;
RELEASE two;
}
} {}
-do_test e__fkey-37.5 {
+do_test e_fkey-37.5 {
catchsql {RELEASE one}
} {1 {foreign key constraint failed}}
-do_test e__fkey-37.6 {
+do_test e_fkey-37.6 {
execsql {ROLLBACK TO one ; RELEASE one}
} {}
# Test that if a COMMIT operation fails due to deferred foreign key
# constraints, any nested savepoints remain open.
#
-do_test e__fkey-38.1 {
+do_test e_fkey-38.1 {
execsql {
DELETE FROM t1 WHERE a>3;
SELECT * FROM t1;
}
} {1 1 2 2 3 3}
-do_test e__fkey-38.2 {
+do_test e_fkey-38.2 {
execsql {
BEGIN;
INSERT INTO t1 VALUES(4, 4);
SELECT * FROM t1;
}
} {1 1 2 2 3 3 4 4 5 6}
-do_test e__fkey-38.3 {
+do_test e_fkey-38.3 {
catchsql COMMIT
} {1 {foreign key constraint failed}}
-do_test e__fkey-38.4 {
+do_test e_fkey-38.4 {
execsql {
ROLLBACK TO one;
COMMIT;
}
} {1 1 2 2 3 3 4 4}
-do_test e__fkey-38.5 {
+do_test e_fkey-38.5 {
execsql {
SAVEPOINT a;
INSERT INTO t1 VALUES(5, 5);
INSERT INTO t1 VALUES(7, 8);
}
} {}
-do_test e__fkey-38.6 {
+do_test e_fkey-38.6 {
catchsql {RELEASE a}
} {1 {foreign key constraint failed}}
-do_test e__fkey-38.7 {
+do_test e_fkey-38.7 {
execsql {ROLLBACK TO c}
catchsql {RELEASE a}
} {1 {foreign key constraint failed}}
-do_test e__fkey-38.8 {
+do_test e_fkey-38.8 {
execsql {
ROLLBACK TO b;
RELEASE a;
# Test that a single FK constraint may have different actions configured
# for ON DELETE and ON UPDATE.
#
-do_test e__fkey-39.1 {
+do_test e_fkey-39.1 {
execsql {
CREATE TABLE p(a, b PRIMARY KEY, c);
CREATE TABLE c1(d, e, f DEFAULT 'k0' REFERENCES p
INSERT INTO c1 VALUES(3, 'xx', 'k3');
}
} {}
-do_test e__fkey-39.2 {
+do_test e_fkey-39.2 {
execsql {
UPDATE p SET b = 'k4' WHERE a = 1;
SELECT * FROM c1;
}
} {1 xx k0 2 xx k2 3 xx k3}
-do_test e__fkey-39.3 {
+do_test e_fkey-39.3 {
execsql {
DELETE FROM p WHERE a = 2;
SELECT * FROM c1;
}
} {1 xx k0 2 xx {} 3 xx k3}
-do_test e__fkey-39.4 {
+do_test e_fkey-39.4 {
execsql {
CREATE UNIQUE INDEX pi ON p(c);
REPLACE INTO p VALUES(5, 'k5', 'III');
# If none is specified explicitly, "NO ACTION" is the default.
#
drop_all_tables
-do_test e__fkey-40.1 {
+do_test e_fkey-40.1 {
execsql {
CREATE TABLE parent(x PRIMARY KEY, y);
CREATE TABLE child1(a,
8 child7 {0 0 parent b {} {NO ACTION} {NO ACTION} NONE}
9 child8 {0 0 parent b {} {NO ACTION} {NO ACTION} NONE}
} {
- do_test e__fkey-40.$tn { execsql "PRAGMA foreign_key_list($zTab)" } $lRes
+ do_test e_fkey-40.$tn { execsql "PRAGMA foreign_key_list($zTab)" } $lRes
}
#-------------------------------------------------------------------------
# it's parent row is updated or deleted.
#
drop_all_tables
-do_test e__fkey-41.1 {
+do_test e_fkey-41.1 {
execsql {
CREATE TABLE parent(p1, p2, PRIMARY KEY(p1, p2));
CREATE TABLE child(c1, c2,
INSERT INTO child VALUES('l', 'm');
}
} {}
-do_test e__fkey-41.2 {
+do_test e_fkey-41.2 {
execsql {
BEGIN;
UPDATE parent SET p1='k' WHERE p1='j';
SELECT * FROM child;
}
} {j k l m}
-do_test e__fkey-41.3 {
+do_test e_fkey-41.3 {
catchsql COMMIT
} {1 {foreign key constraint failed}}
-do_test e__fkey-41.4 {
+do_test e_fkey-41.4 {
execsql ROLLBACK
} {}
# mapped to it.
#
drop_all_tables
-do_test e__fkey-41.1 {
+do_test e_fkey-41.1 {
execsql {
CREATE TABLE parent(p1, p2);
CREATE UNIQUE INDEX parent_i ON parent(p1, p2);
);
}
} {}
-do_test e__fkey-41.2 {
+do_test e_fkey-41.2 {
execsql {
INSERT INTO parent VALUES('a', 'b');
INSERT INTO parent VALUES('c', 'd');
INSERT INTO child2 VALUES('d', 'c');
}
} {}
-do_test e__fkey-41.3 {
+do_test e_fkey-41.3 {
catchsql { DELETE FROM parent WHERE p1 = 'a' }
} {1 {foreign key constraint failed}}
-do_test e__fkey-41.4 {
+do_test e_fkey-41.4 {
catchsql { UPDATE parent SET p2 = 'e' WHERE p1 = 'c' }
} {1 {foreign key constraint failed}}
# statement.
#
drop_all_tables
-do_test e__fkey-42.1 {
+do_test e_fkey-42.1 {
execsql {
CREATE TABLE parent(x PRIMARY KEY);
CREATE TABLE child1(c REFERENCES parent ON UPDATE RESTRICT);
END;
}
} {}
-do_test e__fkey-42.2 {
+do_test e_fkey-42.2 {
catchsql { UPDATE parent SET x = 'key one' WHERE x = 'key1' }
} {1 {foreign key constraint failed}}
-do_test e__fkey-42.3 {
+do_test e_fkey-42.3 {
execsql {
UPDATE parent SET x = 'key two' WHERE x = 'key2';
SELECT * FROM child2;
} {{key two}}
drop_all_tables
-do_test e__fkey-42.4 {
+do_test e_fkey-42.4 {
execsql {
CREATE TABLE parent(x PRIMARY KEY);
CREATE TABLE child1(c REFERENCES parent ON DELETE RESTRICT);
END;
}
} {}
-do_test e__fkey-42.5 {
+do_test e_fkey-42.5 {
catchsql { DELETE FROM parent WHERE x = 'key1' }
} {1 {foreign key constraint failed}}
-do_test e__fkey-42.6 {
+do_test e_fkey-42.6 {
execsql {
DELETE FROM parent WHERE x = 'key2';
SELECT * FROM child2;
} {{}}
drop_all_tables
-do_test e__fkey-42.7 {
+do_test e_fkey-42.7 {
execsql {
CREATE TABLE parent(x PRIMARY KEY);
CREATE TABLE child1(c REFERENCES parent ON DELETE RESTRICT);
INSERT INTO child2 VALUES('key2');
}
} {}
-do_test e__fkey-42.8 {
+do_test e_fkey-42.8 {
catchsql { REPLACE INTO parent VALUES('key1') }
} {1 {foreign key constraint failed}}
-do_test e__fkey-42.9 {
+do_test e_fkey-42.9 {
execsql {
REPLACE INTO parent VALUES('key2');
SELECT * FROM child2;
# Test that RESTRICT is enforced immediately, even for a DEFERRED constraint.
#
drop_all_tables
-do_test e__fkey-43.1 {
+do_test e_fkey-43.1 {
execsql {
CREATE TABLE parent(x PRIMARY KEY);
CREATE TABLE child1(c REFERENCES parent ON UPDATE RESTRICT
BEGIN;
}
} {}
-do_test e__fkey-43.2 {
+do_test e_fkey-43.2 {
catchsql { UPDATE parent SET x = 'key one' WHERE x = 'key1' }
} {1 {foreign key constraint failed}}
-do_test e__fkey-43.3 {
+do_test e_fkey-43.3 {
execsql { UPDATE parent SET x = 'key two' WHERE x = 'key2' }
} {}
-do_test e__fkey-43.4 {
+do_test e_fkey-43.4 {
catchsql COMMIT
} {1 {foreign key constraint failed}}
-do_test e__fkey-43.5 {
+do_test e_fkey-43.5 {
execsql {
UPDATE child2 SET c = 'key two';
COMMIT;
} {}
drop_all_tables
-do_test e__fkey-43.6 {
+do_test e_fkey-43.6 {
execsql {
CREATE TABLE parent(x PRIMARY KEY);
CREATE TABLE child1(c REFERENCES parent ON DELETE RESTRICT
BEGIN;
}
} {}
-do_test e__fkey-43.7 {
+do_test e_fkey-43.7 {
catchsql { DELETE FROM parent WHERE x = 'key1' }
} {1 {foreign key constraint failed}}
-do_test e__fkey-43.8 {
+do_test e_fkey-43.8 {
execsql { DELETE FROM parent WHERE x = 'key2' }
} {}
-do_test e__fkey-43.9 {
+do_test e_fkey-43.9 {
catchsql COMMIT
} {1 {foreign key constraint failed}}
-do_test e__fkey-43.10 {
+do_test e_fkey-43.10 {
execsql {
UPDATE child2 SET c = NULL;
COMMIT;
# Test SET NULL actions.
#
drop_all_tables
-do_test e__fkey-44.1 {
+do_test e_fkey-44.1 {
execsql {
CREATE TABLE pA(x PRIMARY KEY);
CREATE TABLE cA(c REFERENCES pA ON DELETE SET NULL);
INSERT INTO cB VALUES(X'1234');
}
} {}
-do_test e__fkey-44.2 {
+do_test e_fkey-44.2 {
execsql {
DELETE FROM pA WHERE rowid = 1;
SELECT quote(x) FROM pA;
}
} {X'1234'}
-do_test e__fkey-44.3 {
+do_test e_fkey-44.3 {
execsql {
SELECT quote(c) FROM cA;
}
} {NULL}
-do_test e__fkey-44.4 {
+do_test e_fkey-44.4 {
execsql {
UPDATE pA SET x = X'8765' WHERE rowid = 2;
SELECT quote(x) FROM pA;
}
} {X'8765'}
-do_test e__fkey-44.5 {
+do_test e_fkey-44.5 {
execsql { SELECT quote(c) FROM cB }
} {NULL}
# Test SET DEFAULT actions.
#
drop_all_tables
-do_test e__fkey-45.1 {
+do_test e_fkey-45.1 {
execsql {
CREATE TABLE pA(x PRIMARY KEY);
CREATE TABLE cA(c DEFAULT X'0000' REFERENCES pA ON DELETE SET DEFAULT);
INSERT INTO cB VALUES(X'1234');
}
} {}
-do_test e__fkey-45.2 {
+do_test e_fkey-45.2 {
execsql {
DELETE FROM pA WHERE rowid = 3;
SELECT quote(x) FROM pA;
}
} {X'0000' X'9999' X'1234'}
-do_test e__fkey-45.3 {
+do_test e_fkey-45.3 {
execsql { SELECT quote(c) FROM cA }
} {X'0000'}
-do_test e__fkey-45.4 {
+do_test e_fkey-45.4 {
execsql {
UPDATE pA SET x = X'8765' WHERE rowid = 4;
SELECT quote(x) FROM pA;
}
} {X'0000' X'9999' X'8765'}
-do_test e__fkey-45.5 {
+do_test e_fkey-45.5 {
execsql { SELECT quote(c) FROM cB }
} {X'9999'}
# Test ON DELETE CASCADE actions.
#
drop_all_tables
-do_test e__fkey-46.1 {
+do_test e_fkey-46.1 {
execsql {
CREATE TABLE p1(a, b UNIQUE);
CREATE TABLE c1(c REFERENCES p1(b) ON DELETE CASCADE, d);
SELECT count(*) FROM c1;
}
} {3}
-do_test e__fkey-46.2 {
+do_test e_fkey-46.2 {
execsql {
DELETE FROM p1 WHERE a = 4;
SELECT d, c FROM c1;
}
} {{} {} 5 5}
-do_test e__fkey-46.3 {
+do_test e_fkey-46.3 {
execsql {
DELETE FROM p1;
SELECT d, c FROM c1;
}
} {{} {}}
-do_test e__fkey-46.4 {
+do_test e_fkey-46.4 {
execsql { SELECT * FROM p1 }
} {}
# Test ON UPDATE CASCADE actions.
#
drop_all_tables
-do_test e__fkey-47.1 {
+do_test e_fkey-47.1 {
execsql {
CREATE TABLE p1(a, b UNIQUE);
CREATE TABLE c1(c REFERENCES p1(b) ON UPDATE CASCADE, d);
SELECT count(*) FROM c1;
}
} {3}
-do_test e__fkey-47.2 {
+do_test e_fkey-47.2 {
execsql {
UPDATE p1 SET b = 10 WHERE b = 5;
SELECT d, c FROM c1;
}
} {{} {} 4 4 5 10}
-do_test e__fkey-47.3 {
+do_test e_fkey-47.3 {
execsql {
UPDATE p1 SET b = 11 WHERE b = 4;
SELECT d, c FROM c1;
}
} {{} {} 4 11 5 10}
-do_test e__fkey-47.4 {
+do_test e_fkey-47.4 {
execsql {
UPDATE p1 SET b = 6 WHERE b IS NULL;
SELECT d, c FROM c1;
}
} {{} {} 4 11 5 10}
-do_test e__fkey-46.5 {
+do_test e_fkey-46.5 {
execsql { SELECT * FROM p1 }
} {{} 6 4 11 5 10}
# of foreignkeys.html.
#
drop_all_tables
-do_test e__fkey-48.1 {
+do_test e_fkey-48.1 {
execsql {
CREATE TABLE artist(
artistid INTEGER PRIMARY KEY,
INSERT INTO track VALUES(13, 'My Way', 2);
}
} {}
-do_test e__fkey-48.2 {
+do_test e_fkey-48.2 {
execsql {
UPDATE artist SET artistid = 100 WHERE artistname = 'Dean Martin';
}
} {}
-do_test e__fkey-48.3 {
+do_test e_fkey-48.3 {
execsql { SELECT * FROM artist }
} {2 {Frank Sinatra} 100 {Dean Martin}}
-do_test e__fkey-48.4 {
+do_test e_fkey-48.4 {
execsql { SELECT * FROM track }
} {11 {That's Amore} 100 12 {Christmas Blues} 100 13 {My Way} 2}
# requirement not to violate the foreign key constraint.
#
drop_all_tables
-do_test e__fkey-49.1 {
+do_test e_fkey-49.1 {
execsql {
CREATE TABLE parent(a COLLATE nocase, b, c, PRIMARY KEY(c, a));
CREATE TABLE child(d DEFAULT 'a', e, f DEFAULT 'c',
INSERT INTO child VALUES('one', 'two', 'three');
}
} {}
-do_test e__fkey-49.2 {
+do_test e_fkey-49.2 {
execsql {
BEGIN;
UPDATE parent SET a = '' WHERE a = 'oNe';
SELECT * FROM child;
}
} {a two c}
-do_test e__fkey-49.3 {
+do_test e_fkey-49.3 {
execsql {
ROLLBACK;
DELETE FROM parent WHERE a = 'A';
SELECT * FROM parent;
}
} {ONE two three}
-do_test e__fkey-49.4 {
+do_test e_fkey-49.4 {
catchsql { UPDATE parent SET a = '' WHERE a = 'oNe' }
} {1 {foreign key constraint failed}}
# (R-28220-46694).
#
drop_all_tables
-do_test e__fkey-50.1 {
+do_test e_fkey-50.1 {
execsql {
CREATE TABLE artist(
artistid INTEGER PRIMARY KEY,
INSERT INTO track VALUES(14, 'Mr. Bojangles', 3);
}
} {}
-do_test e__fkey-50.2 {
+do_test e_fkey-50.2 {
catchsql { DELETE FROM artist WHERE artistname = 'Sammy Davis Jr.' }
} {1 {foreign key constraint failed}}
-do_test e__fkey-50.3 {
+do_test e_fkey-50.3 {
execsql {
INSERT INTO artist VALUES(0, 'Unknown Artist');
DELETE FROM artist WHERE artistname = 'Sammy Davis Jr.';
}
} {}
-do_test e__fkey-50.4 {
+do_test e_fkey-50.4 {
execsql { SELECT * FROM artist }
} {0 {Unknown Artist}}
-do_test e__fkey-50.5 {
+do_test e_fkey-50.5 {
execsql { SELECT * FROM track }
} {14 {Mr. Bojangles} 0}
# 5. Execute applicable AFTER trigger programs.
#
drop_all_tables
-do_test e__fkey-51.1 {
+do_test e_fkey-51.1 {
proc maxparent {args} { db one {SELECT max(x) FROM parent} }
db func maxparent maxparent
INSERT INTO child VALUES(1);
}
} {}
-do_test e__fkey-51.2 {
+do_test e_fkey-51.2 {
execsql {
UPDATE parent SET x = 22;
SELECT * FROM parent UNION ALL SELECT 'xxx' UNION ALL SELECT a FROM child;
}
} {22 21 23 xxx 22}
-do_test e__fkey-51.3 {
+do_test e_fkey-51.3 {
execsql {
DELETE FROM child;
DELETE FROM parent;
# is 'distinct' from the old or not.
#
drop_all_tables
-do_test e__fkey-52.1 {
+do_test e_fkey-52.1 {
execsql {
CREATE TABLE zeus(a INTEGER COLLATE NOCASE, b, PRIMARY KEY(a, b));
CREATE TABLE apollo(c, d,
SELECT * FROM apollo;
}
} {ABC xyz}
-do_test e__fkey-52.2 {
+do_test e_fkey-52.2 {
execsql {
UPDATE zeus SET a = 1, b = 1;
SELECT * FROM apollo;
}
} {1 1}
-do_test e__fkey-52.3 {
+do_test e_fkey-52.3 {
execsql {
UPDATE zeus SET a = 1, b = 1;
SELECT typeof(c), c, typeof(d), d FROM apollo;
}
} {integer 1 integer 1}
-do_test e__fkey-52.4 {
+do_test e_fkey-52.4 {
execsql {
UPDATE zeus SET a = '1';
SELECT typeof(c), c, typeof(d), d FROM apollo;
}
} {integer 1 integer 1}
-do_test e__fkey-52.5 {
+do_test e_fkey-52.5 {
execsql {
UPDATE zeus SET b = '1';
SELECT typeof(c), c, typeof(d), d FROM apollo;
}
} {integer 1 text 1}
-do_test e__fkey-52.6 {
+do_test e_fkey-52.6 {
execsql {
UPDATE zeus SET b = NULL;
SELECT typeof(c), c, typeof(d), d FROM apollo;
# that is distinct from its previous value.
#
drop_all_tables
-do_test e__fkey-53.1 {
+do_test e_fkey-53.1 {
execsql {
CREATE TABLE parent(x PRIMARY KEY);
CREATE TABLE child(y REFERENCES parent ON UPDATE SET NULL);
INSERT INTO child VALUES('key');
}
} {}
-do_test e__fkey-53.2 {
+do_test e_fkey-53.2 {
execsql {
UPDATE parent SET x = 'key';
SELECT IFNULL(y, 'null') FROM child;
}
} {key}
-do_test e__fkey-53.3 {
+do_test e_fkey-53.3 {
execsql {
UPDATE parent SET x = 'key2';
SELECT IFNULL(y, 'null') FROM child;
B "CREATE TABLE t1(a, b, FOREIGN KEY(c,b) REFERENCES t2(d))"
{1 {number of columns in foreign key does not match the number of columns in the referenced table}}
} {
- do_test e__fkey-54.$tn.off {
+ do_test e_fkey-54.$tn.off {
drop_all_tables
execsql {PRAGMA foreign_keys = OFF}
catchsql $zCreateTbl
} $lRes
- do_test e__fkey-54.$tn.on {
+ do_test e_fkey-54.$tn.on {
drop_all_tables
execsql {PRAGMA foreign_keys = ON}
catchsql $zCreateTbl
proc test_efkey_6 {tn zAlter isError} {
drop_all_tables
- do_test e___fkey-56.$tn.1 "
+ do_test e_fkey-56.$tn.1 "
execsql { CREATE TABLE tbl(a, b) }
[list catchsql $zAlter]
" [lindex {{0 {}} {1 {Cannot add a REFERENCES column with non-NULL default value}}} $isError]
#
# Test that these adjustments are visible in the sqlite_master table.
#
-do_test e___fkey-56.1 {
+do_test e_fkey-56.1 {
drop_all_tables
execsql {
CREATE TABLE 'p 1 "parent one"'(a REFERENCES 'p 1 "parent one"', b, PRIMARY KEY(b));
-- CREATE TABLE q(a, b, PRIMARY KEY(b));
}
} {}
-do_test e___fkey-56.2 {
+do_test e_fkey-56.2 {
execsql { ALTER TABLE 'p 1 "parent one"' RENAME TO p }
} {}
-do_test e___fkey-56.3 {
+do_test e_fkey-56.3 {
execsql {
UPDATE p SET a = 'xxx', b = 'xxx';
SELECT * FROM p;
SELECT * FROM c3;
}
} {xxx xxx 1 xxx 1 xxx 1 xxx}
-do_test e___fkey-56.4 {
+do_test e_fkey-56.4 {
execsql { SELECT sql FROM sqlite_master WHERE type = 'table'}
} [list \
{CREATE TABLE "p"(a REFERENCES "p", b, PRIMARY KEY(b))} \
# Check that a DROP TABLE does an implicit DELETE FROM. Which does not
# cause any triggers to fire, but does fire foreign key actions.
#
-do_test e___fkey-57.1 {
+do_test e_fkey-57.1 {
drop_all_tables
execsql {
CREATE TABLE p(a, b, PRIMARY KEY(a, b));
}
} {}
-do_test e___fkey-57.2 {
+do_test e_fkey-57.2 {
execsql {
INSERT INTO p VALUES('a', 'b');
INSERT INTO c1 VALUES('a', 'b');
SELECT * FROM c1;
}
} {{} {}}
-do_test e___fkey-57.3 {
+do_test e_fkey-57.3 {
execsql { SELECT * FROM c2 }
} {{} {}}
-do_test e___fkey-57.4 {
+do_test e_fkey-57.4 {
execsql { SELECT * FROM c3 }
} {}
-do_test e___fkey-57.5 {
+do_test e_fkey-57.5 {
execsql { SELECT * FROM log }
} {}
-do_test e___fkey-57.6 {
+do_test e_fkey-57.6 {
execsql ROLLBACK
} {}
-do_test e___fkey-57.7 {
+do_test e_fkey-57.7 {
execsql {
BEGIN;
DELETE FROM p;
# If an IMMEDIATE foreign key fails as a result of a DROP TABLE, the
# DROP TABLE command fails.
#
-do_test e___fkey-58.1 {
+do_test e_fkey-58.1 {
execsql {
DELETE FROM c1;
DELETE FROM c2;
execsql { INSERT INTO c5 VALUES('a', 'b') }
catchsql { DROP TABLE p }
} {1 {foreign key constraint failed}}
-do_test e___fkey-58.2 {
+do_test e_fkey-58.2 {
execsql { SELECT * FROM p }
} {a b}
-do_test e___fkey-58.3 {
+do_test e_fkey-58.3 {
catchsql {
BEGIN;
DROP TABLE p;
}
} {1 {foreign key constraint failed}}
-do_test e___fkey-58.4 {
+do_test e_fkey-58.4 {
execsql {
SELECT * FROM p;
SELECT * FROM c5;
# If a DEFERRED foreign key fails as a result of a DROP TABLE, attempting
# to commit the transaction fails unless the violation is fixed.
#
-do_test e___fkey-59.1 {
+do_test e_fkey-59.1 {
execsql {
DELETE FROM c1 ; DELETE FROM c2 ; DELETE FROM c3 ;
DELETE FROM c4 ; DELETE FROM c5 ; DELETE FROM c6 ;
DELETE FROM c7
}
} {}
-do_test e___fkey-59.2 {
+do_test e_fkey-59.2 {
execsql { INSERT INTO c7 VALUES('a', 'b') }
execsql {
BEGIN;
DROP TABLE p;
}
} {}
-do_test e___fkey-59.3 {
+do_test e_fkey-59.3 {
catchsql COMMIT
} {1 {foreign key constraint failed}}
-do_test e___fkey-59.4 {
+do_test e_fkey-59.4 {
execsql { CREATE TABLE p(a, b, PRIMARY KEY(a, b)) }
catchsql COMMIT
} {1 {foreign key constraint failed}}
-do_test e___fkey-59.5 {
+do_test e_fkey-59.5 {
execsql { INSERT INTO p VALUES('a', 'b') }
execsql COMMIT
} {}
# "DELETE FROM tbl" are ignored.
#
drop_all_tables
-do_test e___fkey-60.1 {
+do_test e_fkey-60.1 {
execsql {
PRAGMA foreign_keys = OFF;
INSERT INTO c3 VALUES(1, 2);
}
} {}
-do_test e___fkey-60.2 {
+do_test e_fkey-60.2 {
execsql { PRAGMA foreign_keys = ON }
catchsql { DELETE FROM p }
} {1 {no such table: main.nosuchtable}}
-do_test e___fkey-60.3 {
+do_test e_fkey-60.3 {
execsql {
BEGIN;
DROP TABLE p;
ROLLBACK;
}
} {{} 2}
-do_test e___fkey-60.4 {
+do_test e_fkey-60.4 {
execsql { CREATE TABLE nosuchtable(x PRIMARY KEY) }
catchsql { DELETE FROM p }
} {1 {foreign key mismatch}}
-do_test e___fkey-60.5 {
+do_test e_fkey-60.5 {
execsql { DROP TABLE c1 }
catchsql { DELETE FROM p }
} {1 {foreign key mismatch}}
-do_test e___fkey-60.6 {
+do_test e_fkey-60.6 {
execsql { DROP TABLE c2 }
execsql { DELETE FROM p }
} {}
# 2. Modifying foreign key definitions when a parent table is RENAMEd.
# 3. Running an implicit DELETE FROM command as part of DROP TABLE.
#
-do_test e___fkey-61.1.1 {
+do_test e_fkey-61.1.1 {
drop_all_tables
execsql { CREATE TABLE t1(a, b) }
catchsql { ALTER TABLE t1 ADD COLUMN c DEFAULT 'xxx' REFERENCES t2 }
} {1 {Cannot add a REFERENCES column with non-NULL default value}}
-do_test e___fkey-61.1.2 {
+do_test e_fkey-61.1.2 {
execsql { PRAGMA foreign_keys = OFF }
execsql { ALTER TABLE t1 ADD COLUMN c DEFAULT 'xxx' REFERENCES t2 }
execsql { SELECT sql FROM sqlite_master WHERE name = 't1' }
} {{CREATE TABLE t1(a, b, c DEFAULT 'xxx' REFERENCES t2)}}
-do_test e___fkey-61.1.3 {
+do_test e_fkey-61.1.3 {
execsql { PRAGMA foreign_keys = ON }
} {}
-do_test e___fkey-61.2.1 {
+do_test e_fkey-61.2.1 {
drop_all_tables
execsql {
CREATE TABLE p(a UNIQUE);
ROLLBACK;
}
} {{CREATE TABLE c(b REFERENCES "parent"(a))}}
-do_test e___fkey-61.2.2 {
+do_test e_fkey-61.2.2 {
execsql {
PRAGMA foreign_keys = OFF;
ALTER TABLE p RENAME TO parent;
SELECT sql FROM sqlite_master WHERE name = 'c';
}
} {{CREATE TABLE c(b REFERENCES p(a))}}
-do_test e___fkey-61.2.3 {
+do_test e_fkey-61.2.3 {
execsql { PRAGMA foreign_keys = ON }
} {}
-do_test e___fkey-61.3.1 {
+do_test e_fkey-61.3.1 {
drop_all_tables
execsql {
CREATE TABLE p(a UNIQUE);
ROLLBACK;
}
} {{}}
-do_test e___fkey-61.3.2 {
+do_test e_fkey-61.3.2 {
execsql {
PRAGMA foreign_keys = OFF;
DROP TABLE p;
SELECT * FROM c;
}
} {x}
-do_test e___fkey-61.3.3 {
+do_test e_fkey-61.3.3 {
execsql { PRAGMA foreign_keys = ON }
} {}
#
foreach zMatch [list SIMPLE PARTIAL FULL Simple parTIAL FuLL ] {
drop_all_tables
- do_test e___fkey-62.$zMatch.1 {
+ do_test e_fkey-62.$zMatch.1 {
execsql "
CREATE TABLE p(a, b, c, PRIMARY KEY(b, c));
CREATE TABLE c(d, e, f, FOREIGN KEY(e, f) REFERENCES p MATCH $zMatch);
"
} {}
- do_test e___fkey-62.$zMatch.2 {
+ do_test e_fkey-62.$zMatch.2 {
execsql { INSERT INTO p VALUES(1, 2, 3) }
# MATCH SIMPLE behaviour: Allow any child key that contains one or more
# that it is possible to create both immediate and deferred constraints.
#
drop_all_tables
-do_test e__fkey-62.1 {
+do_test e_fkey-62.1 {
catchsql { SET CONSTRAINTS ALL IMMEDIATE }
} {1 {near "SET": syntax error}}
-do_test e__fkey-62.2 {
+do_test e_fkey-62.2 {
catchsql { SET CONSTRAINTS ALL DEFERRED }
} {1 {near "SET": syntax error}}
-do_test e__fkey-62.3 {
+do_test e_fkey-62.3 {
execsql {
CREATE TABLE p(a, b, PRIMARY KEY(a, b));
CREATE TABLE cd(c, d,
BEGIN;
}
} {}
-do_test e__fkey-62.4 {
+do_test e_fkey-62.4 {
catchsql { INSERT INTO ci VALUES('x', 'y') }
} {1 {foreign key constraint failed}}
-do_test e__fkey-62.5 {
+do_test e_fkey-62.5 {
catchsql { INSERT INTO cd VALUES('x', 'y') }
} {0 {}}
-do_test e__fkey-62.6 {
+do_test e_fkey-62.6 {
catchsql { COMMIT }
} {1 {foreign key constraint failed}}
-do_test e__fkey-62.7 {
+do_test e_fkey-62.7 {
execsql {
DELETE FROM cd;
COMMIT;
"
}
-do_test e___fkey-63.1.1 {
+do_test e_fkey-63.1.1 {
test_on_delete_recursion $SQLITE_MAX_TRIGGER_DEPTH
} {0 0}
-do_test e___fkey-63.1.2 {
+do_test e_fkey-63.1.2 {
test_on_delete_recursion [expr $SQLITE_MAX_TRIGGER_DEPTH+1]
} {1 {too many levels of trigger recursion}}
-do_test e___fkey-63.1.3 {
+do_test e_fkey-63.1.3 {
sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 5
test_on_delete_recursion 5
} {0 0}
-do_test e___fkey-63.1.4 {
+do_test e_fkey-63.1.4 {
test_on_delete_recursion 6
} {1 {too many levels of trigger recursion}}
-do_test e___fkey-63.1.5 {
+do_test e_fkey-63.1.5 {
sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 1000000
} {5}
-do_test e___fkey-63.2.1 {
+do_test e_fkey-63.2.1 {
test_on_update_recursion $SQLITE_MAX_TRIGGER_DEPTH
} {0 0}
-do_test e___fkey-63.2.2 {
+do_test e_fkey-63.2.2 {
test_on_update_recursion [expr $SQLITE_MAX_TRIGGER_DEPTH+1]
} {1 {too many levels of trigger recursion}}
-do_test e___fkey-63.2.3 {
+do_test e_fkey-63.2.3 {
sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 5
test_on_update_recursion 5
} {0 0}
-do_test e___fkey-63.2.4 {
+do_test e_fkey-63.2.4 {
test_on_update_recursion 6
} {1 {too many levels of trigger recursion}}
-do_test e___fkey-63.2.5 {
+do_test e_fkey-63.2.5 {
sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 1000000
} {5}
drop_all_tables
execsql "PRAGMA recursive_triggers = $recursive_triggers_setting"
- do_test e__fkey-64.$recursive_triggers_setting.1 {
+ do_test e_fkey-64.$recursive_triggers_setting.1 {
execsql {
CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1 ON DELETE CASCADE);
INSERT INTO t1 VALUES(1, NULL);
SELECT count(*) FROM t1;
}
} {5}
- do_test e__fkey-64.$recursive_triggers_setting.2 {
+ do_test e_fkey-64.$recursive_triggers_setting.2 {
execsql { SELECT count(*) FROM t1 WHERE a = 1 }
} {1}
- do_test e__fkey-64.$recursive_triggers_setting.3 {
+ do_test e_fkey-64.$recursive_triggers_setting.3 {
execsql {
DELETE FROM t1 WHERE a = 1;
SELECT count(*) FROM t1;