Reputation: 11
This works but i need to be able to change the value of the product_name
String query = "UPDATE UserTable SET _quantity=_quantity - 1 WHERE product_name ='Hammer'";
myDatabase.execSQL(query);
This does not work and I can't see why.
String test = "Hammer";
String query = "UPDATE UserTable SET _quantity=_quantity - 1 WHERE product_name ='%"+test+ "%'";
myDatabase.execSQL(query);
Upvotes: 0
Views: 59
Reputation: 23638
You need to remove %
symbols from your query. This symbols are used to match the strings values if you want to match anything like what he wants %mer%
would match hammer
Try as below:
String query = "UPDATE UserTable SET _quantity=_quantity - 1 WHERE product_name ='"+test+ "'";
Upvotes: 0
Reputation: 1477
Try this code
i think it will work
ContentValues data = new ContentValues();
data.put("Column Name", column_value);
i.e,
data.put("_quantity", 3);
myDatabase.update(TABLE_NAME ,data,"product_name = ?",new String[]{test});
Upvotes: 1
Reputation: 651
To match a pattern you should use the LIKE statement:
String test = "Hammer";
String query = "UPDATE UserTable SET _quantity=_quantity - 1 WHERE product_name LIKE '%"+test+ "%'";
myDatabase.execSQL(query);
Upvotes: 0