public class FoodLogDBH
extends android.database.sqlite.SQLiteOpenHelper
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COLUMN_CALORIES |
static java.lang.String |
COLUMN_CARBS |
static java.lang.String |
COLUMN_DATE |
static java.lang.String |
COLUMN_FAT |
static java.lang.String |
COLUMN_FOOD |
static java.lang.String |
COLUMN_ID |
static java.lang.String |
COLUMN_MEAL |
static java.lang.String |
COLUMN_PROTEIN |
static java.lang.String |
COLUMN_TIME |
static java.lang.String |
FOODLOGS_TABLE |
Constructor and Description |
---|
FoodLogDBH(android.content.Context context)
On first construction, creates a database with a name and a version
|
Modifier and Type | Method and Description |
---|---|
void |
addArray(java.util.ArrayList<FoodLog> foodlogList)
Inserting an ArrayList of food log objects given in parameters into the db
|
void |
deleteOne(FoodLog foodlog)
Delete a row in the table where the id equals to the id of the food log given as a parameter
|
int |
getCaloriesByDate(java.lang.String date)
Get the sum of all calories eaten for a given date.
|
int |
getCaloriesByMealByDate(java.lang.String meal,
java.lang.String date)
Get the sum of all calories eaten on a specific meal on a given date.
|
java.util.List<FoodLog> |
getFoodLog(java.lang.String dateDisplayed)
Get an ArrayList of all the food logs for a given date.
|
int |
getSumByDate(java.lang.String column,
java.lang.String date)
Get the sum of any column for a given date
|
void |
onCreate(android.database.sqlite.SQLiteDatabase db)
Used only the first time.
|
void |
onUpgrade(android.database.sqlite.SQLiteDatabase db,
int oldVersion,
int newVersion)
Handles actions on upgrade to another version.
|
void |
updateOne(FoodLog foodLog,
java.lang.String name,
java.lang.String meal,
java.lang.String time,
int calories,
double carbs,
double protein,
double fat)
Updates the values of an entry for a given food log.
|
public static final java.lang.String COLUMN_DATE
public static final java.lang.String COLUMN_FOOD
public static final java.lang.String FOODLOGS_TABLE
public static final java.lang.String COLUMN_MEAL
public static final java.lang.String COLUMN_ID
public static final java.lang.String COLUMN_TIME
public static final java.lang.String COLUMN_CALORIES
public static final java.lang.String COLUMN_CARBS
public static final java.lang.String COLUMN_PROTEIN
public static final java.lang.String COLUMN_FAT
public FoodLogDBH(@Nullable android.content.Context context)
context
- activity classpublic void onCreate(android.database.sqlite.SQLiteDatabase db)
onCreate
in class android.database.sqlite.SQLiteOpenHelper
db
- database createdpublic void onUpgrade(android.database.sqlite.SQLiteDatabase db, int oldVersion, int newVersion)
onUpgrade
in class android.database.sqlite.SQLiteOpenHelper
db
- database upgradedoldVersion
- newVersion
- public void updateOne(FoodLog foodLog, java.lang.String name, java.lang.String meal, java.lang.String time, int calories, double carbs, double protein, double fat)
foodLog
- food log object to be alteredname
- name of the food logmeal
- meal of the food logtime
- time of the food logcalories
- caloric value of the food logcarbs
- carb value of the food logprotein
- protein value of the food logfat
- fat value of the food logpublic void deleteOne(FoodLog foodlog)
foodlog
- to be deletedpublic void addArray(java.util.ArrayList<FoodLog> foodlogList)
foodlogList
- ArrayList to be insertedpublic java.util.List<FoodLog> getFoodLog(java.lang.String dateDisplayed)
dateDisplayed
- date for the food logs to displaypublic int getCaloriesByDate(java.lang.String date)
date
- date for which calories will be summedpublic int getCaloriesByMealByDate(java.lang.String meal, java.lang.String date)
meal
- meal for which calories will be summeddate
- date for which calories will be summedpublic int getSumByDate(java.lang.String column, java.lang.String date)
column
- column for which calories will be summeddate
- date for which calories will be summed