Example #1
0
  public void testInsertReadDb() {
    DbHelper dbHelper = new DbHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    ContentValues values = getBookValues();

    long retEan = db.insert(AlexandriaContract.BookEntry.TABLE_NAME, null, values);
    assertEquals(ean, retEan);

    String[] columns = {
      AlexandriaContract.BookEntry._ID,
      AlexandriaContract.BookEntry.TITLE,
      AlexandriaContract.BookEntry.IMAGE_URL,
      AlexandriaContract.BookEntry.SUBTITLE,
      AlexandriaContract.BookEntry.DESC
    };

    // A cursor is your primary interface to the query results.
    Cursor cursor =
        db.query(
            AlexandriaContract.BookEntry.TABLE_NAME, // Table to Query
            columns,
            null, // Columns for the "where" clause
            null, // Values for the "where" clause
            null, // columns to group by
            null, // columns to filter by row groups
            null // sort order
            );

    validateCursor(cursor, values);
    values = getAuthorValues();

    retEan = db.insert(AlexandriaContract.AuthorEntry.TABLE_NAME, null, values);

    columns =
        new String[] {AlexandriaContract.AuthorEntry._ID, AlexandriaContract.AuthorEntry.AUTHOR};

    cursor =
        db.query(
            AlexandriaContract.AuthorEntry.TABLE_NAME, // Table to Query
            columns,
            null, // Columns for the "where" clause
            null, // Values for the "where" clause
            null, // columns to group by
            null, // columns to filter by row groups
            null // sort order
            );

    validateCursor(cursor, values);
    // test category table
    values = getCategoryValues();
    retEan = db.insert(AlexandriaContract.CategoryEntry.TABLE_NAME, null, values);

    columns =
        new String[] {
          AlexandriaContract.CategoryEntry._ID, AlexandriaContract.CategoryEntry.CATEGORY
        };

    cursor =
        db.query(
            AlexandriaContract.CategoryEntry.TABLE_NAME, // Table to Query
            columns,
            null, // Columns for the "where" clause
            null, // Values for the "where" clause
            null, // columns to group by
            null, // columns to filter by row groups
            null // sort order
            );

    validateCursor(cursor, values);
    dbHelper.close();
  }