Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- nutrition.db:
- Ingredient(ID, name, kcal);
- Meal(ID, name, ingredientId1, ingredientId2);
- MealInstance(ID, mealId, date, amountOfIngr1, amountOfIngr2) ...
- public class MyDatabase {
- private static final String DATABASE_NAME = "my_database.db";
- private static final int DATABASE_VERSION = 1;
- public static final String TABLE_ONE = "tableOne";
- public static final String TABLE_TWO = "tableTwo";
- public static final String TABLE_THREE = "tableThree";
- public MyDatabase(Context _context)
- {
- mDbHelper = new MyDbOpenHelper(_context, DATABASE_NAME, null, DATABASE_VERSION);
- }
- //add code to declare your columns for each table
- //add methods for opening/closing database, etc...
- private static class MyDbOpenHelper extends SQLiteOpenHelper {
- //SETUP THE NORMAL SQLite COMMANDS THAT YOU USE TO CREATE A TABLE
- private static final String CREATE_TABLE_ONE = "create table if not exists " + TABLE_ONE...;
- private static final String CREATE_TABLE_TWO = "create table if not exists " + TABLE_TWO...;
- private static final String CREATE_TABLE_THREE = "create table if not exists " + TABLE_THREE...;
- public StatsDbOpenHelper(Context context, String name, CursorFactory factory, int version)
- {
- super(context, name, factory, version);
- }
- @Override
- public void onCreate(SQLiteDatabase _db)
- {
- //ALL OF YOUR TABLES ARE CREATED HERE WHEN YOUR DATABASE IS FIRST CREATED
- _db.execSQL(CREATE_TABLE_ONE);
- _db.execSQL(CREATE_TABLE_TWO);
- _db.execSQL(CREATE_TABLE_THREE);
- }
- }
- }
Add Comment
Please, Sign In to add comment