Example #1
0
  /** 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;
  }