David Vedvick


Custom SQLite Access Difficulties in Android

It is surprisingly difficult to access the SQLite database that the Android API exposes in anyway that is not using Android's native APIs. There's certainly no native JDBI wrapper supplied.

This is unacceptable for me; mapping fields to database fields by hand is something that we have automated numerous times in the last couple decades. The Android API does not do this. SQLite Access from the Android library is like going back to the ADO.net ages, here's an example I found duckduckgo'ing the internet:

return database.query(DATABASE_TABLE,
  null, null, null, null, null);

If you're thinking the above SCREAMING_CAPS look like they may be string constants, you would not be mistaken. Yes, the bare Android SQLite library drops you back to mapping an object manually. Hello, 2000.

So where did I go from here? What I've been using for a while is OrmLite, and while that certainly works, it has some massive memory leak problems, which, for a library that touts itself as "Lite" (I mean, it's in the name), is not very "lite" :).

Next steps were to look for a library that just bridged the database result set to object mapping gap, which is all I really wanted; ideally, something like Dapper for Java. Once again, numerous tools exist in this space but none supported Android out of the box.

DbUtils from the Apache foundation looks promising, but it once again needs JDBI drivers. Perhaps with SQLDroid I will achieve what I've always wanted!

Note posted on Wednesday, September 23, 2015 7:11 AM CDT - link