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 long insert() { ContentValues cv = new ContentValues(); db.open(); cv.put(KEY_NAME, name); cv.put(KEY_CATEGORY, category); cv.put(KEY_INGREDIENTS, ingredients); cv.put(KEY_INSTRUCTIONS, instructions); long id = db.insert(KEY_TABLE_NAME, cv); db.close(); return id; }
public void test() throws Exception { new Plant(); try { Path dbPath = Paths.get("vcow.db"); Files.deleteIfExists(dbPath); int maxRootBlockSize = 1000; try (Db db = new Db(new BaseRegistry(), dbPath, maxRootBlockSize)) { Files.deleteIfExists(dbPath); db.registerTransaction("SecondaryTran", SecondaryTran.class); db.open(true); String timestampId = db.update("SecondaryTran").call(); } } finally { Plant.close(); } }
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; }
public boolean delete() { db.open(); boolean done = db.delete(KEY_TABLE_NAME, _id); db.close(); return done; }