我尝试使用 HDBC-sqlite3 haskell 库启用外键。这个库使用了一个小助手 c - 函数
int sqlite3_open2(const char *filename, finalizeonce **ppo)
依次调用sqlite3_open
。在sqlite 文档中,我发现了sqlite3_db_config
应该启用外键的不错的功能。为了测试它,我快速添加了 2 行sqlite3_open2
(清单的最后两行):
int sqlite3_open2(const char *filename, finalizeonce **ppo) {
sqlite3 *ppDb;
finalizeonce *newobj;
int res, *resFK, resFK1;
fprintf(stderr, "DB pointer: %d\n", ppDb);
res = sqlite3_open(filename, &ppDb);
resFK1 = sqlite3_db_config(ppDb, 1002, 1, resFK);
fprintf(stderr, "\nForeign Keys: ON/OFF:%d ERR:%d\n", resFK, resFK1);
...
结果令我惊讶:Foreign Keys: ON/OFF:0 ERR:1
.
有人可以给我一个提示我做错了什么或者启用外键的正确方法是什么?