Guest User

Untitled

a guest
Jul 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. nutrition.db:
  2. Ingredient(ID, name, kcal);
  3. Meal(ID, name, ingredientId1, ingredientId2);
  4. MealInstance(ID, mealId, date, amountOfIngr1, amountOfIngr2) ...
  5.  
  6. public class MyDatabase {
  7.  
  8. private static final String DATABASE_NAME = "my_database.db";
  9. private static final int DATABASE_VERSION = 1;
  10.  
  11. public static final String TABLE_ONE = "tableOne";
  12. public static final String TABLE_TWO = "tableTwo";
  13. public static final String TABLE_THREE = "tableThree";
  14.  
  15. public MyDatabase(Context _context)
  16. {
  17. mDbHelper = new MyDbOpenHelper(_context, DATABASE_NAME, null, DATABASE_VERSION);
  18. }
  19.  
  20. //add code to declare your columns for each table
  21. //add methods for opening/closing database, etc...
  22.  
  23. private static class MyDbOpenHelper extends SQLiteOpenHelper {
  24.  
  25. //SETUP THE NORMAL SQLite COMMANDS THAT YOU USE TO CREATE A TABLE
  26. private static final String CREATE_TABLE_ONE = "create table if not exists " + TABLE_ONE...;
  27. private static final String CREATE_TABLE_TWO = "create table if not exists " + TABLE_TWO...;
  28. private static final String CREATE_TABLE_THREE = "create table if not exists " + TABLE_THREE...;
  29.  
  30. public StatsDbOpenHelper(Context context, String name, CursorFactory factory, int version)
  31. {
  32. super(context, name, factory, version);
  33. }
  34.  
  35. @Override
  36. public void onCreate(SQLiteDatabase _db)
  37. {
  38. //ALL OF YOUR TABLES ARE CREATED HERE WHEN YOUR DATABASE IS FIRST CREATED
  39. _db.execSQL(CREATE_TABLE_ONE);
  40. _db.execSQL(CREATE_TABLE_TWO);
  41. _db.execSQL(CREATE_TABLE_THREE);
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment