Esempio n. 1
0
  private boolean executeMigrations(SQLiteDatabase db, int oldVersion, int newVersion) {
    boolean migrationExecuted = false;
    try {
      final List<String> files = Arrays.asList(Cache.getContext().getAssets().list(MIGRATION_PATH));
      Collections.sort(files, new NaturalOrderComparator());

      db.beginTransaction();
      try {
        for (String file : files) {
          try {
            final int version = Integer.valueOf(file.replace(".sql", ""));

            if (version > oldVersion && version <= newVersion) {
              executeSqlScript(db, file);
              migrationExecuted = true;

              Log.i(file + " executed succesfully.");
            }
          } catch (NumberFormatException e) {
            Log.w("Skipping invalidly named file: " + file, e);
          }
        }
        db.setTransactionSuccessful();
      } finally {
        db.endTransaction();
      }
    } catch (IOException e) {
      Log.e("Failed to execute migrations.", e);
    }

    return migrationExecuted;
  }
Esempio n. 2
0
 private void executePragmas(SQLiteDatabase db) {
   if (SQLiteUtils.FOREIGN_KEYS_SUPPORTED) {
     db.execSQL("PRAGMA foreign_keys=ON;");
     Log.i("Foreign Keys supported. Enabling foreign key features.");
   }
 }