简体   繁体   中英

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.

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

对于那些看到这个问题的人来说,现在可以说有一个很棒的设计: http//greendao-orm.com/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM