0

I would like to my query to the database look like this:

UPDATE table_name SET salary = salary + cash WHERE id_wallet = id_wallet2

cash and id_wallet2- transmitted by method

I wrote this method. But the method changes the salary, do not bear the extra money. Do you have any ideas how to do it?

  public void AddCashWallet(int id_wallet, double cash){
    ContentValues contentValues1 = new ContentValues();
    ContentValues contentValues2 = new ContentValues();
    contentValues2.put(Wallets.COLUMNS.id_walllet, id_wallet);
    contentValues1.put(Wallets.COLUMNS.currency_cash,cash);
    DbHelper.getWritableDatabase().update(Wallets.TABLE_NAME,contentValues1,""+contentValues2,null);
}

But I want my query look like this: UPDATE table_name SET salary = salary + cash WHERE id_wallet = id_wallet2 In this moment look like: UPDATE table_name SET salary = cash WHERE id_wallet = id_wallet2

Adrien
  • 11
  • 5

1 Answers1

-1

That's not how to update.

ContentValues contentValues = new ContentValues();
contentValues.put(Wallets.COLUMNS.currency_cash,cash);

String selection = Wallets.COLUMNS.id_walllet + " = ?";
String[] selectionArgs = { String.valueOf(id_wallet) };

DbHelper.getWritableDatabase().update(
    Wallets.TABLE_NAME,contentValues,selection,selectionArgs);

}

https://developer.android.com/training/basics/data-storage/databases.html

https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

nasch
  • 5,330
  • 6
  • 31
  • 52
  • Ok. But I want my query look like this: UPDATE table_name SET salary = salary + cash WHERE id_wallet = id_wallet2 In this moment look like: UPDATE table_name SET salary = cash WHERE id_wallet = id_wallet2 – Adrien Dec 16 '16 at 00:58
  • You may be better off doing that with raw SQL. – nasch Dec 16 '16 at 21:46