I started usi开发者_JS百科ng SQLite for my project and I found there are many libraries supporting it like Qt, pysqlite, Poco C++ etc. I also found out that previous SQLite versions didn't support foreign keys.
How do the drivers know what sqlite executable to use? And how do I know they support what version of sqlite they support?
Another question: How do I enable foreign keys in sqlite by default?
The answer is: it depends.
Some applications will use a statically linked sqlite, others will link dynamically against the .dll or .so (depending on your OS). And of the ones linking against the dynamic library, whether it uses a system-wide or application-folder version depends on the application.
I (thankfully) haven't seen any apps that go through the sqlite.exe.
You need to issue pragma command to enable it
SQLite manages the foreign keys, not the ad-hoc library. Each library (if they are half-decent) will have their documentation which will list what version of SQLite is supported.
To determine if foreign keys are turned on in SQLite:
PRAGMA foreign_keys;
To turn on foreign keys:
PRAGMA foreign_keys = ON;
EDIT: This must be turned on not only before database creation, but at every connection for SQLite to activate foreign keys and their magic. (This is because foreign keys are not legacy, but is expected to change).
精彩评论