【问题标题】:Content provider doesn't delete row内容提供者不删除行
【发布时间】:2013-03-24 20:38:24
【问题描述】:

奇怪的是我的内容提供商没有删除我要求的行。据我所知,它应该可以工作,但我不明白为什么它不工作。

这是我的提供者中的删除方法:

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    SQLiteDatabase db = helper.getWritableDatabase();

    switch (uriMatcher.match(uri)) {
    case SINGLE_ROW:
        String rowID = uri.getPathSegments().get(1);

        selection = KEY_ROWID
                + "="
                + rowID
                + (!TextUtils.isEmpty(selection) ? " AND (" + selection
                        + ')' : "");
        Log.i("Selection", "" +  selection);
        break;
    case ALLROWS:
        Log.i("Deleted", "All rows");
        break;

    default:
        Log.i("Switch case", "default value");
        break;
    }

    if (selection == null) {
        selection = "1";
    }

    int deleteCount = db.delete(helper.DATABASE_TABLE, selection,
            selectionArgs);
    Log.i("Deleted rows",
            "" + db.delete(helper.DATABASE_TABLE, selection, selectionArgs));
    getContext().getContentResolver().notifyChange(uri, null);

    return deleteCount;
}

这是日志输出,它表明没有删除任何行,这对我来说毫无意义。 谁能帮忙?

03-24 22:36:34.809: I/Selection(27648): _id=2
**03-24 22:36:34.809: I/Deleted rows(27648): 0**
03-24 22:36:34.814: I/Delete Uri(27648): content://com.shifts.provider/shiftsTEST/2

【问题讨论】:

    标签: android android-contentprovider


    【解决方案1】:

    我自己发现了问题 - 我已经重构了这样的方法:

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        SQLiteDatabase db = helper.getWritableDatabase();
    
    
        int deleteCount = db.delete(helper.DATABASE_TABLE, KEY_ID + "="
                + Integer.valueOf(selection), null);
        Log.i("Selection", "" + selection);
    
        getContext().getContentResolver().notifyChange(uri, null);
    
        return deleteCount;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 2012-04-05
      • 1970-01-01
      相关资源
      最近更新 更多