Ejemplo n.º 1
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Cursor retCursor;
    //        Log.v(LOG_TAG, "query, " + "uri = [" + uri + "], projection = [" + projection
    //                + "], selection = [" + selection + "], selectionArgs = [" + log(selectionArgs)
    //                + "], sortOrder = [" + sortOrder + "]");
    switch (uriMatcher.match(uri)) {
      case BOOK:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.BookEntry.TABLE_NAME,
                    projection,
                    selection,
                    //                        selection==null? null : selectionArgs,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case AUTHOR:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.AuthorEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case CATEGORY:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.CategoryEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case BOOK_ID:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.BookEntry.TABLE_NAME,
                    projection,
                    AlexandriaContract.BookEntry._ID + " = '" + ContentUris.parseId(uri) + "'",
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case AUTHOR_ID:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.AuthorEntry.TABLE_NAME,
                    projection,
                    AlexandriaContract.AuthorEntry._ID + " = '" + ContentUris.parseId(uri) + "'",
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case CATEGORY_ID:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.CategoryEntry.TABLE_NAME,
                    projection,
                    AlexandriaContract.CategoryEntry._ID + " = '" + ContentUris.parseId(uri) + "'",
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case BOOK_FULLDETAIL:
        String[] bfd_projection = {
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.TITLE,
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.SUBTITLE,
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.IMAGE_URL,
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.DESC,
          "group_concat(DISTINCT "
              + AlexandriaContract.AuthorEntry.TABLE_NAME
              + "."
              + AlexandriaContract.AuthorEntry.AUTHOR
              + ") as "
              + AlexandriaContract.AuthorEntry.AUTHOR,
          "group_concat(DISTINCT "
              + AlexandriaContract.CategoryEntry.TABLE_NAME
              + "."
              + AlexandriaContract.CategoryEntry.CATEGORY
              + ") as "
              + AlexandriaContract.CategoryEntry.CATEGORY
        };
        retCursor =
            bookFull.query(
                dbHelper.getReadableDatabase(),
                bfd_projection,
                AlexandriaContract.BookEntry.TABLE_NAME
                    + "."
                    + AlexandriaContract.BookEntry._ID
                    + " = '"
                    + ContentUris.parseId(uri)
                    + "'",
                selectionArgs,
                AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry._ID,
                null,
                sortOrder);
        break;
      case BOOK_FULL:
        String[] bf_projection = {
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.TITLE,
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.IMAGE_URL,
          "group_concat(DISTINCT "
              + AlexandriaContract.AuthorEntry.TABLE_NAME
              + "."
              + AlexandriaContract.AuthorEntry.AUTHOR
              + ") as "
              + AlexandriaContract.AuthorEntry.AUTHOR,
          "group_concat(DISTINCT "
              + AlexandriaContract.CategoryEntry.TABLE_NAME
              + "."
              + AlexandriaContract.CategoryEntry.CATEGORY
              + ") as "
              + AlexandriaContract.CategoryEntry.CATEGORY
        };
        retCursor =
            bookFull.query(
                dbHelper.getReadableDatabase(),
                bf_projection,
                null,
                selectionArgs,
                AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry._ID,
                null,
                sortOrder);
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    retCursor.setNotificationUri(getContext().getContentResolver(), uri);

    return retCursor;
  }
Ejemplo n.º 2
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Cursor retCursor;
    switch (uriMatcher.match(uri)) {
      case BOOK:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.BookEntry.TABLE_NAME,
                    projection,
                    selection,
                    selection == null ? null : selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case AUTHOR:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.AuthorEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case CATEGORY:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.CategoryEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case BOOK_ID:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.BookEntry.TABLE_NAME,
                    projection,
                    AlexandriaContract.BookEntry._ID + " = '" + ContentUris.parseId(uri) + "'",
                    null /*selectionArgs*/, // AlexSt: mistake - selectionArgs will be ignored as
                                            // there is no '?' in selection clause
                    null,
                    null,
                    sortOrder);
        break;
      case AUTHOR_ID:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.AuthorEntry.TABLE_NAME,
                    projection,
                    AlexandriaContract.AuthorEntry._ID + " = '" + ContentUris.parseId(uri) + "'",
                    null /*selectionArgs*/, // AlexSt: mistake - selectionArgs will be ignored as
                                            // there is no '?' in selection clause
                    null,
                    null,
                    sortOrder);
        break;
      case CATEGORY_ID:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    AlexandriaContract.CategoryEntry.TABLE_NAME,
                    projection,
                    AlexandriaContract.CategoryEntry._ID + " = '" + ContentUris.parseId(uri) + "'",
                    null /*selectionArgs*/, // AlexSt: mistake - selectionArgs will be ignored as
                                            // there is no '?' in selection clause
                    null,
                    null,
                    sortOrder);
        break;
      case BOOK_FULLDETAIL:
        String[] bfd_projection = {
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.TITLE,
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.SUBTITLE,
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.IMAGE_URL,
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.DESC,
          "group_concat(DISTINCT "
              + AlexandriaContract.AuthorEntry.TABLE_NAME
              + "."
              + AlexandriaContract.AuthorEntry.AUTHOR
              + ") as "
              + AlexandriaContract.AuthorEntry.AUTHOR,
          "group_concat(DISTINCT "
              + AlexandriaContract.CategoryEntry.TABLE_NAME
              + "."
              + AlexandriaContract.CategoryEntry.CATEGORY
              + ") as "
              + AlexandriaContract.CategoryEntry.CATEGORY
        };
        retCursor =
            bookFull.query(
                dbHelper.getReadableDatabase(),
                bfd_projection,
                AlexandriaContract.BookEntry.TABLE_NAME
                    + "."
                    + AlexandriaContract.BookEntry._ID
                    + " = '"
                    + ContentUris.parseId(uri)
                    + "'",
                null /*selectionArgs*/, // AlexSt: mistake - selectionArgs will be ignored as there
                                        // is no '?' in selection clause
                AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry._ID,
                null,
                sortOrder);
        break;
      case BOOK_FULL:
        String[] bf_projection = {
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.TITLE,
          AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry.IMAGE_URL,
          "group_concat(DISTINCT "
              + AlexandriaContract.AuthorEntry.TABLE_NAME
              + "."
              + AlexandriaContract.AuthorEntry.AUTHOR
              + ") as "
              + AlexandriaContract.AuthorEntry.AUTHOR,
          "group_concat(DISTINCT "
              + AlexandriaContract.CategoryEntry.TABLE_NAME
              + "."
              + AlexandriaContract.CategoryEntry.CATEGORY
              + ") as "
              + AlexandriaContract.CategoryEntry.CATEGORY
        };
        retCursor =
            bookFull.query(
                dbHelper.getReadableDatabase(),
                bf_projection,
                null,
                null /*selectionArgs*/, // AlexSt: mistake - selectionArgs will be ignored as there
                                        // is no '?' in selection clause
                AlexandriaContract.BookEntry.TABLE_NAME + "." + AlexandriaContract.BookEntry._ID,
                null,
                sortOrder);
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    retCursor.setNotificationUri(getContext().getContentResolver(), uri);

    return retCursor;
  }