Tuesday, April 26, 2011

Android, sqlite, and foreign keys

I think its about time to do a post actually about android development.  One thing I discovered while setting up the database for gmml was that the older versions of the android os use a fairly outdated version of sqlite which do not implement foreign keys.  It will parse your statements fine but not actually do anything with the foreign keys you declare.

Sqlite version for each OS version

/*   
     *   Android 1.5 (Cupcake): 3.5.9
     *  Android 1.6 (Donut): 3.5.9
     *  Android 2.1 (Eclair): 3.5.9
     *  Android 2.2 (Froyo): 3.6.22 - First to support foreign keys
     *  Android 2.3 (Gingerbread): 3.6.22
     *  Android 3.0 (Honeycomb): 3.7.4
    */

Why is this important to know you may ask?  Well in version 0.10 of gmmp I experienced crashing on my thunderbolt (2.2) when trying to delete the database, but didn't experience it at all when testing in 1.6.  Turns out I was deleting tables out of order and violating some of the db constaints which are only present on 2.2+ causing an unhandled exception to be thrown.

I have corrected the issue so it shouldn't crash in the next version