Shaw
Shaw

Reputation: 1139

Android: Creating a SQLite database with a relationship

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.

Upvotes: 3

Views: 19187

Answers (3)

alex
alex

Reputation: 94

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

Upvotes: 1

RobGThai
RobGThai

Reputation: 5969

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 :)

Upvotes: 2

Siddharth Lele
Siddharth Lele

Reputation: 27748

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.

Upvotes: 1

Related Questions