I am struggling with using the update function of Sqlite in my android app. I am simply trying to add 1 to the value that already exists in a row.
This is what I currently have:
public void updateItemQty(int SKU) {
SQLiteDatabase db = getWritableDatabase();
String p[] = new String[]{String.valueOf(SKU)};
ContentValues args = new ContentValues();
args.put(Keys.Key_SENTQTY, Keys.Key_SENTQTY + 1);
try {
db.update(Keys.Key_CARTONITEMTABLE, args, Keys.Key_SKU + " = ? AND " + Keys.Key_STATUS + " = 0 ", p);
} catch (SQLiteException e) {
e.printStackTrace();
}
db.close();
}
This issue being that instead of adding 1 to my key.KEY_SENTQTY, it just enters sent_qty1 into the table! How do I achieve what I am after?
Thanks
update table set col1 = col1 + 1 where col2=somevalue) or read value first add 1 in java code and then update with new value using db.update (for safe you should use transaction) ... there is no way to increment/add value directly using db.update