Using sqlite pragma statements to configure database?
I am having a problem executing the foreign_key pragma statement in my project. At the moment I have this written into the program.
SQLiteStatement pragma = db.compileStatement("PRAGMA foreign_key = ON;");
pragma.execute;
Those statements are executed after the db is created and from that point the tables are created, which all works fine.
The problem is when I debug the db using sqlite3 I execute the (pragma foreign_key;) statement in sqlite3 and it always shows that foreign_keys are off unless I explicitly enable it during debug.
So my question is how do I execute PRAGMA statements in my application?
just for reference t开发者_运维百科he sqlite version is 3.6.22 which has foreign keys off by default but doesn't have the omit foreign key or omit trigger defined. and I am aware that I need to define triggers to enforce the foreign key constraints. Although I do wonder why.
The foreign_keys
pragma sets a session variable; it's not part of the database schema. It defaults to off for every "connection", and if you want to turn it on, you need to turn it on for each connection.
精彩评论