What I want is to add and remove new value to the existing value in Sqlite android. What I've read from the android documentation is this method, but it's not working in my case cause it's removing the existing value with the new one that's being provided.
here's my code:
public boolean updateCigaretteStock(String cigaretteName, int quantity, int totalCost) {
ContentValues values = new ContentValues();
values.put(CigaretteStockEntry.COLUMN_QTY, quantity);
values.put(CigaretteStockEntry.COLUMN_TOTAL_COST, totalCost);
String whereClause = CigaretteStockEntry.COLUMN_CIGARETTE_NAME + " = ?";
String[] whereArgs = {cigaretteName};
int rowAffected = writableDatabase.update(CigaretteStockEntry.TABLE_NAME, values, whereClause, whereArgs);
return (rowAffected > 0);
}
I've also tried to modify the method:
public boolean updateCigaretteStock(String cigaretteName, int quantity, int totalCost) {
ContentValues values = new ContentValues();
values.put(CigaretteStockEntry.COLUMN_QTY, CigaretteStockEntry.COLUMN_QTY + " + " + quantity);
values.put(CigaretteStockEntry.COLUMN_TOTAL_COST, CigaretteStockEntry.COLUMN_TOTAL_COST + " + " + totalCost);
String whereClause = CigaretteStockEntry.COLUMN_CIGARETTE_NAME + " = ?";
String[] whereArgs = {cigaretteName};
int rowAffected = writableDatabase.update(CigaretteStockEntry.TABLE_NAME, values, whereClause, whereArgs);
return (rowAffected > 0);
}
But it isn't working too. It showing the value in the columns for example :
(quantity + new value)
(total_cost + new value)
Any help?