private void createTable(SQLiteDatabase database, List<Column> existingColumns, String name) { ColumnConsumer consumer = new ColumnConsumer(); SQL sql = new SQL(); sql.raw("CREATE TABLE "); sql.escaped(name); sql.raw(" ("); for (Column column : existingColumns) { Column consumed = consumer.alter(column); if (consumed != null) { sql.separate(", "); sql.raw(consumed.ddl()); } } for (AlterColumn alter : consumer.alters) { if (alter instanceof CreateColumn) { sql.separate(", "); sql.raw(alter.alter(null).ddl()); } else { throw new SQLException(alter.toString()); } } sql.raw(")"); database.execSQL(sql.toString()); }
private void moveRows( SQLiteDatabase database, List<Column> existingColumns, String from, String to) { ColumnConsumer consumer = new ColumnConsumer(); SQL insertInto = new SQL(); SQL select = new SQL(); insertInto.raw("INSERT INTO "); insertInto.escaped(to); insertInto.raw(" ("); select.raw("SELECT "); for (Column column : existingColumns) { Column consumed = consumer.alter(column); if (consumed != null) { insertInto.separate(", "); insertInto.escaped(consumed.name); select.separate(", "); select.escaped(column.name); } } insertInto.raw(")"); select.raw(" FROM "); select.escaped(from); database.execSQL(insertInto.toString() + select.toString()); }