views:

50

answers:

3

I started using 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?

A: 

You need to issue pragma command to enable it

Giorgi
A: 

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).

MPelletier
I checked Poco 1.3.6 and it says that it supports SQLite 3.6.20 . What I asked was whether is it the libs that implement sqlite or they use the system wide binaries. And how do I enable Foreign keys through the libs.Though the formulation of question is not right I hope you understand it.
Xolve
Then the answer is the SQLite binary (just a single dll, named sqlite3.dll usually) which implements the foreign key. Poco makes the cut pretty close, as SQLite has foreign key support since 3.6.19.
MPelletier
What about linux?
Xolve
The pre-compiled linux version might have different options, but will have the same command with the same syntax.
MPelletier
Sometimes the ad-hoc library and sqlite can't be separated. .NET lib System.Data.Sqlite is an example. Read here: http://sqlite.phxsoftware.com/. "System.Data.SQLite is the original SQLite database engine and a complete ADO.NET 2.0/3.5 provider all rolled into a single mixed mode assembly. "
TTT
@TTT: Interesting. Still, they would be ill-advised to implement foreign keys outside of SQLite for that special distro. Mind you, they very well could decide to not have foreign keys at all...
MPelletier
@MPelletier, In means in practice that there is a gap between when a new feature is added to sqlite (for instance foreign keys) and the time that .net developers like me can use it. You have to wait until system.data.sqlite is upgraded.
TTT
@TTT: Yes it does. Ah, the woes of pre-compiled libraries (as opposed to compile-yourself, many of which are shamefully incomplete).
MPelletier
+1  A: 

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.

snemarch