@Override public Sql[] generateSql( final AddAutoIncrementStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { List<Sql> statements = new ArrayList<Sql>(); // define alter table logic SQLiteDatabase.AlterTableVisitor rename_alter_visitor = new SQLiteDatabase.AlterTableVisitor() { @Override public ColumnConfig[] getColumnsToAdd() { return new ColumnConfig[0]; } @Override public boolean copyThisColumn(ColumnConfig column) { return true; } @Override public boolean createThisColumn(ColumnConfig column) { if (column.getName().equals(statement.getColumnName())) { column.setAutoIncrement(true); column.setType("INTEGER"); } return true; } @Override public boolean createThisIndex(Index index) { return true; } }; try { // alter table for (SqlStatement generatedStatement : SQLiteDatabase.getAlterTableStatements( rename_alter_visitor, database, statement.getCatalogName(), statement.getSchemaName(), statement.getTableName())) { statements.addAll( Arrays.asList( SqlGeneratorFactory.getInstance().generateSql(generatedStatement, database))); } } catch (DatabaseException e) { e.printStackTrace(); } return statements.toArray(new Sql[statements.size()]); }
@Override public Sql[] generateSql( AddAutoIncrementStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { return new Sql[] { new UnparsedSql( "ALTER TABLE " + database.escapeTableName( statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()) + " MODIFY " + database.escapeColumnName( statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), statement.getColumnName()) + " " + DataTypeFactory.getInstance() .fromDescription(statement.getColumnDataType() + "{autoIncrement:true}") .toDatabaseDataType(database), getAffectedColumn(statement)) }; }