I found an interesting blog that helped me re-think of how I'm using the SQLiteOpenHelper class in my code. The class' purpose is to essentially create or upgrade a new database each time you install or upgrade an Android application. Unfortunately, since I was using the tutorial's DBAdapter class, I missed this idiosyncrasy that makes it seem that this class is database specific as opposed to being table specific, which the author of this blog post has duly noted. You could also say that this class might be application specific as it requires the Context class (which turns out to be the Activity) to be passed in so that this class can judge whether or not to run the create or upgrade methods.
I still want to develop something that is more table based for my code as opposed to having a giant kludge of a class containing every single method for my data operations. Probably, if I refactor the original class to operate partly to create/open/close the database and hand off the connection and then separate the SQL queries into another abstract class, that might solve my issue. So the class utilizing SQLLiteOpenHelper would have all the create/drop statements for the tables. It will probably have a convenience method to grab the database connection on top of methods to open/close the database.
That all said, this is still why I'm not feeling warm and fuzzy in dealing with the sample code from Google. Sure, this is a tutorial, but it's quite simplistic. Also, I think I might need to do some research to see if any libraries for wrapping a lot of this low level code exist.
Trackbacks: (Trackback URL)