예제 #1
0
  public boolean update(Book book) {
    boolean updated = false;

    try {
      open();

      ContentValues cv = new ContentValues();
      cv.put(DBHelper.KEY_TITLE, book.getTitle());
      cv.put(DBHelper.KEY_AUTHOR, book.getAuthor());

      updated =
          getDB()
                  .update(
                      DBHelper.TABLE_BOOKS,
                      cv,
                      DBHelper.KEY_ID + " = ?",
                      new String[] {String.valueOf(book.getId())})
              > 0;

      close();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      close();
    }

    return updated;
  }
예제 #2
0
  public boolean insert(Book book) {
    boolean inserted = false;

    try {
      open();

      ContentValues contentValues = new ContentValues();
      contentValues.put(DBHelper.KEY_TITLE, book.getTitle());
      contentValues.put(DBHelper.KEY_AUTHOR, book.getAuthor());

      long id = getDB().insert(DBHelper.TABLE_BOOKS, null, contentValues);

      inserted = -1 != id;

      close();

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      close();
    }

    return inserted;
  }