1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Fix a problem with "PRAGMA foreign_key_check" where if a table in one

schema appears to have foreign key constraints against another table in
a different schema, the pragma will try to check the constraints even though
they do not apply because they are in different schemas.

FossilOrigin-Name: 81bc4b65ae2a68128b0be75a7a3d4f47f05cc588ff130ba56366ab9b16289228
This commit is contained in:
drh
2020-07-03 12:15:59 +00:00
parent 15cedda902
commit ec1650a239
4 changed files with 37 additions and 15 deletions

View File

@ -430,4 +430,25 @@ do_catchsql_test 11.1 {
PRAGMA foreign_key_check;
} {1 {foreign key mismatch - "c11" referencing "tt"}}
# 2020-07-03 Bug in foreign_key_check discovered while working on the
# forum reports that pragma_foreign_key_check does not accept an argument:
# If two separate schemas seem to reference one another, that causes
# problems for foreign_key_check.
#
reset_db
do_execsql_test 12.0 {
ATTACH ':memory:' as aux;
CREATE TABLE aux.t1(a INTEGER PRIMARY KEY, b TEXT REFERENCES t2);
CREATE TABLE main.t2(x TEXT PRIMARY KEY, y INT);
INSERT INTO main.t2 VALUES('abc',11),('def',22),('xyz',99);
INSERT INTO aux.t1 VALUES(5,'abc'),(7,'xyz'),(9,'oops');
PRAGMA foreign_key_check=t1;
} {t1 5 t2 0 t1 7 t2 0 t1 9 t2 0}
do_execsql_test 12.1 {
CREATE TABLE aux.t2(x TEXT PRIMARY KEY, y INT);
INSERT INTO aux.t2 VALUES('abc',11),('def',22),('xyz',99);
PRAGMA foreign_key_check=t1;
} {t1 9 t2 0}
finish_test