コード例 #1
0
ファイル: AnkiDb.java プロジェクト: RoyGF/Anki-Android
  /** Open a database connection to an ".anki" SQLite file. */
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  public AnkiDb(String ankiFilename) {
    // Since API 11 we can provide a custom error handler which doesn't delete the database on
    // corruption
    if (CompatHelper.isHoneycomb()) {
      mDatabase =
          SQLiteDatabase.openDatabase(
              ankiFilename,
              null,
              (SQLiteDatabase.OPEN_READWRITE + SQLiteDatabase.CREATE_IF_NECESSARY)
                  | SQLiteDatabase.NO_LOCALIZED_COLLATORS,
              new MyDbErrorHandler());
    } else {
      mDatabase =
          SQLiteDatabase.openDatabase(
              ankiFilename,
              null,
              (SQLiteDatabase.OPEN_READWRITE + SQLiteDatabase.CREATE_IF_NECESSARY)
                  | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
    }

    if (mDatabase != null) {
      // TODO: we can remove this eventually once everyone has stopped using old AnkiDroid clients
      // with WAL
      CompatHelper.getCompat().disableDatabaseWriteAheadLogging(mDatabase);
      mDatabase.rawQuery("PRAGMA synchronous = 2", null);
    }
    // getDatabase().beginTransactionNonExclusive();
    mMod = false;
  }
コード例 #2
0
  private String getMessage() {
    switch (getArguments().getInt("dialogType")) {
      case DIALOG_LOAD_FAILED:
        if (!CompatHelper.isHoneycomb()) {
          // Before honeycomb there's no way to know if the db has actually been corrupted
          // so we show a non-specific message.
          return res()
              .getString(
                  R.string.open_collection_failed_message, res().getString(R.string.repair_deck));
        } else if (databaseCorruptFlag) {
          // The sqlite database has been corrupted (DatabaseErrorHandler.onCorrupt() was called)
          // Show a specific message appropriate for the situation
          return res()
              .getString(R.string.corrupt_db_message, res().getString(R.string.repair_deck));

        } else {
          // Generic message shown when a libanki task failed
          return res()
              .getString(
                  R.string.access_collection_failed_message, res().getString(R.string.link_help));
        }
      case DIALOG_DB_ERROR:
        return res().getString(R.string.answering_error_message);
      case DIALOG_REPAIR_COLLECTION:
        return res().getString(R.string.repair_deck_dialog, BackupManager.BROKEN_DECKS_SUFFIX);
      case DIALOG_RESTORE_BACKUP:
        return res().getString(R.string.backup_restore_no_backups);
      case DIALOG_NEW_COLLECTION:
        return res().getString(R.string.backup_del_collection_question);
      case DIALOG_CONFIRM_DATABASE_CHECK:
        return res().getString(R.string.check_db_warning);
      case DIALOG_CONFIRM_RESTORE_BACKUP:
        return res().getString(R.string.restore_backup);
      case DIALOG_FULL_SYNC_FROM_SERVER:
        return res().getString(R.string.backup_full_sync_from_server_question);
      case DIALOG_CURSOR_SIZE_LIMIT_EXCEEDED:
        return res().getString(R.string.cursor_size_limit_exceeded);
      default:
        return getArguments().getString("dialogMessage");
    }
  }