@Override
 protected void deleteBookmark(Bookmark bookmark) {
   if (myDeleteBookmarkStatement == null) {
     myDeleteBookmarkStatement =
         myDatabase.compileStatement("DELETE FROM Bookmarks WHERE bookmark_id = ?");
   }
   myDeleteBookmarkStatement.bindLong(1, bookmark.getId());
   myDeleteBookmarkStatement.execute();
 }
  @Override
  protected long saveBookmark(Bookmark bookmark) {
    SQLiteStatement statement;
    if (bookmark.getId() == -1) {
      if (myInsertBookmarkStatement == null) {
        myInsertBookmarkStatement =
            myDatabase.compileStatement(
                "INSERT OR IGNORE INTO Bookmarks (book_id,bookmark_text,creation_time,modification_time,access_time,access_counter,model_id,paragraph,word,char,visible) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
      }
      statement = myInsertBookmarkStatement;
    } else {
      if (myUpdateBookmarkStatement == null) {
        myUpdateBookmarkStatement =
            myDatabase.compileStatement(
                "UPDATE Bookmarks SET book_id = ?, bookmark_text = ?, creation_time =?, modification_time = ?,access_time = ?, access_counter = ?, model_id = ?, paragraph = ?, word = ?, char = ?, visible = ? WHERE bookmark_id = ?");
      }
      statement = myUpdateBookmarkStatement;
    }

    statement.bindLong(1, bookmark.getBookId());
    statement.bindString(2, bookmark.getText());
    SQLiteUtil.bindDate(statement, 3, bookmark.getTime(Bookmark.CREATION));
    SQLiteUtil.bindDate(statement, 4, bookmark.getTime(Bookmark.MODIFICATION));
    SQLiteUtil.bindDate(statement, 5, bookmark.getTime(Bookmark.ACCESS));
    statement.bindLong(6, bookmark.getAccessCount());
    SQLiteUtil.bindString(statement, 7, bookmark.ModelId);
    statement.bindLong(8, bookmark.ParagraphIndex);
    statement.bindLong(9, bookmark.ElementIndex);
    statement.bindLong(10, bookmark.CharIndex);
    statement.bindLong(11, bookmark.IsVisible ? 1 : 0);

    if (statement == myInsertBookmarkStatement) {
      return statement.executeInsert();
    } else {
      final long id = bookmark.getId();
      statement.bindLong(12, id);
      statement.execute();
      return id;
    }
  }
Пример #3
0
 public void deleteBookmark(Bookmark bookmark) {
   if (bookmark != null && bookmark.getId() != -1) {
     myDatabase.deleteBookmark(bookmark);
   }
 }