Validate input fields

// Make sure that the fields are all set if (values.containsKey(BookTableMetaData.CREATED_DATE) == false) { values.put(BookTableMetaData.CREATED_DATE, now);

if (values.containsKey(BookTableMetaData.MODIFIED_DATE) == false) { values.put(BookTableMetaData.MODIFIED_DATE, now);

if (values.containsKey(BookTableMetaData.BOOK_NAME) == false) { throw new SOLException(

"Failed to insert row because Book Name is needed " + uri);

if (values.containsKey(BookTableMetaData.BOOK_ISBN) == false) { values.put(BookTableMetaData.BOOK_ISBN, "Unknown ISBN");

if (values.containsKey(BookTableMetaData.BOOK_AUTHOR) == false) { values.put(BookTableMetaData.BOOK_ISBN, "Unknown Author");

SOLiteDatabase db = mOpenHelper.getWritableDatabase();

long rowId = db.insert(BookTableMetaData.TABLE_NAME

, BookTableMetaData.BOOK_NAME, values);

Uri insertedBookUri = ContentUris.withAppendedId(

BookTableMetaData.CONTENT_URI, rowId); getContext().getContentResolver().notifyChange(insertedBookUri, null); return insertedBookUri;

throw new SOLException("Failed to insert row into " + uri);

0 0

Post a comment