Affects Version/s: None
Fix Version/s: None
To be able to enforce foreign key constraints in SQLite you need to execute the following statement:
However, this statement can't be used from within a transaction. From the SQLite docs:
It is not possible to enable or disable foreign key constraints in the middle of a multi-statement transaction (when SQLite is not in autocommit mode). Attempting to do so does not return an error; it simply has no effect.
In clojure.java.jdbc both do-commands and do-prepared unconditionally run the supplied statements in a transaction. To me it seems like these two functions are the only ones that provide a way to execute an arbitrary SQL statement.
Example using [org.clojure/java.jdbc "0.2.3"] and [org.xerial/sqlite-jdbc "3.7.2"]:
When using this function instead of do-commands foreign keys work as expected:
This function is simply do-commands with execute-batch inlined and the wrapping transaction form removed.