How do I use struct arrays or similar data structures in Android/SQLite?

非 Y 不嫁゛ 提交于 2019-12-08 11:24:07

问题


I am developing an events storing app where each event has its guest list. I am new to android and also sqlite so any help would be greatly appreciated.

e.g in C language it would be

struct event{    
   int ID;
   String eventName;
   String place,date,comments,venue;
  // guest[] myGuestList;  (i can not achieve this goal) 
}

struct guest{
    String guestName;
    String guestContact;
    String guestEmail;
}

this is somewhat my requirement in the Android app im developing. So far I have achieved creating a SQLite database which maintains a table of events. How do I add a guestList to each of my events in my SQLite database? What is the best design for my requirement?


回答1:


Depends if same guest can be included in multiple events. If yes, you would need three tables, one for events, one for guests. The third table will link guestID to EventID, one row per guest per event.
If no, you can skip the third table, and add the eventID directly to the guest table.
This is a common SQL setup, and you should to a little SQL research before you continue.



来源:https://stackoverflow.com/questions/38559909/how-do-i-use-struct-arrays-or-similar-data-structures-in-android-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!