Your Ad Here

Saturday, February 7, 2009

2 quick tips on Database development on Android

[no, this is not really a pic of me]

I've been teaching myself development for the Android platform for a few months now, and I thought I'd share a couple of what I consider not-so-well documented requirements for setting up successful database applications on the platform.

These are solutions that I personally have found poorly documented for the beginner, and it took me some time to stumble upon them.

These are not written in stone, and I'm sure a more capable developer may have other ways of doing this, all comments/suggestions welcome!

Firstly, create your entire database schema with one 'create' statement.
I didn't find this easily documented as a requirement but this link on code.google.com spells it out nicely.

Secondly, when creating a database with multiple tables, incorporate the database name into your table create statements. Like this:

private static final String CREATE_ITEMS_TABLE =
" create table " + DATABASE_NAME +"." + ITEMS_TABLE +
" (_id integer primary key autoincrement," +
" title text not null);";

db.execSQL(CREATE_ITEMS_TABLE);


.. This took me a good while to realise, as your application will compile and work successfully for any transactions involving the first table, but not subsequent ones. You'll receive 'table not found' errors if you look in the debugger error messages.

I stumbled upon this via a diagram on the sqlite site:

.. more diagrams here for your reference.

Most of the examples available only use one table to demonstrate techniques, but as anyone who has been coding for more than a few months will know, all even slightly complex applications will require more.

Anyway, hope this has been useful to someone out there. If it has, please let me know.

And again, if I've got something wrong, please let me know... we're all in this together :).



till next time,
G

No comments:

Your Ad Here

Search Me