public static boolean deleteTable(Databases db) { try { SQLiteDatabase sql = db.getWritableDatabase(); String query = "DELETE from " + TABLE_NAME; LOG.log("Query:", "Query:" + query); sql.execSQL(query); sql.close(); return true; } catch (Exception e) { return false; } }
public static FoodItem getAnObject(Databases db, FoodItem item) { FoodItem gradeTemp = null; SQLiteDatabase dbRead = db.getReadableDatabase(); String query = "select * from " + TABLE_NAME + " WHERE " + FOOD_ID + " = " + item.id + ""; LOG.log("Query:", "Query:" + query); Cursor c = dbRead.rawQuery(query, null); if (c.moveToFirst()) { gradeTemp = getAnObjectFromCursor(c); } c.close(); dbRead.close(); return gradeTemp; }
public static ArrayList<FoodItem> getAllObject(Databases db) { ArrayList<FoodItem> grades = new ArrayList<FoodItem>(); SQLiteDatabase dbRead = db.getReadableDatabase(); String query = "select * from " + TABLE_NAME; LOG.log("Query:", "Query:" + query); Cursor c = dbRead.rawQuery(query, null); if (c.moveToFirst()) { do { FoodItem gradeTemp = getAnObjectFromCursor(c); grades.add(gradeTemp); } while (c.moveToNext()); } c.close(); dbRead.close(); return grades; }
public static boolean inseartOperation(Databases db, FoodItem item) { SQLiteDatabase sql = db.getWritableDatabase(); String query = ""; query = "insert into " + TABLE_NAME + " (" + FOOD_ID + "," + NAME + "," + RATE + "," + DESCRIPTION + "," + IMAGE_URL + ") values (" + "" + item.id + "" + "," + "'" + item.name + "'" + "," + "" + item.rate + "" + "," + "'" + item.description + "'" + "," + "'" + item.imageUrl + "'" + ");"; LOG.log("Query:", "Query:" + query); sql.execSQL(query); return true; }
public static boolean updateOperation(Databases db, FoodItem item) { SQLiteDatabase sql = db.getWritableDatabase(); String query = ""; query = "update " + TABLE_NAME + " SET " + FOOD_ID + " = " + item.id + " , " + NAME + " = '" + item.name + "' , " + RATE + " = " + item.rate + " , " + DESCRIPTION + " = '" + item.description + "' , " + IMAGE_URL + " = '" + item.imageUrl + "' " + " WHERE " + FOOD_ID + " = " + item.id + ""; LOG.log("Query:", "Query:" + query); sql.execSQL(query); sql.close(); return true; }