-
-
Save jezinka/0f08f97de42c5cbd94220435ece8a31d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MealContract extends BaseTable implements BaseColumns { | |
String COLUMN_NAME_NAME; | |
private String SQL_GET_ALL_RECORD; | |
public MealContract() { | |
this.TABLE_NAME = "meal"; | |
this.COLUMN_NAME_NAME = "name"; | |
this.SQL_CREATE_ENTRIES = "CREATE TABLE " + TABLE_NAME + " (" + | |
_ID + " INTEGER PRIMARY KEY," + | |
COLUMN_NAME_NAME + " TEXT)"; | |
this.SQL_GET_ALL_RECORD = "select " + this.COLUMN_NAME_NAME + " from " + this.TABLE_NAME + " order by " + this.COLUMN_NAME_NAME; | |
} | |
public boolean insertMeal(Context context, String name) { | |
String tableName = this.getTableName(); | |
ContentValues contentValues = new ContentValues(); | |
contentValues.put("name", name); | |
CoNaObiadDbHelper helper = new CoNaObiadDbHelper(context); | |
helper.insertValuesDbHelper(tableName, contentValues); | |
return true; | |
} | |
public ArrayList<String> getAllMeals(SQLiteOpenHelper helper) { | |
ArrayList<String> array_list = new ArrayList<String>(); | |
SQLiteDatabase db = helper.getReadableDatabase(); | |
Cursor res = db.rawQuery(this.SQL_GET_ALL_RECORD, null); | |
if (res != null && res.getCount() > 0) { | |
res.moveToFirst(); | |
do { | |
String mealName = res.getString(res.getColumnIndex(this.COLUMN_NAME_NAME)); | |
array_list.add(mealName); | |
} while (res.moveToNext()); | |
} | |
db.close(); | |
return array_list; | |
} | |
public boolean isAnyMealSaved(SQLiteOpenHelper helper) { | |
SQLiteDatabase db = helper.getReadableDatabase(); | |
return queryNumEntries(db, "meal") > 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment