schematic icon indicating copy to clipboard operation
schematic copied to clipboard

How to validate content values before insertion or update?

Open VaibhavAWD opened this issue 6 years ago • 0 comments

As we validate the content values in typical content provider before performing insertion or update like this example shown below,

private Uri insertMember(Uri uri, ContentValues values) {
    if (values.size() == 0) {
        return null;
    }

    String name = values.getAsString(MemberEntry.COLUMN_NAME);
    if (!isValidName(name)) {
        throw new IllegalArgumentException("Invalid Name");
    }

    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    long newRowId = db.insert(MemberEntry.TABLE_NAME, null, values);
    if (newRowId == -1) {
        Log.d(LOG_TAG, "Failed to insert row");
        return null;
    }
    return ContentUris.withAppendedId(uri, newRowId);
}

Similarly, how do we validate content values when using this library?

VaibhavAWD avatar Mar 30 '19 06:03 VaibhavAWD