Code example for SQLiteDatabase

Methods: beginTransactionendTransactionsetTransactionSuccessful

0
    @Override 
    public int deleteItem(SQLiteDatabase db, ContentProvider provider, Uri uri, String where,
            String[] whereArgs) {
        int count;
        try { 
            db.beginTransaction();
            final long childId = ContentUris.parseId(uri);
            final Uri parent = ProviderUtils.removeLastPathSegments(uri, 2);
 
            final int rows = removeRelation(db, ContentUris.parseId(parent), childId);
 
            if (rows == 0) {
                throw new IllegalArgumentException("There is no relation between " + parent
                        + " and " + mToTable + ": ID " + childId);
            } 
 
            if (mToContentUri != null) {
                count = provider.delete(ContentUris.withAppendedId(mToContentUri, childId), where,
                        whereArgs);
            } else { 
                count = db.delete(mToTable,
                        ProviderUtils.addExtraWhere(where, BaseColumns._ID + "=?"),
                        ProviderUtils.addExtraWhereArgs(whereArgs, String.valueOf(childId)));
            } 
 
            db.setTransactionSuccessful();
 
        } finally { 
            db.endTransaction();
        } 
        return count;
    } 
 
    /*