Skip to content

load! seems to ignore foreign key errors when inserting data. #240

@fonterrageoff

Description

@fonterrageoff

If I create a table with foreign key constraints, and then use load! to load data that violates those foreign key constraints, I get a silent failure.

The errors work if you INSERT bad data:

using SQLite, Tables
db = SQLite.DB();
Q = q -> DBInterface.execute(db, q);
Q("PRAGMA foreign_keys=ON;");
Q("CREATE TABLE a (key INTEGER PRIMARY KEY);");
Q("CREATE TABLE b (aref INTEGER, FOREIGN KEY (aref) REFERENCES a(key));");
Q("INSERT INTO a (key) VALUES (1);");
Q("INSERT INTO b (aref) VALUES (2);");

And you get a clear error message:

ERROR: SQLiteException("FOREIGN KEY constraint failed")
Stacktrace:
 [1] execute(db::SQLite.DB, stmt::SQLite._Stmt, params::NamedTuple{(), Tuple{}})
   @ SQLite ~\.julia\packages\SQLite\jf6KT\src\SQLite.jl:453
...

But if you load!:

input = Tables.table(fill(2, 1, 1), header=[:aref]);
input |> SQLite.load!(db, "b", ifnotexists=false);

you get no error, but

println([v[1] for v in Q("SELECT * from b;")]);

shows that b is empty:

Any[]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions