public ArrayList getAll() { ArrayList<Recipe> list = new ArrayList<Recipe>(); db.open(); Cursor cursor = db.fetchAll(KEY_TABLE_NAME); if (cursor == null || cursor.getCount() < 1) return null; cursor.moveToFirst(); /*Get column IDs*/ int col_name = cursor.getColumnIndex(KEY_NAME); int col_category = cursor.getColumnIndex(KEY_CATEGORY); int col_ingredients = cursor.getColumnIndex(KEY_INGREDIENTS); int col_instructions = cursor.getColumnIndex(KEY_INSTRUCTIONS); int col__id = cursor.getColumnIndex(KEY__ID); do { Recipe recipe = new Recipe(); recipe.name = cursor.getString(col_name); recipe.category = cursor.getString(col_category); recipe.ingredients = cursor.getString(col_ingredients); recipe.instructions = cursor.getString(col_instructions); recipe._id = cursor.getInt(col__id); Log.e("Test:RECIPE - id", cursor.getInt(col__id) + ""); list.add(recipe); } while (cursor.moveToNext()); db.close(); return list; }
public Recipe get(int id) { Recipe recipe; db.open(); Cursor cursor = db.fetch(KEY_TABLE_NAME, id); if (cursor == null || cursor.getCount() < 1) return null; cursor.moveToFirst(); /*Get column IDs*/ int col_name = cursor.getColumnIndex(KEY_NAME); int col_category = cursor.getColumnIndex(KEY_CATEGORY); int col_ingredients = cursor.getColumnIndex(KEY_INGREDIENTS); int col_instructions = cursor.getColumnIndex(KEY_INSTRUCTIONS); int col__id = cursor.getColumnIndex(KEY__ID); do { recipe = new Recipe(); recipe.name = cursor.getString(col_name); recipe.category = cursor.getString(col_category); recipe.ingredients = cursor.getString(col_ingredients); recipe.instructions = cursor.getString(col_instructions); recipe._id = Integer.parseInt(cursor.getString(col__id)); } while (cursor.moveToNext()); db.close(); return recipe; }