So I wrote what I thought was a pretty good and useful DBAdapter class. I wrote some getters, inserters and updaters. Each method had a db.open(), did some stuff, and db.close, returning a cursor. I thought all I would have to do in my main code was write something like Cursor c = db.getAllThings() and then I would be able to iterate over the cursor. Well, I found out that when I closed the db in the DBAdapter, my cursor was invalid. So I removed the db.open and db.close from the DBAdapter class and I do it on each call.
db.open();
Cursor c = db.getAllThings();
db.close();
Well, then I saw a bunch of errors that I wasn’t closing my cursors. Great, I can’t put that in the DBAdapter class either. I have to do it on each call. So now I have
db.open();
Cursor c = db.getAllThings();
c.close();
db.close();
Four lines of code to get that data. Oh, and don’t forget that I have to MoveToFirst and who knows what else.
So, how do you guys write a good, helpful DBAdapter class? Or is this about as good as it gets?
That’s pretty much how I do it – I’d think that’s the correct and best way to do it.