0

Oddly, I cannot find an answer to this question. I'm doing table designs with the assumption that I'll be able to use foreign keys in my Android app. If I can't using the default sdk, are there other options? Can I gen a build with the pragma and include it as a lib?

1 Answers1

2

Quoting the SQLite documentation:

...support for SQL foreign key constraints [was] introduced in SQLite version 3.6.19

According to the SO question serving as our repository of version info, API Level 8+ should have a new-enough SQLite version to offer foreign key support. That should be enough for most developers.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    That says "foreign key constraints." Foreign key support (in the sense of being able to create joins) has probably been available long before that. – Robert Harvey Oct 04 '14 at 15:38
  • @RobertHarvey: I'm preferring to be conservative in my interpretation of the question. When I think "foreign keys", I usually think of "foreign key constraints". But your point is valid -- I am fairly certain that `JOIN` has been around in SQLite longer than Android has been around in general. – CommonsWare Oct 04 '14 at 15:42
  • Thanks for the API Level info. Do you know if foreign key support is enabled by default. My reading of the SQLite doco suggests that it is not. – Johnny Raved Oct 04 '14 at 20:14
  • @JohnnyRaved: "Do you know if foreign key support is enabled by default" -- hmmmm... `setForeignKeyConstraintsEnabled()` was added to `SQLiteDatabase` in API Level 16, so it's at least possible to use them starting then. Prior to that, [you need to execute the `PRAGMA` yourself](http://stackoverflow.com/a/3266882/115145). – CommonsWare Oct 04 '14 at 20:21