Пример #1
0
  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());
  }
Пример #2
0
    private Column alter(Column column) {
      for (AlterColumn alter : this.alters) {
        if (alter.alters(column)) {
          this.alters.remove(alter);

          return alter.alter(column);
        }
      }
      return column;
    }