Reputation: 41
I'm using SQLite3 and I know that foreign key support is disabled default for some compatibility reasons. But I want to build my own SQLite3 with foreign key enabled default. I have reviewed some of the source code (Amalgamation version) and I found a macro evaluation
#if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
| SQLITE_ForeignKeys
#endif
I tried to add macro define
#define SQLITE_DEFAULT_FOREIGN_KEYS 1
either inside or outside
#ifndef SQLITE_OMIT_TRIGGER
#ifndef SQLITE_OMIT_FOREIGN_KE
And built, but it made no difference, the default value of foreign key were still 0.
So my question is: how do I modify the source code to enable foreign key default? (I know it is easy to trigger, but this is a difference question.)
Upvotes: 2
Views: 167
Reputation: 41
... I'm sorry but I did succeed, and the problem showed up because I ran a difference sqlite3.exe due to my path settings. After my modification,
PRAGMA foreign_keys;
in sqlite shell output 1 and it is still triggerable. In default case, when I try to insert a row with an invalid foreign key reference, it reports an "FOREIGN KEY constraint failed" error.
Upvotes: 2