// Update single ScavItem public void updateScavItem(ScavItem scavItem) { SQLiteDatabase db = this.getWritableDatabase(); Log.d(TAG, db.toString()); ContentValues values = new ContentValues(); values.put(KEY_NAME, scavItem.get_name()); // ScavItem name values.put(KEY_ADDRESS, scavItem.get_address()); // ScavItem address values.put(KEY_DIRECTIONS, scavItem.get_directions()); // ScavItem directions values.put(KEY_IMAGE, scavItem.get_image()); // ScavItem image // Update the corresponding row try { int i = db.update( TABLE_SCAV_ITEMS, values, KEY_ID + "=?", new String[] {String.valueOf(scavItem.get_id())}); if (i <= 0) { Log.e(TAG, "Update failed in a weird way"); } } catch (Exception e) { Log.e(TAG, "Update failed", e); } db.close(); }
// Add new ScavItem public void addScavItem(ScavItem scavItem) { // get a handle on the current database SQLiteDatabase db = this.getWritableDatabase(); // ContentValues object to store ScavItem info ContentValues values = new ContentValues(); values.put(KEY_NAME, scavItem.get_name()); // ScavItem name values.put(KEY_ADDRESS, scavItem.get_address()); // ScavItem address values.put(KEY_DIRECTIONS, scavItem.get_directions()); // ScavItem directions values.put(KEY_IMAGE, scavItem.get_image()); // ScavItem image // Insert row to database try { db.insert(TABLE_SCAV_ITEMS, null, values); Log.v(TAG, "Row inserted!"); } catch (Exception e) { Log.e(TAG, "Unable to insert row", e); } db.close(); }