android contentprovider 관련 질문입니다.

조회수 1268회

Udacity의 Developing Android Apps에 나오는 예제인데요... contentproivder의 delete()를 구현하고 있습니다. 주석에 달아놓은 것처럼 selection이 null이면 전체 row를 삭제 합니다. 그러기 위해 selection을 다시 '1'로 만드는데 이렇게 했을 때 전체 row가 삭제되는 이유가 뭘까요?

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    int rowsDeleted = 0;

    // this makes delete all rows return the number of rows deleted
    if (null == selection) selection = “1”;
    switch (match) {
    case WEATHER :
        rowsDeleted = db.delete(WeatherContract.WeatherEntry.TABLE_NAME, selection, selectionArgs);
        break;
    case LOCATION :
        rowsDeleted = db.delete(WeatherContract.LocationEntry.TABLE_NAME, selection, selectionArgs);
        break;
    default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }


    if (rowsDeleted != 0)
        getContext().getContentResolver().notifyChange(uri, null);

    return rowsDeleted;
}
  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)