// Upgrading database @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { this.db = db; Log.i(Constants.TAG, "Upgrading database version from " + oldVersion + " to " + newVersion); UpgradeProcessor.process(oldVersion, newVersion); try { for (String sqlFile : AssetUtils.list(SQL_DIR, mContext.getAssets())) { if (sqlFile.startsWith(UPGRADE_QUERY_PREFIX)) { int fileVersion = Integer.parseInt( sqlFile.substring( UPGRADE_QUERY_PREFIX.length(), sqlFile.length() - UPGRADE_QUERY_SUFFIX.length())); if (fileVersion > oldVersion && fileVersion <= newVersion) { execSqlFile(sqlFile, db); } } } Log.i(Constants.TAG, "Database upgrade successful"); } catch (IOException e) { throw new RuntimeException("Database upgrade failed", e); } }
// Creating Tables @Override public void onCreate(SQLiteDatabase db) { try { Log.i(Constants.TAG, "Database creation"); execSqlFile(CREATE_QUERY, db); } catch (IOException exception) { throw new RuntimeException("Database creation failed", exception); } }