I am trying to update an SQLiteDatabase but for some reason update always fails and returns 0 (rows updated).
If I remove String selection = null;, then all rows are updated, but I just want to update the row WHERE eId = ? and I provide the eId. All of the values in ContentValues are correct and non null. Been racking my brain for hours now..maybe a fresh set of eyes on this will help, thanks in advance!
NOTE: propertyItem is OK and all of the values coming from my form are correct. The problem breaks at update when I use the selection variable.
/// COLUMN_NAME_EID == "eId"
public int updatePropertyItem (PropertyItem propertyItem) {
SQLiteDatabase db = mDbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
if ( propertyItem.title != null )values.put(DatabaseContract.DataEntry.COLUMN_NAME_TITLE, propertyItem.title);
if ( propertyItem.category != null ) values.put(DatabaseContract.DataEntry.COLUMN_NAME_CATEGORY, propertyItem.category);
if ( propertyItem.serial != null ) values.put(DatabaseContract.DataEntry.COLUMN_NAME_SERIAL, propertyItem.serial);
if ( propertyItem.note != null ) values.put(DatabaseContract.DataEntry.COLUMN_NAME_NOTE, propertyItem.note);
if ( propertyItem.purchaseDate != null ) values.put(DatabaseContract.DataEntry.COLUMN_NAME_PURCHASE_DATE, propertyItem.purchaseDate);
if ( propertyItem.currentValue != null ) values.put(DatabaseContract.DataEntry.COLUMN_NAME_CURRENT_VALUE, propertyItem.currentValue);
if ( propertyItem.replacementValue != null ) values.put(DatabaseContract.DataEntry.COLUMN_NAME_REPLACE_VALUE, propertyItem.replacementValue);
if ( propertyItem.store != null ) values.put(DatabaseContract.DataEntry.COLUMN_NAME_STORE, propertyItem.store);
values.put(DatabaseContract.DataEntry.COLUMN_NAME_WARRANTY, propertyItem.warranty);
values.put(DatabaseContract.DataEntry.COLUMN_NAME_FAVORITE, propertyItem.favorite);
String selection = DatabaseContract.DataEntry.COLUMN_NAME_EID + " = ? ";
String[] selectionArgs = new String[] { String.valueOf(propertyItem.eId) };
int rowsUpdated = db.update(DatabaseContract.DataEntry.TABLE_NAME, values, selection, selectionArgs);
db.close();
return rowsUpdated;
}