use of liquibase.change.ColumnConfig in project liquibase by liquibase.
the class InsertExecutablePreparedStatement method generateSql.
@Override
protected String generateSql(List<ColumnConfig> cols) {
StringBuilder sql = new StringBuilder("INSERT INTO ");
StringBuilder params = new StringBuilder("VALUES(");
sql.append(database.escapeTableName(getCatalogName(), getSchemaName(), getTableName()));
sql.append("(");
for (ColumnConfig column : getColumns()) {
if (database.supportsAutoIncrement() && Boolean.TRUE.equals(column.isAutoIncrement())) {
continue;
}
sql.append(database.escapeColumnName(getCatalogName(), getSchemaName(), getTableName(), column.getName()));
sql.append(", ");
params.append("?, ");
cols.add(column);
}
sql.deleteCharAt(sql.lastIndexOf(" "));
sql.deleteCharAt(sql.lastIndexOf(","));
params.deleteCharAt(params.lastIndexOf(" "));
params.deleteCharAt(params.lastIndexOf(","));
params.append(")");
sql.append(") ");
sql.append(params);
return sql.toString();
}
use of liquibase.change.ColumnConfig in project liquibase by liquibase.
the class InsertOrUpdateGeneratorOracleTest method testInsertSequenceValWithSchema.
@Test
public void testInsertSequenceValWithSchema() {
OracleDatabase database = new OracleDatabase();
InsertGenerator generator = new InsertGenerator();
InsertStatement statement = new InsertStatement("mycatalog", "myschema", "mytable");
ColumnConfig columnConfig = new ColumnConfig();
columnConfig.setValueSequenceNext(new SequenceNextValueFunction("myschema.my_seq"));
columnConfig.setName("col3");
statement.addColumn(columnConfig);
Sql[] sql = generator.generateSql(statement, database, null);
String theSql = sql[0].toSql();
assertEquals("INSERT INTO mycatalog.mytable (col3) VALUES (\"myschema\".\"my_seq\".nextval)", theSql);
}
use of liquibase.change.ColumnConfig in project liquibase by liquibase.
the class InsertOrUpdateGeneratorPostgresTest method testInsertSequenceValWithSchema.
@Test
public void testInsertSequenceValWithSchema() {
PostgresDatabase postgresDatabase = new PostgresDatabase();
InsertGenerator generator = new InsertGenerator();
InsertStatement statement = new InsertStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
ColumnConfig columnConfig = new ColumnConfig();
columnConfig.setValueSequenceNext(new SequenceNextValueFunction(SCHEMA_NAME + '.' + SEQUENCE_NAME));
columnConfig.setName("col3");
statement.addColumn(columnConfig);
Sql[] sql = generator.generateSql(statement, postgresDatabase, null);
String theSql = sql[0].toSql();
assertEquals(String.format("INSERT INTO %s.%s (col3) VALUES (nextval('%s.%s'))", SCHEMA_NAME, TABLE_NAME, SCHEMA_NAME, SEQUENCE_NAME), theSql);
}
Aggregations