Pages

Monday, May 24, 2010

First experience with SQLLite

Well it more like the first problem i have with SQLLite in android. If you follow the notepad tutorial for android, you're going to think that this is like any regular database mapping in java. Especially for those of you that used to working with ORM such as hibernate.

When you want to add a second table naturally you'll create another class to handle that table. Well it turn out in SQLLite (in the SQLiteOpenHelper Constructor) if the database is already open, then it wont call the next onCreate() method. So your second table wouldn't be created.

this link explain it more throughly. To solve it you need to put the table creation in one place. The better approach is to open the db in a single class and pass around the handler to other class that actually handle the database functionality. That way you wont be stuck with one single file to handle the database (we're trying to stick with OOP principles here) :).

Another good link about DB/SQLLite handling in android is this link. This will tell you how to ship your android application with prebake database file.

~FD

No comments: