Skip to content

How to validate content values before insertion or update? #92

@VaibhavAWD

Description

@VaibhavAWD

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions