Code example for SQLiteDatabase

Methods: deletequery

0
 
        switch (sUriMatcher.match(uri)) {
        case APP_ID:
        	int uid = 0, execUid = 0;
        	String cmd = null;
            Cursor c = mDb.query(Apps.TABLE_NAME,
                    new String[] { Apps.UID, Apps.EXEC_UID, Apps.EXEC_CMD },
                    Apps._ID + "=" + uri.getPathSegments().get(1) +
                    (!TextUtils.isEmpty(selection)? " AND (" +
                            selection  + ")":""),
                    selectionArgs,
                    null, null, null); 
            if (c.moveToFirst()) {
            	uid = c.getInt(c.getColumnIndex(Apps.UID));
            	execUid = c.getInt(c.getColumnIndex(Apps.EXEC_UID));
            	cmd = c.getString(c.getColumnIndex(Apps.EXEC_CMD));
            } 
            c.close();
            count = mDb.delete(Apps.TABLE_NAME,
                    Apps._ID + "=" + uri.getPathSegments().get(1) +
                    (!TextUtils.isEmpty(selection)? " AND (" +
                            selection  + ")":""),
                    selectionArgs);
            Util.deleteStoreFile(mContext, uid, execUid, cmd);
            // No break here so we can fall through and delete associated logs 
        case APP_ID_LOGS:
        case LOGS_APP_ID:
            count += mDb.delete(Logs.TABLE_NAME,
                    Logs.APP_ID + "=" + uri.getPathSegments().get(1) +
                    (!TextUtils.isEmpty(selection)? " AND (" +
                            selection  + ")":""),
                    selectionArgs);
            break; 
        case APP_CLEAN:
            count = mDb.delete(Apps.TABLE_NAME, selection, selectionArgs);
            break; 
        case LOGS:
            count = mDb.delete(Logs.TABLE_NAME, selection, selectionArgs);
            break; 
        default: 
            throw new IllegalArgumentException("Unsupported URI: " + uri);
        } 
        getContext().getContentResolver().notifyChange(uri, null);