3

I am trying to create an application which requires a two table SQLite database with a one to many relationship.

Basicly the first table will allow a user to create an employee, when they will tap on the employee it will take them to a second activity which will allow users to add multiple phone numbers for that employee which is stored in a second table.

I don't really know where to start,regarding creating a database with two tables and a relationship. Every example I seem to come across only deminstrate a one table database connection.

I would be greatful for any help/advice/a tutorial which demos this kind of functionality.

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
Shaw
  • 1,039
  • 3
  • 9
  • 18

3 Answers3

2

This tutorial leads me to successfully creating DAO class implementation: http://www.vogella.de/articles/AndroidSQLite/article.html

There's no enforced relationship though, I heard it's not good for performance anyway so I stop looking.

I end up having one DBHandler that keep tracks of DB version for create/update tables. I also have DBOpenHelper for help opening/close connections. Since I have two tables (for the purpose of example I will stick with Employee and Contact), I have one DAO of each type both contain DBOpenHelper.

Hope this helps :)

RobGThai
  • 5,937
  • 8
  • 41
  • 59
1

For those who are seeing this question now arguably has a great design here: http://greendao-orm.com/

alex
  • 104
  • 4
  • 10
1

A search on Google gave this tutorial. It demonstrates QUERIES on multiple tables using JOIN. You could probably extrapolate the QUERY concept and use them to add entries. Just a thought really, but hope it helps you go in the right direction.

http://mobile.tutsplus.com/tutorials/android/android-sqlite/

A similar question on SO: Android: SQLite one-to-many design

This one does not have a definitive answer either. But, again, it might help.

Community
  • 1
  • 1
Siddharth Lele
  • 27,623
  • 15
  • 98
  • 151
  • Thanks for the help, I reckon there are not many examples showing a relationship between tables for a good reason... Probably doesn't work great in Android as of yet! ;) – Shaw Mar 26 '12 at 12:58