robotoworks / mechanoid

Eclipse plugin providing a set of DSL's for the rapid development of Android apps
58 stars 26 forks source link

[MECHDB] Add Support for Foreign Key #76

Open bsagal opened 11 years ago

bsagal commented 11 years ago

There does not seem to be a way the specify Foreign key references in MECHDB

fluxtah commented 11 years ago

Do we know if Android supports foreign keys? I have never used them in an app because I assumed they were not supported and they are often an unnecessary overhead, however it should be easy enough to add.

What do you think?

bsagal commented 11 years ago

Sqlite supports (http://www.sqlite.org/foreignkeys.html) it and it provides constancy when adding records,

fluxtah commented 11 years ago

So there are a few interesting issues with this, looks like foreign key contraints were available from Android 2.2 but have to be enabled with a PRAGMA Statement:

http://code.google.com/p/android/issues/detail?id=11607

http://stackoverflow.com/questions/2545558/foreign-key-constraints-in-android-using-sqlite-on-delete-cascade

The stack post is interesting because its only until Android 4.1 (API LEVEL 16) that a specific method was introduced to enable foreign keys:

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#setForeignKeyConstraintsEnabled(boolean)

I can look at implementing this feature after I finish writing docs (currently rewriting documentation), and I am also willing to except pull requests that implement it.

imhoff commented 11 years ago

Any progress on integrating the foreign key definitions into the grammar of mechdb? I would be keen trying this out.

fluxtah commented 11 years ago

I can see if I can get some time to add the grammar constructs, I put this off because I am yet to make an app that enforces key constraints, I have always seen Android DB as a lightweight data cache so i try to keep my tables as flat as possible, I believe this is how most apps use it.

I am happy to except pull requests that add grammar support to this! :) Anyone willing to give it a try should gain an understanding of xtext http://www.eclipse.org/Xtext/