Back to project page android-sqlite-helper.
The source code is released under:
Apache License
If you think the Android project android-sqlite-helper listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.ichigotake.sqlitehelper.ddl; /* w w w . ja v a 2 s . com*/ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import net.ichigotake.sqlitehelper.dml.Select; import net.ichigotake.sqlitehelper.schema.Table; import net.ichigotake.sqlitehelper.schema.TableField; public class AlterTable { private final SQLiteDatabase database; private final Table<?> table; public AlterTable(SQLiteDatabase database, Table<?> table) { this.database = database; this.table = table; } public void addColumn() { for (TableField field : table.getTableFields()) { Cursor cursor = new Select(database, table).execute(); boolean fieldExists = cursor.getColumnIndex(field.getFieldName()) >= 0; if (fieldExists) { continue; } database.execSQL(buildQuery(field)); } } /* visible for testing */ String buildQuery(TableField field) { return "ALTER TABLE " + table.getTableName() + " ADD COLUMN " + field.getFieldName() + " " + field.getFieldType().getReservedName(); } }