Beispiel #1
0
  /** Insert a set of flashcards (linked list) in a single transaction. */
  private void insertFlashcardSet(Flashcard head) {
    openDB();
    SQLiteStatement stmt = getCompiledStatement(SQL_INSERT_FC);
    boolean gotError = false;

    _curDB.beginTransaction();
    try {
      for (Flashcard fc = head; fc != null; fc = Flashcard.Chain.getNext(fc)) {

        stmt.bindLong(1, _importState.getRandomId());
        stmt.bindString(2, fc.getLang1Str());
        stmt.bindString(3, fc.getLang2Str());
        stmt.execute();
      }
      _curDB.setTransactionSuccessful();
    } catch (SQLException e) {
      gotError = true;
      MsgDispatcher.sendMessageToUI(MsgType.MSG_SHOW_ERROR_MSG, 0, 0, "unable to insert fc");
    } finally {
      _curDB.endTransaction();
    }

    Flashcard.Chain.releaseChain(head);

    // tell controller to send us more data if insert went fine.
    if (!gotError) {
      MsgDispatcher.sendMessageToController(MsgType.MSG_CONTINUE_IMPORT, 0, 0, null);
    }
  }
Beispiel #2
0
  /** update the level and count for the given flashcard in the database. */
  private void updateFlashcard(Flashcard fc) {
    openDB();

    _curDB.beginTransaction();
    try {
      // Delete old entry if any.
      SQLiteStatement dStmt = getCompiledStatement(SQL_DELETE_FCS);
      dStmt.bindString(1, fc.getLang1Str());
      dStmt.execute();

      // insert new state entry.
      SQLiteStatement iStmt = getCompiledStatement(SQL_INSERT_FCS);
      iStmt.bindString(1, fc.getLang1Str());
      iStmt.bindLong(2, fc.getLevel());
      iStmt.bindLong(3, fc.getRightGuessCount());
      iStmt.execute();
      _curDB.setTransactionSuccessful();
    } catch (SQLException e) {
      MsgDispatcher.sendMessageToUI(
          MsgType.MSG_SHOW_ERROR_MSG, 0, 0, "unable to update id=" + fc.getID());
    } finally {
      _curDB.endTransaction();
    }

    // this flashcard is no longer used by anyone so release it.
    fc.release();
  }
Beispiel #3
0
 /** create the database schema (tables). Assumes database is already open. */
 private void createSchema() {
   try {
     _curDB.execSQL(SQL_CREATE_FC_TBL);
     _curDB.execSQL(SQL_CREATE_FCS_TBL);
   } catch (SQLException e) {
     MsgDispatcher.sendMessageToUI(MsgType.MSG_SHOW_ERROR_MSG, 0, 0, "unable to create schema");
   }
 }