I am trying to use rawQuery
and execSQL
methods for manipulating my database, instead of the .update
, .insert
, etc. I am
From the Android SQLiteDatabase class documentation:
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
It has no means to return any data (such as the number of affected rows). Instead, you're encouraged to use insert(String, String, ContentValues), update(String, ContentValues, String, String[]), et al, when possible.
Then later:
For UPDATE statements, use any of the following instead.
update(String, ContentValues, String, String[])
updateWithOnConflict(String, ContentValues, String, String[], int)
As far as I can tell, the execSQL
method is more for higher level database operations, such as creating tables and changing schema, and the .query
, .update
, .delete
, etc. methods should be used to modify rows. I'm not sure you have another option besides .update to perform this operation.
here is an sample update Query:
public boolean updateCartTable(String retailerName, String mCouponId){
final ContentValues values = new ContentValues();
values.put(TableConstantName.COUPON_ONLY_STATUS, 1);
values.put(TableConstantName.COUPON_SRORE_DEALS_STATUS, 1);
values.put(TableConstantName.COUPON_CATAGORY, "C");
try {
sDb.beginTransaction();
final boolean state = sDb.update(TableConstantName.COUPON_TABLE, values, TableConstantName.CART_COUPON_RETAILER_NAME + "=" + "'"+retailerName+"'"+ " AND "+TableConstantName.CART_COUPON_ID + "=" + "'"+mCouponId+"'", null)>0;
sDb.setTransactionSuccessful();
return state;
} catch (SQLException e) {
throw e;
} finally {
sDb.endTransaction();
}
}