1

I seem to encounter a minor bug somewhere in the code and it is pissing me off because I seem not to find it.

Anyways the insert method as well as the update method works fine. This is the code I use for delete method:

 @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        // Get writeable database
        SQLiteDatabase database = mDbHelper.getWritableDatabase();

        final int match = sUriMatcher.match(uri);
        switch (match) {
            case HISTORY:
                // Delete all rows that match the selection and selection args
                return database.delete(HistoryContract.HistoryEntry.TABLE_NAME, selection, selectionArgs);
            case HISTORY_ID:
                // Delete a single row given by the ID in the URI
                selection = HistoryContract.HistoryEntry._ID + "=?";
                selectionArgs = new String[] { String.valueOf(ContentUris.parseId(uri)) };
                return database.delete(HistoryContract.HistoryEntry.TABLE_NAME, selection, selectionArgs);
            default:
                throw new IllegalArgumentException("Deletion is not supported for " + uri);
        }
    }

URI matcher :

private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);

// Static initializer. This is run the first time anything is called from this class.
static {
    // The calls to addURI() go here, for all of the content URI patterns that the provider
    // should recognize. All paths added to the UriMatcher have a corresponding code to return
    // when a match is found.

    // TODO: Add 2 content URIs to URI matcher


    sUriMatcher.addURI(HistoryContract.CONTENT_AUTHORITY,HistoryContract.PATH_HISTORY,HISTORY);
    sUriMatcher.addURI(HistoryContract.CONTENT_AUTHORITY,HistoryContract.PATH_HISTORY + "/#",HISTORY_ID);
}

Call of delete method :

 int rowsDeleted = getContentResolver().delete(mCurrentHistoryUri,null,null);

The mCurrentHistoryUri I pass to the activity in the intent with :

 displayIntent.setData(currentHistoryUri);

It gives proper URI and when I write out in LOG rows Deleted I get number of 0.

The object is displayed via cursorloader.

****EDIT**** I've tried to play with select statement and checked the song name to fit the displayed song (tho i dont want to use this beacuse of possible deletion on multiply rows), and the delete works , any idea?

Luka Čagalj
  • 31
  • 1
  • 6

0 Answers0