app/src/main/java/db/juhaku/juhakudb/core/android/DatabaseHelper.java
/**
     * Create or update database tables based on comparison. Tables will be inserted or
     * altered but nothing will be removed.
     * @param db SQLiteDatabase to save tables for.
     * @param oldSchema Schema to compare current {@link Schema} for.
     */
Create or update database tables based on comparison. Tables will be inserted or
altered but nothing will be removed.
@param db SQLiteDatabase to save tables for.
@param oldSchema Schema to compare current  Schema for.
Create or update database tables based on comparison . Tables will be inserted or altered but nothing will be removed . @param db SQLiteDatabase to save tables for . @param oldSchema Schema to compare current Schema for .
private void updateDb(SQLiteDatabase db, Schema oldSchema) {
        for (Schema table : Schema.toSet(schema)) {
            Schema oldTable;
            if ((oldTable = oldSchema.getElement(table.getName())) == null) {
                db.execSQL(table.toDDL(DDL.CREATE));
            } else {
                for (Entry<String, Schema> entry : table.getElements().entrySet()) {
                    if (oldTable.getElement(entry.getKey()) == null) {
                        db.execSQL(DDL.alterTable(table, entry.getValue()));
                    }
                }
            }
            createConstrains(db, table);
        }
    }
private void updateDb ( SQLiteDatabase db , Schema oldSchema ) { for ( Schema table : Schema . toSet ( schema ) ) { Schema oldTable ; if ( ( oldTable = oldSchema . getElement ( table . getName ( ) ) ) == null ) { db . execSQL ( table . toDDL ( DDL . CREATE ) ) ; } else { for ( Entry < String , Schema > entry : table . getElements ( ) . entrySet ( ) ) { if ( oldTable . getElement ( entry . getKey ( ) ) == null ) { db . execSQL ( DDL . alterTable ( table , entry . getValue ( ) ) ) ; } } } createConstrains ( db , table ) ; } }
Create or update database tables based on comparison.
Create or update database tables based on comparison .
// if table is not found from previous schema, add it, otherwise alter it if necessary. // if old column not found, add it.